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:
Robert Osfield
2013-10-25 14:54:15 +00:00
parent 2025c511f0
commit 4a660f6266
37 changed files with 511 additions and 397 deletions

View File

@@ -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);

View File

@@ -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
View 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

View 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

View File

@@ -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(); }

View File

@@ -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;
};
}

View File

@@ -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;

View File

@@ -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
};
}

View File

@@ -48,8 +48,6 @@ class OSGPRESENTATION_EXPORT KeyEventHandler : public osgGA::GUIEventHandler
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv);
virtual void accept(osgGA::GUIEventHandlerVisitor& v);
virtual void getUsage(osg::ApplicationUsage& usage) const;
void doOperation();

View File

@@ -45,8 +45,6 @@ class OSGPRESENTATION_EXPORT PickEventHandler : public osgGA::GUIEventHandler
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv);
virtual void accept(osgGA::GUIEventHandlerVisitor& v);
virtual void getUsage(osg::ApplicationUsage& usage) const;
void doOperation();

View File

@@ -254,11 +254,6 @@ public:
void set(osg::Node* model);
virtual void accept(osgGA::GUIEventHandlerVisitor& v) { v.visit(*this); }
/** Event traversal node callback method.*/
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
virtual void getUsage(osg::ApplicationUsage& usage) const;

View File

@@ -43,10 +43,10 @@ class OSGVIEWER_EXPORT ViewConfig : public osg::Object
ViewConfig(const ViewConfig& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osg::Object(rhs,copyop) {}
META_Object(osgViewer,ViewConfig);
/** configure method that is overridden by Config subclasses.*/
virtual void configure(osgViewer::View& /*view*/) const {}
/** convinience method for getting the relavent display settings to use.*/
virtual osg::DisplaySettings* getActiveDisplaySetting(osgViewer::View& view) const;
};
@@ -129,7 +129,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/** Get the const View's image pager.*/
const osgDB::ImagePager* getImagePager() const;
/** Add a Device.
* The Device is polled on each new frame via it's Device::checkEvents() method and any events generated then collected via Device::getEventQueue()*/
void addDevice(osgGA::Device* eventSource);
@@ -167,13 +167,13 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
void home();
typedef std::list< osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlers;
typedef std::list< osg::ref_ptr<osgGA::EventHandler> > EventHandlers;
/** Add an EventHandler that adds handling of events to the View.*/
void addEventHandler(osgGA::GUIEventHandler* eventHandler);
void addEventHandler(osgGA::EventHandler* eventHandler);
/** Remove an EventHandler from View.*/
void removeEventHandler(osgGA::GUIEventHandler* eventHandler);
void removeEventHandler(osgGA::EventHandler* eventHandler);
/** Get the View's list of EventHandlers.*/
EventHandlers& getEventHandlers() { return _eventHandlers; }
@@ -216,14 +216,14 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/** Get the FusionDistanceValue. Note, only used for USE_FUSION_DISTANCE_VALUE & PROPORTIONAL_TO_SCREEN_DISTANCE modes.*/
float getFusionDistanceValue() const { return _fusionDistanceValue; }
/** Apply a viewer configuration to set up Cameras and Windowing. */
void apply(ViewConfig* config);
ViewConfig* getLastAppliedViewConfig() { return _lastAppliedViewConfig.get(); }
const ViewConfig* getLastAppliedViewConfig() const { return _lastAppliedViewConfig.get(); }
/** deprecated, use view.apply(new osgViewer::AcrossAllWindows()). */
void setUpViewAcrossAllScreens();
@@ -242,7 +242,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/** deprecated. use view.apply(new osgViewer::WoWVxDisplay(type (20 to 42), screenNum). */
void setUpViewForWoWVxDisplay(unsigned int screenNum, unsigned char wow_content, unsigned char wow_factor, unsigned char wow_offset, float wow_disparity_Zd, float wow_disparity_vz, float wow_disparity_M, float wow_disparity_C);
/** Convenience method for setting up depth partitioning on the specified camera.*/
bool setUpDepthPartitionForCamera(osg::Camera* cameraToPartition, DepthPartitionSettings* dps=0);
@@ -254,7 +254,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/** Return true if this view contains a specified camera.*/
bool containsCamera(const osg::Camera* camera) const;
/** deprecated. */
const osg::Camera* getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const;
@@ -264,14 +264,14 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/** deprecated. */
bool computeIntersections(float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
/** Compute intersections of a ray, starting the current mouse position, through the specified camera. */
bool computeIntersections(const osgGA::GUIEventAdapter& ea, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
/** Compute intersections of a ray, starting the current mouse position, through the specified master camera's window/eye coordinates and a specified nodePath's subgraph. */
bool computeIntersections(const osgGA::GUIEventAdapter& ea, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
/** Compute intersections of a ray through the specified camera. */
bool computeIntersections(const osg::Camera* camera, osgUtil::Intersector::CoordinateFrame cf, float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
@@ -284,7 +284,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
public:
osg::Texture* createDistortionTexture(int width, int height);
osg::Camera* assignRenderToTextureCamera(osg::GraphicsContext* gc, int width, int height, osg::Texture* texture);
osg::Camera* assignKeystoneDistortionCamera(osg::DisplaySettings* ds, osg::GraphicsContext* gc, int x, int y, int width, int height, GLenum buffer, osg::Texture* texture, Keystone* keystone);
@@ -300,7 +300,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
osg::ref_ptr<osg::DisplaySettings> _ds;
double _eyeScale;
};
public:
@@ -334,7 +334,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
float _fusionDistanceValue;
osg::ref_ptr<ViewConfig> _lastAppliedViewConfig;
};
}