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

@ -202,7 +202,8 @@ void DataConverter::write(CameraPacket& cameraPacket)
itr != cameraPacket._events.end(); itr != cameraPacket._events.end();
++itr) ++itr)
{ {
write(*(*itr)); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (event) write(*(event));
} }
} }

View File

@ -54,11 +54,6 @@ bool PointsEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActio
return false; return false;
} }
void PointsEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
{
v.visit(*this);
}
void PointsEventHandler::getUsage(osg::ApplicationUsage& usage) const void PointsEventHandler::getUsage(osg::ApplicationUsage& usage) const
{ {
usage.addKeyboardMouseBinding("+","Increase point size"); usage.addKeyboardMouseBinding("+","Increase point size");

View File

@ -25,8 +25,6 @@ class PointsEventHandler : public osgGA::GUIEventHandler
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&); virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
virtual void accept(osgGA::GUIEventHandlerVisitor& v);
void getUsage(osg::ApplicationUsage& usage) const; void getUsage(osg::ApplicationUsage& usage) const;
void setStateSet(osg::StateSet* stateset) { _stateset=stateset; } void setStateSet(osg::StateSet* stateset) { _stateset=stateset; }

View File

@ -52,12 +52,6 @@ bool ShowEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
return false; return false;
} }
void ShowEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
{
v.visit(*this);
}
void ShowEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const void ShowEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const
{ {
} }

View File

@ -29,8 +29,6 @@ class ShowEventHandler : public osgGA::GUIEventHandler
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv); 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; virtual void getUsage(osg::ApplicationUsage& usage) const;
}; };

View File

@ -139,22 +139,13 @@ struct ExampleTimelineUsage : public osgGA::GUIEventHandler
} }
_releaseKey = false; _releaseKey = false;
} }
traverse(node, nv);
} }
else else
{ {
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv); osgGA::GUIEventHandler::operator()(node, nv);
if (ev && ev->getActionAdapter() && !ev->getEvents().empty())
{
for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin();
itr != ev->getEvents().end();
++itr)
{
handleWithCheckAgainstIgnoreHandledEventsMask(*(*itr), *(ev->getActionAdapter()), node, nv);
} }
} }
}
traverse(node, nv);
}
}; };

View File

@ -376,7 +376,8 @@ class DataConverter
itr != cameraPacket._events.end(); itr != cameraPacket._events.end();
++itr) ++itr)
{ {
write(*(*itr)); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (event) write(*event);
} }
} }

View File

@ -163,6 +163,9 @@ class OSGGA_EXPORT CameraManipulator : public GUIEventHandler
*/ */
virtual void init(const GUIEventAdapter& ,GUIActionAdapter&) {} 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. */ /** Handle events, return true if handled, false otherwise. */
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us); virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);

View File

@ -38,7 +38,7 @@ class OSGGA_EXPORT Device : public osg::Object
int getCapabilities() const { return _capabilities; } int getCapabilities() const { return _capabilities; }
virtual bool checkEvents() { return _eventQueue.valid() ? !(getEventQueue()->empty()) : false; } 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); virtual void sendEvents(const EventQueue::Events& events);
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; } void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }

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,7 +33,7 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
EventQueue(GUIEventAdapter::MouseYOrientation mouseYOrientation=GUIEventAdapter::Y_INCREASING_DOWNWARDS); 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 bool empty() const
{ {
@ -57,7 +57,7 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
void appendEvents(Events& events); void appendEvents(Events& events);
/** Add an event to the end of the event queue.*/ /** 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 /** Specify if mouse coordinates should be transformed into a pre defined input range, or whether they

View File

@ -51,16 +51,12 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
const osgGA::GUIActionAdapter* getActionAdapter() const { return _actionAdapter; } const osgGA::GUIActionAdapter* getActionAdapter() const { return _actionAdapter; }
void addEvent(Event* event);
typedef std::list< osg::ref_ptr<GUIEventAdapter> > EventList; void removeEvent(Event* event);
void addEvent(GUIEventAdapter* event);
void removeEvent(GUIEventAdapter* event);
void setEventHandled(bool handled) { _handled = handled; } void setEventHandled(bool handled) { _handled = handled; }
bool getEventHandled() const { return _handled; } bool getEventHandled() const { return _handled; }
void setEvents(const EventQueue::Events& events) { _events = events; } void setEvents(const EventQueue::Events& events) { _events = events; }
EventQueue::Events& getEvents() { return _events; } EventQueue::Events& getEvents() { return _events; }
const EventQueue::Events& getEvents() const { return _events; } const EventQueue::Events& getEvents() const { return _events; }
@ -137,7 +133,6 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
bool _handled; bool _handled;
EventQueue::Events _events; EventQueue::Events _events;
}; };
} }

View File

@ -11,13 +11,14 @@
* OpenSceneGraph Public License for more details. * OpenSceneGraph Public License for more details.
*/ */
#ifndef OSGGA_EVENT #ifndef OSGGA_GUIEVENTADAPTER
#define OSGGA_EVENT 1 #define OSGGA_GUIEVENTADAPTER 1
#include <osg/Object> #include <osg/Object>
#include <osg/Matrix> #include <osg/Matrix>
#include <osg/GraphicsContext> #include <osg/GraphicsContext>
#include <osgGA/Export>
#include <osgGA/Event>
namespace osgGA{ namespace osgGA{
@ -77,7 +78,7 @@ struct PointerData : public osg::Referenced
/** Event class for storing Keyboard, mouse and window events. /** Event class for storing Keyboard, mouse and window events.
*/ */
class OSGGA_EXPORT GUIEventAdapter : public osg::Object class OSGGA_EXPORT GUIEventAdapter : public Event
{ {
public: public:
@ -448,6 +449,9 @@ public:
META_Object(osgGA, GUIEventAdapter); META_Object(osgGA, GUIEventAdapter);
virtual GUIEventAdapter* asGUIEventAdapter() { return this; }
virtual const GUIEventAdapter* asGUIEventAdapter() const { return this; }
/** Get the accumulated event state singleton. /** Get the accumulated event state singleton.
* Typically all EventQueue will share this single GUIEventAdapter object for tracking * Typically all EventQueue will share this single GUIEventAdapter object for tracking
@ -467,12 +471,6 @@ public:
/** get the event type. */ /** get the event type. */
virtual EventType getEventType() const { return _eventType; } 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. */ /** deprecated function for getting time of event. */
double time() const { return _time; } double time() const { return _time; }
@ -709,7 +707,6 @@ public:
mutable bool _handled; mutable bool _handled;
EventType _eventType; EventType _eventType;
double _time;
osg::observer_ptr<osg::GraphicsContext> _context; osg::observer_ptr<osg::GraphicsContext> _context;
int _windowX; int _windowX;

View File

@ -20,7 +20,7 @@
#include <osg/Drawable> #include <osg/Drawable>
#include <osg/ApplicationUsage> #include <osg/ApplicationUsage>
#include <osgGA/Export> #include <osgGA/EventHandler>
#include <osgGA/GUIEventAdapter> #include <osgGA/GUIEventAdapter>
#include <osgGA/GUIActionAdapter> #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: 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() : _ignoreHandledEventsMask(GUIEventAdapter::NONE) {}
GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop): GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::NodeCallback(eh, copyop), EventHandler(eh, copyop)
osg::Drawable::EventCallback(eh, copyop),
_ignoreHandledEventsMask(eh._ignoreHandledEventsMask) {} _ignoreHandledEventsMask(eh._ignoreHandledEventsMask) {}
#endif
META_Object(osgGA,GUIEventHandler); META_Object(osgGA,GUIEventHandler);
/** Event traversal node callback method.*/ /** Handle event. Override the handle(..) method in your event handlers to respond to events. */
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv);
/** Event traversal drawable callback method.*/
virtual void event(osg::NodeVisitor* nv, osg::Drawable* drawable);
/** Handle events, return true if handled, false otherwise. */ /** Handle events, return true if handled, false otherwise. */
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*) { return handle(ea,aa); } 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 /** 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. * 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(,,,) * Note, this method is an inline method, and not appropriate for users to override, override the handle(,,,)
@ -86,10 +89,11 @@ public:
return false; return false;
} }
} }
#endif
/** Deprecated, Handle events, return true if handled, false otherwise. */ /** Deprecated, Handle events, return true if handled, false otherwise. */
virtual bool handle(const GUIEventAdapter&,GUIActionAdapter&) { return false; } 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 /** 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. * 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(,) * 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 */ /** Set a mask of osgGA::GUIEeventAdapter::Event to be ignored if marked as handled */
void setIgnoreHandledEventsMask(unsigned int mask) { _ignoreHandledEventsMask = mask; } void setIgnoreHandledEventsMask(unsigned int mask) { _ignoreHandledEventsMask = mask; }
@ -120,18 +121,8 @@ public:
protected: protected:
unsigned int _ignoreHandledEventsMask; unsigned int _ignoreHandledEventsMask;
};
#ifdef USE_DEPRECATED_API
// keep for backwards compatibility
class GUIEventHandlerVisitor
{
public:
void visit(GUIEventHandler&) {}
};
#endif #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 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; virtual void getUsage(osg::ApplicationUsage& usage) const;
void doOperation(); 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 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; virtual void getUsage(osg::ApplicationUsage& usage) const;
void doOperation(); void doOperation();

View File

@ -254,11 +254,6 @@ public:
void set(osg::Node* model); 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 bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
virtual void getUsage(osg::ApplicationUsage& usage) const; virtual void getUsage(osg::ApplicationUsage& usage) const;

View File

@ -167,13 +167,13 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
void home(); 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.*/ /** 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.*/ /** Remove an EventHandler from View.*/
void removeEventHandler(osgGA::GUIEventHandler* eventHandler); void removeEventHandler(osgGA::EventHandler* eventHandler);
/** Get the View's list of EventHandlers.*/ /** Get the View's list of EventHandlers.*/
EventHandlers& getEventHandlers() { return _eventHandlers; } EventHandlers& getEventHandlers() { return _eventHandlers; }

View File

@ -372,7 +372,6 @@ bool PropertyInterface::copyPropertyObjectFromObject(const osg::Object* object,
{ {
if (areTypesCompatible(valueType, sourceType)) if (areTypesCompatible(valueType, sourceType))
{ {
OSG_NOTICE<<"Calling get"<<std::endl;
return serializer->get(*object, valuePtr); return serializer->get(*object, valuePtr);
} }
else else
@ -396,7 +395,6 @@ bool PropertyInterface::copyPropertyObjectToObject(osg::Object* object, const st
{ {
if (areTypesCompatible(valueType, destinationType)) if (areTypesCompatible(valueType, destinationType))
{ {
OSG_NOTICE<<"Calling set"<<std::endl;
return serializer->set(*object, const_cast<void*>(valuePtr)); return serializer->set(*object, const_cast<void*>(valuePtr));
} }
else else

View File

@ -11,6 +11,8 @@ SET(TARGET_H
${HEADER_PATH}/AnimationPathManipulator ${HEADER_PATH}/AnimationPathManipulator
${HEADER_PATH}/DriveManipulator ${HEADER_PATH}/DriveManipulator
${HEADER_PATH}/Device ${HEADER_PATH}/Device
${HEADER_PATH}/Event
${HEADER_PATH}/EventHandler
${HEADER_PATH}/EventQueue ${HEADER_PATH}/EventQueue
${HEADER_PATH}/EventVisitor ${HEADER_PATH}/EventVisitor
${HEADER_PATH}/Export ${HEADER_PATH}/Export
@ -38,6 +40,8 @@ SET(TARGET_SRC
AnimationPathManipulator.cpp AnimationPathManipulator.cpp
DriveManipulator.cpp DriveManipulator.cpp
Device.cpp Device.cpp
Event.cpp
EventHandler.cpp
EventQueue.cpp EventQueue.cpp
EventVisitor.cpp EventVisitor.cpp
FirstPersonManipulator.cpp FirstPersonManipulator.cpp

View File

@ -28,7 +28,7 @@ Device::Device(const Device& es, const osg::CopyOp& copyop):
setEventQueue(new EventQueue); setEventQueue(new EventQueue);
} }
void Device::sendEvent(const GUIEventAdapter& /*event*/) void Device::sendEvent(const Event& /*event*/)
{ {
OSG_WARN << "Device::sendEvent not implemented!" << std::endl; OSG_WARN << "Device::sendEvent not implemented!" << std::endl;
} }

25
src/osgGA/Event.cpp Normal file
View File

@ -0,0 +1,25 @@
/* -*-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.
*/
#include <osgGA/Event>
using namespace osgGA;
Event::Event():
_time(0.0)
{}
Event::Event(const Event& rhs, const osg::CopyOp& copyop):
osg::Object(rhs, copyop),
_time(rhs._time)
{}

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.
*/
#include <osgGA/GUIEventHandler>
#include <osgGA/EventVisitor>
using namespace osgGA;
void EventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv)
{
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv);
if (ev && ev->getActionAdapter() && !ev->getEvents().empty())
{
for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin();
itr != ev->getEvents().end();
++itr)
{
handle(itr->get(), node, nv);
}
}
if (node->getNumChildrenRequiringEventTraversal()>0 || _nestedCallback.valid()) traverse(node,nv);
}
void EventHandler::event(osg::NodeVisitor* nv, osg::Drawable* drawable)
{
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv);
if (ev && ev->getActionAdapter() && !ev->getEvents().empty())
{
for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin();
itr != ev->getEvents().end();
++itr)
{
handle(itr->get(), drawable, nv);
}
}
}
bool EventHandler::handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv)
{
OSG_NOTICE<<"Handle event "<<event<<std::endl;
return false;
}

View File

@ -51,7 +51,7 @@ void EventQueue::appendEvents(Events& events)
_eventQueue.insert(_eventQueue.end(), events.begin(), events.end()); _eventQueue.insert(_eventQueue.end(), events.begin(), events.end());
} }
void EventQueue::addEvent(GUIEventAdapter* event) void EventQueue::addEvent(Event* event)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex); OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);
_eventQueue.push_back(event); _eventQueue.push_back(event);

View File

@ -28,14 +28,14 @@ EventVisitor::~EventVisitor()
{ {
} }
void EventVisitor::addEvent(GUIEventAdapter* event) void EventVisitor::addEvent(Event* event)
{ {
_events.push_back(event); _events.push_back(event);
} }
void EventVisitor::removeEvent(GUIEventAdapter* event) void EventVisitor::removeEvent(Event* event)
{ {
EventList::iterator itr = std::find(_events.begin(),_events.end(),event); EventQueue::Events::iterator itr = std::find(_events.begin(), _events.end(), event);
if (itr!=_events.end()) _events.erase(itr); if (itr!=_events.end()) _events.erase(itr);
} }

View File

@ -25,7 +25,6 @@ osg::ref_ptr<GUIEventAdapter>& GUIEventAdapter::getAccumulatedEventState()
GUIEventAdapter::GUIEventAdapter(): GUIEventAdapter::GUIEventAdapter():
_handled(false), _handled(false),
_eventType(NONE), _eventType(NONE),
_time(0.0),
_windowX(0), _windowX(0),
_windowY(0), _windowY(0),
_windowWidth(1280), _windowWidth(1280),
@ -48,10 +47,9 @@ GUIEventAdapter::GUIEventAdapter():
{} {}
GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs,const osg::CopyOp& copyop): GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs,const osg::CopyOp& copyop):
osg::Object(rhs,copyop), osgGA::Event(rhs,copyop),
_handled(rhs._handled), _handled(rhs._handled),
_eventType(rhs._eventType), _eventType(rhs._eventType),
_time(rhs._time),
_context(rhs._context), _context(rhs._context),
_windowX(rhs._windowX), _windowX(rhs._windowX),
_windowY(rhs._windowY), _windowY(rhs._windowY),

View File

@ -16,33 +16,21 @@
using namespace osgGA; using namespace osgGA;
// adapt EventHandler usage to old style GUIEventHandler usage
void GUIEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv) bool GUIEventHandler::handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv)
{ {
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv); osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv);
if (ev && ev->getActionAdapter() && !ev->getEvents().empty()) osgGA::GUIEventAdapter* ea = event->asGUIEventAdapter();
if (ea && ev && ev->getActionAdapter())
{ {
for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin(); #if 1
itr != ev->getEvents().end(); bool handled = handle(*ea, *(ev->getActionAdapter()), object, nv);
++itr) if (handled) ea->setHandled(true);
{ return handled;
handleWithCheckAgainstIgnoreHandledEventsMask(*(*itr), *(ev->getActionAdapter()), node, nv); #else
} return handleWithCheckAgainstIgnoreHandledEventsMask(*ea, *(ev->getActionAdapter()), object, nv);
} #endif
if (node->getNumChildrenRequiringEventTraversal()>0 || _nestedCallback.valid()) traverse(node,nv);
}
void GUIEventHandler::event(osg::NodeVisitor* nv, osg::Drawable* drawable)
{
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv);
if (ev && ev->getActionAdapter() && !ev->getEvents().empty())
{
for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin();
itr != ev->getEvents().end();
++itr)
{
handleWithCheckAgainstIgnoreHandledEventsMask(*(*itr), *(ev->getActionAdapter()), drawable, nv);
}
} }
return false;
} }

View File

@ -305,8 +305,8 @@ void Dragger::traverse(osg::NodeVisitor& nv)
itr != ev->getEvents().end(); itr != ev->getEvents().end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* ea = itr->get(); osgGA::GUIEventAdapter* ea = (*itr)->asGUIEventAdapter();
if (handle(*ea, *(ev->getActionAdapter()))) ea->setHandled(true); if (ea && handle(*ea, *(ev->getActionAdapter()))) ea->setHandled(true);
} }
} }
return; return;

View File

@ -187,7 +187,9 @@ void Cursor::traverse(osg::NodeVisitor& nv)
itr != events.end(); itr != events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (!event) continue;
switch(event->getEventType()) switch(event->getEventType())
{ {
case(osgGA::GUIEventAdapter::PUSH): case(osgGA::GUIEventAdapter::PUSH):

View File

@ -65,12 +65,6 @@ bool KeyEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAd
return false; return false;
} }
void KeyEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
{
v.visit(*this);
}
void KeyEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const void KeyEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const
{ {
} }

View File

@ -131,12 +131,6 @@ bool PickEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
return false; return false;
} }
void PickEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
{
v.visit(*this);
}
void PickEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const void PickEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const
{ {
} }

View File

@ -967,25 +967,6 @@ double SlideEventHandler::getCurrentTimeDelayBetweenSlides() const
return _timePerSlide; return _timePerSlide;
} }
void SlideEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv)
{
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv);
if (ev)
{
if (node->getNumChildrenRequiringEventTraversal()>0) traverse(node,nv);
if (ev->getActionAdapter() && !ev->getEvents().empty())
{
for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin();
itr != ev->getEvents().end();
++itr)
{
handleWithCheckAgainstIgnoreHandledEventsMask(*(*itr), *(ev->getActionAdapter()), node, nv);
}
}
}
}
bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa) bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
{ {

View File

@ -257,7 +257,8 @@ void Timeout::traverse(osg::NodeVisitor& nv)
itr != events.end(); itr != events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (!event) continue;
bool keyEvent = event->getEventType()==osgGA::GUIEventAdapter::KEYDOWN || event->getEventType()==osgGA::GUIEventAdapter::KEYUP; bool keyEvent = event->getEventType()==osgGA::GUIEventAdapter::KEYDOWN || event->getEventType()==osgGA::GUIEventAdapter::KEYUP;

View File

@ -916,7 +916,7 @@ void CompositeViewer::reprojectPointerData(osgGA::GUIEventAdapter& source_event,
struct SortEvents struct SortEvents
{ {
bool operator() (const osg::ref_ptr<osgGA::GUIEventAdapter>& lhs,const osg::ref_ptr<osgGA::GUIEventAdapter>& rhs) const bool operator() (const osg::ref_ptr<osgGA::Event>& lhs,const osg::ref_ptr<osgGA::Event>& rhs) const
{ {
return lhs->getTime() < rhs->getTime(); return lhs->getTime() < rhs->getTime();
} }
@ -961,7 +961,8 @@ void CompositeViewer::eventTraversal()
itr != gw_events.end(); itr != gw_events.end();
++itr) ++itr)
{ {
(*itr)->setGraphicsContext(gw); osgGA::GUIEventAdapter* ea = (*itr)->asGUIEventAdapter();
if (ea) ea->setGraphicsContext(gw);
} }
all_events.insert(all_events.end(), gw_events.begin(), gw_events.end()); all_events.insert(all_events.end(), gw_events.begin(), gw_events.end());
@ -976,7 +977,8 @@ void CompositeViewer::eventTraversal()
itr != all_events.end(); itr != all_events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (!event) continue;
switch(event->getEventType()) switch(event->getEventType())
{ {
@ -1059,7 +1061,9 @@ void CompositeViewer::eventTraversal()
itr != all_events.end(); itr != all_events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (!event) continue;
switch(event->getEventType()) switch(event->getEventType())
{ {
case(osgGA::GUIEventAdapter::CLOSE_WINDOW): case(osgGA::GUIEventAdapter::CLOSE_WINDOW):
@ -1118,7 +1122,8 @@ void CompositeViewer::eventTraversal()
itr != veitr->second.end(); itr != veitr->second.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (!event) continue;
switch(event->getEventType()) switch(event->getEventType())
{ {
case(osgGA::GUIEventAdapter::KEYUP): case(osgGA::GUIEventAdapter::KEYUP):
@ -1148,16 +1153,15 @@ void CompositeViewer::eventTraversal()
++veitr) ++veitr)
{ {
View* view = veitr->first; View* view = veitr->first;
_eventVisitor->setActionAdapter(view);
if (view && view->getSceneData()) if (view && view->getSceneData())
{ {
_eventVisitor->setActionAdapter(view);
for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin(); for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin();
itr != veitr->second.end(); itr != veitr->second.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::Event* event = itr->get();
_eventVisitor->reset(); _eventVisitor->reset();
_eventVisitor->addEvent( event ); _eventVisitor->addEvent( event );
@ -1205,18 +1209,18 @@ void CompositeViewer::eventTraversal()
++veitr) ++veitr)
{ {
View* view = veitr->first; View* view = veitr->first;
_eventVisitor->setActionAdapter(view);
for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin(); for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin();
itr != veitr->second.end(); itr != veitr->second.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::Event* event = itr->get();
for(View::EventHandlers::iterator hitr = view->getEventHandlers().begin(); for(View::EventHandlers::iterator hitr = view->getEventHandlers().begin();
hitr != view->getEventHandlers().end(); hitr != view->getEventHandlers().end();
++hitr) ++hitr)
{ {
(*hitr)->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *view, 0, _eventVisitor.get()); (*hitr)->handle( event, view, _eventVisitor.get());
} }
} }
} }
@ -1226,16 +1230,16 @@ void CompositeViewer::eventTraversal()
++veitr) ++veitr)
{ {
View* view = veitr->first; View* view = veitr->first;
_eventVisitor->setActionAdapter(view);
for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin(); for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin();
itr != veitr->second.end(); itr != veitr->second.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::Event* event = itr->get();
if (view->getCameraManipulator()) if (view->getCameraManipulator())
{ {
view->getCameraManipulator()->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *view); view->getCameraManipulator()->handle( event, view, _eventVisitor.get());
} }
} }
} }

View File

@ -395,7 +395,7 @@ void View::home()
} }
void View::addEventHandler(osgGA::GUIEventHandler* eventHandler) void View::addEventHandler(osgGA::EventHandler* eventHandler)
{ {
EventHandlers::iterator itr = std::find(_eventHandlers.begin(), _eventHandlers.end(), eventHandler); EventHandlers::iterator itr = std::find(_eventHandlers.begin(), _eventHandlers.end(), eventHandler);
if (itr == _eventHandlers.end()) if (itr == _eventHandlers.end())
@ -404,7 +404,7 @@ void View::addEventHandler(osgGA::GUIEventHandler* eventHandler)
} }
} }
void View::removeEventHandler(osgGA::GUIEventHandler* eventHandler) void View::removeEventHandler(osgGA::EventHandler* eventHandler)
{ {
EventHandlers::iterator itr = std::find(_eventHandlers.begin(), _eventHandlers.end(), eventHandler); EventHandlers::iterator itr = std::find(_eventHandlers.begin(), _eventHandlers.end(), eventHandler);
if (itr != _eventHandlers.end()) if (itr != _eventHandlers.end())

View File

@ -889,7 +889,8 @@ void Viewer::eventTraversal()
itr != gw_events.end(); itr != gw_events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (!event) continue;
event->setGraphicsContext(gw); event->setGraphicsContext(gw);
@ -943,7 +944,8 @@ void Viewer::eventTraversal()
itr != gw_events.end(); itr != gw_events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (!event) continue;
switch(event->getEventType()) switch(event->getEventType())
{ {
case(osgGA::GUIEventAdapter::CLOSE_WINDOW): case(osgGA::GUIEventAdapter::CLOSE_WINDOW):
@ -981,7 +983,8 @@ void Viewer::eventTraversal()
itr != events.end(); itr != events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (!event) continue;
switch(event->getEventType()) switch(event->getEventType())
{ {
case(osgGA::GUIEventAdapter::KEYUP): case(osgGA::GUIEventAdapter::KEYUP):
@ -1009,7 +1012,8 @@ void Viewer::eventTraversal()
itr != events.end(); itr != events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (!event) continue;
_eventVisitor->reset(); _eventVisitor->reset();
_eventVisitor->addEvent( event ); _eventVisitor->addEvent( event );
@ -1055,13 +1059,12 @@ void Viewer::eventTraversal()
itr != events.end(); itr != events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::Event* event = itr->get();
for(EventHandlers::iterator hitr = _eventHandlers.begin(); for(EventHandlers::iterator hitr = _eventHandlers.begin();
hitr != _eventHandlers.end(); hitr != _eventHandlers.end();
++hitr) ++hitr)
{ {
(*hitr)->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *this, 0, _eventVisitor.get()); (*hitr)->handle( event, 0, _eventVisitor.get());
} }
} }
@ -1070,10 +1073,10 @@ void Viewer::eventTraversal()
itr != events.end(); itr != events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::Event* event = itr->get();
if (_cameraManipulator.valid()) if (event && _cameraManipulator.valid())
{ {
_cameraManipulator->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *this); _cameraManipulator->handle( event, 0, _eventVisitor.get());
} }
} }