Introduce GUIEventHandler::handleWithCheckAgainstIgnoreHandledEventsMask() methods

to help make it easier to get event handles to ingore events that have already been handled.
This commit is contained in:
Robert Osfield 2007-09-14 10:44:46 +00:00
parent 290adbe7ab
commit d5cc0e966f
6 changed files with 55 additions and 18 deletions

View File

@ -262,7 +262,7 @@ public:
/** Set whether this event has been handled by an event handler or not.*/ /** Set whether this event has been handled by an event handler or not.*/
void setHandled(bool handled) { _handled = handled; } void setHandled(bool handled) const { _handled = handled; }
/** Get whether this event has been handled by an event handler or not.*/ /** Get whether this event has been handled by an event handler or not.*/
bool getHandled() const { return _handled; } bool getHandled() const { return _handled; }
@ -403,7 +403,7 @@ public:
/** Force users to create on heap, so that multiple referencing is safe.*/ /** Force users to create on heap, so that multiple referencing is safe.*/
virtual ~GUIEventAdapter(); virtual ~GUIEventAdapter();
bool _handled; mutable bool _handled;
EventType _eventType; EventType _eventType;
double _time; double _time;

View File

@ -51,8 +51,9 @@ class OSGGA_EXPORT GUIEventHandler : public osg::NodeCallback, public osg::Drawa
{ {
public: public:
GUIEventHandler() : _ignoreUsedEventsMask(GUIEventAdapter::NONE) {} GUIEventHandler() : _ignoreHandledEventsMask(GUIEventAdapter::NONE) {}
GUIEventHandler(const GUIEventHandler&,const osg::CopyOp&) {} GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp&):
_ignoreHandledEventsMask(eh._ignoreHandledEventsMask) {}
META_Object(osgGA,GUIEventHandler); META_Object(osgGA,GUIEventHandler);
@ -65,19 +66,58 @@ public:
/** Handle events, return true if handled, false otherwise. */ /** Handle events, return true if handled, false otherwise. */
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*) { return handle(ea,aa); } 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. */ /** Convnience method that only passes on to the handle(,,,) method events that either haven't been
* handled yet, or have been handled but haven't be set to be ignored by the IgnoreHandledEventsMask.
* Note, this method is an inline method, and not appropriate for users to override, override the handle(,,,)
* method instead.*/
inline bool handleWithCheckAgainstIgnoreHandledEventsMask(const GUIEventAdapter& ea,GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv)
{
if (!ea.getHandled() ||
(ea.getEventType() & _ignoreHandledEventsMask)==0)
{
bool handled = handle(ea,aa,object,nv);
if (handled) ea.setHandled(true);
return handled;
}
else
{
return false;
}
}
/** Deprecated, Handle events, return true if handled, false otherwise. */
virtual bool handle(const GUIEventAdapter&,GUIActionAdapter&) { return false; } virtual bool handle(const GUIEventAdapter&,GUIActionAdapter&) { return false; }
/** Convnience method that only passes on to the handle(,) method events that either haven't been
* handled yet, or have been handled but haven't be set to be ignored by the IgnoreHandledEventsMask.
* Note, this method is an inline method, and not appropriate for users to override, override the handle(,)
* method instead.*/
inline bool handleWithCheckAgainstIgnoreHandledEventsMask(const GUIEventAdapter& ea,GUIActionAdapter& aa)
{
if (!ea.getHandled() ||
(ea.getEventType() & _ignoreHandledEventsMask)==0)
{
bool handled = handle(ea,aa);
if (handled) ea.setHandled(true);
return handled;
}
else
{
return false;
}
}
/** Get the keyboard and mouse usage of this manipulator.*/ /** Get the keyboard and mouse usage of this manipulator.*/
virtual void getUsage(osg::ApplicationUsage&) const {} virtual void getUsage(osg::ApplicationUsage&) const {}
/** Set a mask of osgGA::GUIEeventAdapter::Event to be ignored if marked as handled */ /** Set a mask of osgGA::GUIEeventAdapter::Event to be ignored if marked as handled */
void setIgnoreUsedEventsMask(unsigned int mask) { _ignoreUsedEventsMask = mask; } void setIgnoreHandledEventsMask(unsigned int mask) { _ignoreHandledEventsMask = mask; }
unsigned int getIgnoreUsedEventsMask() const { return _ignoreUsedEventsMask; }; /** Get the event mask of the osgGA::GUIEeventAdapter::Event to be ignored if marked as handled */
unsigned int getIgnoreHandledEventsMask() const { return _ignoreHandledEventsMask; };
protected: protected:
unsigned int _ignoreUsedEventsMask; unsigned int _ignoreHandledEventsMask;
}; };

View File

@ -26,10 +26,7 @@ void GUIEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv)
itr != ev->getEvents().end(); itr != ev->getEvents().end();
++itr) ++itr)
{ {
if (handle(*(*itr), *(ev->getActionAdapter()), node, nv)) handleWithCheckAgainstIgnoreHandledEventsMask(*(*itr), *(ev->getActionAdapter()), node, nv);
{
(*itr)->setHandled(true);
}
} }
} }
if (node->getNumChildrenRequiringEventTraversal()>0) traverse(node,nv); if (node->getNumChildrenRequiringEventTraversal()>0) traverse(node,nv);
@ -44,7 +41,7 @@ void GUIEventHandler::event(osg::NodeVisitor* nv, osg::Drawable* drawable)
itr != ev->getEvents().end(); itr != ev->getEvents().end();
++itr) ++itr)
{ {
handle(*(*itr), *(ev->getActionAdapter()), drawable, nv); handleWithCheckAgainstIgnoreHandledEventsMask(*(*itr), *(ev->getActionAdapter()), drawable, nv);
} }
} }
} }

View File

@ -950,12 +950,12 @@ void CompositeViewer::eventTraversal()
hitr != view->getEventHandlers().end(); hitr != view->getEventHandlers().end();
++hitr) ++hitr)
{ {
if ((*hitr)->handle( *event, *view, 0, 0)) event->setHandled(true); (*hitr)->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *view, 0, 0);
} }
if (view->getCameraManipulator()) if (view->getCameraManipulator())
{ {
if (view->getCameraManipulator()->handle( *event, *view)) event->setHandled(true); view->getCameraManipulator()->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *view);
} }
} }
} }

View File

@ -457,7 +457,7 @@ void GraphicsWindowX11::init()
getEventQueue()->setCurrentEventState(osgGA::GUIEventAdapter::getAccumulatedEventState().get()); getEventQueue()->setCurrentEventState(osgGA::GUIEventAdapter::getAccumulatedEventState().get());
WindowData* inheritedWindowData = dynamic_cast<WindowData*>(_traits->inheritedWindowData.get()); // WindowData* inheritedWindowData = dynamic_cast<WindowData*>(_traits->inheritedWindowData.get());
_display = XOpenDisplay(_traits->displayName().c_str()); _display = XOpenDisplay(_traits->displayName().c_str());

View File

@ -1327,12 +1327,12 @@ void Viewer::eventTraversal()
hitr != _eventHandlers.end(); hitr != _eventHandlers.end();
++hitr) ++hitr)
{ {
if ((*hitr)->handle( *event, *this, 0, 0)) event->setHandled(true); (*hitr)->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *this, 0, 0);
} }
if (_cameraManipulator.valid()) if (_cameraManipulator.valid())
{ {
if (_cameraManipulator->handle( *event, *this)) event->setHandled(true); _cameraManipulator->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *this);
} }
} }