@ -111,6 +111,8 @@ namespace NLGUI
_ClampRight = true ; // clamp on the right of the text
_ClampRight = true ; // clamp on the right of the text
_OverflowText = " ... " ;
_OverflowText = " ... " ;
_Localized = true ;
_LetterColors = NULL ;
_LetterColors = NULL ;
_Setuped = false ;
_Setuped = false ;
_AutoClampOffset = 0 ;
_AutoClampOffset = 0 ;
@ -211,7 +213,7 @@ namespace NLGUI
_Index = 0xFFFFFFFF ;
_Index = 0xFFFFFFFF ;
_ModulateGlobalColor = vt . _ModulateGlobalColor ;
_ModulateGlobalColor = vt . _ModulateGlobalColor ;
_Localized = vt . _Localized ;
// remove previous lines
// remove previous lines
clearLines ( ) ;
clearLines ( ) ;
@ -244,6 +246,11 @@ namespace NLGUI
std : : string CViewText : : getTextProperty ( const std : : string & name ) const
std : : string CViewText : : getTextProperty ( const std : : string & name ) const
{
{
if ( name = = " localize " )
{
return toString ( _Localized ) ;
}
else
if ( name = = " color " )
if ( name = = " color " )
{
{
return toString ( _Color ) ;
return toString ( _Color ) ;
@ -418,6 +425,18 @@ namespace NLGUI
bool CViewText : : setTextProperty ( const std : : string & name , const std : : string & value )
bool CViewText : : setTextProperty ( const std : : string & name , const std : : string & value )
{
{
if ( name = = " localize " )
{
bool b ;
if ( fromString ( value , b ) )
{
_Localized = b ;
setTextLocalized ( _HardText . empty ( ) ? _Text : _HardText ) ; // FIXME: setCase?
_TextLength = 0 ;
}
return true ;
}
else
if ( name = = " color " )
if ( name = = " color " )
{
{
CRGBA c ;
CRGBA c ;
@ -649,28 +668,19 @@ namespace NLGUI
return true ;
return true ;
}
}
else
else
if ( name = = " hardtext " )
if ( name = = " text " )
{
# if 1
if ( NLMISC : : startsWith ( value , " ui " ) )
{
{
_Text = CI18N : : get ( value ) ;
setTextLocalized ( value ) ; // FIXME: setCase?
_TextLength = 0 ;
_TextLength = 0 ;
_HardText = value ;
invalidateContent ( ) ;
return true ;
}
}
else
else
if ( name = = " hardtext " )
{
{
_Text = value ;
_Localized = true ;
_TextLength = 0 ;
setTextLocalized ( value ) ; // FIXME: setCase?
_HardText . clear ( ) ;
}
# else
_Text = value ;
_TextLength = 0 ;
_TextLength = 0 ;
_HardText . clear ( ) ;
if ( NLMISC : : startsWith ( value , " ui " ) )
_HardText = _Text ;
# endif
invalidateContent ( ) ;
invalidateContent ( ) ;
return true ;
return true ;
}
}
@ -705,6 +715,8 @@ namespace NLGUI
bool CViewText : : serializeTextOptions ( xmlNodePtr node ) const
bool CViewText : : serializeTextOptions ( xmlNodePtr node ) const
{
{
xmlSetProp ( node , BAD_CAST " localize " , BAD_CAST toString ( _Localized ) . c_str ( ) ) ;
xmlSetProp ( node , BAD_CAST " color " , BAD_CAST toString ( _Color ) . c_str ( ) ) ;
xmlSetProp ( node , BAD_CAST " color " , BAD_CAST toString ( _Color ) . c_str ( ) ) ;
xmlSetProp ( node , BAD_CAST " global_color " , BAD_CAST toString ( _ModulateGlobalColor ) . c_str ( ) ) ;
xmlSetProp ( node , BAD_CAST " global_color " , BAD_CAST toString ( _ModulateGlobalColor ) . c_str ( ) ) ;
@ -784,7 +796,7 @@ namespace NLGUI
serializeTextOptions ( node ) ;
serializeTextOptions ( node ) ;
xmlSetProp ( node , BAD_CAST " hard text" , BAD_CAST _Text . c_str ( ) ) ;
xmlSetProp ( node , BAD_CAST " text" , BAD_CAST ( _HardText . empty ( ) ? _Text . c_str ( ) : _HardText . c_str ( ) ) ) ;
xmlSetProp ( node , BAD_CAST " hardtext_format " , BAD_CAST _HardTextFormat . c_str ( ) ) ;
xmlSetProp ( node , BAD_CAST " hardtext_format " , BAD_CAST _HardTextFormat . c_str ( ) ) ;
return node ;
return node ;
@ -795,6 +807,9 @@ namespace NLGUI
{
{
CXMLAutoPtr prop ;
CXMLAutoPtr prop ;
prop = xmlGetProp ( cur , ( xmlChar * ) " localize " ) ;
if ( prop ) _Localized = convertBool ( ( const char * ) prop ) ;
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " color " ) ;
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " color " ) ;
_Color = CRGBA ( 255 , 255 , 255 , 255 ) ;
_Color = CRGBA ( 255 , 255 , 255 , 255 ) ;
if ( prop )
if ( prop )
@ -1000,18 +1015,8 @@ namespace NLGUI
if ( prop )
if ( prop )
{
{
const char * propPtr = prop ;
const char * propPtr = prop ;
if ( NLMISC : : startsWith ( propPtr , " ui " ) )
_Localized = true ;
{
setTextLocalized ( propPtr ) ;
_HardText = propPtr ;
_Text = CI18N : : get ( propPtr ) ;
_TextLength = 0 ;
}
else
{
_HardText . clear ( ) ;
_Text = propPtr ;
_TextLength = 0 ;
}
setCase ( _Text , _CaseMode ) ;
setCase ( _Text , _CaseMode ) ;
_TextLength = 0 ;
_TextLength = 0 ;
}
}
@ -1427,18 +1432,70 @@ namespace NLGUI
}
}
// ***************************************************************************
// ***************************************************************************
void CViewText : : setText ( const std : : string & text )
void CViewText : : setTextLocalized ( const std : : string & text , bool localized )
{
if ( localized ! = _Localized )
{
_Localized = localized ;
// Always recompute if localization and text changed
setTextLocalized ( text ) ;
setCase ( _Text , _CaseMode ) ;
_TextLength = 0 ;
invalidateContent ( ) ;
}
else
{
setText ( text ) ;
}
}
// ***************************************************************************
void CViewText : : setLocalized ( bool localized )
{
if ( localized ! = _Localized )
{
const std : : string & text = _HardText . empty ( ) ? _Text : _HardText ;
_Localized = localized ;
if ( ! text . empty ( ) & & NLMISC : : startsWith ( text , " ui " ) )
{
setTextLocalized ( text ) ;
setCase ( _Text , _CaseMode ) ;
_TextLength = 0 ;
invalidateContent ( ) ;
}
}
nlassert ( _Text . empty ( ) | | ( ( _Localized & & ( NLMISC : : startsWith ( getText ( ) , " ui " ) ) ) = = ( _HardText . empty ( ) = = _Text . empty ( ) ) ) ) ;
}
// ***************************************************************************
void CViewText : : setTextLocalized ( const std : : string & text )
{
if ( _Localized & & NLMISC : : startsWith ( text , " ui " ) )
{
_HardText = text ;
_Text = CI18N : : get ( text ) ;
}
else
{
{
_Text = text ;
_HardText . clear ( ) ;
_HardText . clear ( ) ;
}
}
// ***************************************************************************
void CViewText : : setText ( const std : : string & text )
{
// common case: no special format, no case mode => easy cache test
// common case: no special format, no case mode => easy cache test
if ( _FormatTags . empty ( ) & & _CaseMode = = CaseNormal )
if ( _FormatTags . empty ( ) & & _CaseMode = = CaseNormal )
{
{
if ( text ! = _Text )
if ( _HardText . empty ( ) ? text ! = _Text : text ! = _Hard Text)
{
{
_Text = text ;
setTextLocalized ( text ) ;
_TextLength = 0 ;
_TextLength = 0 ;
// no need to call "setCase (_Text, _CaseMode);" since CaseNormal:
// no need to call "setCase (_Text, _CaseMode);" since CaseNormal:
invalidateContent ( ) ;
invalidateContent ( ) ;
}
}
}
}
else
else
@ -1446,26 +1503,34 @@ namespace NLGUI
// if the view text had some format before, no choice, must recompute all
// if the view text had some format before, no choice, must recompute all
if ( ! _FormatTags . empty ( ) )
if ( ! _FormatTags . empty ( ) )
{
{
_Text = text ;
setTextLocalized ( text ) ;
setCase ( _Text , _CaseMode ) ;
setCase ( _Text , _CaseMode ) ;
_TextLength = 0 ;
_TextLength = 0 ;
invalidateContent ( ) ;
invalidateContent ( ) ;
}
}
// else test if after the case change the cache succeed
// else test if after the case change the cache succeed
else
else
{
{
// compute the temp cased text
// compute the temp cased text
std : : string tempText = text ;
std : : string holdText , holdHardText ;
setCase ( tempText , _CaseMode ) ;
holdText . swap ( _Text ) ;
if ( tempText ! = _Text )
holdHardText . swap ( _HardText ) ;
setTextLocalized ( text ) ;
setCase ( _Text , _CaseMode ) ;
if ( holdText ! = _Text )
{
{
_Text = tempText ;
_TextLength = 0 ;
_TextLength = 0 ;
invalidateContent ( ) ;
invalidateContent ( ) ;
}
}
else
{
holdText . swap ( _Text ) ;
}
}
}
}
}
nlassert ( _Text . empty ( ) | | ( ( _Localized & & ( NLMISC : : startsWith ( text , " ui " ) ) ) = = ( _HardText . empty ( ) = = _Text . empty ( ) ) ) ) ;
// clear format tags if any
// clear format tags if any
_FormatTags . clear ( ) ;
_FormatTags . clear ( ) ;
}
}
@ -2396,16 +2461,13 @@ namespace NLGUI
// ***************************************************************************
// ***************************************************************************
void CViewText : : setHardText ( const std : : string & ht )
void CViewText : : setHardText ( const std : : string & ht )
{
{
if ( NLMISC : : startsWith ( ht , " ui " ) )
if ( ! _Localized )
{
{
setText ( CI18N: : get ( ht ) ) ;
setText ( std: : string ( ) ) ;
_ HardText = ht ;
_ Localized = true ;
}
}
else
{
setText ( ht ) ;
setText ( ht ) ;
}
}
}
// ***************************************************************************
// ***************************************************************************
ucstring CViewText : : getTextAsUtf16 ( ) const
ucstring CViewText : : getTextAsUtf16 ( ) const
@ -3367,6 +3429,7 @@ namespace NLGUI
// Copy to Text (preserve Memory)
// Copy to Text (preserve Memory)
contReset ( _Text ) ;
contReset ( _Text ) ;
_Text = tempText ;
_Text = tempText ;
_HardText . clear ( ) ;
_TextLength = 0 ;
_TextLength = 0 ;
CInterfaceGroup * parent = getParent ( ) ;
CInterfaceGroup * parent = getParent ( ) ;
@ -3477,6 +3540,7 @@ namespace NLGUI
// Copy to Text (preserve Memory)
// Copy to Text (preserve Memory)
contReset ( _Text ) ;
contReset ( _Text ) ;
_Text = tempText ;
_Text = tempText ;
_HardText . clear ( ) ;
_TextLength = 0 ;
_TextLength = 0 ;
invalidateContent ( ) ;
invalidateContent ( ) ;
}
}
@ -3560,6 +3624,11 @@ namespace NLGUI
# define SERIAL_UINT(val) { uint32 tmp = (uint32) val; f.serial(tmp); val = (uint) tmp; }
# define SERIAL_UINT(val) { uint32 tmp = (uint32) val; f.serial(tmp); val = (uint) tmp; }
# define SERIAL_SINT(val) { sint32 tmp = (sint32) val; f.serial(tmp); val = (sint) tmp; }
# define SERIAL_SINT(val) { sint32 tmp = (sint32) val; f.serial(tmp); val = (sint) tmp; }
CViewBase : : serial ( f ) ;
CViewBase : : serial ( f ) ;
int version = f . serialVersion ( 101 ) ;
nlassert ( version > = 100 ) ;
f . serial ( _Localized ) ;
SERIAL_SINT ( _FontSize ) ;
SERIAL_SINT ( _FontSize ) ;
SERIAL_UINT ( _FontWidth ) ;
SERIAL_UINT ( _FontWidth ) ;
SERIAL_UINT ( _FontHeight ) ;
SERIAL_UINT ( _FontHeight ) ;