Implemented Widget::handle, handleImplementation, traverse and travseImplementation() wrappers to enable them to be extended via scripting
This commit is contained in:
@@ -190,6 +190,14 @@ void Widget::traverse(osg::NodeVisitor& nv)
|
|||||||
osg::CallbackObject* co = osg::getCallbackObject(this, "traverse");
|
osg::CallbackObject* co = osg::getCallbackObject(this, "traverse");
|
||||||
if (co)
|
if (co)
|
||||||
{
|
{
|
||||||
|
// currently lua scripting takes a ref count so messes up handling of NodeVisitor's created on stack,
|
||||||
|
// so don't attempt to call the sctipt.
|
||||||
|
if (nv.referenceCount()==0)
|
||||||
|
{
|
||||||
|
traverseImplementation(nv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
osg::Parameters inputParameters, outputParameters;
|
osg::Parameters inputParameters, outputParameters;
|
||||||
inputParameters.push_back(&nv);
|
inputParameters.push_back(&nv);
|
||||||
co->run(this, inputParameters, outputParameters);
|
co->run(this, inputParameters, outputParameters);
|
||||||
@@ -204,6 +212,7 @@ void Widget::traverseImplementation(osg::NodeVisitor& nv)
|
|||||||
{
|
{
|
||||||
if (!_graphicsInitialized && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR) createGraphics();
|
if (!_graphicsInitialized && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR) createGraphics();
|
||||||
|
|
||||||
|
|
||||||
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv);
|
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv);
|
||||||
if (ev)
|
if (ev)
|
||||||
{
|
{
|
||||||
@@ -236,18 +245,17 @@ bool Widget::handle(osgGA::EventVisitor* ev, osgGA::Event* event)
|
|||||||
osg::CallbackObject* co = osg::getCallbackObject(this, "handle");
|
osg::CallbackObject* co = osg::getCallbackObject(this, "handle");
|
||||||
if (co)
|
if (co)
|
||||||
{
|
{
|
||||||
|
// currently lua scripting takes a ref count so messes up handling of NodeVisitor's created on stack,
|
||||||
|
// so don't attempt to call the sctipt.
|
||||||
|
if (ev->referenceCount()==0)
|
||||||
|
{
|
||||||
|
return handleImplementation(ev, event);
|
||||||
|
}
|
||||||
|
|
||||||
osg::Parameters inputParameters, outputParameters;
|
osg::Parameters inputParameters, outputParameters;
|
||||||
inputParameters.push_back(ev);
|
inputParameters.push_back(ev);
|
||||||
inputParameters.push_back(event);
|
inputParameters.push_back(event);
|
||||||
if (co->run(this, inputParameters, outputParameters))
|
return co->run(this, inputParameters, outputParameters) && outputParameters.size()>=1;
|
||||||
{
|
|
||||||
if (outputParameters.size()>=1)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -255,7 +263,7 @@ bool Widget::handle(osgGA::EventVisitor* ev, osgGA::Event* event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Widget::handleImplementation(osgGA::EventVisitor* /*ev*/, osgGA::Event* /*event*/)
|
bool Widget::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,58 @@ struct LeaveImplementation : public osgDB::MethodObject
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct Traverse : public osgDB::MethodObject
|
||||||
|
{
|
||||||
|
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters&) const
|
||||||
|
{
|
||||||
|
osgGA::Widget* widget = reinterpret_cast<osgGA::Widget*>(objectPtr);
|
||||||
|
osg::NodeVisitor* nv = (inputParameters.size()>=1) ? dynamic_cast<osg::NodeVisitor*>(inputParameters[0].get()) : 0;
|
||||||
|
if (!nv) return false;
|
||||||
|
widget->traverse(*nv);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TraverseImplementation : public osgDB::MethodObject
|
||||||
|
{
|
||||||
|
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters&) const
|
||||||
|
{
|
||||||
|
osgGA::Widget* widget = reinterpret_cast<osgGA::Widget*>(objectPtr);
|
||||||
|
osg::NodeVisitor* nv = (inputParameters.size()>=1) ? dynamic_cast<osg::NodeVisitor*>(inputParameters[0].get()) : 0;
|
||||||
|
if (!nv) return false;
|
||||||
|
widget->traverseImplementation(*nv);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Handle : public osgDB::MethodObject
|
||||||
|
{
|
||||||
|
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters&) const
|
||||||
|
{
|
||||||
|
osgGA::Widget* widget = reinterpret_cast<osgGA::Widget*>(objectPtr);
|
||||||
|
osgGA::EventVisitor* ev = (inputParameters.size()>=1) ? dynamic_cast<osgGA::EventVisitor*>(inputParameters[0].get()) : 0;
|
||||||
|
osgGA::Event* event = (inputParameters.size()>=2) ? dynamic_cast<osgGA::Event*>(inputParameters[1].get()) : 0;
|
||||||
|
if (!widget || !ev || !event) return false;
|
||||||
|
widget->handle(ev, event);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct HandleImplementation : public osgDB::MethodObject
|
||||||
|
{
|
||||||
|
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters&) const
|
||||||
|
{
|
||||||
|
osgGA::Widget* widget = reinterpret_cast<osgGA::Widget*>(objectPtr);
|
||||||
|
osgGA::EventVisitor* ev = (inputParameters.size()>=1) ? dynamic_cast<osgGA::EventVisitor*>(inputParameters[0].get()) : 0;
|
||||||
|
osgGA::Event* event = (inputParameters.size()>=2) ? dynamic_cast<osgGA::Event*>(inputParameters[1].get()) : 0;
|
||||||
|
if (!widget || !ev || !event) return false;
|
||||||
|
widget->handleImplementation(ev, event);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
REGISTER_OBJECT_WRAPPER( Widget,
|
REGISTER_OBJECT_WRAPPER( Widget,
|
||||||
new osgGA::Widget,
|
new osgGA::Widget,
|
||||||
osgGA::Widget,
|
osgGA::Widget,
|
||||||
@@ -89,5 +141,10 @@ REGISTER_OBJECT_WRAPPER( Widget,
|
|||||||
ADD_METHOD_OBJECT( "leave", Leave );
|
ADD_METHOD_OBJECT( "leave", Leave );
|
||||||
ADD_METHOD_OBJECT( "leaveImplementation", LeaveImplementation );
|
ADD_METHOD_OBJECT( "leaveImplementation", LeaveImplementation );
|
||||||
|
|
||||||
|
ADD_METHOD_OBJECT( "traverse", Traverse );
|
||||||
|
ADD_METHOD_OBJECT( "traverseImplementation", TraverseImplementation );
|
||||||
|
|
||||||
|
ADD_METHOD_OBJECT( "handle", Handle );
|
||||||
|
ADD_METHOD_OBJECT( "handleImplementation", HandleImplementation );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user