From fd3bef5158d0db1f074d086216d20e51b24bb669 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 20 Sep 2002 14:48:41 +0000 Subject: [PATCH] From Daniel, changed setEventHandler to addEventHandler. --- include/osgGLUT/Viewer | 7 +-- src/osgGLUT/Viewer.cpp | 115 ++++++++++++++++++++++++++++------------- 2 files changed, 83 insertions(+), 39 deletions(-) diff --git a/include/osgGLUT/Viewer b/include/osgGLUT/Viewer index 486b368b3..6566b0f25 100644 --- a/include/osgGLUT/Viewer +++ b/include/osgGLUT/Viewer @@ -13,6 +13,7 @@ #include #include +#include #include @@ -81,7 +82,7 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgGA::GUIActionAdapter void selectCameraManipulator(unsigned int pos, unsigned int viewport = 0); - void setEventHandler(osgGA::GUIEventHandler* handler,unsigned int viewport = 0); + void addEventHandler(osgGA::GUIEventHandler* handler,unsigned int viewport = 0); // derived from osgGA::GUIActionAdapter virtual void requestRedraw() {} // redraw always by idle callback done. @@ -96,6 +97,7 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgGA::GUIActionAdapter const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); } typedef std::vector > CameraManipList; + typedef std::vector > EventHandlerList; protected: @@ -124,8 +126,7 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgGA::GUIActionAdapter osg::ref_ptr _cameraManipulator; CameraManipList _cameraManipList; - osg::ref_ptr _eventHandler; - + EventHandlerList _eventHandlerList; }; typedef std::vector ViewportList; diff --git a/src/osgGLUT/Viewer.cpp b/src/osgGLUT/Viewer.cpp index f7f417447..70f9bd7a4 100644 --- a/src/osgGLUT/Viewer.cpp +++ b/src/osgGLUT/Viewer.cpp @@ -317,10 +317,10 @@ unsigned int Viewer::registerCameraManipulator(osgGA::CameraManipulator* cm, return pos; } -void Viewer::setEventHandler(osgGA::GUIEventHandler* handler,unsigned int viewport) +void Viewer::addEventHandler(osgGA::GUIEventHandler* handler,unsigned int viewport) { ViewportDef &viewp = _viewportList[viewport]; - viewp._eventHandler = handler; + viewp._eventHandlerList.push_back( handler ); } void Viewer::setFocusedViewport(unsigned int pos) @@ -369,13 +369,18 @@ float Viewer::app(unsigned int viewport) osg::ref_ptr ea = osgNew GLUTEventAdapter; ea->adaptFrame(_frameStamp->getReferenceTime()); - if (_viewportList[viewport]._eventHandler.valid() && _viewportList[viewport]._eventHandler->handle(*ea,*this)) - { - // event handler handle this call. + bool handled = false; + for ( EventHandlerList::iterator eh = + _viewportList[viewport]._eventHandlerList.begin(); + eh != _viewportList[viewport]._eventHandlerList.end(); eh++ ) { + if ( eh->valid() ) { + if ( (*eh)->handle(*ea,*this) ) { + handled = true; + } + } } - else if (_viewportList[viewport]._cameraManipulator->handle(*ea,*this)) - { - // osg::notify(osg::INFO) << "Handled update frame"<< std::endl; + if ( !handled ) { + _viewportList[viewport]._cameraManipulator->handle(*ea,*this); } @@ -744,9 +749,13 @@ void Viewer::reshape(GLint w, GLint h) { // osg::notify(osg::INFO) << "Handled reshape "<< std::endl; } - if (itr->_eventHandler.valid() && itr->_eventHandler->handle(*ea,*this)) - { - // event handler handle this call. + for ( EventHandlerList::iterator eh = itr->_eventHandlerList.begin(); + eh != itr->_eventHandlerList.end(); eh++ ) { + if ( eh->valid() ) { + if ( (*eh)->handle(*ea,*this) ) { + // event handler handle this call. + } + } } } @@ -758,13 +767,22 @@ void Viewer::mouseMotion(int x, int y) osg::ref_ptr ea = osgNew GLUTEventAdapter; ea->adaptMouseMotion(clockSeconds(),x,y); - if (_viewportList[_focusedViewport]._eventHandler.valid() && _viewportList[_focusedViewport]._eventHandler->handle(*ea,*this)) - { - // event handler handle this call. + bool handled = false; + for ( EventHandlerList::iterator eh = + _viewportList[_focusedViewport]._eventHandlerList.begin(); + eh != _viewportList[_focusedViewport]._eventHandlerList.end(); + eh++ ) { + if ( eh->valid() ) { + if ( (*eh)->handle(*ea,*this) ) { + handled = true; + } + } } - else if (_viewportList[_focusedViewport]._cameraManipulator->handle(*ea,*this)) - { - // osg::notify(osg::INFO) << "Handled mouseMotion "<_buttonMask<<" x="<_mx<<" y="<_my<< std::endl; + if ( !handled ) { + if ( _viewportList[_focusedViewport]._cameraManipulator->handle( + *ea,*this) ) { + // osg::notify(osg::INFO) << "Handled mouseMotion "<_buttonMask<<" x="<_mx<<" y="<_my<< std::endl; + } } _mx = x; @@ -786,13 +804,22 @@ void Viewer::mousePassiveMotion(int x, int y) setFocusedViewport(focus); } - if (_viewportList[_focusedViewport]._eventHandler.valid() && _viewportList[_focusedViewport]._eventHandler->handle(*ea,*this)) - { - // event handler handle this call. + bool handled = false; + for ( EventHandlerList::iterator eh = + _viewportList[_focusedViewport]._eventHandlerList.begin(); + eh != _viewportList[_focusedViewport]._eventHandlerList.end(); + eh++ ) { + if ( eh->valid() ) { + if ( (*eh)->handle(*ea,*this) ) { + handled = true; + } + } } - else if (_viewportList[_focusedViewport]._cameraManipulator->handle(*ea,*this)) - { - // osg::notify(osg::INFO) << "Handled mousePassiveMotion "<_buttonMask<<" x="<_mx<<" y="<_my<< std::endl; + if ( !handled ) { + if ( _viewportList[_focusedViewport]._cameraManipulator->handle( + *ea,*this) ) { + // osg::notify(osg::INFO) << "Handled mousePassiveMotion "<_buttonMask<<" x="<_mx<<" y="<_my<< std::endl; + } } } @@ -814,13 +841,22 @@ void Viewer::mouse(int button, int state, int x, int y) setFocusedViewport(focus); } - if (_viewportList[_focusedViewport]._eventHandler.valid() && _viewportList[_focusedViewport]._eventHandler->handle(*ea,*this)) - { - // event handler handle this call. + bool handled = false; + for ( EventHandlerList::iterator eh = + _viewportList[_focusedViewport]._eventHandlerList.begin(); + eh != _viewportList[_focusedViewport]._eventHandlerList.end(); + eh++ ) { + if ( eh->valid() ) { + if ( (*eh)->handle(*ea,*this) ) { + handled = true; + } + } } - else if (_viewportList[_focusedViewport]._cameraManipulator->handle(*ea,*this)) - { + if ( !handled ) { + if ( _viewportList[_focusedViewport]._cameraManipulator->handle( + *ea,*this) ) { // osg::notify(osg::INFO) << "Handled mouse "<_buttonMask<<" x="<_mx<<" y="<_my<< std::endl; + } } } @@ -832,17 +868,24 @@ void Viewer::keyboard(unsigned char key, int x, int y) osg::ref_ptr ea = osgNew GLUTEventAdapter; ea->adaptKeyboard(clockSeconds(),key,x,y); - if (_viewportList[_focusedViewport]._eventHandler.valid() && _viewportList[_focusedViewport]._eventHandler->handle(*ea,*this)) - { - return; + bool handled = false; + for ( EventHandlerList::iterator eh = + _viewportList[_focusedViewport]._eventHandlerList.begin(); + eh != _viewportList[_focusedViewport]._eventHandlerList.end(); + eh++ ) { + if ( eh->valid() ) { + if ( (*eh)->handle(*ea,*this) ) { + return; + } + } } - else if (_viewportList[_focusedViewport]._cameraManipulator->handle(*ea,*this)) - { - return; + if ( !handled ) { + if ( _viewportList[_focusedViewport]._cameraManipulator->handle( + *ea,*this) ) { + return; + } } - - if (key>='1' && key<='3') { int pos = key-'1';