Added: CViewText centered text mode option.
--HG-- branch : develop
This commit is contained in:
parent
ec9a0e6d38
commit
f4ade875a3
2 changed files with 26 additions and 3 deletions
|
@ -37,7 +37,7 @@ namespace NLGUI
|
||||||
class CViewText : public CViewBase
|
class CViewText : public CViewBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum TTextMode { ClipWord, DontClipWord, Justified };
|
enum TTextMode { ClipWord, DontClipWord, Justified, Centered };
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DECLARE_UI_CLASS(CViewText)
|
DECLARE_UI_CLASS(CViewText)
|
||||||
|
|
|
@ -312,6 +312,9 @@ namespace NLGUI
|
||||||
case Justified:
|
case Justified:
|
||||||
return "justified";
|
return "justified";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Centered:
|
||||||
|
return "centered";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
@ -522,6 +525,9 @@ namespace NLGUI
|
||||||
else
|
else
|
||||||
if( value == "justified" )
|
if( value == "justified" )
|
||||||
_TextMode = Justified;
|
_TextMode = Justified;
|
||||||
|
else
|
||||||
|
if( value == "centered" )
|
||||||
|
_TextMode = Centered;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -716,6 +722,10 @@ namespace NLGUI
|
||||||
case Justified:
|
case Justified:
|
||||||
just = "justified";
|
just = "justified";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Centered:
|
||||||
|
just = "centered";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlSetProp( node, BAD_CAST "justification", BAD_CAST just.c_str() );
|
xmlSetProp( node, BAD_CAST "justification", BAD_CAST just.c_str() );
|
||||||
|
@ -843,6 +853,7 @@ namespace NLGUI
|
||||||
if (nlstricmp("clip_word", (const char *) prop) == 0) _TextMode = ClipWord;
|
if (nlstricmp("clip_word", (const char *) prop) == 0) _TextMode = ClipWord;
|
||||||
else if (nlstricmp("dont_clip_word", (const char *) prop) == 0) _TextMode = DontClipWord;
|
else if (nlstricmp("dont_clip_word", (const char *) prop) == 0) _TextMode = DontClipWord;
|
||||||
else if (nlstricmp("justified", (const char *) prop) == 0) _TextMode = Justified;
|
else if (nlstricmp("justified", (const char *) prop) == 0) _TextMode = Justified;
|
||||||
|
else if (nlstricmp("centered", (const char *) prop) == 0) _TextMode = Centered;
|
||||||
else nlwarning("<CViewText::parse> bad text mode");
|
else nlwarning("<CViewText::parse> bad text mode");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1195,7 +1206,18 @@ namespace NLGUI
|
||||||
{
|
{
|
||||||
CLine &currLine = *_Lines[i];
|
CLine &currLine = *_Lines[i];
|
||||||
// current x position
|
// current x position
|
||||||
float px = (float) (_XReal * _Scale + ((i==0) ? (sint)_FirstLineX : 0));
|
float px = (float) (_XReal * _Scale + ((i==0) ? _FirstLineX : 0.f));
|
||||||
|
|
||||||
|
// Center line to computed maximum line width (_WReal)
|
||||||
|
//
|
||||||
|
// Does not give most accurate result when _WReal is much smaller than parent,
|
||||||
|
// but _WReal also defines mouseover hotspot/tooltip area.
|
||||||
|
//
|
||||||
|
// May not work correctly in CGroupParagraph (multiple text elements).
|
||||||
|
//
|
||||||
|
if (_TextMode == Centered)
|
||||||
|
px += (float)(_WReal * _Scale - (currLine.getWidth() + (i == 0 ? _FirstLineX : 0.f)) )/ 2.f;
|
||||||
|
|
||||||
// draw each words of the line
|
// draw each words of the line
|
||||||
for(uint k = 0; k < currLine.getNumWords(); ++k)
|
for(uint k = 0; k < currLine.getNumWords(); ++k)
|
||||||
{
|
{
|
||||||
|
@ -2039,6 +2061,7 @@ namespace NLGUI
|
||||||
switch(_TextMode)
|
switch(_TextMode)
|
||||||
{
|
{
|
||||||
case ClipWord: updateTextContextMultiLine(nMaxWidth); break;
|
case ClipWord: updateTextContextMultiLine(nMaxWidth); break;
|
||||||
|
case Centered: // fallthru to DontClipWord
|
||||||
case DontClipWord: updateTextContextMultiLineJustified(nMaxWidth, false); break;
|
case DontClipWord: updateTextContextMultiLineJustified(nMaxWidth, false); break;
|
||||||
case Justified: updateTextContextMultiLineJustified(nMaxWidth, true); break;
|
case Justified: updateTextContextMultiLineJustified(nMaxWidth, true); break;
|
||||||
}
|
}
|
||||||
|
@ -2869,7 +2892,7 @@ namespace NLGUI
|
||||||
return (sint32)ceilf(_FontHeight / _Scale);
|
return (sint32)ceilf(_FontHeight / _Scale);
|
||||||
}
|
}
|
||||||
// If we can't clip the words, return the size of the largest word
|
// If we can't clip the words, return the size of the largest word
|
||||||
else if ((_TextMode == DontClipWord) || (_TextMode == Justified))
|
else if ((_TextMode == DontClipWord) || (_TextMode == Justified) || (_TextMode == Centered))
|
||||||
{
|
{
|
||||||
NL3D::UTextContext *TextContext = CViewRenderer::getTextContext(_FontName);
|
NL3D::UTextContext *TextContext = CViewRenderer::getTextContext(_FontName);
|
||||||
TextContext->setHotSpot (UTextContext::BottomLeft);
|
TextContext->setHotSpot (UTextContext::BottomLeft);
|
||||||
|
|
Loading…
Reference in a new issue