diff --git a/include/osgDB/ObjectWrapper b/include/osgDB/ObjectWrapper index 86d459134..56e1df68c 100644 --- a/include/osgDB/ObjectWrapper +++ b/include/osgDB/ObjectWrapper @@ -249,8 +249,6 @@ protected: typedef CLASS MyClass; \ void wrapper_propfunc_##NAME(const char* domain, osgDB::ObjectWrapper* wrapper) -#define ADD_METHOD_OBJECT( METHODNAME, METHODOBJECTCLASS ) wrapper->addMethodObject(METHODNAME, new METHODOBJECTCLASS()); - class OSGDB_EXPORT RegisterCompressorProxy { public: diff --git a/include/osgDB/Serializer b/include/osgDB/Serializer index 835e651ad..43b6e4d79 100644 --- a/include/osgDB/Serializer +++ b/include/osgDB/Serializer @@ -1703,6 +1703,22 @@ public: #define REMOVE_SERIALIZER(PROP) \ wrapper->markSerializerAsRemoved( #PROP ); +#define ADD_METHOD_OBJECT( METHODNAME, METHODOBJECTCLASS ) wrapper->addMethodObject(METHODNAME, new METHODOBJECTCLASS()); + +#define ADD_METHOD(METHODNAME) \ + { \ + struct MethodCaller : public osgDB::MethodObject \ + { \ + virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const \ + { \ + MyClass* obj = reinterpret_cast(objectPtr); \ + obj->METHODNAME(); \ + return true; \ + } \ + }; \ + wrapper->addMethodObject(#METHODNAME, new MethodCaller()); \ + } + } #endif diff --git a/include/osgUI/PushButton b/include/osgUI/PushButton index 966ba2092..a7c969faf 100644 --- a/include/osgUI/PushButton +++ b/include/osgUI/PushButton @@ -37,6 +37,13 @@ public: virtual void enterImplementation(); virtual void leaveImplementation(); + virtual void pressed() { if (!runCallbacks("pressed")) pressedImplementation(); } + virtual void pressedImplementation(); + + virtual void released() { if (!runCallbacks("released")) releasedImplementation(); } + virtual void releasedImplementation(); + + protected: virtual ~PushButton() {} diff --git a/src/osgUI/PushButton.cpp b/src/osgUI/PushButton.cpp index fc6c1b49c..879e210fb 100644 --- a/src/osgUI/PushButton.cpp +++ b/src/osgUI/PushButton.cpp @@ -40,15 +40,13 @@ bool PushButton::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* eve case(osgGA::GUIEventAdapter::PUSH): if (_buttonSwitch.valid()) { - _buttonSwitch->setSingleChildOn(2); - runCallbacks("pressed"); + pressed(); } break; case(osgGA::GUIEventAdapter::RELEASE): if (_buttonSwitch.valid()) { - _buttonSwitch->setSingleChildOn(1); - runCallbacks("released"); + released(); } break; default: @@ -107,3 +105,13 @@ void PushButton::createGraphicsImplementation() } } + +void PushButton::pressedImplementation() +{ + _buttonSwitch->setSingleChildOn(2); +} + +void PushButton::releasedImplementation() +{ + _buttonSwitch->setSingleChildOn(1); +} diff --git a/src/osgWrappers/serializers/osgUI/PushButton.cpp b/src/osgWrappers/serializers/osgUI/PushButton.cpp index 2f8550ae4..a2d1e5f27 100644 --- a/src/osgWrappers/serializers/osgUI/PushButton.cpp +++ b/src/osgWrappers/serializers/osgUI/PushButton.cpp @@ -11,4 +11,8 @@ REGISTER_OBJECT_WRAPPER( PushButton, "osg::Object osg::Node osg::Group osgUI::Widget osgUI::PushButton" ) { ADD_STRING_SERIALIZER( Text, std::string()); + ADD_METHOD( pressed ); + ADD_METHOD( pressedImplementation ); + ADD_METHOD( released ); + ADD_METHOD( releasedImplementation ); } diff --git a/src/osgWrappers/serializers/osgUI/Widget.cpp b/src/osgWrappers/serializers/osgUI/Widget.cpp index 1e701f441..f84c6ff71 100644 --- a/src/osgWrappers/serializers/osgUI/Widget.cpp +++ b/src/osgWrappers/serializers/osgUI/Widget.cpp @@ -5,67 +5,6 @@ #include -struct CreateGraphics : public osgDB::MethodObject -{ - virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const - { - osgUI::Widget* widget = reinterpret_cast(objectPtr); - widget->createGraphics(); - return true; - } -}; - -struct CreateGraphicsImplementation : public osgDB::MethodObject -{ - virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const - { - osgUI::Widget* widget = reinterpret_cast(objectPtr); - widget->createGraphicsImplementation(); - return true; - } -}; - -struct Enter : public osgDB::MethodObject -{ - virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const - { - osgUI::Widget* widget = reinterpret_cast(objectPtr); - widget->enter(); - return true; - } -}; - -struct EnterImplementation : public osgDB::MethodObject -{ - virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const - { - osgUI::Widget* widget = reinterpret_cast(objectPtr); - widget->enterImplementation(); - return true; - } -}; - -struct Leave : public osgDB::MethodObject -{ - virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const - { - osgUI::Widget* widget = reinterpret_cast(objectPtr); - widget->leave(); - return true; - } -}; - -struct LeaveImplementation : public osgDB::MethodObject -{ - virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const - { - osgUI::Widget* widget = reinterpret_cast(objectPtr); - widget->leaveImplementation(); - return true; - } -}; - - struct Traverse : public osgDB::MethodObject { virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters&) const @@ -137,14 +76,14 @@ REGISTER_OBJECT_WRAPPER( Widget, ADD_OBJECT_SERIALIZER( TextSettings, osgUI::TextSettings, NULL ); - ADD_METHOD_OBJECT( "createGraphics", CreateGraphics ); - ADD_METHOD_OBJECT( "createGraphicsImplementation", CreateGraphicsImplementation ); + ADD_METHOD( createGraphics ); + ADD_METHOD( createGraphicsImplementation ); - ADD_METHOD_OBJECT( "enter", Enter ); - ADD_METHOD_OBJECT( "enterImplementation", EnterImplementation ); + ADD_METHOD( enter ); + ADD_METHOD( enterImplementation ); - ADD_METHOD_OBJECT( "leave", Leave ); - ADD_METHOD_OBJECT( "leaveImplementation", LeaveImplementation ); + ADD_METHOD( leave ); + ADD_METHOD( leaveImplementation ); ADD_METHOD_OBJECT( "traverse", Traverse ); ADD_METHOD_OBJECT( "traverseImplementation", TraverseImplementation );