From 2255771b74a132193fe6fb87488beacb7db61eb0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 20 Dec 2006 21:13:29 +0000 Subject: [PATCH] Further work osgViewer::Viewer and related classes. --- examples/osgcamera/osgcamera.cpp | 23 +- .../osgkeyboardmouse/osgkeyboardmouse.cpp | 12 +- .../osgsimpleviewerProducer.cpp | 10 +- include/osgGA/EventQueue | 21 +- include/osgGA/GUIEventAdapter | 1 + include/osgViewer/GraphicsWindow | 2 + include/osgViewer/GraphicsWindowX11 | 261 +++++++++++++++++- include/osgViewer/Scene | 1 + include/osgViewer/View | 5 + include/osgViewer/Viewer | 1 + src/osgGA/EventQueue.cpp | 9 +- src/osgViewer/View.cpp | 51 +++- src/osgViewer/Viewer.cpp | 155 ++++++++++- src/osgWrappers/osgGA/EventQueue.cpp | 35 ++- src/osgWrappers/osgViewer/GraphicsWindow.cpp | 4 + src/osgWrappers/osgViewer/Scene.cpp | 8 + src/osgWrappers/osgViewer/View.cpp | 16 ++ src/osgWrappers/osgViewer/Viewer.cpp | 1 + 18 files changed, 580 insertions(+), 36 deletions(-) diff --git a/examples/osgcamera/osgcamera.cpp b/examples/osgcamera/osgcamera.cpp index 9a8609253..2e6b43ec8 100644 --- a/examples/osgcamera/osgcamera.cpp +++ b/examples/osgcamera/osgcamera.cpp @@ -28,11 +28,26 @@ #include #include +#include + void renderCamera(osg::Camera* camera) { osg::GraphicsContext* gc = camera->getGraphicsContext(); if (!gc) return; +#if 0 + osgViewer::GraphicsWindowX11* gwX11 = dynamic_cast(gc); + if (gwX11) + { + gwX11->checkEvents(); + + osgGA::EventQueue::Events events; + if (gwX11->getEventQueue()->takeEvents(events)) + { + } + } +#endif + osgUtil::SceneView* sceneView = dynamic_cast(camera->getRenderingCache(0)); if (!sceneView) return; @@ -77,6 +92,8 @@ int main( int argc, char **argv ) viewMatrix.makeLookAt(bs.center()-osg::Vec3(0.0,2.0f*bs.radius(),0.0),bs.center(),osg::Vec3(0.0f,0.0f,1.0f)); osg::ref_ptr viewer = new osgViewer::Viewer; + viewer->setSceneData(loadedModel.get()); + viewer->setCameraManipulator(new osgGA::TrackballManipulator()); viewer->setUpViewAcrossAllScreens(); viewer->realize(); @@ -113,10 +130,12 @@ int main( int argc, char **argv ) // do the update traversal. loadedModel->accept(updateVisitor); + viewer->frameAdvance(); + viewer->frameEventTraversal(); + viewer->frameUpdateTraversal(); - viewer->getCamera()->setViewMatrix(viewMatrix); + // viewer->getCamera()->setViewMatrix(viewMatrix); - viewer->updateSlaves(); if (viewer->getCamera() && viewer->getCamera()->getGraphicsContext()) renderCamera(viewer->getCamera()); diff --git a/examples/osgkeyboardmouse/osgkeyboardmouse.cpp b/examples/osgkeyboardmouse/osgkeyboardmouse.cpp index 9976ab448..1a0c48e72 100644 --- a/examples/osgkeyboardmouse/osgkeyboardmouse.cpp +++ b/examples/osgkeyboardmouse/osgkeyboardmouse.cpp @@ -163,6 +163,10 @@ public: { _mx = ea.getX(); _my = ea.getY(); + + osg::notify(osg::NOTICE)<<"_mx="<<_mx<<" _my="<<_my<getCurrentEventState()->setInputRange(-1.0, -1.0, 1.0, 1.0); + viewer.getEventQueue()->setUseFixedMouseInputRange(true); + viewer.getEventQueue()->setMouseInputRange(-1.0, -1.0, 1.0, 1.0); // Producer has the y axis increase upwards, like OpenGL, and contary to most Windowing toolkits. // we need to construct the event queue so that it knows about this convention. viewer.getEventQueue()->getCurrentEventState()->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS); + viewer.init(); @@ -370,7 +376,7 @@ int main( int argc, char **argv ) while( renderSurface->isRealized() && !kbmcb->done()) { // update the window dimensions, in case the window has been resized. - viewer.getEventQueue()->windowResize(0,0,renderSurface->getWindowWidth(),renderSurface->getWindowHeight(), false); + viewer.getEventQueue()->windowResize(0,0,renderSurface->getWindowWidth(),renderSurface->getWindowHeight()); // pass any keyboard mouse events onto the local keyboard mouse callback. kbm->update( *kbmcb ); diff --git a/examples/osgsimpleviewerProducer/osgsimpleviewerProducer.cpp b/examples/osgsimpleviewerProducer/osgsimpleviewerProducer.cpp index 438515ff1..0b68a7b26 100644 --- a/examples/osgsimpleviewerProducer/osgsimpleviewerProducer.cpp +++ b/examples/osgsimpleviewerProducer/osgsimpleviewerProducer.cpp @@ -96,7 +96,8 @@ class GraphicsWindowProducer : public virtual osgViewer::GraphicsWindow, public // set the mouse input range. // Producer defaults to using non-dimensional units, so we pass this onto osgGA, most windowing toolkits use pixel coords so use the window size instead. - getEventQueue()->getCurrentEventState()->setInputRange(-1.0, -1.0, 1.0, 1.0); + getEventQueue()->setUseFixedMouseInputRange(true); + getEventQueue()->setMouseInputRange(-1.0, -1.0, 1.0, 1.0); // Producer has the y axis increase upwards, like OpenGL, and contary to most Windowing toolkits. // we need to construct the event queue so that it knows about this convention. @@ -107,7 +108,7 @@ class GraphicsWindowProducer : public virtual osgViewer::GraphicsWindow, public void setWindowRectangle(int x, int y, unsigned int width, unsigned int height, bool resize = true) { Producer::RenderSurface::setWindowRectangle(x, y, width, height, resize); - getEventQueue()->windowResize(x,y,width,height, false); + getEventQueue()->windowResize(x,y,width,height); } void realize() { Producer::RenderSurface::realize(); _kbm->startThread(); } @@ -159,7 +160,7 @@ int main( int argc, char **argv ) while( viewer.isRealized() ) { // update the window dimensions, in case the window has been resized. - viewer.getEventQueue()->windowResize(0,0,viewer.getWindowWidth(),viewer.getWindowHeight(), false); + viewer.getEventQueue()->windowResize(0,0,viewer.getWindowWidth(),viewer.getWindowHeight()); viewer.frame(); @@ -215,7 +216,8 @@ int main( int argc, char **argv ) // set the mouse input range. // Producer defaults to using non-dimensional units, so we pass this onto osgGA, most windowing toolkits use pixel coords so use the window size instead. - viewer.getEventQueue()->getCurrentEventState()->setInputRange(-1.0, -1.0, 1.0, 1.0); + viewer.getEventQueue()->setUseFixedMouseInputRange(true); + viewer.getEventQueue()->setMouseInputRange(-1.0, -1.0, 1.0, 1.0); // Producer has the y axis increase upwards, like OpenGL, and contary to most Windowing toolkits. // we need to construct the event queue so that it knows about this convention. diff --git a/include/osgGA/EventQueue b/include/osgGA/EventQueue index 5612d6abd..6ba05d79b 100644 --- a/include/osgGA/EventQueue +++ b/include/osgGA/EventQueue @@ -50,9 +50,18 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced /** Add an event to the end of the event queue.*/ void addEvent(GUIEventAdapter* event); + /** Specify if mouse coordinates should be transformed into a pre defined input range, or whether they + * should be simply based on as local coordinates to the window that generated the mouse events.*/ + void setUseFixedMouseInputRange(bool useFixedMouseInputRange) { _useFixedMouseInputRange = useFixedMouseInputRange; } + + /** Get whether the mouse coordinates should be transformed into a pre defined input range.*/ + bool getUseFixedMouseInputRange() { return _useFixedMouseInputRange; } + + /** Set the mouse input range.*/ + void setMouseInputRange(float xMin, float yMin, float xMax, float yMax) { getCurrentEventState()->setInputRange(xMin, yMin, xMax, yMax); } /** Method for adapting window resize event, placing this event on the back of the event queue. */ - void windowResize(int x, int y, unsigned int width, unsigned int height, bool updateMouseRange = true); + void windowResize(int x, int y, unsigned int width, unsigned int height); /** Method for adapting mouse scroll wheel events, placing this event on the back of the event queue. */ void mouseScroll(GUIEventAdapter::ScrollingMotion sm); @@ -84,11 +93,11 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */ void mouseButtonRelease(float x, float y, unsigned int button); - /** Method for adapting keyboard press events.*/ - void keyPress(GUIEventAdapter::KeySymbol key); + /** Method for adapting keyboard press events. Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings.*/ + void keyPress(int key); - /** Method for adapting keyboard press events.*/ - void keyRelease(GUIEventAdapter::KeySymbol key); + /** Method for adapting keyboard press events. Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings.*/ + void keyRelease(int key); /** Method for adapting frame events.*/ void frame(double t); @@ -114,6 +123,8 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced osg::ref_ptr _accumulateEventState; + bool _useFixedMouseInputRange; + osg::Timer_t _startTick; mutable OpenThreads::Mutex _eventQueueMutex; Events _eventQueue; diff --git a/include/osgGA/GUIEventAdapter b/include/osgGA/GUIEventAdapter index 9536af5b9..6ab551f73 100644 --- a/include/osgGA/GUIEventAdapter +++ b/include/osgGA/GUIEventAdapter @@ -271,6 +271,7 @@ public: /** deprecated function for getting time of event. */ double time() const { return _time; } + /** set window rectangle. */ void setWindowRectangle(int x, int y, unsigned int width, unsigned int height, bool updateMouseRange = true); diff --git a/include/osgViewer/GraphicsWindow b/include/osgViewer/GraphicsWindow index 906a884b3..6f2b5db02 100644 --- a/include/osgViewer/GraphicsWindow +++ b/include/osgViewer/GraphicsWindow @@ -40,6 +40,8 @@ class OSGVIEWER_EXPORT GraphicsWindow : public osg::GraphicsContext, public osgG osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); } const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); } + virtual void checkEvents() {} + public: /** Realise the GraphicsContext implementation, diff --git a/include/osgViewer/GraphicsWindowX11 b/include/osgViewer/GraphicsWindowX11 index 68f050b54..1b5fbd371 100644 --- a/include/osgViewer/GraphicsWindowX11 +++ b/include/osgViewer/GraphicsWindowX11 @@ -16,6 +16,9 @@ * These elements are license under OSGPL as above, with Copyright (C) 2001-2004 Don Burns. */ +#ifndef OSGVIEWER_GRAPHICSWINDOWX11 +#define OSGVIEWER_GRAPHICSWINDOWX11 1 + #include #include @@ -23,11 +26,16 @@ #include #include +#include +#include #include #define GLX_GLXEXT_PROTOTYPES 1 #include +namespace osgViewer +{ + class GraphicsContextX11 : public osg::GraphicsContext { public: @@ -110,14 +118,20 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow /** Make this graphics context current.*/ virtual void makeCurrentImplementation(); - /** swap the front and back buffers.*/ + /** Swap the front and back buffers.*/ virtual void swapBuffersImplementation(); + /** Check to see if any events have been generated.*/ + virtual void checkEvents(); + protected: bool createVisualInfo(); void setBorder(bool flag); void init(); + + void transformMouseXY(float& x, float& y); + void adaptKey(XKeyEvent& keyevent, int& keySymbol, unsigned int& modifierMask); Display* _display; Window _parent; @@ -280,6 +294,7 @@ void GraphicsWindowX11::init() XWindowAttributes watt; XGetWindowAttributes( _display, _parent, &watt ); // unsigned int parentWindowHeight = watt.height; + osg::notify(osg::NOTICE)<<"First watt.x = "<(_traits->_screenNum); i++ ) + { + screenOrigin_x -= DisplayWidth(_display, i); + } + + wx += (screenOrigin_x - _traits->_x); + wy += (screenOrigin_y - _traits->_y); + } + + float mx = wx; + float my = wy; + transformMouseXY(mx, my); + getEventQueue()->mouseMotion(mx, my); + + break; + } + + case ButtonPress : + { + if( ev.xbutton.button == Button4 ) + { + getEventQueue()->mouseScroll(osgGA::GUIEventAdapter::SCROLL_UP); + } + else if( ev.xbutton.button == Button5) + { + getEventQueue()->mouseScroll(osgGA::GUIEventAdapter::SCROLL_DOWN); + } + else + { + float mx = ev.xbutton.x; + float my = ev.xmotion.y; + transformMouseXY(mx, my); + getEventQueue()->mouseButtonPress(mx, my, ev.xbutton.button); + } + break; + } + + case ButtonRelease : + { + if( ev.xbutton.button == Button4 ) + { + getEventQueue()->mouseScroll(osgGA::GUIEventAdapter::SCROLL_UP); + } + else if( ev.xbutton.button == Button5) + { + getEventQueue()->mouseScroll(osgGA::GUIEventAdapter::SCROLL_DOWN); + } + else + { + float mx = ev.xbutton.x; + float my = ev.xmotion.y; + transformMouseXY(mx, my); + getEventQueue()->mouseButtonRelease(mx, my, ev.xbutton.button); + } + break; + } + + case KeyPress: + { + int keySymbol = 0; + unsigned int modifierMask = 0; + adaptKey(ev.xkey, keySymbol, modifierMask); + + getEventQueue()->keyPress(keySymbol); + getEventQueue()->getCurrentEventState()->setModKeyMask(modifierMask); + break; + } + + case KeyRelease: + { + int keySymbol = 0; + unsigned int modifierMask = 0; + adaptKey(ev.xkey, keySymbol, modifierMask); + + getEventQueue()->keyRelease(keySymbol); + getEventQueue()->getCurrentEventState()->setModKeyMask(modifierMask); + break; + } + + default: + osg::notify(osg::NOTICE)<<"Other event"<getUseFixedMouseInputRange()) + { + osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState(); + x = eventState->getXmin() + (eventState->getXmax()-eventState->getXmin())*x/float(_traits->_width); + y = eventState->getYmin() + (eventState->getYmax()-eventState->getYmin())*y/float(_traits->_height); + } +} + +void GraphicsWindowX11::adaptKey(XKeyEvent& keyevent, int& keySymbol, unsigned int& modifierMask) +{ + // KeySym ks = XKeycodeToKeysym( _display, keyevent.keycode, 0 ); + + static XComposeStatus state; + unsigned char keybuf[32]; + XLookupString( &keyevent, (char *)keybuf, sizeof(keybuf), NULL, &state ); + + modifierMask = 0; + if( keyevent.state & ShiftMask ) + { + modifierMask |= osgGA::GUIEventAdapter::MODKEY_SHIFT; + } + if( keyevent.state & LockMask ) + { + modifierMask |= osgGA::GUIEventAdapter::MODKEY_CAPS_LOCK; + } + if( keyevent.state & ControlMask ) + { + modifierMask |= osgGA::GUIEventAdapter::MODKEY_CTRL; + } + if( keyevent.state & Mod1Mask ) + { + modifierMask |= osgGA::GUIEventAdapter::MODKEY_ALT; + } + if( keyevent.state & Mod2Mask ) + { + modifierMask |= osgGA::GUIEventAdapter::MODKEY_NUM_LOCK; + } + if( keyevent.state & Mod4Mask ) + { + modifierMask |= osgGA::GUIEventAdapter::MODKEY_META; + } + + keySymbol = keybuf[0]; +} struct X11WindowingSystemInterface : public osg::GraphicsContext::WindowingSystemInterface { + + X11WindowingSystemInterface() + { + } + virtual unsigned int getNumScreens(const osg::GraphicsContext::ScreenIdentifier& si) { const char* displayString = si._hostName.c_str(); @@ -453,6 +705,7 @@ struct X11WindowingSystemInterface : public osg::GraphicsContext::WindowingSyste return new GraphicsWindowX11(traits); } } + }; struct RegisterWindowingSystemInterfaceProxy @@ -469,3 +722,7 @@ struct RegisterWindowingSystemInterfaceProxy }; RegisterWindowingSystemInterfaceProxy createWindowingSystemInterfaceProxy; + +} + +#endif diff --git a/include/osgViewer/Scene b/include/osgViewer/Scene index c2ddae250..c7147b8ce 100644 --- a/include/osgViewer/Scene +++ b/include/osgViewer/Scene @@ -39,6 +39,7 @@ class OSGVIEWER_EXPORT Scene : public virtual osg::Referenced osg::Node* getSceneData(); const osg::Node* getSceneData() const; + osg::FrameStamp* getFrameStamp() { return _frameStamp.get(); } void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; } osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); } diff --git a/include/osgViewer/View b/include/osgViewer/View index 18a542719..fb919405e 100644 --- a/include/osgViewer/View +++ b/include/osgViewer/View @@ -31,6 +31,10 @@ class OSGVIEWER_EXPORT View : public osg::View osg::Node* getSceneData() { return _scene.valid() ? _scene->getSceneData() : 0; } const osg::Node* getSceneData() const { return _scene.valid() ? _scene->getSceneData() : 0; } + void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; } + osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); } + const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); } + void setCameraManipulator(osgGA::MatrixManipulator* manipulator); osgGA::MatrixManipulator* getCameraManipulator() { return _cameraManipulator.get(); } const osgGA::MatrixManipulator* getCameraManipulator() const { return _cameraManipulator.get(); } @@ -56,6 +60,7 @@ class OSGVIEWER_EXPORT View : public osg::View virtual ~View(); osg::ref_ptr _scene; + osg::ref_ptr _eventQueue; osg::ref_ptr _cameraManipulator; EventHandlers _eventHandlers; diff --git a/include/osgViewer/Viewer b/include/osgViewer/Viewer index 8d39a853f..0f57985c2 100644 --- a/include/osgViewer/Viewer +++ b/include/osgViewer/Viewer @@ -52,6 +52,7 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View public: void init(); + bool _firstFrame; protected: diff --git a/src/osgGA/EventQueue.cpp b/src/osgGA/EventQueue.cpp index c659d0bdb..f0b9c16d1 100644 --- a/src/osgGA/EventQueue.cpp +++ b/src/osgGA/EventQueue.cpp @@ -18,6 +18,7 @@ using namespace osgGA; EventQueue::EventQueue(GUIEventAdapter::MouseYOrientation mouseYOrientation) { + _useFixedMouseInputRange = false; _startTick = osg::Timer::instance()->tick(); _accumulateEventState = new GUIEventAdapter(); _accumulateEventState->setMouseYOrientation(mouseYOrientation); @@ -77,9 +78,9 @@ bool EventQueue::copyEvents(Events& events) const } -void EventQueue::windowResize(int x, int y, unsigned int width, unsigned int height, bool updateMouseRange) +void EventQueue::windowResize(int x, int y, unsigned int width, unsigned int height) { - _accumulateEventState->setWindowRectangle(x, y, width, height, updateMouseRange); + _accumulateEventState->setWindowRectangle(x, y, width, height, !_useFixedMouseInputRange); GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); event->setEventType(GUIEventAdapter::RESIZE); @@ -252,7 +253,7 @@ void EventQueue::mouseButtonRelease(float x, float y, unsigned int button) addEvent(event); } -void EventQueue::keyPress(GUIEventAdapter::KeySymbol key) +void EventQueue::keyPress(int key) { switch(key) { @@ -290,7 +291,7 @@ void EventQueue::keyPress(GUIEventAdapter::KeySymbol key) addEvent(event); } -void EventQueue::keyRelease(GUIEventAdapter::KeySymbol key) +void EventQueue::keyRelease(int key) { switch(key) { diff --git a/src/osgViewer/View.cpp b/src/osgViewer/View.cpp index 8115f7854..251d5942d 100644 --- a/src/osgViewer/View.cpp +++ b/src/osgViewer/View.cpp @@ -18,10 +18,21 @@ using namespace osgViewer; +class ActionAdapter : public osgGA::GUIActionAdapter +{ +public: + virtual ~ActionAdapter() {} + + virtual void requestRedraw() { /*osg::notify(osg::NOTICE)<<"requestRedraw()"<setNode(getSceneData()); + + osg::ref_ptr dummyEvent = _eventQueue->createEvent(); + + ActionAdapter aa; + _cameraManipulator->home(*dummyEvent, aa); + } +} + void View::setUpViewAcrossAllScreens() { osg::GraphicsContext::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); @@ -86,6 +111,11 @@ void View::setUpViewAcrossAllScreens() else { double rotate_x = - double(numScreens-1) * 0.5 * fovx; + + float inputRangeMinX = 0.0f; + float inputRangeMinY = 0.0f; + + float maxHeight = 0.0f; for(unsigned int i=0; igetEventQueue()->setUseFixedMouseInputRange(true); + gw->getEventQueue()->getCurrentEventState()->setInputRange(inputRangeMinX, inputRangeMinY, inputRangeMinX+float(width),inputRangeMinY+float(height) ); + inputRangeMinX += float(width); + + if (maxHeight < float(height)) maxHeight = float(height); } else { @@ -122,6 +158,9 @@ void View::setUpViewAcrossAllScreens() addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate( rotate_x, 0.0, 1.0, 0.0)); } + + getEventQueue()->setUseFixedMouseInputRange(true); + getEventQueue()->getCurrentEventState()->setInputRange(0.0f, 0.0, inputRangeMinX, maxHeight); } setUpRenderingSupport(); @@ -156,6 +195,16 @@ void View::assignSceneDataToCameras() { osg::Node* sceneData = _scene.valid() ? _scene->getSceneData() : 0; + if (_cameraManipulator.valid()) + { + _cameraManipulator->setNode(sceneData); + + osg::ref_ptr dummyEvent = _eventQueue->createEvent(); + + ActionAdapter aa; + _cameraManipulator->home(*dummyEvent, aa); + } + if (_camera.valid()) { _camera->removeChildren(0,_camera->getNumChildren()); diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index cce0f3649..cdaebe586 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -18,7 +18,19 @@ using namespace osgViewer; -Viewer::Viewer() +class ActionAdapter : public osgGA::GUIActionAdapter +{ +public: + virtual ~ActionAdapter() {} + + virtual void requestRedraw() { /*osg::notify(osg::NOTICE)<<"requestRedraw()"< initEvent = _eventQueue->createEvent(); + initEvent->setEventType(osgGA::GUIEventAdapter::FRAME); + + if (_cameraManipulator.valid()) + { + ActionAdapter aa; + _cameraManipulator->init(*initEvent, aa); + } +} + void Viewer::realize() { osg::notify(osg::NOTICE)<<"Viewer::realize()"<frameAdvance(); } void Viewer::frameEventTraversal() { - osg::notify(osg::NOTICE)<<"Viewer::frameEventTraversal() not implemented yet."<getGraphicsContext()) + { + osgViewer::GraphicsWindow* gw = dynamic_cast(_camera->getGraphicsContext()); + if (gw) + { + gw->checkEvents(); + gw->getEventQueue()->takeEvents(events); + } + } + + for(unsigned int i=0; igetGraphicsContext()) + { + osgViewer::GraphicsWindow* gw = dynamic_cast(slave._camera->getGraphicsContext()); + if (gw) + { + gw->checkEvents(); + gw->getEventQueue()->takeEvents(events); + } + } + } + + _eventQueue->frame( _scene->getFrameStamp()->getReferenceTime() ); + + _eventQueue->takeEvents(events); + + osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState(); + for(osgGA::EventQueue::Events::iterator itr = events.begin(); + itr != events.end(); + ++itr) + { + osgGA::GUIEventAdapter* event = itr->get(); + event->setInputRange(eventState->getXmin(), eventState->getYmin(), eventState->getXmax(), eventState->getYmax()); + } + +#if 0 + // osg::notify(osg::NOTICE)<<"Events "<get(); + switch(event->getEventType()) + { + case(osgGA::GUIEventAdapter::PUSH): + osg::notify(osg::NOTICE)<<" PUSH "<getButton()<<" x="<getX()<<" y="<getY()<getButton()<<" x="<getX()<<" y="<getY()<getButtonMask()<<" x="<getX()<<" y="<getY()<getButtonMask()<<" x="<getX()<<" y="<getY()<getScrollingMotion()<getKey()<<"'"<getKey()<<"'"<get(); + + bool handled = false; + + if (_cameraManipulator.valid()) + { + _cameraManipulator->handle( *event, aa); + } + + for(EventHandlers::iterator hitr = _eventHandlers.begin(); + hitr != _eventHandlers.end() && !handled; + ++hitr) + { + handled = (*hitr)->handle( *event, aa, 0, 0); + } + } } void Viewer::frameUpdateTraversal() { - osg::notify(osg::NOTICE)<<"Viewer::frameUpdateTraversal() not implemented yet."<setViewMatrix(_cameraManipulator->getInverseMatrix()); + } + + updateSlaves(); } void Viewer::frameCullTraversal() diff --git a/src/osgWrappers/osgGA/EventQueue.cpp b/src/osgWrappers/osgGA/EventQueue.cpp index f3d6c2cbc..0d12748e7 100644 --- a/src/osgWrappers/osgGA/EventQueue.cpp +++ b/src/osgWrappers/osgGA/EventQueue.cpp @@ -50,10 +50,22 @@ BEGIN_OBJECT_REFLECTOR(osgGA::EventQueue) __void__addEvent__GUIEventAdapter_P1, "Add an event to the end of the event queue. ", ""); - I_MethodWithDefaults5(void, windowResize, IN, int, x, , IN, int, y, , IN, unsigned int, width, , IN, unsigned int, height, , IN, bool, updateMouseRange, true, - __void__windowResize__int__int__unsigned_int__unsigned_int__bool, - "Method for adapting window resize event, placing this event on the back of the event queue. ", - ""); + I_Method1(void, setUseFixedMouseInputRange, IN, bool, useFixedMouseInputRange, + __void__setUseFixedMouseInputRange__bool, + "Specify if mouse coordinates should be transformed into a pre defined input range, or whether they should be simply based on as local coordinates to the window that generated the mouse events. ", + ""); + I_Method0(bool, getUseFixedMouseInputRange, + __bool__getUseFixedMouseInputRange, + "Get whether the mouse coordinates should be transformed into a pre defined input range. ", + ""); + I_Method4(void, setMouseInputRange, IN, float, xMin, IN, float, yMin, IN, float, xMax, IN, float, yMax, + __void__setMouseInputRange__float__float__float__float, + "Set the mouse input range. ", + ""); + I_Method4(void, windowResize, IN, int, x, IN, int, y, IN, unsigned int, width, IN, unsigned int, height, + __void__windowResize__int__int__unsigned_int__unsigned_int, + "Method for adapting window resize event, placing this event on the back of the event queue. ", + ""); I_Method1(void, mouseScroll, IN, osgGA::GUIEventAdapter::ScrollingMotion, sm, __void__mouseScroll__GUIEventAdapter_ScrollingMotion, "Method for adapting mouse scroll wheel events, placing this event on the back of the event queue. ", @@ -90,14 +102,14 @@ BEGIN_OBJECT_REFLECTOR(osgGA::EventQueue) __void__mouseButtonRelease__float__float__unsigned_int, "Method for adapting mouse button release events, placing this event on the back of the event queue. ", "Button numbering is 1 for left mouse button, 2 for middle, 3 for right. "); - I_Method1(void, keyPress, IN, osgGA::GUIEventAdapter::KeySymbol, key, - __void__keyPress__GUIEventAdapter_KeySymbol, + I_Method1(void, keyPress, IN, int, key, + __void__keyPress__int, "Method for adapting keyboard press events. ", - ""); - I_Method1(void, keyRelease, IN, osgGA::GUIEventAdapter::KeySymbol, key, - __void__keyRelease__GUIEventAdapter_KeySymbol, + "Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings. "); + I_Method1(void, keyRelease, IN, int, key, + __void__keyRelease__int, "Method for adapting keyboard press events. ", - ""); + "Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings. "); I_Method1(void, frame, IN, double, t, __void__frame__double, "Method for adapting frame events. ", @@ -138,6 +150,9 @@ BEGIN_OBJECT_REFLECTOR(osgGA::EventQueue) I_SimpleProperty(double, Time, __double__getTime, 0); + I_SimpleProperty(bool, UseFixedMouseInputRange, + __bool__getUseFixedMouseInputRange, + __void__setUseFixedMouseInputRange__bool); END_REFLECTOR BEGIN_VALUE_REFLECTOR(osg::ref_ptr< osgGA::GUIEventAdapter >) diff --git a/src/osgWrappers/osgViewer/GraphicsWindow.cpp b/src/osgWrappers/osgViewer/GraphicsWindow.cpp index 662642350..c645fe243 100644 --- a/src/osgWrappers/osgViewer/GraphicsWindow.cpp +++ b/src/osgWrappers/osgViewer/GraphicsWindow.cpp @@ -40,6 +40,10 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::GraphicsWindow) __C5_osgGA_EventQueue_P1__getEventQueue, "", ""); + I_Method0(void, checkEvents, + __void__checkEvents, + "", + ""); I_Method0(bool, realizeImplementation, __bool__realizeImplementation, "Realise the GraphicsContext implementation, Pure virtual - must be implemented by concrate implementations of GraphicsContext. ", diff --git a/src/osgWrappers/osgViewer/Scene.cpp b/src/osgWrappers/osgViewer/Scene.cpp index 2d2b54c17..e05b26c2e 100644 --- a/src/osgWrappers/osgViewer/Scene.cpp +++ b/src/osgWrappers/osgViewer/Scene.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -43,6 +44,10 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::Scene) __C5_osg_Node_P1__getSceneData, "", ""); + I_Method0(osg::FrameStamp *, getFrameStamp, + __osg_FrameStamp_P1__getFrameStamp, + "", + ""); I_Method1(void, setEventQueue, IN, osgGA::EventQueue *, eventQueue, __void__setEventQueue__osgGA_EventQueue_P1, "", @@ -104,6 +109,9 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::Scene) I_SimpleProperty(osgGA::EventQueue *, EventQueue, __osgGA_EventQueue_P1__getEventQueue, __void__setEventQueue__osgGA_EventQueue_P1); + I_SimpleProperty(osg::FrameStamp *, FrameStamp, + __osg_FrameStamp_P1__getFrameStamp, + 0); I_SimpleProperty(osg::Node *, SceneData, __osg_Node_P1__getSceneData, __void__setSceneData__osg_Node_P1); diff --git a/src/osgWrappers/osgViewer/View.cpp b/src/osgWrappers/osgViewer/View.cpp index ce80e5cb0..1a2cd2427 100644 --- a/src/osgWrappers/osgViewer/View.cpp +++ b/src/osgWrappers/osgViewer/View.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -42,6 +43,18 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::View) __C5_osg_Node_P1__getSceneData, "", ""); + I_Method1(void, setEventQueue, IN, osgGA::EventQueue *, eventQueue, + __void__setEventQueue__osgGA_EventQueue_P1, + "", + ""); + I_Method0(osgGA::EventQueue *, getEventQueue, + __osgGA_EventQueue_P1__getEventQueue, + "", + ""); + I_Method0(const osgGA::EventQueue *, getEventQueue, + __C5_osgGA_EventQueue_P1__getEventQueue, + "", + ""); I_Method1(void, setCameraManipulator, IN, osgGA::MatrixManipulator *, manipulator, __void__setCameraManipulator__osgGA_MatrixManipulator_P1, "", @@ -84,6 +97,9 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::View) I_SimpleProperty(osgViewer::View::EventHandlers &, EventHandlers, __EventHandlers_R1__getEventHandlers, 0); + I_SimpleProperty(osgGA::EventQueue *, EventQueue, + __osgGA_EventQueue_P1__getEventQueue, + __void__setEventQueue__osgGA_EventQueue_P1); I_SimpleProperty(osg::Node *, SceneData, __osg_Node_P1__getSceneData, __void__setSceneData__osg_Node_P1); diff --git a/src/osgWrappers/osgViewer/Viewer.cpp b/src/osgWrappers/osgViewer/Viewer.cpp index 2950416b4..6832500bf 100644 --- a/src/osgWrappers/osgViewer/Viewer.cpp +++ b/src/osgWrappers/osgViewer/Viewer.cpp @@ -65,5 +65,6 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::Viewer) __void__init, "", ""); + I_PublicMemberProperty(bool, _firstFrame); END_REFLECTOR