Changed: Allow to set font size without adding global font size coef

--HG--
branch : develop
This commit is contained in:
Nimetu 2019-01-08 11:32:01 +02:00
parent dda8a36ee2
commit 8b69d673be
2 changed files with 53 additions and 11 deletions

View file

@ -82,7 +82,7 @@ namespace NLGUI
void setText (const ucstring &text);
void setFontName (const std::string &name);
void setFontSize (sint nFontSize);
void setFontSize (sint nFontSize, bool coef = true);
void setEmbolden (bool nEmbolden);
void setOblique (bool nOblique);
void setColor (const NLMISC::CRGBA &color);
@ -243,6 +243,7 @@ namespace NLGUI
std::string _FontName;
/// the font size
sint _FontSize;
bool _FontSizeCoef;
bool _Embolden;
bool _Oblique;
// width of the font in pixel. Just a Hint for tabing format (computed with '_')

View file

@ -65,6 +65,7 @@ namespace NLGUI
_FontSize = 12 +
CWidgetManager::getInstance()->getSystemOption( CWidgetManager::OptionAddCoefFont ).getValSInt32();
_FontSizeCoef = true;
_FontName.clear();
_Embolden = false;
_Oblique = false;
@ -141,6 +142,7 @@ namespace NLGUI
setupDefault ();
_FontSize = FontSize + CWidgetManager::getInstance()->getSystemOption( CWidgetManager::OptionAddCoefFont).getValSInt32();
_FontSizeCoef = true;
_Color = Color;
_Shadow = Shadow;
_ShadowOutline = ShadowOutline;
@ -185,6 +187,7 @@ namespace NLGUI
_PosRef = vt._PosRef;
_FontSize = vt._FontSize;
_FontSizeCoef = vt._FontSizeCoef;
_Embolden = vt._Embolden;
_Oblique = vt._Oblique;
_Underlined = vt._Underlined;
@ -248,9 +251,15 @@ namespace NLGUI
else
if( name == "fontsize" )
{
return toString(
_FontSize - CWidgetManager::getInstance()->getSystemOption( CWidgetManager::OptionAddCoefFont ).getValSInt32()
);
if (_FontSizeCoef)
return toString(_FontSize - CWidgetManager::getInstance()->getSystemOption( CWidgetManager::OptionAddCoefFont ).getValSInt32());
return toString(_FontSize);
}
else
if ( name == "fontsize_coef" )
{
return toString(_FontSizeCoef);
}
else
if( name == "fontweight" )
@ -425,6 +434,22 @@ namespace NLGUI
return true;
}
else
if( name == "fontsize_coef" )
{
bool b;
bool oldValue = _FontSizeCoef;
if (fromString( value, b) )
_FontSizeCoef = b;
// must only change font size when current state changes
if (_FontSizeCoef != oldValue)
{
if (_FontSizeCoef)
_FontSize += CWidgetManager::getInstance()->getSystemOption( CWidgetManager::OptionAddCoefFont ).getValSInt32();
else
_FontSize -= CWidgetManager::getInstance()->getSystemOption( CWidgetManager::OptionAddCoefFont ).getValSInt32();
}
}
else
if( name == "fontweight" )
{
if (value == "bold")
@ -653,10 +678,11 @@ namespace NLGUI
{
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 "fontsize",
BAD_CAST toString(
_FontSize - CWidgetManager::getInstance()->getSystemOption( CWidgetManager::OptionAddCoefFont ).getValSInt32()
).c_str() );
sint32 fontSize = _FontSize;
if (_FontSizeCoef) fontSize -= CWidgetManager::getInstance()->getSystemOption( CWidgetManager::OptionAddCoefFont ).getValSInt32();
xmlSetProp( node, BAD_CAST "fontsize", BAD_CAST toString(fontSize).c_str() );
xmlSetProp( node, BAD_CAST "fontsize_coef", BAD_CAST toString(_FontSizeCoef).c_str() );
std::string fontweight("normal");
if (_Embolden)
@ -755,6 +781,16 @@ namespace NLGUI
_FontSize += CWidgetManager::getInstance()->getSystemOption( CWidgetManager::OptionAddCoefFont).getValSInt32();
}
prop = (char*) xmlGetProp( cur, (xmlChar*)"fontsize_coef" );
_FontSizeCoef = true;
if (prop)
{
_FontSizeCoef = convertBool(prop);
if (!_FontSizeCoef)
_FontSize -= CWidgetManager::getInstance()->getSystemOption( CWidgetManager::OptionAddCoefFont).getValSInt32();
}
prop = (char*) xmlGetProp( cur, (xmlChar*)"fontweight" );
_Embolden = false;
if (prop)
@ -1395,9 +1431,11 @@ namespace NLGUI
}
// ***************************************************************************
void CViewText::setFontSize (sint nFontSize)
void CViewText::setFontSize (sint nFontSize, bool coef)
{
_FontSize = nFontSize + CWidgetManager::getInstance()->getSystemOption( CWidgetManager::OptionAddCoefFont).getValSInt32();
_FontSize = nFontSize;
if (coef) _FontSize += CWidgetManager::getInstance()->getSystemOption( CWidgetManager::OptionAddCoefFont).getValSInt32();
_FontSizeCoef = coef;
computeFontSize ();
invalidateContent();
}
@ -1405,7 +1443,10 @@ namespace NLGUI
// ***************************************************************************
sint CViewText::getFontSize() const
{
return _FontSize - CWidgetManager::getInstance()->getSystemOption( CWidgetManager::OptionAddCoefFont).getValSInt32();
if (_FontSizeCoef)
return _FontSize - CWidgetManager::getInstance()->getSystemOption( CWidgetManager::OptionAddCoefFont).getValSInt32();
return _FontSize;
}
// ***************************************************************************