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.*/
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.*/
bool getHandled() const { return _handled; }
@@ -403,7 +403,7 @@ public:
/** Force users to create on heap, so that multiple referencing is safe.*/
virtual ~GUIEventAdapter();
bool _handled;
mutable bool _handled;
EventType _eventType;
double _time;

View File

@@ -51,8 +51,9 @@ class OSGGA_EXPORT GUIEventHandler : public osg::NodeCallback, public osg::Drawa
{
public:
GUIEventHandler() : _ignoreUsedEventsMask(GUIEventAdapter::NONE) {}
GUIEventHandler(const GUIEventHandler&,const osg::CopyOp&) {}
GUIEventHandler() : _ignoreHandledEventsMask(GUIEventAdapter::NONE) {}
GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp&):
_ignoreHandledEventsMask(eh._ignoreHandledEventsMask) {}
META_Object(osgGA,GUIEventHandler);
@@ -65,19 +66,58 @@ public:
/** 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. */
/** 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; }
/** 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.*/
virtual void getUsage(osg::ApplicationUsage&) const {}
/** 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:
unsigned int _ignoreUsedEventsMask;
unsigned int _ignoreHandledEventsMask;
};