Introduce new osgGA::Event and osgGA::EventHandler base classes that the old GUIEventAdapter and GUIEventHandler now subclass from.
The new osgGA::Event is written to support more generic events than the original GUIEventAdapter which are written for keyboard and mouse events.
This commit is contained in:
@@ -87,7 +87,7 @@ class OSGGA_EXPORT CameraManipulator : public GUIEventHandler
|
||||
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
|
||||
virtual osg::Matrixd getInverseMatrix() const = 0;
|
||||
|
||||
/** update the camera for the current frame, typically called by the viewer classes.
|
||||
/** update the camera for the current frame, typically called by the viewer classes.
|
||||
Default implementation simply set the camera view matrix. */
|
||||
virtual void updateCamera(osg::Camera& camera) { camera.setViewMatrix(getInverseMatrix()); }
|
||||
|
||||
@@ -163,6 +163,9 @@ class OSGGA_EXPORT CameraManipulator : public GUIEventHandler
|
||||
*/
|
||||
virtual void init(const GUIEventAdapter& ,GUIActionAdapter&) {}
|
||||
|
||||
/** Handle event. Override the handle(..) method in your event handlers to respond to events. */
|
||||
virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv) { return GUIEventHandler::handle(event, object, nv); }
|
||||
|
||||
/** Handle events, return true if handled, false otherwise. */
|
||||
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
|
||||
@@ -29,16 +29,16 @@ class OSGGA_EXPORT Device : public osg::Object
|
||||
RECEIVE_EVENTS = 1,
|
||||
SEND_EVENTS = 2
|
||||
} Capabilities;
|
||||
|
||||
|
||||
Device();
|
||||
Device(const Device& es, const osg::CopyOp& copyop);
|
||||
|
||||
META_Object(osgGA,Device);
|
||||
|
||||
|
||||
int getCapabilities() const { return _capabilities; }
|
||||
|
||||
|
||||
virtual bool checkEvents() { return _eventQueue.valid() ? !(getEventQueue()->empty()) : false; }
|
||||
virtual void sendEvent(const GUIEventAdapter& ea);
|
||||
virtual void sendEvent(const Event& ea);
|
||||
virtual void sendEvents(const EventQueue::Events& events);
|
||||
|
||||
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
|
||||
@@ -47,17 +47,17 @@ class OSGGA_EXPORT Device : public osg::Object
|
||||
|
||||
protected:
|
||||
void setCapabilities(int capabilities) { _capabilities = capabilities; }
|
||||
|
||||
|
||||
virtual ~Device();
|
||||
|
||||
/** Prevent unwanted copy operator.*/
|
||||
Device& operator = (const Device&) { return *this; }
|
||||
|
||||
osg::ref_ptr<osgGA::EventQueue> _eventQueue;
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
int _capabilities;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
52
include/osgGA/Event
Normal file
52
include/osgGA/Event
Normal file
@@ -0,0 +1,52 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGGA_EVENT
|
||||
#define OSGGA_EVENT 1
|
||||
|
||||
#include <osgGA/Export>
|
||||
#include <osg/Object>
|
||||
|
||||
namespace osgGA {
|
||||
|
||||
// forward declare
|
||||
class GUIEventAdapter;
|
||||
|
||||
/** Base Event class.*/
|
||||
class OSGGA_EXPORT Event : public osg::Object
|
||||
{
|
||||
public:
|
||||
Event();
|
||||
|
||||
Event(const Event& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgGA, Event);
|
||||
|
||||
virtual GUIEventAdapter* asGUIEventAdapter() { return 0; }
|
||||
virtual const GUIEventAdapter* asGUIEventAdapter() const { return 0; }
|
||||
|
||||
/** set time in seconds of event. */
|
||||
void setTime(double time) { _time = time; }
|
||||
|
||||
/** get time in seconds of event. */
|
||||
double getTime() const { return _time; }
|
||||
|
||||
protected:
|
||||
virtual ~Event() {}
|
||||
|
||||
double _time;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
63
include/osgGA/EventHandler
Normal file
63
include/osgGA/EventHandler
Normal file
@@ -0,0 +1,63 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGGA_EVENTHANDLER
|
||||
#define OSGGA_EVENTHANDLER 1
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/Drawable>
|
||||
#include <osg/ApplicationUsage>
|
||||
|
||||
#include <osgGA/Export>
|
||||
#include <osgGA/GUIEventAdapter>
|
||||
#include <osgGA/GUIActionAdapter>
|
||||
|
||||
|
||||
namespace osgGA{
|
||||
|
||||
/**
|
||||
EventHandler is base class for adding handling of events, either as node event callback, drawable event callback or an event handler attached directly to the view(er)
|
||||
*/
|
||||
|
||||
class OSGGA_EXPORT EventHandler : public osg::NodeCallback, public osg::Drawable::EventCallback
|
||||
{
|
||||
public:
|
||||
|
||||
EventHandler() {}
|
||||
EventHandler(const EventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
osg::NodeCallback(eh, copyop),
|
||||
osg::Drawable::EventCallback(eh, copyop) {}
|
||||
|
||||
META_Object(osgGA, EventHandler);
|
||||
|
||||
/** Event traversal node callback method. There is no need to override this method in subclasses of EventHandler as this implementation calls handle(..) for you. */
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
||||
|
||||
/** Event traversal drawable callback method. There is no need to override this method in subclasses of EventHandler as this implementation calls handle(..) for you. */
|
||||
virtual void event(osg::NodeVisitor* nv, osg::Drawable* drawable);
|
||||
|
||||
/** Handle event. Override the handle(..) method in your event handlers to respond to events. */
|
||||
virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv);
|
||||
|
||||
/** Get the user interface usage of this event handler, i.e. keyboard and mouse bindings.*/
|
||||
virtual void getUsage(osg::ApplicationUsage&) const {}
|
||||
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -33,14 +33,14 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
|
||||
|
||||
EventQueue(GUIEventAdapter::MouseYOrientation mouseYOrientation=GUIEventAdapter::Y_INCREASING_DOWNWARDS);
|
||||
|
||||
typedef std::list< osg::ref_ptr<GUIEventAdapter> > Events;
|
||||
typedef std::list< osg::ref_ptr<Event> > Events;
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);
|
||||
return _eventQueue.empty();
|
||||
}
|
||||
|
||||
|
||||
/** Set events.*/
|
||||
void setEvents(Events& events);
|
||||
|
||||
@@ -57,7 +57,7 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
|
||||
void appendEvents(Events& events);
|
||||
|
||||
/** Add an event to the end of the event queue.*/
|
||||
void addEvent(GUIEventAdapter* event);
|
||||
void addEvent(Event* event);
|
||||
|
||||
|
||||
/** Specify if mouse coordinates should be transformed into a pre defined input range, or whether they
|
||||
@@ -70,7 +70,7 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
|
||||
|
||||
/** Set the graphics context associated with this event queue.*/
|
||||
void setGraphicsContext(osg::GraphicsContext* context) { getCurrentEventState()->setGraphicsContext(context); }
|
||||
|
||||
|
||||
osg::GraphicsContext* getGraphicsContext() { return getCurrentEventState()->getGraphicsContext(); }
|
||||
|
||||
const osg::GraphicsContext* getGraphicsContext() const { return getCurrentEventState()->getGraphicsContext(); }
|
||||
|
||||
@@ -51,16 +51,12 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
|
||||
|
||||
const osgGA::GUIActionAdapter* getActionAdapter() const { return _actionAdapter; }
|
||||
|
||||
|
||||
typedef std::list< osg::ref_ptr<GUIEventAdapter> > EventList;
|
||||
|
||||
void addEvent(GUIEventAdapter* event);
|
||||
void removeEvent(GUIEventAdapter* event);
|
||||
void addEvent(Event* event);
|
||||
void removeEvent(Event* event);
|
||||
|
||||
void setEventHandled(bool handled) { _handled = handled; }
|
||||
bool getEventHandled() const { return _handled; }
|
||||
|
||||
|
||||
void setEvents(const EventQueue::Events& events) { _events = events; }
|
||||
EventQueue::Events& getEvents() { return _events; }
|
||||
const EventQueue::Events& getEvents() const { return _events; }
|
||||
@@ -137,7 +133,6 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
|
||||
|
||||
bool _handled;
|
||||
EventQueue::Events _events;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -11,13 +11,14 @@
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGGA_EVENT
|
||||
#define OSGGA_EVENT 1
|
||||
#ifndef OSGGA_GUIEVENTADAPTER
|
||||
#define OSGGA_GUIEVENTADAPTER 1
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osg/Matrix>
|
||||
#include <osg/GraphicsContext>
|
||||
#include <osgGA/Export>
|
||||
|
||||
#include <osgGA/Event>
|
||||
|
||||
namespace osgGA{
|
||||
|
||||
@@ -77,7 +78,7 @@ struct PointerData : public osg::Referenced
|
||||
|
||||
/** Event class for storing Keyboard, mouse and window events.
|
||||
*/
|
||||
class OSGGA_EXPORT GUIEventAdapter : public osg::Object
|
||||
class OSGGA_EXPORT GUIEventAdapter : public Event
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -448,6 +449,9 @@ public:
|
||||
|
||||
META_Object(osgGA, GUIEventAdapter);
|
||||
|
||||
virtual GUIEventAdapter* asGUIEventAdapter() { return this; }
|
||||
virtual const GUIEventAdapter* asGUIEventAdapter() const { return this; }
|
||||
|
||||
|
||||
/** Get the accumulated event state singleton.
|
||||
* Typically all EventQueue will share this single GUIEventAdapter object for tracking
|
||||
@@ -467,12 +471,6 @@ public:
|
||||
/** get the event type. */
|
||||
virtual EventType getEventType() const { return _eventType; }
|
||||
|
||||
/** set time in seconds of event. */
|
||||
void setTime(double time) { _time = time; }
|
||||
|
||||
/** get time in seconds of event. */
|
||||
double getTime() const { return _time; }
|
||||
|
||||
/** deprecated function for getting time of event. */
|
||||
double time() const { return _time; }
|
||||
|
||||
@@ -709,7 +707,6 @@ public:
|
||||
|
||||
mutable bool _handled;
|
||||
EventType _eventType;
|
||||
double _time;
|
||||
|
||||
osg::observer_ptr<osg::GraphicsContext> _context;
|
||||
int _windowX;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <osg/Drawable>
|
||||
#include <osg/ApplicationUsage>
|
||||
|
||||
#include <osgGA/Export>
|
||||
#include <osgGA/EventHandler>
|
||||
#include <osgGA/GUIEventAdapter>
|
||||
#include <osgGA/GUIActionAdapter>
|
||||
|
||||
@@ -47,27 +47,30 @@ This request is made via the GUIActionAdapter class.
|
||||
|
||||
*/
|
||||
|
||||
class OSGGA_EXPORT GUIEventHandler : public osg::NodeCallback, public osg::Drawable::EventCallback
|
||||
class OSGGA_EXPORT GUIEventHandler : public EventHandler
|
||||
{
|
||||
public:
|
||||
|
||||
#if 1
|
||||
GUIEventHandler() {}
|
||||
GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
EventHandler(eh, copyop) {}
|
||||
#else
|
||||
GUIEventHandler() : _ignoreHandledEventsMask(GUIEventAdapter::NONE) {}
|
||||
GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop):
|
||||
osg::NodeCallback(eh, copyop),
|
||||
osg::Drawable::EventCallback(eh, copyop),
|
||||
GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
EventHandler(eh, copyop)
|
||||
_ignoreHandledEventsMask(eh._ignoreHandledEventsMask) {}
|
||||
#endif
|
||||
|
||||
META_Object(osgGA,GUIEventHandler);
|
||||
|
||||
/** Event traversal node callback method.*/
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
||||
|
||||
/** Event traversal drawable callback method.*/
|
||||
virtual void event(osg::NodeVisitor* nv, osg::Drawable* drawable);
|
||||
/** Handle event. Override the handle(..) method in your event handlers to respond to events. */
|
||||
virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv);
|
||||
|
||||
/** Handle events, return true if handled, false otherwise. */
|
||||
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*) { return handle(ea,aa); }
|
||||
|
||||
#if 0
|
||||
/** Convenience 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(,,,)
|
||||
@@ -86,10 +89,11 @@ public:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
/** Deprecated, Handle events, return true if handled, false otherwise. */
|
||||
virtual bool handle(const GUIEventAdapter&,GUIActionAdapter&) { return false; }
|
||||
|
||||
#if 0
|
||||
/** Convenience 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(,)
|
||||
@@ -109,9 +113,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/** 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 setIgnoreHandledEventsMask(unsigned int mask) { _ignoreHandledEventsMask = mask; }
|
||||
|
||||
@@ -120,18 +121,8 @@ public:
|
||||
|
||||
protected:
|
||||
unsigned int _ignoreHandledEventsMask;
|
||||
|
||||
};
|
||||
|
||||
#ifdef USE_DEPRECATED_API
|
||||
// keep for backwards compatibility
|
||||
class GUIEventHandlerVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
void visit(GUIEventHandler&) {}
|
||||
};
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user