CHANGED: #1471 Implemented property setting for CCtrlButton.

This commit is contained in:
dfighter1985 2012-08-03 21:34:48 +02:00
parent b5c8726553
commit dce0640024
2 changed files with 83 additions and 14 deletions

View file

@ -43,7 +43,10 @@ namespace NLGUI
_Align = 0; _Align = 0;
} }
void setAlignFromString( const std::string &s );
std::string getProperty( const std::string &name ) const; std::string getProperty( const std::string &name ) const;
void setProperty( const std::string &name, const std::string &value );
// Init part // Init part
virtual bool parse (xmlNodePtr cur,CInterfaceGroup * parentGroup); virtual bool parse (xmlNodePtr cur,CInterfaceGroup * parentGroup);

View file

@ -28,6 +28,36 @@ NLMISC_REGISTER_OBJECT(CViewBase, CCtrlButton, std::string, "button");
namespace NLGUI namespace NLGUI
{ {
void CCtrlButton::setAlignFromString( const std::string &s )
{
_Align = 0;
std::string::size_type i;
for( i = 0; i < s.size(); i++ )
{
char c = toLower( s[ i ] );
switch( c ){
case 'l':
_Align &= ~1;
break;
case 'r':
_Align |= 1;
break;
case 'b':
_Align &= ~2;
break;
case 't':
_Align |= 2;
break;
}
}
}
std::string CCtrlButton::getProperty( const std::string &name ) const std::string CCtrlButton::getProperty( const std::string &name ) const
{ {
if( name == "tx_normal" ) if( name == "tx_normal" )
@ -67,6 +97,55 @@ namespace NLGUI
return CCtrlBaseButton::getProperty( name ); return CCtrlBaseButton::getProperty( name );
} }
void CCtrlButton::setProperty( const std::string &name, const std::string &value )
{
if( name == "tx_normal" )
{
std::string s = CViewRenderer::getInstance()->getTextureNameFromId( _TextureIdNormal );
if( !_TextureIdNormal.setTexture( value.c_str() ) )
{
_TextureIdNormal.setTexture( s.c_str() );
}
return;
}
else
if( name == "tx_pushed" )
{
std::string s = CViewRenderer::getInstance()->getTextureNameFromId( _TextureIdPushed );
if( !_TextureIdPushed.setTexture( value.c_str() ) )
{
_TextureIdPushed.setTexture( s.c_str() );
}
return;
}
else
if( name == "tx_over" )
{
std::string s = CViewRenderer::getInstance()->getTextureNameFromId( _TextureIdOver );
if( !_TextureIdOver.setTexture( value.c_str() ) )
{
_TextureIdOver.setTexture( s.c_str() );
}
return;
}
else
if( name == "scale" )
{
bool b;
if( fromString( value, b ) )
_Scale = b;
return;
}
else
if( name == "align" )
{
setAlignFromString( value );
return;
}
else
CCtrlBaseButton::setProperty( name, value );
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool CCtrlButton::parse(xmlNodePtr cur, CInterfaceGroup * parentGroup) bool CCtrlButton::parse(xmlNodePtr cur, CInterfaceGroup * parentGroup)
{ {
@ -115,22 +194,9 @@ namespace NLGUI
prop = (char*) xmlGetProp (cur, (xmlChar*)"align"); prop = (char*) xmlGetProp (cur, (xmlChar*)"align");
_Align = 0;
if (prop) if (prop)
{ {
const char *seekPtr = prop.getDatas(); setAlignFromString( std::string( prop ) );
while (*seekPtr != 0)
{
if ((*seekPtr=='l')||(*seekPtr=='L'))
_Align &= ~1;
if ((*seekPtr=='r')||(*seekPtr=='R'))
_Align |= 1;
if ((*seekPtr=='b')||(*seekPtr=='B'))
_Align &= ~2;
if ((*seekPtr=='t')||(*seekPtr=='T'))
_Align |= 2;
++seekPtr;
}
} }