60 #include "CursorPainter.hh" 61 #include "QtBaseViewer.hh" 85 glDeleteTextures (1, &texture_);
93 nativeCursor_ = _cursor;
96 if (!(initialized_ && enabled_ && hasCursor_) || forceNative_) {
98 v->setCursor ((forceNative_)? nativeCursor_ : cursor_);
111 glGenTextures (1, &texture_);
114 if(!OpenFlipper::Options::coreProfile())
116 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
117 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
119 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
120 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
125 if (enabled_ && hasCursor_ && !forceNative_)
128 v->setCursor (Qt::BlankCursor);
134 v->setCursor ((forceNative_)? nativeCursor_ : cursor_);
143 views_.append (_viewer);
164 float xscale = zPos[0];
165 float yscale = -zPos[1];
167 glPushAttrib (GL_ALL_ATTRIB_BITS);
179 glColor4f (1.0, 1.0, 1.0, 1.0);
181 float x1 = -xOff_ * xscale;
182 float x2 = (32 - xOff_) * xscale;
183 float y1 = -yOff_ * yscale;
184 float y2 = (32 - yOff_) * yscale;
189 glVertex3f (x1, y1, 0);
191 glVertex3f (x1, y2, 0);
193 glVertex3f (x2, y2, 0);
195 glVertex3f (x2, y1, 0);
206 cursorPos_ = _scenePos;
225 if (_enabled && hasCursor_)
228 v->setCursor (Qt::BlankCursor);
233 v->setCursor ((forceNative_)? nativeCursor_ : cursor_);
242 return initialized_ && enabled_ && hasCursor_ && mouseIn_ && !forceNative_;
254 unsigned char buf[4096];
264 switch (nativeCursor_.shape())
266 case Qt::ArrowCursor:
267 cImg.load (OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"cursor_arrow.png");
269 case Qt::PointingHandCursor:
270 cImg.load (OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"cursor_move.png");
272 case Qt::WhatsThisCursor:
273 cImg.load (OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"cursor_whatsthis.png");
275 case Qt::BitmapCursor:
277 cImg = QImage(( nativeCursor_.pixmap().toImage() ) );
281 xOff_ = nativeCursor_.hotSpot().x();
282 yOff_ = nativeCursor_.hotSpot().y();
285 std::cerr <<
"cursorToTexture: Unknown cursor shape!" << nativeCursor_.shape() << std::endl;
290 if (cImg.width () != 32 || cImg.height () != 32) {
291 std::cerr <<
"cursorToTexture: Dimension error" << nativeCursor_.shape() << std::endl;
297 for (
int y = 0; y < cImg.height (); y++)
298 for (
int x = 0; x < cImg.width (); x++)
300 QRgb pix = cImg.pixel (x, y);
301 buf[index] = qRed (pix);
302 buf[index+1] = qGreen (pix);
303 buf[index+2] = qBlue (pix);
304 buf[index+3] = qAlpha (pix);
311 if (!OpenFlipper::Options::coreProfile())
315 glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0,
316 GL_RGBA, GL_UNSIGNED_BYTE, buf);
319 if (!OpenFlipper::Options::coreProfile())
336 return QRectF (-xOff_, -yOff_, 32, 32);
344 forceNative_ = _enabled;
346 if (!(initialized_ && enabled_ && hasCursor_) || forceNative_)
349 v->setCursor ((forceNative_)? nativeCursor_ : cursor_);
355 v->setCursor (Qt::BlankCursor);
359 void CursorPainter::cursorToCursor()
363 switch (nativeCursor_.shape())
365 case Qt::ArrowCursor:
366 pix.load (OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"cursor_arrow.png");
367 if (!pix.isNull() && pix.width() == 32 && pix.height() == 32)
369 cursor_ = QCursor (pix, 0, 0);
372 cursor_ = nativeCursor_;
374 case Qt::PointingHandCursor:
375 pix.load (OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"cursor_move.png");
376 if (!pix.isNull() && pix.width() == 32 && pix.height() == 32)
378 cursor_ = QCursor (pix, 0, 0);
381 cursor_ = nativeCursor_;
384 cursor_ = nativeCursor_;
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
~CursorPainter()
Destructor.
QPointF cursorPosition()
Return the current cursor position.
void setEnabled(bool _enabled)
Enabled/Disables gl cursor painting.
bool enabled()
Returns true if cursor painting is enabled and compatible cursor is set.
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
void initializeGL()
Needs to be called after the gl context has been set up to initialize internal values.
static void bindTexture(GLenum _target, GLuint _buffer)
replaces glBindTexture, supports locking
void updateCursorPosition(QPointF _scenePos)
Sets the current cursor position.
void setMouseIn(bool _in)
Inform the cursor painter about mouse enter / leave.
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
void setCursor(const QCursor &_cursor)
Sets the current used cursor.
QRectF cursorBoundingBox()
Bounding box of the cursor.
void paintCursor(ACG::GLState *_state)
Cursor painting function. The _state has to be setup that 0,0,0 is at the cursor position.
void registerViewer(glViewer *_viewer)
Add a glViewer that will use this CursorPainter.
CursorPainter(QObject *_parent=0)
Constructor.
static void blendFunc(GLenum _sfactor, GLenum _dfactor)
replaces glBlendFunc, supports locking
void setCursorPainter(CursorPainter *_cursorPainter)
sets the current cursor painter
void setForceNative(bool _enabled)
Enabled/Disables native cursors.