66 #include "CursorPainter.hh" 67 #include "QtBaseViewer.hh" 91 glDeleteTextures (1, &texture_);
99 nativeCursor_ = _cursor;
102 if (!(initialized_ && enabled_ && hasCursor_) || forceNative_) {
104 v->setCursor ((forceNative_)? nativeCursor_ : cursor_);
117 glGenTextures (1, &texture_);
120 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
121 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
122 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
123 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
128 if (enabled_ && hasCursor_ && !forceNative_)
131 v->setCursor (Qt::BlankCursor);
137 v->setCursor ((forceNative_)? nativeCursor_ : cursor_);
146 views_.append (_viewer);
167 float xscale = zPos[0];
168 float yscale = -zPos[1];
170 glPushAttrib (GL_ALL_ATTRIB_BITS);
182 glColor4f (1.0, 1.0, 1.0, 1.0);
184 float x1 = -xOff_ * xscale;
185 float x2 = (32 - xOff_) * xscale;
186 float y1 = -yOff_ * yscale;
187 float y2 = (32 - yOff_) * yscale;
192 glVertex3f (x1, y1, 0);
194 glVertex3f (x1, y2, 0);
196 glVertex3f (x2, y2, 0);
198 glVertex3f (x2, y1, 0);
209 cursorPos_ = _scenePos;
228 if (_enabled && hasCursor_)
231 v->setCursor (Qt::BlankCursor);
236 v->setCursor ((forceNative_)? nativeCursor_ : cursor_);
245 return initialized_ && enabled_ && hasCursor_ && mouseIn_ && !forceNative_;
257 unsigned char buf[4096];
267 switch (nativeCursor_.shape())
269 case Qt::ArrowCursor:
270 cImg.load (OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"cursor_arrow.png");
272 case Qt::PointingHandCursor:
273 cImg.load (OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"cursor_move.png");
275 case Qt::WhatsThisCursor:
276 cImg.load (OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"cursor_whatsthis.png");
278 case Qt::BitmapCursor:
280 cImg = QImage(( nativeCursor_.pixmap().toImage() ) );
284 xOff_ = nativeCursor_.hotSpot().x();
285 yOff_ = nativeCursor_.hotSpot().y();
288 std::cerr <<
"cursorToTexture: Unknown cursor shape!" << nativeCursor_.shape() << std::endl;
293 if (cImg.width () != 32 || cImg.height () != 32) {
294 std::cerr <<
"cursorToTexture: Dimension error" << nativeCursor_.shape() << std::endl;
300 for (
int y = 0; y < cImg.height (); y++)
301 for (
int x = 0; x < cImg.width (); x++)
303 QRgb pix = cImg.pixel (x, y);
304 buf[index] = qRed (pix);
305 buf[index+1] = qGreen (pix);
306 buf[index+2] = qBlue (pix);
307 buf[index+3] = qAlpha (pix);
313 glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0,
314 GL_RGBA, GL_UNSIGNED_BYTE, buf);
332 return QRectF (-xOff_, -yOff_, 32, 32);
340 forceNative_ = _enabled;
342 if (!(initialized_ && enabled_ && hasCursor_) || forceNative_)
345 v->setCursor ((forceNative_)? nativeCursor_ : cursor_);
351 v->setCursor (Qt::BlankCursor);
355 void CursorPainter::cursorToCursor()
359 switch (nativeCursor_.shape())
361 case Qt::ArrowCursor:
362 pix.load (OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"cursor_arrow.png");
363 if (!pix.isNull() && pix.width() == 32 && pix.height() == 32)
365 cursor_ = QCursor (pix, 0, 0);
368 cursor_ = nativeCursor_;
370 case Qt::PointingHandCursor:
371 pix.load (OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"cursor_move.png");
372 if (!pix.isNull() && pix.width() == 32 && pix.height() == 32)
374 cursor_ = QCursor (pix, 0, 0);
377 cursor_ = nativeCursor_;
380 cursor_ = nativeCursor_;
CursorPainter(QObject *_parent=0)
Constructor.
static void enable(GLenum _cap)
replaces glEnable, but supports locking
void setMouseIn(bool _in)
Inform the cursor painter about mouse enter / leave.
void updateCursorPosition(QPointF _scenePos)
Sets the current cursor position.
void registerViewer(glViewer *_viewer)
Add a glViewer that will use this CursorPainter.
void setEnabled(bool _enabled)
Enabled/Disables gl cursor painting.
bool enabled()
Returns true if cursor painting is enabled and compatible cursor is set.
QRectF cursorBoundingBox()
Bounding box of the cursor.
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
void paintCursor(ACG::GLState *_state)
Cursor painting function. The _state has to be setup that 0,0,0 is at the cursor position.
~CursorPainter()
Destructor.
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
QPointF cursorPosition()
Return the current cursor position.
static void disable(GLenum _cap)
replaces glDisable, but supports locking
void setForceNative(bool _enabled)
Enabled/Disables native cursors.
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 setCursor(const QCursor &_cursor)
Sets the current used cursor.
void setCursorPainter(CursorPainter *_cursorPainter)
sets the current cursor painter
static void blendFunc(GLenum _sfactor, GLenum _dfactor)
replaces glBlendFunc, supports locking