diff --git a/include/osgGA/EventQueue b/include/osgGA/EventQueue index 32a88acf6..ef8463ec1 100644 --- a/include/osgGA/EventQueue +++ b/include/osgGA/EventQueue @@ -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(); diff --git a/include/osgGA/GUIEventAdapter b/include/osgGA/GUIEventAdapter index 2147d9f7f..f81f05f47 100644 --- a/include/osgGA/GUIEventAdapter +++ b/include/osgGA/GUIEventAdapter @@ -14,22 +14,15 @@ #ifndef OSGGA_EVENT #define OSGGA_EVENT 1 -#include +#include #include 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; } diff --git a/src/osgGA/EventQueue.cpp b/src/osgGA/EventQueue.cpp index 7e57b7554..038db29c0 100644 --- a/src/osgGA/EventQueue.cpp +++ b/src/osgGA/EventQueue.cpp @@ -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); +}; + + diff --git a/src/osgGA/GUIEventAdapter.cpp b/src/osgGA/GUIEventAdapter.cpp index 5095b4003..01215ed1b 100644 --- a/src/osgGA/GUIEventAdapter.cpp +++ b/src/osgGA/GUIEventAdapter.cpp @@ -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),