diff --git a/include/osgGA/EventVisitor b/include/osgGA/EventVisitor index bc9f22635..0eeba411d 100644 --- a/include/osgGA/EventVisitor +++ b/include/osgGA/EventVisitor @@ -63,6 +63,10 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor void addEvent(GUIEventAdapter* event); void removeEvent(GUIEventAdapter* event); + + bool getEventHandled() const { return _handled; } + + void setEventHandled(bool handled) { _handled = handled; } virtual void reset(); @@ -134,6 +138,7 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor osgGA::GUIActionAdapter* _actionAdapter; EventList _events; + bool _handled; }; diff --git a/src/osgGA/EventVisitor.cpp b/src/osgGA/EventVisitor.cpp index cdd134fc4..3611a9818 100644 --- a/src/osgGA/EventVisitor.cpp +++ b/src/osgGA/EventVisitor.cpp @@ -17,7 +17,9 @@ using namespace osg; using namespace osgGA; -EventVisitor::EventVisitor():NodeVisitor(UPDATE_VISITOR,TRAVERSE_ALL_CHILDREN) +EventVisitor::EventVisitor() +: NodeVisitor(UPDATE_VISITOR,TRAVERSE_ALL_CHILDREN), + _handled(false) { } @@ -41,4 +43,5 @@ void EventVisitor::removeEvent(GUIEventAdapter* event) void EventVisitor::reset() { _events.clear(); + _handled = false; } diff --git a/src/osgGA/GUIEventHandler.cpp b/src/osgGA/GUIEventHandler.cpp index 994221e61..89ebbd9ee 100644 --- a/src/osgGA/GUIEventHandler.cpp +++ b/src/osgGA/GUIEventHandler.cpp @@ -26,7 +26,11 @@ void GUIEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv) itr != ev->getEventList().end(); ++itr) { - handle(*(*itr), *(ev->getActionAdapter()), node, nv); + if (handle(*(*itr), *(ev->getActionAdapter()), node, nv)) + { + ev->setEventHandled(true); + return; + } } } traverse(node,nv); diff --git a/src/osgProducer/Viewer.cpp b/src/osgProducer/Viewer.cpp index 3c62e3847..b49333f21 100644 --- a/src/osgProducer/Viewer.cpp +++ b/src/osgProducer/Viewer.cpp @@ -81,11 +81,11 @@ public: _piv.setTraversalMask(traversalMask); } - // Aug 2003 added to pass the nodemaskOverride to the PickIntersectVisitor + // Aug 2003 added to pass the nodemaskOverride to the PickIntersectVisitor // may be used make the visitor override the nodemask to visit invisible actions inline void setNodeMaskOverride(osg::Node::NodeMask mask) { - _piv.setNodeMaskOverride(mask); - _nodeMaskOverride = mask; } + _piv.setNodeMaskOverride(mask); + _nodeMaskOverride = mask; } virtual void apply(osg::Projection& pr) @@ -698,17 +698,21 @@ void Viewer::update() ++event_itr) { bool handled = false; - for(EventHandlerList::iterator handler_itr=_eventHandlerList.begin(); - handler_itr!=_eventHandlerList.end() && !handled; - ++handler_itr) - { - handled = (*handler_itr)->handle(*(*event_itr),*this,0,0); - } + if (_eventVisitor.valid()) { _eventVisitor->reset(); _eventVisitor->addEvent(event_itr->get()); getTopMostSceneData()->accept(*_eventVisitor); + if (_eventVisitor->getEventHandled()) + handled = true; + } + + for(EventHandlerList::iterator handler_itr=_eventHandlerList.begin(); + handler_itr!=_eventHandlerList.end() && !handled; + ++handler_itr) + { + handled = (*handler_itr)->handle(*(*event_itr),*this,0,0); } } @@ -1014,3 +1018,4 @@ void Viewer::getUsage(osg::ApplicationUsage& usage) const (*itr)->getUsage(usage); } } +