From 569973afa739d1f7ac942424828ca133facfa88b Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 3 Aug 2012 21:34:48 +0200 Subject: [PATCH] CHANGED: #1471 Implemented property setting for CCtrlButton. --HG-- branch : gsoc2012-gui-editor --- code/nel/include/nel/gui/ctrl_button.h | 3 + code/nel/src/gui/ctrl_button.cpp | 94 ++++++++++++++++++++++---- 2 files changed, 83 insertions(+), 14 deletions(-) diff --git a/code/nel/include/nel/gui/ctrl_button.h b/code/nel/include/nel/gui/ctrl_button.h index 4fc44ae02..ac832421f 100644 --- a/code/nel/include/nel/gui/ctrl_button.h +++ b/code/nel/include/nel/gui/ctrl_button.h @@ -43,7 +43,10 @@ namespace NLGUI _Align = 0; } + void setAlignFromString( const std::string &s ); + std::string getProperty( const std::string &name ) const; + void setProperty( const std::string &name, const std::string &value ); // Init part virtual bool parse (xmlNodePtr cur,CInterfaceGroup * parentGroup); diff --git a/code/nel/src/gui/ctrl_button.cpp b/code/nel/src/gui/ctrl_button.cpp index 6fcf5f8ee..108e99e16 100644 --- a/code/nel/src/gui/ctrl_button.cpp +++ b/code/nel/src/gui/ctrl_button.cpp @@ -28,6 +28,36 @@ NLMISC_REGISTER_OBJECT(CViewBase, CCtrlButton, std::string, "button"); 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 { if( name == "tx_normal" ) @@ -67,6 +97,55 @@ namespace NLGUI 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) { @@ -115,22 +194,9 @@ namespace NLGUI prop = (char*) xmlGetProp (cur, (xmlChar*)"align"); - _Align = 0; if (prop) { - const char *seekPtr = prop.getDatas(); - 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; - } + setAlignFromString( std::string( prop ) ); }