From Mathias Froelich, "have done an interface to change the mouse cursor in the X11 graphics

window.
The win32 implementation is still in its original shape since I have no win32
implementation available.

I have chosen the enum approach for the first cut. That is benefitial since
the user does not need to track creation of mouse cursors for different
windows and displays in presence of multiple viewer windows.

The default set of available mouse shapes is the same set that was available
with glut. That set served many OpenGL applications well, so the hope is that
this is enough.

Even though, that implementation is still extensible:
I have digged out the way SDL defines new mouse cursors and added a still
documented out function prototype in the GraphicsWindow that can be used to
extend the current implemtation for arbitrary mouse shapes. That is not
implemented yet.

I hope that somebody with a win32 test system can catch up that implementation
on win32."
This commit is contained in:
Robert Osfield
2007-06-01 19:43:28 +00:00
parent 604bd9b6d7
commit 822868ca31
3 changed files with 139 additions and 42 deletions

View File

@@ -61,8 +61,39 @@ class OSGVIEWER_EXPORT GraphicsWindow : public osg::GraphicsContext, public osgG
/** Get focus on if the pointer is in this window.*/
virtual void grabFocusIfPointerInWindow() { osg::notify(osg::NOTICE)<<"GraphicsWindow::grabFocusIfPointerInWindow(..) not implemented."<<std::endl; }
/** Mouse cursor types, the same ones already present with ancient glut ... */
enum MouseCursor {
InheritCursor,
NoCursor,
RightArrowCursor,
LeftArrowCursor,
InfoCursor,
DestroyCursor,
HelpCursor,
CycleCursor,
SprayCursor,
WaitCursor,
TextCursor,
CrosshairCursor,
UpDownCursor,
LeftRightCursor,
TopSideCursor,
BottomSideCursor,
LeftSideCursor,
RightSideCursor,
TopLeftCorner,
TopRightCorner,
BottomRightCorner,
BottomLeftCorner
};
/** Switch on/off the cursor.*/
virtual void useCursor(bool /*cursorOn*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::useCursor(..) not implemented."<<std::endl; }
virtual void useCursor(bool cursorOn) { setCursor(cursorOn ? InheritCursor : NoCursor); }
/** Set mouse cursor to a specific shape.*/
virtual void setCursor(MouseCursor /*mouseCursor*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setCursor(..) not implemented."<<std::endl; }
/** Create a new mouse cursor from the usual bitmap data.*/
//virtual MouseCursor createCursor(const char *data, const char *mask, unsigned w, unsigned h, unsigned hotx, unsigned hoty) { osg::notify(osg::NOTICE)<<"GraphicsWindow::createCursor(..) not implemented."<<std::endl; }
public:

View File

@@ -41,8 +41,6 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow
_window(0),
_visualInfo(0),
_glxContext(0),
_defaultCursor(0),
_nullCursor(0),
_currentCursor(0),
_initialized(false),
_realized(false),
@@ -108,9 +106,9 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow
/** Set the window's position and size.*/
virtual void setWindowRectangle(int x, int y, int width, int height);
/** Switch on/off the cursor.*/
virtual void useCursor(bool cursorOn);
/** Set mouse cursor to a specific shape.*/
virtual void setCursor(MouseCursor cursor);
/** WindowData is used to pass in the X11 window handle attached the GraphicsContext::Traits structure. */
struct WindowData : public osg::Referenced
{
@@ -127,22 +125,20 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow
Display* getDisplay() const { return _display; }
Display* getEventDisplay() const { return _eventDisplay; }
Display* getDisplayToUse() const ;
Window& getParent() { return _parent; }
Window& getWindow() { return _window; }
GLXContext& getGLXContext() { return _glxContext; }
Cursor& getDefaultCursor() { return _defaultCursor; }
Cursor& getNullCursor() { return _nullCursor; }
Cursor& getCurrentCursor() { return _nullCursor; }
Cursor getCurrentCursor() { return _currentCursor; }
protected:
~GraphicsWindowX11();
Cursor getOrCreateCursor(MouseCursor mouseShape);
bool createVisualInfo();
void init();
@@ -158,8 +154,6 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow
XVisualInfo* _visualInfo;
GLXContext _glxContext;
Cursor _defaultCursor;
Cursor _nullCursor;
Cursor _currentCursor;
Atom _deleteWindow;
@@ -168,6 +162,8 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow
bool _realized;
double _timeOfLastCheckEvents;
std::map<MouseCursor,Cursor> _mouseCursorMap;
};
}