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
This commit is contained in:
Robert Osfield
2014-02-08 17:53:51 +00:00
parent 1319c2d281
commit 3dcca431a9
4 changed files with 69 additions and 10 deletions

View File

@@ -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) )
{

View File

@@ -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<char>(b?1:0)); }
virtual void writeChar( char c ) { _str.push_back(c); }
virtual void writeUChar( unsigned char c ) { _str.push_back(static_cast<char>(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); }

View File

@@ -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("<<object<<", "<<propertyName<<") has callback object method need to call it, ref="<<lco->getRef()<<std::endl;
return 1;
}
@@ -560,6 +559,16 @@ int LuaScriptEngine::pushPropertyToStack(osg::Object* object, const std::string&
switch(type)
{
case(osgDB::BaseSerializer::RW_BOOL):
{
bool value;
if (_pi.getProperty(object, propertyName, value))
{
lua_pushboolean(_lua, value ? 1 : 0);
return 1;
}
break;
}
case(osgDB::BaseSerializer::RW_STRING):
{
std::string value;
@@ -708,11 +717,9 @@ int LuaScriptEngine::pushPropertyToStack(osg::Object* object, const std::string&
osg::Object* value = 0;
if (_pi.getProperty(object, propertyName, value))
{
OSG_NOTICE<<"Sucessful getProperty("<<object<<", "<<propertyName<<" "<<value<<std::endl;
pushObject(value);
return 1;
}
OSG_NOTICE<<"Error getProperty("<<object<<", "<<propertyName<<" "<<value<<" Failed"<<std::endl;
break;
}
default:
@@ -746,7 +753,12 @@ int LuaScriptEngine::setPropertyFromStack(osg::Object* object, const std::string
{
if (lua_isboolean(_lua, -1))
{
_pi.setProperty(object, propertyName, static_cast<bool>(lua_toboolean(_lua, -1)!=0));
_pi.setProperty(object, propertyName, static_cast<bool>(lua_toboolean(_lua, -1)));
return 0;
}
else if (lua_isnumber(_lua, -1))
{
_pi.setProperty(object, propertyName, static_cast<bool>(lua_tonumber(_lua, -1)!=0));
return 0;
}
break;

View File

@@ -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<osgGA::Widget*>(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<osgGA::Widget*>(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<osgGA::Widget*>(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<osgGA::Widget*>(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<osgGA::Widget*>(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<osgGA::Widget*>(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 );
}