mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-22 23:26:15 +00:00
Add embolden, oblique, underline, strikethrough styles to CViewText
--HG-- branch : develop
This commit is contained in:
parent
c760b1e3d9
commit
55672485c9
2 changed files with 129 additions and 1 deletions
|
@ -81,6 +81,8 @@ namespace NLGUI
|
|||
|
||||
void setText (const ucstring &text);
|
||||
void setFontSize (sint nFontSize);
|
||||
void setEmbolden (bool nEmbolden);
|
||||
void setOblique (bool nOblique);
|
||||
void setColor (const NLMISC::CRGBA &color);
|
||||
void setShadow (bool bShadow);
|
||||
void setShadowOutline (bool bShadowOutline);
|
||||
|
@ -101,6 +103,8 @@ namespace NLGUI
|
|||
|
||||
ucstring getText() const { return _Text; }
|
||||
sint getFontSize() const;
|
||||
bool getEmbolden() { return _Embolden; }
|
||||
bool getOblique() { return _Oblique; }
|
||||
NLMISC::CRGBA getColor() { return _Color; }
|
||||
bool getShadow() { return _Shadow; }
|
||||
bool getShadowOutline() { return _ShadowOutline; }
|
||||
|
@ -125,6 +129,8 @@ namespace NLGUI
|
|||
uint getLastLineW () const;
|
||||
void setUnderlined (bool underlined) { _Underlined = underlined; }
|
||||
bool getUnderlined () const { return _Underlined; }
|
||||
void setStrikeThrough (bool linethrough) { _StrikeThrough = linethrough; }
|
||||
bool getStrikeThrough () const { return _StrikeThrough; }
|
||||
// true if the viewText is a single line clamped.
|
||||
bool isSingleLineTextClamped() const {return _SingleLineTextClamped;}
|
||||
|
||||
|
@ -220,6 +226,8 @@ namespace NLGUI
|
|||
NL3D::UTextContext::CStringInfo _Info;
|
||||
/// the font size
|
||||
sint _FontSize;
|
||||
bool _Embolden;
|
||||
bool _Oblique;
|
||||
// width of the font in pixel. Just a Hint for tabing format (computed with '_')
|
||||
uint _FontWidth;
|
||||
// height of the font in pixel.
|
||||
|
@ -374,6 +382,7 @@ namespace NLGUI
|
|||
bool _TextSelection : 1;
|
||||
bool _InvalidTextContext : 1;
|
||||
bool _Underlined : 1;
|
||||
bool _StrikeThrough : 1;
|
||||
bool _ContinuousUpdate : 1;
|
||||
bool _Setuped : 1;
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ namespace NLGUI
|
|||
{
|
||||
_CaseMode = CaseNormal;
|
||||
_Underlined = false;
|
||||
_StrikeThrough = false;
|
||||
_ContinuousUpdate = false;
|
||||
_Active = true;
|
||||
_X = 0;
|
||||
|
@ -58,6 +59,8 @@ namespace NLGUI
|
|||
|
||||
_FontSize = 12 +
|
||||
CWidgetManager::getInstance()->getSystemOption( CWidgetManager::OptionAddCoefFont ).getValSInt32();
|
||||
_Embolden = false;
|
||||
_Oblique = false;
|
||||
_Color = CRGBA(255,255,255,255);
|
||||
_Shadow = false;
|
||||
_ShadowOutline = false;
|
||||
|
@ -157,6 +160,10 @@ namespace NLGUI
|
|||
_PosRef = vt._PosRef;
|
||||
|
||||
_FontSize = vt._FontSize;
|
||||
_Embolden = vt._Embolden;
|
||||
_Oblique = vt._Oblique;
|
||||
_Underlined = vt._Underlined;
|
||||
_StrikeThrough = vt._StrikeThrough;
|
||||
_Color = vt._Color;
|
||||
_Shadow = vt._Shadow;
|
||||
_ShadowOutline = vt._ShadowOutline;
|
||||
|
@ -221,6 +228,21 @@ namespace NLGUI
|
|||
);
|
||||
}
|
||||
else
|
||||
if( name == "fontweight" )
|
||||
{
|
||||
if (_Embolden)
|
||||
return "bold";
|
||||
|
||||
return "normal";
|
||||
}
|
||||
if( name == "fontstyle" )
|
||||
{
|
||||
if (_Oblique)
|
||||
return "oblique";
|
||||
|
||||
return "normal";
|
||||
}
|
||||
else
|
||||
if( name == "shadow" )
|
||||
{
|
||||
return toString( _Shadow );
|
||||
|
@ -286,6 +308,11 @@ namespace NLGUI
|
|||
return toString( _Underlined );
|
||||
}
|
||||
else
|
||||
if( name == "strikthrough" )
|
||||
{
|
||||
return toString( _StrikeThrough );
|
||||
}
|
||||
else
|
||||
if( name == "case_mode" )
|
||||
{
|
||||
return toString( uint32( _CaseMode ) );
|
||||
|
@ -358,6 +385,20 @@ namespace NLGUI
|
|||
return true;
|
||||
}
|
||||
else
|
||||
if( name == "fontweight" )
|
||||
{
|
||||
if (value == "bold")
|
||||
_Embolden = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
if( name == "fontstyle" )
|
||||
{
|
||||
if( value == "oblique" )
|
||||
_Oblique = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if( name == "shadow" )
|
||||
{
|
||||
bool b;
|
||||
|
@ -444,6 +485,14 @@ namespace NLGUI
|
|||
return true;
|
||||
}
|
||||
else
|
||||
if( name == "strikethrough" )
|
||||
{
|
||||
bool b;
|
||||
if( fromString( value, b ) )
|
||||
_StrikeThrough = b;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if( name == "case_mode" )
|
||||
{
|
||||
uint32 i;
|
||||
|
@ -533,6 +582,16 @@ namespace NLGUI
|
|||
_FontSize - CWidgetManager::getInstance()->getSystemOption( CWidgetManager::OptionAddCoefFont ).getValSInt32()
|
||||
).c_str() );
|
||||
|
||||
std::string fontweight("normal");
|
||||
if (_Embolden)
|
||||
fontweight = "bold";
|
||||
xmlSetProp( node, BAD_CAST "fontweight", BAD_CAST fontweight.c_str() );
|
||||
|
||||
std::string fontstyle("normal");
|
||||
if (_Oblique)
|
||||
fontstyle = "oblique";
|
||||
xmlSetProp( node, BAD_CAST "fontstyle", BAD_CAST fontstyle.c_str() );
|
||||
|
||||
xmlSetProp( node, BAD_CAST "shadow", BAD_CAST toString( _Shadow ).c_str() );
|
||||
xmlSetProp( node, BAD_CAST "shadow_outline", BAD_CAST toString( _ShadowOutline ).c_str() );
|
||||
xmlSetProp( node, BAD_CAST "shadow_color", BAD_CAST toString( _ShadowColor ).c_str() );
|
||||
|
@ -561,6 +620,7 @@ namespace NLGUI
|
|||
xmlSetProp( node, BAD_CAST "multi_line_maxw_only", BAD_CAST toString( _MultiLineMaxWOnly ).c_str() );
|
||||
xmlSetProp( node, BAD_CAST "multi_max_line", BAD_CAST toString( _MultiMaxLine ).c_str() );
|
||||
xmlSetProp( node, BAD_CAST "underlined", BAD_CAST toString( _Underlined ).c_str() );
|
||||
xmlSetProp( node, BAD_CAST "strikethrough", BAD_CAST toString( _StrikeThrough ).c_str() );
|
||||
xmlSetProp( node, BAD_CAST "case_mode", BAD_CAST toString( uint32( _CaseMode ) ).c_str() );
|
||||
xmlSetProp( node, BAD_CAST "over_extend_view_text", BAD_CAST toString( _OverExtendViewText ).c_str() );
|
||||
xmlSetProp( node, BAD_CAST "over_extend_parent_rect",
|
||||
|
@ -614,6 +674,22 @@ namespace NLGUI
|
|||
_FontSize += CWidgetManager::getInstance()->getSystemOption( CWidgetManager::OptionAddCoefFont).getValSInt32();
|
||||
}
|
||||
|
||||
prop = (char*) xmlGetProp( cur, (xmlChar*)"fontweight" );
|
||||
_Embolden = false;
|
||||
if (prop)
|
||||
{
|
||||
if (nlstricmp("bold", (const char*)prop) == 0) _Embolden = true;
|
||||
else nlwarning("<CViewText::parse> bad fontweight '%s'", (const char *)prop);
|
||||
}
|
||||
|
||||
prop = (char*) xmlGetProp( cur, (xmlChar*)"fontstyle" );
|
||||
_Oblique = false;
|
||||
if (prop)
|
||||
{
|
||||
if (nlstricmp("oblique", (const char *) prop) == 0) _Oblique = true;
|
||||
else nlwarning("<CViewText::parse> bad fontstyle '%s'", (const char *)prop);
|
||||
}
|
||||
|
||||
prop = (char*) xmlGetProp( cur, (xmlChar*)"shadow" );
|
||||
_Shadow = false;
|
||||
if (prop)
|
||||
|
@ -668,6 +744,11 @@ namespace NLGUI
|
|||
if (prop)
|
||||
_Underlined = convertBool(prop);
|
||||
|
||||
prop = (char*) xmlGetProp( cur, (xmlChar*)"strikethrough" );
|
||||
_StrikeThrough = false;
|
||||
if (prop)
|
||||
_StrikeThrough = convertBool(prop);
|
||||
|
||||
prop = (char*) xmlGetProp( cur, (xmlChar*)"case_mode" );
|
||||
_CaseMode = CaseNormal;
|
||||
if (prop)
|
||||
|
@ -887,6 +968,8 @@ namespace NLGUI
|
|||
TextContext->setShadeOutline (_ShadowOutline);
|
||||
TextContext->setShadeColor (shcol);
|
||||
TextContext->setFontSize (_FontSize);
|
||||
TextContext->setEmbolden (_Embolden);
|
||||
TextContext->setOblique (_Oblique);
|
||||
|
||||
float y = (float)(_YReal) * ooh; // y is expressed in scree, coordinates [0..1]
|
||||
//y += _LinesInfos[_LinesInfos.size()-1].StringLine / h;
|
||||
|
@ -953,7 +1036,7 @@ namespace NLGUI
|
|||
// skip spaces before current word
|
||||
float firstSpace = currWord.NumSpaces * currLine.getSpaceWidth();
|
||||
sint line_width = 0;
|
||||
if (_Underlined)
|
||||
if (_Underlined || _StrikeThrough)
|
||||
{
|
||||
line_width = (sint)floorf(currLine.getWidthWithoutSpaces() + currLine.getSpaceWidth());
|
||||
line_width -= (sint)floorf(firstSpace);
|
||||
|
@ -971,6 +1054,9 @@ namespace NLGUI
|
|||
if (_Underlined)
|
||||
rVR.drawRotFlipBitmap (_RenderLayer, (sint)floorf(px), y_line, line_width, 1, 0, false, rVR.getBlankTextureId(), col);
|
||||
|
||||
if (_StrikeThrough)
|
||||
rVR.drawRotFlipBitmap (_RenderLayer, (sint)floorf(px), y_line + (_FontHeight / 2), line_width, 1, 0, false, rVR.getBlankTextureId(), col);
|
||||
|
||||
// skip word
|
||||
px += currWord.Info.StringWidth;
|
||||
}
|
||||
|
@ -1002,6 +1088,8 @@ namespace NLGUI
|
|||
TextContext->setShadeOutline (_ShadowOutline);
|
||||
TextContext->setShadeColor (shcol);
|
||||
TextContext->setFontSize (_FontSize);
|
||||
TextContext->setEmbolden (_Embolden);
|
||||
TextContext->setOblique (_Oblique);
|
||||
|
||||
|
||||
if(_LetterColors!=NULL && !TextContext->isSameLetterColors(_LetterColors, _Index))
|
||||
|
@ -1032,6 +1120,9 @@ namespace NLGUI
|
|||
if (_Underlined)
|
||||
rVR.drawRotFlipBitmap (_RenderLayer, _XReal, _YReal+_FontLegHeight-2, _WReal, 1, 0, false, rVR.getBlankTextureId(), col);
|
||||
|
||||
if (_StrikeThrough)
|
||||
rVR.drawRotFlipBitmap (_RenderLayer, _XReal, _YReal+(_FontLegHeight/2), _WReal, 1, 0, false, rVR.getBlankTextureId(), col);
|
||||
|
||||
// reset selection
|
||||
if(_TextSelection)
|
||||
TextContext->resetStringSelection(_Index);
|
||||
|
@ -1154,6 +1245,22 @@ namespace NLGUI
|
|||
return _FontSize - CWidgetManager::getInstance()->getSystemOption( CWidgetManager::OptionAddCoefFont).getValSInt32();
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CViewText::setEmbolden (bool embolden)
|
||||
{
|
||||
_Embolden = embolden;
|
||||
computeFontSize ();
|
||||
invalidateContent();
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CViewText::setOblique (bool oblique)
|
||||
{
|
||||
_Oblique = oblique;
|
||||
computeFontSize ();
|
||||
invalidateContent();
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CViewText::setColor(const NLMISC::CRGBA & color)
|
||||
{
|
||||
|
@ -1679,6 +1786,8 @@ namespace NLGUI
|
|||
TextContext->setShaded (_Shadow);
|
||||
TextContext->setShadeOutline (_ShadowOutline);
|
||||
TextContext->setFontSize (_FontSize);
|
||||
TextContext->setEmbolden (_Embolden);
|
||||
TextContext->setOblique (_Oblique);
|
||||
|
||||
// default state
|
||||
_SingleLineTextClamped= false;
|
||||
|
@ -2000,6 +2109,8 @@ namespace NLGUI
|
|||
TextContext->setShaded (_Shadow);
|
||||
TextContext->setShadeOutline (_ShadowOutline);
|
||||
TextContext->setFontSize (_FontSize);
|
||||
TextContext->setEmbolden (_Embolden);
|
||||
TextContext->setOblique (_Oblique);
|
||||
// CViewRenderer &rVR = *CViewRenderer::getInstance();
|
||||
height = getFontHeight();
|
||||
//
|
||||
|
@ -2132,6 +2243,8 @@ namespace NLGUI
|
|||
TextContext->setShaded (_Shadow);
|
||||
TextContext->setShadeOutline (_ShadowOutline);
|
||||
TextContext->setFontSize (_FontSize);
|
||||
TextContext->setEmbolden (_Embolden);
|
||||
TextContext->setOblique (_Oblique);
|
||||
// find the line where the character is
|
||||
// CViewRenderer &rVR = *CViewRenderer::getInstance();
|
||||
uint charPos = 0;
|
||||
|
@ -2407,6 +2520,8 @@ namespace NLGUI
|
|||
TextContext->setShaded (_Shadow);
|
||||
TextContext->setShadeOutline (_ShadowOutline);
|
||||
TextContext->setFontSize (_FontSize);
|
||||
TextContext->setEmbolden (_Embolden);
|
||||
TextContext->setOblique (_Oblique);
|
||||
|
||||
TCharPos linePos = 0;
|
||||
while (linePos < _Text.length())
|
||||
|
@ -2492,6 +2607,8 @@ namespace NLGUI
|
|||
TextContext->setShaded (_Shadow);
|
||||
TextContext->setShadeOutline (_ShadowOutline);
|
||||
TextContext->setFontSize (_FontSize);
|
||||
TextContext->setEmbolden (_Embolden);
|
||||
TextContext->setOblique (_Oblique);
|
||||
|
||||
// Current position in text
|
||||
TCharPos currPos = 0;
|
||||
|
@ -2544,6 +2661,8 @@ namespace NLGUI
|
|||
TextContext->setShaded (_Shadow);
|
||||
TextContext->setShadeOutline (_ShadowOutline);
|
||||
TextContext->setFontSize (_FontSize);
|
||||
TextContext->setEmbolden (_Embolden);
|
||||
TextContext->setOblique (_Oblique);
|
||||
|
||||
// Letter size
|
||||
UTextContext::CStringInfo si = TextContext->getStringInfo(ucstring("|")); // for now we can't now that directly from UTextContext
|
||||
|
|
Loading…
Reference in a new issue