From ce68304f901ed8deb16ab505f5b96b3b8b745c06 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 25 Feb 2005 23:02:23 +0000 Subject: [PATCH] Improved support GUIEventHandler's being node event callbacks. --- include/osgGA/GUIEventHandler | 5 ++++- src/osgGA/GUIEventHandler.cpp | 10 +++++----- src/osgProducer/Viewer.cpp | 8 ++++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/include/osgGA/GUIEventHandler b/include/osgGA/GUIEventHandler index 12958e4c0..10fe2feae 100644 --- a/include/osgGA/GUIEventHandler +++ b/include/osgGA/GUIEventHandler @@ -72,6 +72,9 @@ public: virtual CompositeGUIEventHandler* getComposite() { return 0; } /** Handle events, return true if handled, false otherwise. */ + virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*) { return handle(ea,aa); } + + /** deprecated, Handle events, return true if handled, false otherwise. */ virtual bool handle(const GUIEventAdapter&,GUIActionAdapter&) { return false; } /** Accept visits from GUIEventHandler visitors */ @@ -98,7 +101,7 @@ public: virtual CompositeGUIEventHandler* getComposite() { return this; } - virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& aa); + virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv); virtual void accept(GUIEventHandlerVisitor& v) { v.visit(*this); } diff --git a/src/osgGA/GUIEventHandler.cpp b/src/osgGA/GUIEventHandler.cpp index 1d2475e64..c899c85d9 100644 --- a/src/osgGA/GUIEventHandler.cpp +++ b/src/osgGA/GUIEventHandler.cpp @@ -26,13 +26,13 @@ void GUIEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv) itr != ev->getEventList().end(); ++itr) { - handle(*(*itr), *(ev->getActionAdapter())); + handle(*(*itr), *(ev->getActionAdapter()), node, nv); } } traverse(node,nv); } -void GUIEventHandler::event(osg::NodeVisitor* nv, osg::Drawable* /*drawable*/) +void GUIEventHandler::event(osg::NodeVisitor* nv, osg::Drawable* drawable) { osgGA::EventVisitor* ev = dynamic_cast(nv); if (ev && ev->getActionAdapter() && !ev->getEventList().empty()) @@ -41,7 +41,7 @@ void GUIEventHandler::event(osg::NodeVisitor* nv, osg::Drawable* /*drawable*/) itr != ev->getEventList().end(); ++itr) { - handle(*(*itr), *(ev->getActionAdapter())); + handle(*(*itr), *(ev->getActionAdapter()), drawable, nv); } } } @@ -56,7 +56,7 @@ void CompositeGUIEventHandler::getUsage(osg::ApplicationUsage& usage) const } } -bool CompositeGUIEventHandler::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa) +bool CompositeGUIEventHandler::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv) { bool result=false; @@ -64,7 +64,7 @@ bool CompositeGUIEventHandler::handle(const GUIEventAdapter& ea,GUIActionAdapter itr!=_children.end(); ++itr) { - result |= (*itr)->handle(ea,aa); + result |= (*itr)->handle(ea, aa, object, nv); } return result; } diff --git a/src/osgProducer/Viewer.cpp b/src/osgProducer/Viewer.cpp index 3d6310cfb..26033ff10 100644 --- a/src/osgProducer/Viewer.cpp +++ b/src/osgProducer/Viewer.cpp @@ -652,9 +652,9 @@ void Viewer::update() handler_itr!=_eventHandlerList.end() && !handled; ++handler_itr) { - handled = (*handler_itr)->handle(*(*event_itr),*this); + handled = (*handler_itr)->handle(*(*event_itr),*this,0,0); } - if (!handled && _eventVisitor.valid()) + if (_eventVisitor.valid()) { _eventVisitor->reset(); _eventVisitor->addEvent(event_itr->get()); @@ -854,7 +854,7 @@ bool Viewer::computeIntersections(float x,float y,unsigned int cameraNum,osg::No bool Viewer::computeIntersections(float x,float y,unsigned int cameraNum,osgUtil::IntersectVisitor::HitList& hits,osg::Node::NodeMask traversalMask) { - return computeIntersections(x,y,cameraNum,getSceneData(),hits,traversalMask); + return computeIntersections(x,y,cameraNum,getTopMostSceneData(),hits,traversalMask); } bool Viewer::computeIntersections(float x,float y,osg::Node *node,osgUtil::IntersectVisitor::HitList& hits,osg::Node::NodeMask traversalMask) @@ -870,7 +870,7 @@ bool Viewer::computeIntersections(float x,float y,osg::Node *node,osgUtil::Inter bool Viewer::computeIntersections(float x,float y,osgUtil::IntersectVisitor::HitList& hits,osg::Node::NodeMask traversalMask) { - return computeIntersections(x,y,getSceneData(),hits,traversalMask); + return computeIntersections(x,y,getTopMostSceneData(),hits,traversalMask); } void Viewer::selectCameraManipulator(unsigned int no)