2015-01-16 07:54:26 +01:00
|
|
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
2022-06-16 21:20:12 +02:00
|
|
|
// Copyright (C) 2016 Nathanaëlle Courant:
|
2016-05-31 17:30:11 +02:00
|
|
|
// Modified the functions to use EnrichedText instead of string.
|
2015-01-16 07:54:26 +01:00
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
2016-05-31 17:30:11 +02:00
|
|
|
#include "static_text.h"
|
2015-01-16 07:54:26 +01:00
|
|
|
|
|
|
|
#include <IGUIFont.h>
|
|
|
|
#include <IVideoDriver.h>
|
|
|
|
#include <rect.h>
|
|
|
|
#include <SColor.h>
|
|
|
|
|
2022-01-08 14:53:25 +01:00
|
|
|
#include "CGUITTFont.h"
|
2015-01-16 07:54:26 +01:00
|
|
|
#include "util/string.h"
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
2016-05-31 17:30:11 +02:00
|
|
|
|
2015-01-16 07:54:26 +01:00
|
|
|
namespace gui
|
|
|
|
{
|
|
|
|
//! constructor
|
2016-05-31 17:30:11 +02:00
|
|
|
StaticText::StaticText(const EnrichedString &text, bool border,
|
2015-01-16 07:54:26 +01:00
|
|
|
IGUIEnvironment* environment, IGUIElement* parent,
|
|
|
|
s32 id, const core::rect<s32>& rectangle,
|
|
|
|
bool background)
|
|
|
|
: IGUIStaticText(environment, parent, id, rectangle),
|
|
|
|
HAlign(EGUIA_UPPERLEFT), VAlign(EGUIA_UPPERLEFT),
|
2020-01-22 19:09:11 +01:00
|
|
|
Border(border), WordWrap(false), Background(background),
|
2015-01-16 07:54:26 +01:00
|
|
|
RestrainTextInside(true), RightToLeft(false),
|
|
|
|
OverrideFont(0), LastBreakFont(0)
|
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
setDebugName("StaticText");
|
|
|
|
#endif
|
|
|
|
|
2020-01-22 19:09:11 +01:00
|
|
|
setText(text);
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! destructor
|
|
|
|
StaticText::~StaticText()
|
|
|
|
{
|
|
|
|
if (OverrideFont)
|
|
|
|
OverrideFont->drop();
|
|
|
|
}
|
|
|
|
|
|
|
|
//! draws the element and its children
|
|
|
|
void StaticText::draw()
|
|
|
|
{
|
|
|
|
if (!IsVisible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
IGUISkin* skin = Environment->getSkin();
|
|
|
|
if (!skin)
|
|
|
|
return;
|
|
|
|
video::IVideoDriver* driver = Environment->getVideoDriver();
|
|
|
|
|
|
|
|
core::rect<s32> frameRect(AbsoluteRect);
|
|
|
|
|
|
|
|
// draw background
|
|
|
|
|
|
|
|
if (Background)
|
2020-01-22 19:09:11 +01:00
|
|
|
driver->draw2DRectangle(getBackgroundColor(), frameRect, &AbsoluteClippingRect);
|
2015-01-16 07:54:26 +01:00
|
|
|
|
|
|
|
// draw the border
|
|
|
|
|
|
|
|
if (Border)
|
|
|
|
{
|
|
|
|
skin->draw3DSunkenPane(this, 0, true, false, frameRect, &AbsoluteClippingRect);
|
|
|
|
frameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X);
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw the text
|
2020-01-22 19:09:11 +01:00
|
|
|
IGUIFont *font = getActiveFont();
|
|
|
|
if (font && BrokenText.size()) {
|
|
|
|
if (font != LastBreakFont)
|
|
|
|
updateText();
|
|
|
|
|
|
|
|
core::rect<s32> r = frameRect;
|
|
|
|
s32 height_line = font->getDimension(L"A").Height + font->getKerningHeight();
|
|
|
|
s32 height_total = height_line * BrokenText.size();
|
|
|
|
if (VAlign == EGUIA_CENTER && WordWrap)
|
2015-01-16 07:54:26 +01:00
|
|
|
{
|
2020-01-22 19:09:11 +01:00
|
|
|
r.UpperLeftCorner.Y = r.getCenter().Y - (height_total / 2);
|
|
|
|
}
|
|
|
|
else if (VAlign == EGUIA_LOWERRIGHT)
|
|
|
|
{
|
|
|
|
r.UpperLeftCorner.Y = r.LowerRightCorner.Y - height_total;
|
|
|
|
}
|
|
|
|
if (HAlign == EGUIA_LOWERRIGHT)
|
|
|
|
{
|
|
|
|
r.UpperLeftCorner.X = r.LowerRightCorner.X -
|
|
|
|
getTextWidth();
|
|
|
|
}
|
2015-01-16 07:54:26 +01:00
|
|
|
|
2020-01-22 19:09:11 +01:00
|
|
|
irr::video::SColor previous_color(255, 255, 255, 255);
|
|
|
|
for (const EnrichedString &str : BrokenText) {
|
|
|
|
if (HAlign == EGUIA_LOWERRIGHT)
|
2015-01-16 07:54:26 +01:00
|
|
|
{
|
2020-01-22 19:09:11 +01:00
|
|
|
r.UpperLeftCorner.X = frameRect.LowerRightCorner.X -
|
|
|
|
font->getDimension(str.c_str()).Width;
|
|
|
|
}
|
2015-01-16 07:54:26 +01:00
|
|
|
|
2020-01-22 19:09:11 +01:00
|
|
|
if (font->getType() == irr::gui::EGFT_CUSTOM) {
|
2022-01-08 14:53:25 +01:00
|
|
|
CGUITTFont *tmp = static_cast<CGUITTFont*>(font);
|
2020-01-22 19:09:11 +01:00
|
|
|
tmp->draw(str,
|
2021-04-02 00:20:16 +02:00
|
|
|
r, HAlign == EGUIA_CENTER, VAlign == EGUIA_CENTER,
|
2020-01-22 19:09:11 +01:00
|
|
|
(RestrainTextInside ? &AbsoluteClippingRect : NULL));
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
// Draw non-colored text
|
|
|
|
font->draw(str.c_str(),
|
|
|
|
r, str.getDefaultColor(), // TODO: Implement colorization
|
|
|
|
HAlign == EGUIA_CENTER, VAlign == EGUIA_CENTER,
|
|
|
|
(RestrainTextInside ? &AbsoluteClippingRect : NULL));
|
|
|
|
}
|
2019-08-06 21:33:13 +02:00
|
|
|
|
2015-01-16 07:54:26 +01:00
|
|
|
|
2020-01-22 19:09:11 +01:00
|
|
|
r.LowerRightCorner.Y += height_line;
|
|
|
|
r.UpperLeftCorner.Y += height_line;
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IGUIElement::draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Sets another skin independent font.
|
|
|
|
void StaticText::setOverrideFont(IGUIFont* font)
|
|
|
|
{
|
|
|
|
if (OverrideFont == font)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (OverrideFont)
|
|
|
|
OverrideFont->drop();
|
|
|
|
|
|
|
|
OverrideFont = font;
|
|
|
|
|
|
|
|
if (OverrideFont)
|
|
|
|
OverrideFont->grab();
|
|
|
|
|
2020-01-22 19:09:11 +01:00
|
|
|
updateText();
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Gets the override font (if any)
|
|
|
|
IGUIFont * StaticText::getOverrideFont() const
|
|
|
|
{
|
|
|
|
return OverrideFont;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Get the font which is used right now for drawing
|
|
|
|
IGUIFont* StaticText::getActiveFont() const
|
|
|
|
{
|
|
|
|
if ( OverrideFont )
|
|
|
|
return OverrideFont;
|
|
|
|
IGUISkin* skin = Environment->getSkin();
|
|
|
|
if (skin)
|
|
|
|
return skin->getFont();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets another color for the text.
|
|
|
|
void StaticText::setOverrideColor(video::SColor color)
|
|
|
|
{
|
2020-01-22 19:09:11 +01:00
|
|
|
ColoredText.setDefaultColor(color);
|
|
|
|
updateText();
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Sets another color for the text.
|
|
|
|
void StaticText::setBackgroundColor(video::SColor color)
|
|
|
|
{
|
2020-01-22 19:09:11 +01:00
|
|
|
ColoredText.setBackground(color);
|
2015-01-16 07:54:26 +01:00
|
|
|
Background = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Sets whether to draw the background
|
|
|
|
void StaticText::setDrawBackground(bool draw)
|
|
|
|
{
|
|
|
|
Background = draw;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Gets the background color
|
|
|
|
video::SColor StaticText::getBackgroundColor() const
|
|
|
|
{
|
2020-01-22 19:09:11 +01:00
|
|
|
IGUISkin *skin = Environment->getSkin();
|
|
|
|
|
|
|
|
return (ColoredText.hasBackground() || !skin) ?
|
|
|
|
ColoredText.getBackground() : skin->getColor(gui::EGDC_3D_FACE);
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Checks if background drawing is enabled
|
|
|
|
bool StaticText::isDrawBackgroundEnabled() const
|
|
|
|
{
|
|
|
|
return Background;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Sets whether to draw the border
|
|
|
|
void StaticText::setDrawBorder(bool draw)
|
|
|
|
{
|
|
|
|
Border = draw;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Checks if border drawing is enabled
|
|
|
|
bool StaticText::isDrawBorderEnabled() const
|
|
|
|
{
|
|
|
|
return Border;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StaticText::setTextRestrainedInside(bool restrainTextInside)
|
|
|
|
{
|
|
|
|
RestrainTextInside = restrainTextInside;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool StaticText::isTextRestrainedInside() const
|
|
|
|
{
|
|
|
|
return RestrainTextInside;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StaticText::setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical)
|
|
|
|
{
|
|
|
|
HAlign = horizontal;
|
|
|
|
VAlign = vertical;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
video::SColor StaticText::getOverrideColor() const
|
|
|
|
{
|
2020-01-22 19:09:11 +01:00
|
|
|
return ColoredText.getDefaultColor();
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
|
2020-05-17 01:03:33 +02:00
|
|
|
video::SColor StaticText::getActiveColor() const
|
|
|
|
{
|
|
|
|
return getOverrideColor();
|
|
|
|
}
|
2015-01-16 07:54:26 +01:00
|
|
|
|
|
|
|
//! Sets if the static text should use the overide color or the
|
|
|
|
//! color in the gui skin.
|
|
|
|
void StaticText::enableOverrideColor(bool enable)
|
|
|
|
{
|
2020-01-22 19:09:11 +01:00
|
|
|
// TODO
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool StaticText::isOverrideColorEnabled() const
|
|
|
|
{
|
2020-01-22 19:09:11 +01:00
|
|
|
return true;
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Enables or disables word wrap for using the static text as
|
|
|
|
//! multiline text control.
|
|
|
|
void StaticText::setWordWrap(bool enable)
|
|
|
|
{
|
|
|
|
WordWrap = enable;
|
2020-01-22 19:09:11 +01:00
|
|
|
updateText();
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool StaticText::isWordWrapEnabled() const
|
|
|
|
{
|
|
|
|
return WordWrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StaticText::setRightToLeft(bool rtl)
|
|
|
|
{
|
|
|
|
if (RightToLeft != rtl)
|
|
|
|
{
|
|
|
|
RightToLeft = rtl;
|
2020-01-22 19:09:11 +01:00
|
|
|
updateText();
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool StaticText::isRightToLeft() const
|
|
|
|
{
|
|
|
|
return RightToLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Breaks the single text line.
|
2020-01-22 19:09:11 +01:00
|
|
|
// Updates the font colors
|
|
|
|
void StaticText::updateText()
|
2015-01-16 07:54:26 +01:00
|
|
|
{
|
2020-01-22 19:09:11 +01:00
|
|
|
const EnrichedString &cText = ColoredText;
|
|
|
|
BrokenText.clear();
|
|
|
|
|
2020-02-01 20:41:32 +01:00
|
|
|
if (cText.hasBackground())
|
2020-01-22 19:09:11 +01:00
|
|
|
setBackgroundColor(cText.getBackground());
|
2020-02-01 20:41:32 +01:00
|
|
|
else
|
|
|
|
setDrawBackground(false);
|
2020-01-22 19:09:11 +01:00
|
|
|
|
|
|
|
if (!WordWrap) {
|
|
|
|
BrokenText.push_back(cText);
|
2015-01-16 07:54:26 +01:00
|
|
|
return;
|
2020-01-22 19:09:11 +01:00
|
|
|
}
|
2015-01-16 07:54:26 +01:00
|
|
|
|
2020-01-22 19:09:11 +01:00
|
|
|
// Update word wrap
|
2015-01-16 07:54:26 +01:00
|
|
|
|
|
|
|
IGUISkin* skin = Environment->getSkin();
|
|
|
|
IGUIFont* font = getActiveFont();
|
|
|
|
if (!font)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LastBreakFont = font;
|
|
|
|
|
2016-05-31 17:30:11 +02:00
|
|
|
EnrichedString line;
|
|
|
|
EnrichedString word;
|
|
|
|
EnrichedString whitespace;
|
|
|
|
s32 size = cText.size();
|
2015-01-16 07:54:26 +01:00
|
|
|
s32 length = 0;
|
|
|
|
s32 elWidth = RelativeRect.getWidth();
|
|
|
|
if (Border)
|
|
|
|
elWidth -= 2*skin->getSize(EGDS_TEXT_DISTANCE_X);
|
|
|
|
wchar_t c;
|
|
|
|
|
2016-05-31 17:30:11 +02:00
|
|
|
//std::vector<irr::video::SColor> colors;
|
2015-01-16 07:54:26 +01:00
|
|
|
|
|
|
|
// We have to deal with right-to-left and left-to-right differently
|
|
|
|
// However, most parts of the following code is the same, it's just
|
|
|
|
// some order and boundaries which change.
|
|
|
|
if (!RightToLeft)
|
|
|
|
{
|
|
|
|
// regular (left-to-right)
|
|
|
|
for (s32 i=0; i<size; ++i)
|
|
|
|
{
|
2016-05-31 17:30:11 +02:00
|
|
|
c = cText.getString()[i];
|
2015-01-16 07:54:26 +01:00
|
|
|
bool lineBreak = false;
|
|
|
|
|
|
|
|
if (c == L'\r') // Mac or Windows breaks
|
|
|
|
{
|
|
|
|
lineBreak = true;
|
2016-05-31 17:30:11 +02:00
|
|
|
//if (Text[i+1] == L'\n') // Windows breaks
|
|
|
|
//{
|
|
|
|
// Text.erase(i+1);
|
|
|
|
// --size;
|
|
|
|
//}
|
2015-01-16 07:54:26 +01:00
|
|
|
c = '\0';
|
|
|
|
}
|
|
|
|
else if (c == L'\n') // Unix breaks
|
|
|
|
{
|
|
|
|
lineBreak = true;
|
|
|
|
c = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isWhitespace = (c == L' ' || c == 0);
|
|
|
|
if ( !isWhitespace )
|
|
|
|
{
|
|
|
|
// part of a word
|
2016-05-31 17:30:11 +02:00
|
|
|
//word += c;
|
|
|
|
word.addChar(cText, i);
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( isWhitespace || i == (size-1))
|
|
|
|
{
|
|
|
|
if (word.size())
|
|
|
|
{
|
|
|
|
// here comes the next whitespace, look if
|
|
|
|
// we must break the last word to the next line.
|
|
|
|
const s32 whitelgth = font->getDimension(whitespace.c_str()).Width;
|
2016-05-31 17:30:11 +02:00
|
|
|
//const std::wstring sanitized = removeEscapes(word.c_str());
|
|
|
|
const s32 wordlgth = font->getDimension(word.c_str()).Width;
|
2015-01-16 07:54:26 +01:00
|
|
|
|
|
|
|
if (wordlgth > elWidth)
|
|
|
|
{
|
|
|
|
// This word is too long to fit in the available space, look for
|
|
|
|
// the Unicode Soft HYphen (SHY / 00AD) character for a place to
|
|
|
|
// break the word at
|
2016-05-31 17:30:11 +02:00
|
|
|
int where = core::stringw(word.c_str()).findFirst( wchar_t(0x00AD) );
|
2015-01-16 07:54:26 +01:00
|
|
|
if (where != -1)
|
|
|
|
{
|
2016-05-31 17:30:11 +02:00
|
|
|
EnrichedString first = word.substr(0, where);
|
|
|
|
EnrichedString second = word.substr(where, word.size() - where);
|
|
|
|
first.addCharNoColor(L'-');
|
|
|
|
BrokenText.push_back(line + first);
|
2015-01-16 07:54:26 +01:00
|
|
|
const s32 secondLength = font->getDimension(second.c_str()).Width;
|
|
|
|
|
|
|
|
length = secondLength;
|
|
|
|
line = second;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No soft hyphen found, so there's nothing more we can do
|
|
|
|
// break to next line
|
|
|
|
if (length)
|
|
|
|
BrokenText.push_back(line);
|
|
|
|
length = wordlgth;
|
|
|
|
line = word;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (length && (length + wordlgth + whitelgth > elWidth))
|
|
|
|
{
|
|
|
|
// break to next line
|
|
|
|
BrokenText.push_back(line);
|
|
|
|
length = wordlgth;
|
|
|
|
line = word;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// add word to line
|
|
|
|
line += whitespace;
|
|
|
|
line += word;
|
|
|
|
length += whitelgth + wordlgth;
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:30:11 +02:00
|
|
|
word.clear();
|
|
|
|
whitespace.clear();
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
|
2016-05-31 17:30:11 +02:00
|
|
|
if ( isWhitespace && c != 0)
|
2015-01-16 07:54:26 +01:00
|
|
|
{
|
2016-05-31 17:30:11 +02:00
|
|
|
whitespace.addChar(cText, i);
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// compute line break
|
|
|
|
if (lineBreak)
|
|
|
|
{
|
|
|
|
line += whitespace;
|
|
|
|
line += word;
|
|
|
|
BrokenText.push_back(line);
|
2016-05-31 17:30:11 +02:00
|
|
|
line.clear();
|
|
|
|
word.clear();
|
|
|
|
whitespace.clear();
|
2015-01-16 07:54:26 +01:00
|
|
|
length = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
line += whitespace;
|
|
|
|
line += word;
|
|
|
|
BrokenText.push_back(line);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// right-to-left
|
|
|
|
for (s32 i=size; i>=0; --i)
|
|
|
|
{
|
2016-05-31 17:30:11 +02:00
|
|
|
c = cText.getString()[i];
|
2015-01-16 07:54:26 +01:00
|
|
|
bool lineBreak = false;
|
|
|
|
|
|
|
|
if (c == L'\r') // Mac or Windows breaks
|
|
|
|
{
|
|
|
|
lineBreak = true;
|
2016-05-31 17:30:11 +02:00
|
|
|
//if ((i>0) && Text[i-1] == L'\n') // Windows breaks
|
|
|
|
//{
|
|
|
|
// Text.erase(i-1);
|
|
|
|
// --size;
|
|
|
|
//}
|
2015-01-16 07:54:26 +01:00
|
|
|
c = '\0';
|
|
|
|
}
|
|
|
|
else if (c == L'\n') // Unix breaks
|
|
|
|
{
|
|
|
|
lineBreak = true;
|
|
|
|
c = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c==L' ' || c==0 || i==0)
|
|
|
|
{
|
|
|
|
if (word.size())
|
|
|
|
{
|
|
|
|
// here comes the next whitespace, look if
|
|
|
|
// we must break the last word to the next line.
|
|
|
|
const s32 whitelgth = font->getDimension(whitespace.c_str()).Width;
|
|
|
|
const s32 wordlgth = font->getDimension(word.c_str()).Width;
|
|
|
|
|
|
|
|
if (length && (length + wordlgth + whitelgth > elWidth))
|
|
|
|
{
|
|
|
|
// break to next line
|
|
|
|
BrokenText.push_back(line);
|
|
|
|
length = wordlgth;
|
|
|
|
line = word;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// add word to line
|
|
|
|
line = whitespace + line;
|
|
|
|
line = word + line;
|
|
|
|
length += whitelgth + wordlgth;
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:30:11 +02:00
|
|
|
word.clear();
|
|
|
|
whitespace.clear();
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (c != 0)
|
2016-05-31 17:30:11 +02:00
|
|
|
// whitespace = core::stringw(&c, 1) + whitespace;
|
|
|
|
whitespace = cText.substr(i, 1) + whitespace;
|
2015-01-16 07:54:26 +01:00
|
|
|
|
|
|
|
// compute line break
|
|
|
|
if (lineBreak)
|
|
|
|
{
|
|
|
|
line = whitespace + line;
|
|
|
|
line = word + line;
|
|
|
|
BrokenText.push_back(line);
|
2016-05-31 17:30:11 +02:00
|
|
|
line.clear();
|
|
|
|
word.clear();
|
|
|
|
whitespace.clear();
|
2015-01-16 07:54:26 +01:00
|
|
|
length = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// yippee this is a word..
|
2016-05-31 17:30:11 +02:00
|
|
|
//word = core::stringw(&c, 1) + word;
|
|
|
|
word = cText.substr(i, 1) + word;
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
line = whitespace + line;
|
|
|
|
line = word + line;
|
|
|
|
BrokenText.push_back(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Sets the new caption of this element.
|
|
|
|
void StaticText::setText(const wchar_t* text)
|
|
|
|
{
|
2020-01-22 19:09:11 +01:00
|
|
|
setText(EnrichedString(text, getOverrideColor()));
|
2016-05-31 17:30:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void StaticText::setText(const EnrichedString &text)
|
|
|
|
{
|
2020-01-22 19:09:11 +01:00
|
|
|
ColoredText = text;
|
|
|
|
IGUIElement::setText(ColoredText.c_str());
|
|
|
|
updateText();
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void StaticText::updateAbsolutePosition()
|
|
|
|
{
|
|
|
|
IGUIElement::updateAbsolutePosition();
|
2020-01-22 19:09:11 +01:00
|
|
|
updateText();
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Returns the height of the text in pixels when it is drawn.
|
|
|
|
s32 StaticText::getTextHeight() const
|
|
|
|
{
|
|
|
|
IGUIFont* font = getActiveFont();
|
|
|
|
if (!font)
|
|
|
|
return 0;
|
|
|
|
|
2020-01-22 19:09:11 +01:00
|
|
|
if (WordWrap) {
|
|
|
|
s32 height = font->getDimension(L"A").Height + font->getKerningHeight();
|
|
|
|
return height * BrokenText.size();
|
|
|
|
}
|
|
|
|
// There may be intentional new lines without WordWrap
|
|
|
|
return font->getDimension(BrokenText[0].c_str()).Height;
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
s32 StaticText::getTextWidth() const
|
|
|
|
{
|
2020-01-22 19:09:11 +01:00
|
|
|
IGUIFont *font = getActiveFont();
|
|
|
|
if (!font)
|
2015-01-16 07:54:26 +01:00
|
|
|
return 0;
|
|
|
|
|
2020-01-22 19:09:11 +01:00
|
|
|
s32 widest = 0;
|
2015-01-16 07:54:26 +01:00
|
|
|
|
2020-01-22 19:09:11 +01:00
|
|
|
for (const EnrichedString &line : BrokenText) {
|
|
|
|
s32 width = font->getDimension(line.c_str()).Width;
|
2015-01-16 07:54:26 +01:00
|
|
|
|
2020-01-22 19:09:11 +01:00
|
|
|
if (width > widest)
|
|
|
|
widest = width;
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
2020-01-22 19:09:11 +01:00
|
|
|
|
|
|
|
return widest;
|
2015-01-16 07:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace gui
|
2016-05-31 17:30:11 +02:00
|
|
|
|
2015-01-16 07:54:26 +01:00
|
|
|
} // end namespace irr
|