Added osg::CallbackObject suport to the experiment Widget base class to enable script language extension of widgets

This commit is contained in:
Robert Osfield
2014-02-06 17:04:40 +00:00
parent 99eb81e743
commit 958a7d0ab0
5 changed files with 101 additions and 14 deletions

View File

@@ -120,12 +120,12 @@ void TransferFunctionWidget::scaleVisibleRange(float center, float delta)
}
void TransferFunctionWidget::traverse(osg::NodeVisitor& nv)
void TransferFunctionWidget::traverseImplementation(osg::NodeVisitor& nv)
{
Widget::traverse(nv);
Widget::traverseImplementation(nv);
}
bool TransferFunctionWidget::handle(osgGA::EventVisitor* ev, osgGA::Event* event)
bool TransferFunctionWidget::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event)
{
osgGA::GUIEventAdapter* ea = event->asGUIEventAdapter();
if (!ea) return false;
@@ -222,7 +222,7 @@ bool TransferFunctionWidget::handle(osgGA::EventVisitor* ev, osgGA::Event* event
return false;
}
void TransferFunctionWidget::createGraphics()
void TransferFunctionWidget::createGraphicsImplementation()
{
// OSG_NOTICE<<"Create graphics"<<std::endl;
@@ -390,5 +390,5 @@ void TransferFunctionWidget::createGraphics()
_geometry->dirtyBound();
// make sure the general widget geometry/state is created and _graphicsInitialized reset to false
Widget::createGraphics();
Widget::createGraphicsImplementation();
}

View File

@@ -31,9 +31,9 @@ public:
TransferFunctionWidget(const TransferFunctionWidget& tfw, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Node(osgUI, TransferFunctionWidget);
void traverse(osg::NodeVisitor& nv);
virtual void traverseImplementation(osg::NodeVisitor& nv);
virtual bool handle(osgGA::EventVisitor* ev, osgGA::Event* event);
virtual bool handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event);
void setTransferFunction(const osg::TransferFunction1D* tf);
osg::TransferFunction1D* getTransferFunction() { return _transferFunction.get(); }
@@ -44,7 +44,7 @@ public:
void translateVisibleRange(float delta);
void scaleVisibleRange(float center, float delta);
virtual void createGraphics();
virtual void createGraphicsImplementation();
protected:
virtual ~TransferFunctionWidget() {}

View File

@@ -14,6 +14,7 @@
#include "Widget.h"
#include <osg/Geode>
#include <osg/ScriptEngine>
#include <osg/Geometry>
#include <osg/MatrixTransform>
#include <osg/io_utils>
@@ -149,16 +150,57 @@ bool Widget::getHasEventFocus() const
}
void Widget::enter()
{
osg::CallbackObject* co = osg::getCallbackObject(this, "enter");
if (co)
{
co->run(this);
}
else
{
enterImplementation();
}
}
void Widget::enterImplementation()
{
OSG_NOTICE<<"enter()"<<std::endl;
}
void Widget::leave()
{
osg::CallbackObject* co = osg::getCallbackObject(this, "leave");
if (co)
{
co->run(this);
}
else
{
leaveImplementation();
}
}
void Widget::leaveImplementation()
{
OSG_NOTICE<<"leave()"<<std::endl;
}
void Widget::traverse(osg::NodeVisitor& nv)
{
osg::CallbackObject* co = osg::getCallbackObject(this, "traverse");
if (co)
{
osg::Parameters inputParameters, outputParameters;
inputParameters.push_back(&nv);
co->run(this, inputParameters, outputParameters);
}
else
{
traverseImplementation(nv);
}
}
void Widget::traverseImplementation(osg::NodeVisitor& nv)
{
if (!_graphicsInitialized && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR) createGraphics();
@@ -190,7 +232,31 @@ void Widget::traverse(osg::NodeVisitor& nv)
}
}
bool Widget::handle(osgGA::EventVisitor* /*ev*/, osgGA::Event* /*event*/)
bool Widget::handle(osgGA::EventVisitor* ev, osgGA::Event* event)
{
osg::CallbackObject* co = osg::getCallbackObject(this, "handle");
if (co)
{
osg::Parameters inputParameters, outputParameters;
inputParameters.push_back(ev);
inputParameters.push_back(event);
if (co->run(this, inputParameters, outputParameters))
{
if (outputParameters.size()>=1)
{
return true;
}
}
return false;
}
else
{
return handleImplementation(ev, event);
}
}
bool Widget::handleImplementation(osgGA::EventVisitor* /*ev*/, osgGA::Event* /*event*/)
{
return false;
}
@@ -213,6 +279,20 @@ bool Widget::computePositionInLocalCoordinates(osgGA::EventVisitor* ev, osgGA::G
void Widget::createGraphics()
{
osg::CallbackObject* co = osg::getCallbackObject(this, "createGraphics");
if (co)
{
co->run(this);
}
else
{
createGraphicsImplementation();
}
}
void Widget::createGraphicsImplementation()
{
_graphicsInitialized = true;
}

View File

@@ -32,12 +32,15 @@ public:
META_Node(osgUI, Widget);
virtual void traverse(osg::NodeVisitor& nv);
virtual void traverseImplementation(osg::NodeVisitor& nv);
virtual bool handle(osgGA::EventVisitor* ev, osgGA::Event* event);
virtual bool handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event);
virtual bool computePositionInLocalCoordinates(osgGA::EventVisitor* ev, osgGA::GUIEventAdapter* event, osg::Vec3& localPosition) const;
virtual void createGraphics();
virtual void createGraphicsImplementation();
virtual void setExtents(const osg::BoundingBox& bb);
const osg::BoundingBox& getExtents() const { return _extents; }
@@ -63,14 +66,17 @@ public:
virtual osg::BoundingSphere computeBound() const;
protected:
virtual ~Widget() {}
/** update any focus related graphics+state to the focused state.*/
virtual void enter();
virtual void enterImplementation();
/** update any focus related graphics+state to the unfocused state.*/
virtual void leave();
virtual void leaveImplementation();
protected:
virtual ~Widget() {}
FocusBehaviour _focusBehaviour;
bool _hasEventFocus;

View File

@@ -420,6 +420,7 @@ int main(int argc, char ** argv)
copyobject->myMethod();
#endif
#if 0
osg::ref_ptr<osg::Object> object = osgDB::readNodeFile("load.lua");
if (object.valid())
{
@@ -441,10 +442,10 @@ int main(int argc, char ** argv)
}
}
return 0;
#endif
#if 0
#if 1
osgViewer::Viewer viewer(arguments);
viewer.addEventHandler(new osgViewer::StatsHandler());