Refactored Callback system in osg::Node, osg::Drawable, osg::StateSet and osg::StateAttribute to use a new osg::Callback base class.
git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14244 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/Drawable>
|
||||
#include <osg/ApplicationUsage>
|
||||
|
||||
@@ -37,12 +36,20 @@ public:
|
||||
|
||||
EventHandler() {}
|
||||
EventHandler(const EventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
osg::Object(eh,copyop),
|
||||
osg::Callback(eh,copyop),
|
||||
osg::NodeCallback(eh, copyop),
|
||||
osg::Drawable::EventCallback(eh, copyop) {}
|
||||
|
||||
META_Object(osgGA, EventHandler);
|
||||
|
||||
virtual bool run(osg::Object* object, osg::Object* data)
|
||||
{
|
||||
osg::Node* node = dynamic_cast<osg::Node*>(object);
|
||||
osg::NodeVisitor* nv = dynamic_cast<osg::NodeVisitor*>(data);
|
||||
operator()(node, nv);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** 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);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <osg/Transform>
|
||||
#include <osg/Projection>
|
||||
#include <osg/OccluderNode>
|
||||
#include <osg/ScriptEngine>
|
||||
|
||||
#include <osgGA/GUIEventAdapter>
|
||||
#include <osgGA/GUIActionAdapter>
|
||||
@@ -68,8 +69,27 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
|
||||
/** During traversal each type of node calls its callbacks and its children traversed. */
|
||||
virtual void apply(osg::Node& node) { handle_callbacks_and_traverse(node); }
|
||||
|
||||
virtual void apply(osg::Geode& node) { handle_geode_callbacks(node); }
|
||||
virtual void apply(osg::Billboard& node) { handle_geode_callbacks(node); }
|
||||
|
||||
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); }
|
||||
|
||||
virtual void apply(osg::LightSource& node) { handle_callbacks_and_traverse(node); }
|
||||
|
||||
@@ -98,34 +118,11 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
|
||||
{
|
||||
handle_callbacks(node.getStateSet());
|
||||
|
||||
osg::NodeCallback* callback = node.getEventCallback();
|
||||
if (callback) (*callback)(&node,this);
|
||||
else if (node.getNumChildrenRequiringEventTraversal()>0) traverse(node);
|
||||
osg::Callback* callback = node.getEventCallback();
|
||||
if (callback) callback->run(&node,this);
|
||||
else if (node.getNumChildrenRequiringUpdateTraversal()>0) traverse(node);
|
||||
}
|
||||
|
||||
inline void handle_geode_callbacks(osg::Geode& node)
|
||||
{
|
||||
handle_callbacks(node.getStateSet());
|
||||
|
||||
osg::NodeCallback* callback = node.getEventCallback();
|
||||
if (callback) (*callback)(&node,this);
|
||||
/*else if (node.getNumChildrenRequiringEventTraversal()>0)*/
|
||||
traverseGeode(node);
|
||||
}
|
||||
|
||||
inline void traverseGeode(osg::Geode& geode)
|
||||
{
|
||||
traverse((osg::Node&)geode);
|
||||
|
||||
// Call the app callbacks on the drawables.
|
||||
for(unsigned int i=0;i<geode.getNumDrawables();++i)
|
||||
{
|
||||
osg::Drawable::EventCallback* callback = geode.getDrawable(i)->getEventCallback();
|
||||
if (callback) callback->event(this,geode.getDrawable(i));
|
||||
|
||||
handle_callbacks(geode.getDrawable(i)->getStateSet());
|
||||
}
|
||||
}
|
||||
|
||||
osgGA::GUIActionAdapter* _actionAdapter;
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/Drawable>
|
||||
#include <osg/ApplicationUsage>
|
||||
|
||||
@@ -54,7 +53,7 @@ public:
|
||||
#if 1
|
||||
GUIEventHandler() {}
|
||||
GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
osg::Object(eh, copyop), EventHandler(eh, copyop) {}
|
||||
osg::Callback(eh, copyop), EventHandler(eh, copyop) {}
|
||||
#else
|
||||
GUIEventHandler() : _ignoreHandledEventsMask(GUIEventAdapter::NONE) {}
|
||||
GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
@@ -123,7 +122,7 @@ protected:
|
||||
unsigned int _ignoreHandledEventsMask;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual ~GUIEventHandler();
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user