From Rafa Giatan and Robert Osfield, added support for User defined events, by adding

UserData to Events.
This commit is contained in:
Robert Osfield 2007-05-19 13:39:55 +00:00
parent a441b1cf35
commit e3747b1004
4 changed files with 29 additions and 14 deletions

View File

@ -181,6 +181,13 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
GUIEventAdapter* getCurrentEventState() { return _accumulateEventState.get(); }
const GUIEventAdapter* getCurrentEventState() const { return _accumulateEventState.get(); }
/** Method for adapting user defined events */
void userEvent(osg::Referenced* userEventData) { userEvent(userEventData, getTime()); }
/** Method for adapting user defined events with specified event time */
void userEvent(osg::Referenced* userEventData, double time);
protected:
virtual ~EventQueue();

View File

@ -14,22 +14,15 @@
#ifndef OSGGA_EVENT
#define OSGGA_EVENT 1
#include <osg/Referenced>
#include <osg/Object>
#include <osgGA/Export>
namespace osgGA{
/**
Pure virtual base class for adapting platform specific GUIEventAdapters into
generic keyboard and mouse GUIEventAdapters.
Used as GUI toolkit-independent input into GUIEventAdapters. Viewer
writers should subclass this base class to implement the functionality
to translate one of their GUI GUIEventAdapters, e.g. a Qt GUIEventAdapter or an MFC GUIEventAdapter,
as appropriate.
/** Event class for storing Keyboard, mouse and window events.
*/
class OSGGA_EXPORT GUIEventAdapter : public osg::Referenced
class OSGGA_EXPORT GUIEventAdapter : public osg::Object
{
public:
@ -55,7 +48,8 @@ public:
PEN_PROXIMITY_ENTER,
PEN_PROXIMITY_LEAVE,
CLOSE_WINDOW,
QUIT_APPLICATION
QUIT_APPLICATION,
USER
};
enum KeySymbol
@ -256,7 +250,9 @@ public:
GUIEventAdapter();
GUIEventAdapter(const GUIEventAdapter& rhs);
GUIEventAdapter(const GUIEventAdapter& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgGA, GUIEventAdapter);
/** Set whether this event has been handled by an event handler or not.*/
void setHandled(bool handled) { _handled = handled; }

View File

@ -358,3 +358,15 @@ GUIEventAdapter* EventQueue::createEvent()
if (_accumulateEventState.valid()) return new GUIEventAdapter(*_accumulateEventState.get());
else return new GUIEventAdapter();
}
void EventQueue::userEvent(osg::Referenced* userEventData, double time)
{
GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState);
event->setEventType(GUIEventAdapter::USER);
event->setUserData(userEventData);
event->setTime(time);
addEvent(event);
};

View File

@ -41,8 +41,8 @@ GUIEventAdapter::GUIEventAdapter():
_tabletPointerType(UNKNOWN)
{}
GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs):
osg::Referenced(),
GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs,const osg::CopyOp& copyop):
osg::Object(rhs,copyop),
_handled(rhs._handled),
_eventType(rhs._eventType),
_time(rhs._time),