From d068f7025a855883222cbf982a76bdccad75635c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 2 Jan 2007 12:50:57 +0000 Subject: [PATCH] Added support for getting all windows and hiding the cursor --- examples/osgcamera/osgcamera.cpp | 4 +--- examples/osgcatch/osgcatch.cpp | 10 +++++++++ include/osgViewer/GraphicsWindow | 3 +++ include/osgViewer/GraphicsWindowX11 | 15 +++++++++++++ include/osgViewer/Viewer | 9 +++++--- src/osgViewer/GraphicsWindowX11.cpp | 31 +++++++++++++++++---------- src/osgViewer/Viewer.cpp | 33 +++++++++++++++++++++++++++++ 7 files changed, 88 insertions(+), 17 deletions(-) diff --git a/examples/osgcamera/osgcamera.cpp b/examples/osgcamera/osgcamera.cpp index e287f0922..0b5955cc6 100644 --- a/examples/osgcamera/osgcamera.cpp +++ b/examples/osgcamera/osgcamera.cpp @@ -36,7 +36,7 @@ int main( int argc, char **argv ) viewer.setCameraManipulator(new osgGA::TrackballManipulator()); viewer.getCamera()->setClearColor(osg::Vec4f(0.6f,0.6f,0.8f,1.0f)); -#if 1 +#if 0 osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); if (!wsi) @@ -100,8 +100,6 @@ int main( int argc, char **argv ) viewer.realize(); - gw->requestWarpPointer(100,100); - bool limitNumberOfFrames = false; unsigned int numFrames = 0; unsigned int maxFrames = 10; diff --git a/examples/osgcatch/osgcatch.cpp b/examples/osgcatch/osgcatch.cpp index 92cfd3ddd..1a0605cc9 100644 --- a/examples/osgcatch/osgcatch.cpp +++ b/examples/osgcatch/osgcatch.cpp @@ -1580,6 +1580,16 @@ int main( int argc, char **argv ) viewer.realize(); + // switch off the cursor + osgViewer::Viewer::Windows windows; + viewer.getWindows(windows); + for(osgViewer::Viewer::Windows::iterator itr = windows.begin(); + itr != windows.end(); + ++itr) + { + (*itr)->useCursor(false); + } + // todo for osgViewer - implement warp pointer // viewer.requestWarpPointer(0.5f,0.5f); diff --git a/include/osgViewer/GraphicsWindow b/include/osgViewer/GraphicsWindow index 065c36494..501895195 100644 --- a/include/osgViewer/GraphicsWindow +++ b/include/osgViewer/GraphicsWindow @@ -51,6 +51,9 @@ class OSGVIEWER_EXPORT GraphicsWindow : public osg::GraphicsContext, public osgG /** Get focus on if the pointer is in this window.*/ virtual void grabFocusIfPointerInWindow() {} + /** Switch on/off the cursor.*/ + virtual void useCursor(bool /*cursorOn*/) {} + public: /** Realise the GraphicsContext implementation, diff --git a/include/osgViewer/GraphicsWindowX11 b/include/osgViewer/GraphicsWindowX11 index b239ff9bf..64ed652cc 100644 --- a/include/osgViewer/GraphicsWindowX11 +++ b/include/osgViewer/GraphicsWindowX11 @@ -89,6 +89,21 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow // Override from GUIActionAdapter virtual void requestWarpPointer(float x,float y); + /** Switch on/off the cursor.*/ + virtual void useCursor(bool cursorOn); + + public: + + // X11 specific aces functions + + Display* getDisplay() { return _display; } + Window& getParent() { return _parent; } + Window& getWindow() { return _window; } + + Cursor& getDefaultCursor() { return _defaultCursor; } + Cursor& getNullCursor() { return _nullCursor; } + Cursor& getCurrentCursor() { return _nullCursor; } + protected: bool createVisualInfo(); diff --git a/include/osgViewer/Viewer b/include/osgViewer/Viewer index b6c153140..8d8448229 100644 --- a/include/osgViewer/Viewer +++ b/include/osgViewer/Viewer @@ -58,13 +58,16 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View osg::Camera* getCameraWithFocus() { return _cameraWithFocus.get(); } const osg::Camera* getCameraWithFocus() const { return _cameraWithFocus.get(); } + typedef std::vector Contexts; + void getContexts(Contexts& contexts); + + typedef std::vector Windows; + void getWindows(Windows& windows); + public: void init(); - typedef std::vector Contexts; - void getContexts(Contexts& contexts); - bool _firstFrame; bool _done; diff --git a/src/osgViewer/GraphicsWindowX11.cpp b/src/osgViewer/GraphicsWindowX11.cpp index 5cb639b56..b3ded69ec 100644 --- a/src/osgViewer/GraphicsWindowX11.cpp +++ b/src/osgViewer/GraphicsWindowX11.cpp @@ -333,6 +333,25 @@ void GraphicsWindowX11::setWindowDecoration(bool flag) osg::notify(osg::NOTICE)<<"Error: GraphicsWindowX11::setBorder(" << flag << ") - couldn't change decorations." << std::endl; } +void GraphicsWindowX11::useCursor(bool cursorOn) +{ + if (cursorOn) + { + _currentCursor = _defaultCursor; + } + else + { + _currentCursor = _nullCursor; + } + + if (_display && _window) + { + XDefineCursor( _display, _window, _currentCursor ); + XFlush(_display); + XSync(_display,0); + } +} + void GraphicsWindowX11::init() { if (_initialized) return; @@ -461,17 +480,7 @@ void GraphicsWindowX11::init() _nullCursor = XCreatePixmapCursor( _display, pixmap, pixmap, &ncol, &ncol, 0, 0 ); } -#if 1 - _currentCursor = _defaultCursor; -#else - _currentCursor = _nullCursor; -#endif - - { - XDefineCursor( _display, _window, _currentCursor ); - XFlush(_display); - XSync(_display,0); - } + useCursor(true); XSelectInput( _display, _window, ExposureMask | StructureNotifyMask | KeyPressMask | KeyReleaseMask | diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index 1785c91b8..9b5e84a41 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -94,6 +94,39 @@ void Viewer::getContexts(Contexts& contexts) } } +void Viewer::getWindows(Windows& windows) +{ + typedef std::set WindowSet; + WindowSet windowSet; + + if (_camera.valid() && _camera->getGraphicsContext()) + { + osgViewer::GraphicsWindow* gw = dynamic_cast(_camera->getGraphicsContext()); + if (gw) windowSet.insert(gw); + } + + for(unsigned int i=0; igetGraphicsContext()) + { + osgViewer::GraphicsWindow* gw = dynamic_cast(slave._camera->getGraphicsContext()); + if (gw) windowSet.insert(gw); + } + } + + windows.clear(); + windows.reserve(windowSet.size()); + + for(WindowSet::iterator itr = windowSet.begin(); + itr != windowSet.end(); + ++itr) + { + windows.push_back(const_cast(*itr)); + } +} + + OpenThreads::Mutex mutex; // Compile operation, that compile OpenGL objects.