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:
parent
2025c511f0
commit
4a660f6266
@ -202,7 +202,8 @@ void DataConverter::write(CameraPacket& cameraPacket)
|
||||
itr != cameraPacket._events.end();
|
||||
++itr)
|
||||
{
|
||||
write(*(*itr));
|
||||
osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
|
||||
if (event) write(*(event));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,11 +54,6 @@ bool PointsEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActio
|
||||
return false;
|
||||
}
|
||||
|
||||
void PointsEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
|
||||
{
|
||||
v.visit(*this);
|
||||
}
|
||||
|
||||
void PointsEventHandler::getUsage(osg::ApplicationUsage& usage) const
|
||||
{
|
||||
usage.addKeyboardMouseBinding("+","Increase point size");
|
||||
|
@ -25,8 +25,6 @@ class PointsEventHandler : public osgGA::GUIEventHandler
|
||||
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
|
||||
|
||||
virtual void accept(osgGA::GUIEventHandlerVisitor& v);
|
||||
|
||||
void getUsage(osg::ApplicationUsage& usage) const;
|
||||
|
||||
void setStateSet(osg::StateSet* stateset) { _stateset=stateset; }
|
||||
|
@ -52,12 +52,6 @@ bool ShowEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ShowEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
|
||||
{
|
||||
v.visit(*this);
|
||||
}
|
||||
|
||||
void ShowEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const
|
||||
{
|
||||
}
|
||||
|
@ -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 void accept(osgGA::GUIEventHandlerVisitor& v);
|
||||
|
||||
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
||||
|
||||
};
|
||||
|
@ -139,21 +139,12 @@ struct ExampleTimelineUsage : public osgGA::GUIEventHandler
|
||||
}
|
||||
_releaseKey = false;
|
||||
}
|
||||
traverse(node, nv);
|
||||
}
|
||||
else
|
||||
{
|
||||
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()), node, nv);
|
||||
}
|
||||
}
|
||||
osgGA::GUIEventHandler::operator()(node, nv);
|
||||
}
|
||||
traverse(node, nv);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -376,7 +376,8 @@ class DataConverter
|
||||
itr != cameraPacket._events.end();
|
||||
++itr)
|
||||
{
|
||||
write(*(*itr));
|
||||
osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
|
||||
if (event) write(*event);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -38,7 +38,7 @@ class OSGGA_EXPORT Device : public osg::Object
|
||||
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; }
|
||||
|
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,7 +33,7 @@ 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
|
||||
{
|
||||
@ -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
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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; }
|
||||
|
@ -372,7 +372,6 @@ bool PropertyInterface::copyPropertyObjectFromObject(const osg::Object* object,
|
||||
{
|
||||
if (areTypesCompatible(valueType, sourceType))
|
||||
{
|
||||
OSG_NOTICE<<"Calling get"<<std::endl;
|
||||
return serializer->get(*object, valuePtr);
|
||||
}
|
||||
else
|
||||
@ -396,7 +395,6 @@ bool PropertyInterface::copyPropertyObjectToObject(osg::Object* object, const st
|
||||
{
|
||||
if (areTypesCompatible(valueType, destinationType))
|
||||
{
|
||||
OSG_NOTICE<<"Calling set"<<std::endl;
|
||||
return serializer->set(*object, const_cast<void*>(valuePtr));
|
||||
}
|
||||
else
|
||||
|
@ -11,6 +11,8 @@ SET(TARGET_H
|
||||
${HEADER_PATH}/AnimationPathManipulator
|
||||
${HEADER_PATH}/DriveManipulator
|
||||
${HEADER_PATH}/Device
|
||||
${HEADER_PATH}/Event
|
||||
${HEADER_PATH}/EventHandler
|
||||
${HEADER_PATH}/EventQueue
|
||||
${HEADER_PATH}/EventVisitor
|
||||
${HEADER_PATH}/Export
|
||||
@ -38,6 +40,8 @@ SET(TARGET_SRC
|
||||
AnimationPathManipulator.cpp
|
||||
DriveManipulator.cpp
|
||||
Device.cpp
|
||||
Event.cpp
|
||||
EventHandler.cpp
|
||||
EventQueue.cpp
|
||||
EventVisitor.cpp
|
||||
FirstPersonManipulator.cpp
|
||||
|
@ -28,7 +28,7 @@ Device::Device(const Device& es, const osg::CopyOp& copyop):
|
||||
setEventQueue(new EventQueue);
|
||||
}
|
||||
|
||||
void Device::sendEvent(const GUIEventAdapter& /*event*/)
|
||||
void Device::sendEvent(const Event& /*event*/)
|
||||
{
|
||||
OSG_WARN << "Device::sendEvent not implemented!" << std::endl;
|
||||
}
|
||||
|
25
src/osgGA/Event.cpp
Normal file
25
src/osgGA/Event.cpp
Normal 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)
|
||||
{}
|
52
src/osgGA/EventHandler.cpp
Normal file
52
src/osgGA/EventHandler.cpp
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.
|
||||
*/
|
||||
|
||||
#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;
|
||||
}
|
@ -51,7 +51,7 @@ void EventQueue::appendEvents(Events& events)
|
||||
_eventQueue.insert(_eventQueue.end(), events.begin(), events.end());
|
||||
}
|
||||
|
||||
void EventQueue::addEvent(GUIEventAdapter* event)
|
||||
void EventQueue::addEvent(Event* event)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);
|
||||
_eventQueue.push_back(event);
|
||||
|
@ -28,14 +28,14 @@ EventVisitor::~EventVisitor()
|
||||
{
|
||||
}
|
||||
|
||||
void EventVisitor::addEvent(GUIEventAdapter* event)
|
||||
void EventVisitor::addEvent(Event* 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);
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@ osg::ref_ptr<GUIEventAdapter>& GUIEventAdapter::getAccumulatedEventState()
|
||||
GUIEventAdapter::GUIEventAdapter():
|
||||
_handled(false),
|
||||
_eventType(NONE),
|
||||
_time(0.0),
|
||||
_windowX(0),
|
||||
_windowY(0),
|
||||
_windowWidth(1280),
|
||||
@ -48,10 +47,9 @@ GUIEventAdapter::GUIEventAdapter():
|
||||
{}
|
||||
|
||||
GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs,const osg::CopyOp& copyop):
|
||||
osg::Object(rhs,copyop),
|
||||
osgGA::Event(rhs,copyop),
|
||||
_handled(rhs._handled),
|
||||
_eventType(rhs._eventType),
|
||||
_time(rhs._time),
|
||||
_context(rhs._context),
|
||||
_windowX(rhs._windowX),
|
||||
_windowY(rhs._windowY),
|
||||
|
@ -16,33 +16,21 @@
|
||||
|
||||
using namespace osgGA;
|
||||
|
||||
|
||||
void GUIEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
// adapt EventHandler usage to old style GUIEventHandler usage
|
||||
bool GUIEventHandler::handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* 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();
|
||||
itr != ev->getEvents().end();
|
||||
++itr)
|
||||
{
|
||||
handleWithCheckAgainstIgnoreHandledEventsMask(*(*itr), *(ev->getActionAdapter()), node, nv);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
#if 1
|
||||
bool handled = handle(*ea, *(ev->getActionAdapter()), object, nv);
|
||||
if (handled) ea->setHandled(true);
|
||||
return handled;
|
||||
#else
|
||||
return handleWithCheckAgainstIgnoreHandledEventsMask(*ea, *(ev->getActionAdapter()), object, nv);
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -305,8 +305,8 @@ void Dragger::traverse(osg::NodeVisitor& nv)
|
||||
itr != ev->getEvents().end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* ea = itr->get();
|
||||
if (handle(*ea, *(ev->getActionAdapter()))) ea->setHandled(true);
|
||||
osgGA::GUIEventAdapter* ea = (*itr)->asGUIEventAdapter();
|
||||
if (ea && handle(*ea, *(ev->getActionAdapter()))) ea->setHandled(true);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
@ -187,7 +187,9 @@ void Cursor::traverse(osg::NodeVisitor& nv)
|
||||
itr != events.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
|
||||
if (!event) continue;
|
||||
|
||||
switch(event->getEventType())
|
||||
{
|
||||
case(osgGA::GUIEventAdapter::PUSH):
|
||||
|
@ -65,12 +65,6 @@ bool KeyEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAd
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void KeyEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
|
||||
{
|
||||
v.visit(*this);
|
||||
}
|
||||
|
||||
void KeyEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const
|
||||
{
|
||||
}
|
||||
|
@ -131,12 +131,6 @@ bool PickEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void PickEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
|
||||
{
|
||||
v.visit(*this);
|
||||
}
|
||||
|
||||
void PickEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const
|
||||
{
|
||||
}
|
||||
|
@ -967,25 +967,6 @@ double SlideEventHandler::getCurrentTimeDelayBetweenSlides() const
|
||||
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)
|
||||
{
|
||||
|
||||
|
@ -257,7 +257,8 @@ void Timeout::traverse(osg::NodeVisitor& nv)
|
||||
itr != events.end();
|
||||
++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;
|
||||
|
||||
|
@ -916,7 +916,7 @@ void CompositeViewer::reprojectPointerData(osgGA::GUIEventAdapter& source_event,
|
||||
|
||||
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();
|
||||
}
|
||||
@ -961,7 +961,8 @@ void CompositeViewer::eventTraversal()
|
||||
itr != gw_events.end();
|
||||
++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());
|
||||
@ -976,7 +977,8 @@ void CompositeViewer::eventTraversal()
|
||||
itr != all_events.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
|
||||
if (!event) continue;
|
||||
|
||||
switch(event->getEventType())
|
||||
{
|
||||
@ -1059,7 +1061,9 @@ void CompositeViewer::eventTraversal()
|
||||
itr != all_events.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
|
||||
if (!event) continue;
|
||||
|
||||
switch(event->getEventType())
|
||||
{
|
||||
case(osgGA::GUIEventAdapter::CLOSE_WINDOW):
|
||||
@ -1118,7 +1122,8 @@ void CompositeViewer::eventTraversal()
|
||||
itr != veitr->second.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
|
||||
if (!event) continue;
|
||||
switch(event->getEventType())
|
||||
{
|
||||
case(osgGA::GUIEventAdapter::KEYUP):
|
||||
@ -1148,16 +1153,15 @@ void CompositeViewer::eventTraversal()
|
||||
++veitr)
|
||||
{
|
||||
View* view = veitr->first;
|
||||
_eventVisitor->setActionAdapter(view);
|
||||
|
||||
if (view && view->getSceneData())
|
||||
{
|
||||
_eventVisitor->setActionAdapter(view);
|
||||
|
||||
for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin();
|
||||
itr != veitr->second.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
osgGA::Event* event = itr->get();
|
||||
|
||||
_eventVisitor->reset();
|
||||
_eventVisitor->addEvent( event );
|
||||
@ -1205,18 +1209,18 @@ void CompositeViewer::eventTraversal()
|
||||
++veitr)
|
||||
{
|
||||
View* view = veitr->first;
|
||||
_eventVisitor->setActionAdapter(view);
|
||||
|
||||
for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin();
|
||||
itr != veitr->second.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
|
||||
osgGA::Event* event = itr->get();
|
||||
for(View::EventHandlers::iterator hitr = view->getEventHandlers().begin();
|
||||
hitr != view->getEventHandlers().end();
|
||||
++hitr)
|
||||
{
|
||||
(*hitr)->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *view, 0, _eventVisitor.get());
|
||||
(*hitr)->handle( event, view, _eventVisitor.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1226,16 +1230,16 @@ void CompositeViewer::eventTraversal()
|
||||
++veitr)
|
||||
{
|
||||
View* view = veitr->first;
|
||||
_eventVisitor->setActionAdapter(view);
|
||||
|
||||
for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin();
|
||||
itr != veitr->second.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
|
||||
osgGA::Event* event = itr->get();
|
||||
if (view->getCameraManipulator())
|
||||
{
|
||||
view->getCameraManipulator()->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *view);
|
||||
view->getCameraManipulator()->handle( event, view, _eventVisitor.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
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);
|
||||
if (itr != _eventHandlers.end())
|
||||
|
@ -889,7 +889,8 @@ void Viewer::eventTraversal()
|
||||
itr != gw_events.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
|
||||
if (!event) continue;
|
||||
|
||||
event->setGraphicsContext(gw);
|
||||
|
||||
@ -943,7 +944,8 @@ void Viewer::eventTraversal()
|
||||
itr != gw_events.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
|
||||
if (!event) continue;
|
||||
switch(event->getEventType())
|
||||
{
|
||||
case(osgGA::GUIEventAdapter::CLOSE_WINDOW):
|
||||
@ -981,7 +983,8 @@ void Viewer::eventTraversal()
|
||||
itr != events.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
|
||||
if (!event) continue;
|
||||
switch(event->getEventType())
|
||||
{
|
||||
case(osgGA::GUIEventAdapter::KEYUP):
|
||||
@ -1009,7 +1012,8 @@ void Viewer::eventTraversal()
|
||||
itr != events.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
|
||||
if (!event) continue;
|
||||
|
||||
_eventVisitor->reset();
|
||||
_eventVisitor->addEvent( event );
|
||||
@ -1055,13 +1059,12 @@ void Viewer::eventTraversal()
|
||||
itr != events.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
|
||||
osgGA::Event* event = itr->get();
|
||||
for(EventHandlers::iterator hitr = _eventHandlers.begin();
|
||||
hitr != _eventHandlers.end();
|
||||
++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)
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
if (_cameraManipulator.valid())
|
||||
osgGA::Event* event = itr->get();
|
||||
if (event && _cameraManipulator.valid())
|
||||
{
|
||||
_cameraManipulator->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *this);
|
||||
_cameraManipulator->handle( event, 0, _eventVisitor.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user