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:
@@ -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);
|
||||
@@ -425,7 +425,7 @@ GUIEventAdapter* EventQueue::touchBegan(unsigned int id, GUIEventAdapter::Touch
|
||||
event->addTouchPoint(id, phase, x, y, 0);
|
||||
if(_firstTouchEmulatesMouse)
|
||||
event->setButton(GUIEventAdapter::LEFT_MOUSE_BUTTON);
|
||||
|
||||
|
||||
addEvent(event);
|
||||
|
||||
return event;
|
||||
@@ -464,7 +464,7 @@ GUIEventAdapter* EventQueue::touchEnded(unsigned int id, GUIEventAdapter::Touch
|
||||
event->addTouchPoint(id, phase, x, y, tap_count);
|
||||
if(_firstTouchEmulatesMouse)
|
||||
event->setButton(GUIEventAdapter::LEFT_MOUSE_BUTTON);
|
||||
|
||||
|
||||
addEvent(event);
|
||||
|
||||
return event;
|
||||
@@ -495,7 +495,7 @@ void EventQueue::frame(double time)
|
||||
GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState);
|
||||
event->setEventType(GUIEventAdapter::FRAME);
|
||||
event->setTime(time);
|
||||
|
||||
|
||||
// OSG_NOTICE<<"frame("<<time<<"), event->getX()="<<event->getX()<<", event->getY()="<<event->getY()<<", event->getXmin()="<<event->getXmin()<<", event->getYmin()="<<event->getYmin()<<", event->getXmax()="<<event->getXmax()<<", event->getYmax()="<<event->getYmax()<<std::endl;
|
||||
|
||||
addEvent(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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user