summaryrefslogtreecommitdiffstats
path: root/src/graphics/engine/text.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphics/engine/text.cpp')
-rw-r--r--src/graphics/engine/text.cpp75
1 files changed, 39 insertions, 36 deletions
diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp
index 36ad660..00b6617 100644
--- a/src/graphics/engine/text.cpp
+++ b/src/graphics/engine/text.cpp
@@ -150,8 +150,8 @@ void CText::FlushCache()
}
void CText::DrawText(const std::string &text, const std::vector<FontMetaChar> &format,
- float size, Math::Point pos, float width, TextAlign align,
- int eol)
+ float size, Math::Point pos, float width, TextAlign align,
+ int eol)
{
float sw = 0.0f;
@@ -172,8 +172,8 @@ void CText::DrawText(const std::string &text, const std::vector<FontMetaChar> &f
}
void CText::DrawText(const std::string &text, FontType font,
- float size, Math::Point pos, float width, TextAlign align,
- int eol)
+ float size, Math::Point pos, float width, TextAlign align,
+ int eol)
{
float sw = 0.0f;
@@ -194,8 +194,8 @@ void CText::DrawText(const std::string &text, FontType font,
}
void CText::SizeText(const std::string &text, const std::vector<FontMetaChar> &format,
- float size, Math::Point pos, TextAlign align,
- Math::Point &start, Math::Point &end)
+ float size, Math::Point pos, TextAlign align,
+ Math::Point &start, Math::Point &end)
{
start = end = pos;
@@ -217,8 +217,8 @@ void CText::SizeText(const std::string &text, const std::vector<FontMetaChar> &f
}
void CText::SizeText(const std::string &text, FontType font,
- float size, Math::Point pos, TextAlign align,
- Math::Point &start, Math::Point &end)
+ float size, Math::Point pos, TextAlign align,
+ Math::Point &start, Math::Point &end)
{
start = end = pos;
@@ -277,7 +277,7 @@ float CText::GetHeight(FontType font, float size)
float CText::GetStringWidth(const std::string &text,
- const std::vector<FontMetaChar> &format, float size)
+ const std::vector<FontMetaChar> &format, float size)
{
assert(StrUtils::Utf8StringLength(text) == format.size());
@@ -344,7 +344,7 @@ float CText::GetCharWidth(UTF8Char ch, FontType font, float size, float offset)
int CText::Justify(const std::string &text, const std::vector<FontMetaChar> &format,
- float size, float width)
+ float size, float width)
{
assert(StrUtils::Utf8StringLength(text) == format.size());
@@ -427,7 +427,7 @@ int CText::Justify(const std::string &text, FontType font, float size, float wid
}
int CText::Detect(const std::string &text, const std::vector<FontMetaChar> &format,
- float size, float offset)
+ float size, float offset)
{
assert(StrUtils::Utf8StringLength(text) == format.size());
@@ -500,7 +500,7 @@ int CText::Detect(const std::string &text, FontType font, float size, float offs
}
void CText::DrawString(const std::string &text, const std::vector<FontMetaChar> &format,
- float size, Math::Point pos, float width, int eol)
+ float size, Math::Point pos, float width, int eol)
{
assert(StrUtils::Utf8StringLength(text) == format.size());
@@ -509,24 +509,18 @@ void CText::DrawString(const std::string &text, const std::vector<FontMetaChar>
FontType font = FONT_COLOBOT;
float start = pos.x;
- unsigned int index = 0;
unsigned int fmtIndex = 0;
- while (index < text.length())
+
+ std::vector<UTF8Char> chars;
+ StringToUTFCharList(text, chars);
+ for (auto it = chars.begin(); it != chars.end(); ++it)
{
font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT);
// TODO: if (font == FONT_BUTTON)
if (font == FONT_BUTTON) continue;
- UTF8Char ch;
-
- int len = StrUtils::Utf8CharSizeAt(text, index);
- if (len >= 1)
- ch.c1 = text[index];
- if (len >= 2)
- ch.c2 = text[index+1];
- if (len >= 3)
- ch.c3 = text[index+2];
+ UTF8Char ch = *it;
float offset = pos.x - start;
float cw = GetCharWidth(ch, font, size, offset);
@@ -545,22 +539,16 @@ void CText::DrawString(const std::string &text, const std::vector<FontMetaChar>
DrawHighlight(hl, pos, charSize);
}
- DrawChar(ch, font, size, pos);
+ DrawCharAndAdjustPos(ch, font, size, pos);
- index += len;
fmtIndex++;
}
// TODO: eol
}
-void CText::DrawString(const std::string &text, FontType font,
- float size, Math::Point pos, float width, int eol)
+void CText::StringToUTFCharList(const std::string &text, std::vector<UTF8Char> &chars)
{
- assert(font != FONT_BUTTON);
-
- m_engine->SetState(ENG_RSTATE_TEXT);
-
unsigned int index = 0;
while (index < text.length())
{
@@ -568,15 +556,30 @@ void CText::DrawString(const std::string &text, FontType font,
int len = StrUtils::Utf8CharSizeAt(text, index);
if (len >= 1)
- ch.c1 = text[index];
+ ch.c1 = text[index];
if (len >= 2)
- ch.c2 = text[index+1];
+ ch.c2 = text[index+1];
if (len >= 3)
- ch.c3 = text[index+2];
+ ch.c3 = text[index+2];
index += len;
- DrawChar(ch, font, size, pos);
+ chars.push_back(ch);
+ }
+}
+
+void CText::DrawString(const std::string &text, FontType font,
+ float size, Math::Point pos, float width, int eol)
+{
+ assert(font != FONT_BUTTON);
+
+ m_engine->SetState(ENG_RSTATE_TEXT);
+
+ std::vector<UTF8Char> chars;
+ StringToUTFCharList(text, chars);
+ for (auto it = chars.begin(); it != chars.end(); ++it)
+ {
+ DrawCharAndAdjustPos(*it, font, size, pos);
}
}
@@ -660,7 +663,7 @@ void CText::DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point size)
m_device->SetRenderState(RENDER_STATE_TEXTURING, true);
}
-void CText::DrawChar(UTF8Char ch, FontType font, float size, Math::Point &pos)
+void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::Point &pos)
{
// TODO: if (font == FONT_BUTTON)
if (font == FONT_BUTTON) return;