Added View::removeEventHandler(..) method and added check into addEventHandler() to prevent handlers being added twice.

This commit is contained in:
Robert Osfield 2009-03-11 14:18:30 +00:00
parent d808149e05
commit 998cfec137
2 changed files with 18 additions and 2 deletions

View File

@ -113,10 +113,13 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
typedef std::list< osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlers;
/** Add an EventHandler that adds handling of events to the View.*/
void addEventHandler(osgGA::GUIEventHandler* eventHandler);
/** Remove an EventHandler from View.*/
void removeEventHandler(osgGA::GUIEventHandler* eventHandler);
/** Get the View's list of EventHandlers.*/
EventHandlers& getEventHandlers() { return _eventHandlers; }

View File

@ -357,7 +357,20 @@ void View::home()
void View::addEventHandler(osgGA::GUIEventHandler* eventHandler)
{
_eventHandlers.push_back(eventHandler);
EventHandlers::iterator itr = std::find(_eventHandlers.begin(), _eventHandlers.end(), eventHandler);
if (itr == _eventHandlers.end())
{
_eventHandlers.push_back(eventHandler);
}
}
void View::removeEventHandler(osgGA::GUIEventHandler* eventHandler)
{
EventHandlers::iterator itr = std::find(_eventHandlers.begin(), _eventHandlers.end(), eventHandler);
if (itr != _eventHandlers.end())
{
_eventHandlers.erase(itr);
}
}
void View::setCoordinateSystemNodePath(const osg::NodePath& nodePath)