EventVisitor
Go to the documentation of this file.
/* -*-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_EVENTVISITOR
#define OSGGA_EVENTVISITOR 1
#include <osg/NodeVisitor>
#include <osg/Node>
#include <osg/Geode>
#include <osg/Billboard>
#include <osg/LOD>
#include <osg/Switch>
#include <osg/LightSource>
#include <osg/Transform>
#include <osg/Projection>
#include <osg/OccluderNode>
#include <osg/ScriptEngine>
#include <osgGA/GUIEventAdapter>
#include <osgGA/GUIEventHandler>
#include <osgGA/GUIActionAdapter>
#include <osgGA/EventQueue>
namespace osgGA {
class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
{
public:
EventVisitor();
virtual ~EventVisitor();
META_NodeVisitor(osgGA, EventVisitor)
virtual osgGA::EventVisitor* asEventVisitor() { return this; }
virtual const osgGA::EventVisitor* asEventVisitor() const { return this; }
void setActionAdapter(osgGA::GUIActionAdapter* actionAdapter) { _actionAdapter=actionAdapter; }
osgGA::GUIActionAdapter* getActionAdapter() { return _actionAdapter; }
const osgGA::GUIActionAdapter* getActionAdapter() const { return _actionAdapter; }
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; }
public:
virtual void reset();
virtual void apply(osg::Node& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::Drawable& drawable)
{
osg::Callback* callback = drawable.getEventCallback();
if (callback)
{
osgGA::EventHandler* eh = callback->asEventHandler();
if (eh)
{
callback->run(&drawable,this);
}
else
{
osg::DrawableEventCallback* drawable_callback = callback->asDrawableEventCallback();
osg::NodeCallback* node_callback = callback->asNodeCallback();
osg::CallbackObject* callback_object = callback->asCallbackObject();
if (drawable_callback) drawable_callback->event(this,&drawable);
if (node_callback) (*node_callback)(&drawable, this);
if (callback_object) callback_object->run(&drawable, this);
if (!drawable_callback && !node_callback && !callback_object) callback->run(&drawable, this);
}
}
handle_callbacks(drawable.getStateSet());
}
// The following overrides are technically redundant as the default implementation would eventually trickle down to
// apply(osg::Node&); - however defining these explicitly should save a couple of virtual function calls
virtual void apply(osg::Geode& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::Billboard& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::LightSource& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::Group& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::Transform& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::Projection& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::Switch& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::LOD& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::OccluderNode& node) { handle_callbacks_and_traverse(node); }
protected:
EventVisitor& operator = (const EventVisitor&) { return *this; }
inline void handle_callbacks(osg::StateSet* stateset)
{
if (stateset && stateset->requiresEventTraversal())
{
stateset->runEventCallbacks(this);
}
}
inline void handle_callbacks_and_traverse(osg::Node& node)
{
handle_callbacks(node.getStateSet());
osg::Callback* callback = node.getEventCallback();
if (callback) callback->run(&node,this);
else if (node.getNumChildrenRequiringEventTraversal()>0) traverse(node);
}
osgGA::GUIActionAdapter* _actionAdapter;
osg::ref_ptr<GUIEventAdapter> _accumulateEventState;
bool _handled;
EventQueue::Events _events;
};
}
#endif
Billboard
EventQueue
GUIActionAdapter
GUIEventAdapter
GUIEventHandler
Geode
LOD
LightSource
NodeVisitor
Node
OccluderNode
Projection
Switch
Transform
osgGA::EventHandler
Definition EventHandler:34
osgGA::EventQueue::Events
std::list< osg::ref_ptr< Event > > Events
Definition EventQueue:36
osgGA::EventVisitor
Definition EventVisitor:42
osgGA::EventVisitor::getEventHandled
bool getEventHandled() const
Definition EventVisitor:68
osgGA::EventVisitor::reset
virtual void reset()
osgGA::EventVisitor::~EventVisitor
virtual ~EventVisitor()
osgGA::EventVisitor::apply
virtual void apply(osg::Projection &node)
Definition EventVisitor:116
osgGA::EventVisitor::getEvents
const EventQueue::Events & getEvents() const
Definition EventVisitor:72
osgGA::EventVisitor::_accumulateEventState
osg::ref_ptr< GUIEventAdapter > _accumulateEventState
Definition EventVisitor:147
osgGA::EventVisitor::getActionAdapter
osgGA::GUIActionAdapter * getActionAdapter()
Definition EventVisitor:60
osgGA::EventVisitor::setEventHandled
void setEventHandled(bool handled)
Definition EventVisitor:67
osgGA::EventVisitor::apply
virtual void apply(osg::Transform &node)
Definition EventVisitor:115
osgGA::EventVisitor::_handled
bool _handled
Definition EventVisitor:149
osgGA::EventVisitor::addEvent
void addEvent(Event *event)
osgGA::EventVisitor::apply
virtual void apply(osg::LightSource &node)
Definition EventVisitor:113
osgGA::EventVisitor::_events
EventQueue::Events _events
Definition EventVisitor:150
osgGA::EventVisitor::EventVisitor
EventVisitor()
osgGA::EventVisitor::removeEvent
void removeEvent(Event *event)
osgGA::EventVisitor::apply
virtual void apply(osg::OccluderNode &node)
Definition EventVisitor:119
osgGA::EventVisitor::getActionAdapter
const osgGA::GUIActionAdapter * getActionAdapter() const
Definition EventVisitor:62
osgGA::EventVisitor::apply
virtual void apply(osg::Node &node)
Definition EventVisitor:79
osgGA::EventVisitor::setActionAdapter
void setActionAdapter(osgGA::GUIActionAdapter *actionAdapter)
Definition EventVisitor:58
osgGA::EventVisitor::getEvents
EventQueue::Events & getEvents()
Definition EventVisitor:71
osgGA::EventVisitor::setEvents
void setEvents(const EventQueue::Events &events)
Definition EventVisitor:70
osgGA::EventVisitor::handle_callbacks
void handle_callbacks(osg::StateSet *stateset)
Definition EventVisitor:127
osgGA::EventVisitor::apply
virtual void apply(osg::Switch &node)
Definition EventVisitor:117
osgGA::EventVisitor::_actionAdapter
osgGA::GUIActionAdapter * _actionAdapter
Definition EventVisitor:145
osgGA::EventVisitor::apply
virtual void apply(osg::Billboard &node)
Definition EventVisitor:112
osgGA::EventVisitor::apply
virtual void apply(osg::Drawable &drawable)
Definition EventVisitor:82
osgGA::EventVisitor::handle_callbacks_and_traverse
void handle_callbacks_and_traverse(osg::Node &node)
Definition EventVisitor:135
osgGA::EventVisitor::apply
virtual void apply(osg::Geode &node)
Definition EventVisitor:111
osgGA::EventVisitor::META_NodeVisitor
META_NodeVisitor(osgGA, EventVisitor) virtual osgGA
Definition EventVisitor:48
osgGA::EventVisitor::apply
virtual void apply(osg::Group &node)
Definition EventVisitor:114
osgGA::EventVisitor::apply
virtual void apply(osg::LOD &node)
Definition EventVisitor:118
osgGA::EventVisitor::asEventVisitor
virtual const osgGA::EventVisitor * asEventVisitor() const
Definition EventVisitor:56
osgGA::Event
Definition Event:27
osgGA::GUIActionAdapter
Definition GUIActionAdapter:62
osg::Billboard
Definition Billboard:27
osg::CallbackObject
Definition Callback:134
osg::CallbackObject::run
bool run(osg::Object *object, osg::Object *data)
osg::Callback
Definition Callback:34
osg::Callback::asCallbackObject
virtual CallbackObject * asCallbackObject()
Definition Callback:49
osg::Callback::asEventHandler
virtual osgGA::EventHandler * asEventHandler()
Definition Callback:70
osg::Callback::asDrawableEventCallback
virtual DrawableEventCallback * asDrawableEventCallback()
Definition Callback:64
osg::Callback::run
virtual bool run(osg::Object *object, osg::Object *data)
Definition Callback:80
osg::Callback::asNodeCallback
virtual NodeCallback * asNodeCallback()
Definition Callback:52
osg::DrawableEventCallback
Definition Callback:320
osg::DrawableEventCallback::event
virtual void event(osg::NodeVisitor *, osg::Drawable *)
Definition Callback:337
osg::Drawable
Definition Drawable:89
osg::Geode
Definition Geode:29
osg::Group
Definition Group:29
osg::LOD
Definition LOD:36
osg::LightSource
Definition LightSource:25
osg::NodeCallback
Definition Callback:215
osg::NodeVisitor
Definition NodeVisitor:82
osg::NodeVisitor::traverse
void traverse(Node &node)
Definition NodeVisitor:274
osg::Node
Definition Node:72
osg::Node::getNumChildrenRequiringEventTraversal
unsigned int getNumChildrenRequiringEventTraversal() const
Definition Node:284
osg::Node::getStateSet
osg::StateSet * getStateSet()
Definition Node:382
osg::Node::getEventCallback
Callback * getEventCallback()
Definition Node:252
osg::OccluderNode
Definition OccluderNode:27
osg::Projection
Definition Projection:25
osg::StateSet
Definition StateSet:46
osg::StateSet::runEventCallbacks
void runEventCallbacks(osg::NodeVisitor *nv)
osg::StateSet::requiresEventTraversal
bool requiresEventTraversal() const
Definition StateSet:496
osg::Switch
Definition Switch:27
osg::Transform
Definition Transform:75
osg::ref_ptr
Definition ref_ptr:32
osgGA
Definition Callback:21
OSGGA_EXPORT
#define OSGGA_EXPORT
Definition osgGA/Export:40
ScriptEngine