From 3dcca431a993b16e0c3eabb24a31ca83ab1d9702 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 8 Feb 2014 17:53:51 +0000 Subject: [PATCH] Fixed handling of setting member variables via the Serializers when the value is the default. Added support for more features of the osgDB::Widget class. Fixed handling of boolean values in the Lua plugin --- include/osgDB/Serializer | 3 +- src/osgDB/PropertyInterface.cpp | 4 +- src/osgPlugins/lua/LuaScriptEngine.cpp | 20 ++++++-- src/osgWrappers/serializers/osgGA/Widget.cpp | 52 +++++++++++++++++++- 4 files changed, 69 insertions(+), 10 deletions(-) diff --git a/include/osgDB/Serializer b/include/osgDB/Serializer index b8f9c6fd8..8d73848a4 100644 --- a/include/osgDB/Serializer +++ b/include/osgDB/Serializer @@ -242,8 +242,7 @@ public: if ( is.isBinary() ) { is >> value; - if ( ParentType::_defaultValue!=value ) - (object.*_setter)( value ); + (object.*_setter)( value ); } else if ( is.matchString(ParentType::_name) ) { diff --git a/src/osgDB/PropertyInterface.cpp b/src/osgDB/PropertyInterface.cpp index 9cd41c940..b56ef3626 100644 --- a/src/osgDB/PropertyInterface.cpp +++ b/src/osgDB/PropertyInterface.cpp @@ -47,7 +47,7 @@ public: _str.insert(_str.size(), ptr, sizeof(T)); } - virtual void writeBool( bool b ) { _str.push_back(b?0:1); } + virtual void writeBool( bool b ) { _str.push_back(static_cast(b?1:0)); } virtual void writeChar( char c ) { _str.push_back(c); } virtual void writeUChar( unsigned char c ) { _str.push_back(static_cast(c)); } virtual void writeShort( short s ) { write(s); } @@ -109,7 +109,7 @@ public: _currentPtr += sizeof(T); } - virtual void readBool( bool& b ) { char c; read(c); b = (c==1);} + virtual void readBool( bool& b ) { char c; read(c); b = (c!=0); } virtual void readChar( char& c ) { read(c); } virtual void readSChar( signed char& c ) { read(c); } virtual void readUChar( unsigned char& c ) { read(c); } diff --git a/src/osgPlugins/lua/LuaScriptEngine.cpp b/src/osgPlugins/lua/LuaScriptEngine.cpp index 36aef26fa..42ff1b084 100644 --- a/src/osgPlugins/lua/LuaScriptEngine.cpp +++ b/src/osgPlugins/lua/LuaScriptEngine.cpp @@ -550,7 +550,6 @@ int LuaScriptEngine::pushPropertyToStack(osg::Object* object, const std::string& if (lco) { lua_rawgeti(_lua, LUA_REGISTRYINDEX, lco->getRef()); - OSG_NOTICE<<"LuaScriptEngine::pushPropertyToStack("<(lua_toboolean(_lua, -1)!=0)); + _pi.setProperty(object, propertyName, static_cast(lua_toboolean(_lua, -1))); + return 0; + } + else if (lua_isnumber(_lua, -1)) + { + _pi.setProperty(object, propertyName, static_cast(lua_tonumber(_lua, -1)!=0)); return 0; } break; diff --git a/src/osgWrappers/serializers/osgGA/Widget.cpp b/src/osgWrappers/serializers/osgGA/Widget.cpp index fb3e5854e..d828b0a15 100644 --- a/src/osgWrappers/serializers/osgGA/Widget.cpp +++ b/src/osgWrappers/serializers/osgGA/Widget.cpp @@ -6,7 +6,7 @@ struct CreateGraphics : public osgDB::MethodObject { - virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const + virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const { osgGA::Widget* widget = reinterpret_cast(objectPtr); widget->createGraphics(); @@ -16,7 +16,7 @@ struct CreateGraphics : public osgDB::MethodObject struct CreateGraphicsImplementation : public osgDB::MethodObject { - virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const + virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const { osgGA::Widget* widget = reinterpret_cast(objectPtr); widget->createGraphicsImplementation(); @@ -24,6 +24,45 @@ struct CreateGraphicsImplementation : public osgDB::MethodObject } }; +struct Enter : public osgDB::MethodObject +{ + virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const + { + osgGA::Widget* widget = reinterpret_cast(objectPtr); + widget->enter(); + return true; + } +}; + +struct EnterImplementation : public osgDB::MethodObject +{ + virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const + { + osgGA::Widget* widget = reinterpret_cast(objectPtr); + widget->enterImplementation(); + return true; + } +}; + +struct Leave : public osgDB::MethodObject +{ + virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const + { + osgGA::Widget* widget = reinterpret_cast(objectPtr); + widget->leave(); + return true; + } +}; + +struct LeaveImplementation : public osgDB::MethodObject +{ + virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const + { + osgGA::Widget* widget = reinterpret_cast(objectPtr); + widget->leaveImplementation(); + return true; + } +}; REGISTER_OBJECT_WRAPPER( Widget, new osgGA::Widget, @@ -36,7 +75,16 @@ REGISTER_OBJECT_WRAPPER( Widget, ADD_ENUM_VALUE( EVENT_DRIVEN_FOCUS_DISABLED ); END_ENUM_SERIALIZER(); + ADD_BOOL_SERIALIZER(HasEventFocus, false); ADD_METHOD_OBJECT( "createGraphics", CreateGraphics ); ADD_METHOD_OBJECT( "createGraphicsImplementation", CreateGraphicsImplementation ); + + ADD_METHOD_OBJECT( "enter", Enter ); + ADD_METHOD_OBJECT( "enterImplementation", EnterImplementation ); + + ADD_METHOD_OBJECT( "leave", Leave ); + ADD_METHOD_OBJECT( "leaveImplementation", LeaveImplementation ); + + }