2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2005-02-25 22:02:48 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* 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
|
2005-02-25 22:02:48 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2005-02-25 22:02:48 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-02-25 22:02:48 +08:00
|
|
|
* 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>
|
2014-06-06 00:26:13 +08:00
|
|
|
#include <osg/ScriptEngine>
|
2005-02-25 22:02:48 +08:00
|
|
|
|
|
|
|
#include <osgGA/GUIEventAdapter>
|
|
|
|
#include <osgGA/GUIActionAdapter>
|
2006-03-08 22:09:47 +08:00
|
|
|
#include <osgGA/EventQueue>
|
2005-02-25 22:02:48 +08:00
|
|
|
|
|
|
|
namespace osgGA {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Basic EventVisitor implementation for animating a scene.
|
|
|
|
* This visitor traverses the scene graph, calling each nodes appCallback if
|
2012-03-22 01:36:20 +08:00
|
|
|
* it exists.
|
2005-02-25 22:02:48 +08:00
|
|
|
*/
|
|
|
|
class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
EventVisitor();
|
|
|
|
virtual ~EventVisitor();
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2013-01-25 02:48:34 +08:00
|
|
|
META_NodeVisitor(osgGA, EventVisitor)
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-02-25 22:02:48 +08:00
|
|
|
void setActionAdapter(osgGA::GUIActionAdapter* actionAdapter) { _actionAdapter=actionAdapter; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-02-25 22:02:48 +08:00
|
|
|
osgGA::GUIActionAdapter* getActionAdapter() { return _actionAdapter; }
|
|
|
|
|
|
|
|
const osgGA::GUIActionAdapter* getActionAdapter() const { return _actionAdapter; }
|
|
|
|
|
2013-10-25 22:54:15 +08:00
|
|
|
void addEvent(Event* event);
|
|
|
|
void removeEvent(Event* event);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2006-03-06 04:46:59 +08:00
|
|
|
void setEventHandled(bool handled) { _handled = handled; }
|
2005-07-27 17:37:26 +08:00
|
|
|
bool getEventHandled() const { return _handled; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2006-03-08 22:09:47 +08:00
|
|
|
void setEvents(const EventQueue::Events& events) { _events = events; }
|
|
|
|
EventQueue::Events& getEvents() { return _events; }
|
|
|
|
const EventQueue::Events& getEvents() const { return _events; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2006-03-06 04:46:59 +08:00
|
|
|
public:
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-02-25 22:02:48 +08:00
|
|
|
virtual void reset();
|
|
|
|
|
|
|
|
/** During traversal each type of node calls its callbacks and its children traversed. */
|
|
|
|
virtual void apply(osg::Node& node) { handle_callbacks_and_traverse(node); }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2014-06-06 00:26:13 +08:00
|
|
|
|
|
|
|
virtual void apply(osg::Drawable& drawable)
|
|
|
|
{
|
|
|
|
osg::Callback* callback = drawable.getEventCallback();
|
|
|
|
if (callback)
|
|
|
|
{
|
|
|
|
osg::Drawable::UpdateCallback* drawable_callback = dynamic_cast<osg::Drawable::UpdateCallback*>(callback);
|
|
|
|
osg::NodeCallback* node_callback = dynamic_cast<osg::NodeCallback*>(callback);
|
|
|
|
osg::CallbackObject* callback_object = dynamic_cast<osg::CallbackObject*>(callback);
|
|
|
|
|
|
|
|
if (drawable_callback) drawable_callback->update(this,&drawable);
|
|
|
|
if (node_callback) (*node_callback)(&drawable, this);
|
|
|
|
|
|
|
|
if ((!drawable_callback && !node_callback) || callback_object) callback_object->run(&drawable, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
handle_callbacks(drawable.getStateSet());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void apply(osg::Geode& node) { handle_callbacks_and_traverse(node); }
|
|
|
|
virtual void apply(osg::Billboard& node) { handle_callbacks_and_traverse(node); }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-02-25 22:02:48 +08:00
|
|
|
virtual void apply(osg::LightSource& node) { handle_callbacks_and_traverse(node); }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-02-25 22:02:48 +08:00
|
|
|
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:
|
|
|
|
|
|
|
|
/** Prevent unwanted copy operator.*/
|
|
|
|
EventVisitor& operator = (const EventVisitor&) { return *this; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-04-25 19:05:02 +08:00
|
|
|
inline void handle_callbacks(osg::StateSet* stateset)
|
|
|
|
{
|
|
|
|
if (stateset && stateset->requiresEventTraversal())
|
|
|
|
{
|
|
|
|
stateset->runEventCallbacks(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-25 22:02:48 +08:00
|
|
|
inline void handle_callbacks_and_traverse(osg::Node& node)
|
|
|
|
{
|
2005-04-25 19:05:02 +08:00
|
|
|
handle_callbacks(node.getStateSet());
|
|
|
|
|
2014-06-06 00:26:13 +08:00
|
|
|
osg::Callback* callback = node.getEventCallback();
|
|
|
|
if (callback) callback->run(&node,this);
|
|
|
|
else if (node.getNumChildrenRequiringUpdateTraversal()>0) traverse(node);
|
2005-02-25 22:02:48 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
|
|
|
|
2006-03-06 04:46:59 +08:00
|
|
|
osgGA::GUIActionAdapter* _actionAdapter;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2006-03-06 04:46:59 +08:00
|
|
|
osg::ref_ptr<GUIEventAdapter> _accumulateEventState;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2006-03-06 04:46:59 +08:00
|
|
|
bool _handled;
|
2006-03-08 22:09:47 +08:00
|
|
|
EventQueue::Events _events;
|
2005-02-25 22:02:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|