summaryrefslogtreecommitdiffstats
path: root/src/graphics/engine
diff options
context:
space:
mode:
authorMichał Zieliński <michal@zielinscy.org.pl>2012-09-24 23:55:52 +0200
committerMichał Zieliński <michal@zielinscy.org.pl>2012-09-24 23:55:52 +0200
commitb06544871ae48871fc302706ecc49b78c6bcb3d2 (patch)
treefa2e01e13a4502c7b2a508f20fa648a53d27488c /src/graphics/engine
parent4e4046f843559811f884839da99dd01c38750c52 (diff)
downloadcolobot-b06544871ae48871fc302706ecc49b78c6bcb3d2.tar.gz
colobot-b06544871ae48871fc302706ecc49b78c6bcb3d2.tar.bz2
colobot-b06544871ae48871fc302706ecc49b78c6bcb3d2.zip
made graphics/engine/text cleaner, I hope
Diffstat (limited to 'src/graphics/engine')
-rw-r--r--src/graphics/engine/text.cpp63
-rw-r--r--src/graphics/engine/text.h4
2 files changed, 35 insertions, 32 deletions
diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp
index 36ad660..da9f4ac 100644
--- a/src/graphics/engine/text.cpp
+++ b/src/graphics/engine/text.cpp
@@ -509,24 +509,17 @@ 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);
+ 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,15 +538,36 @@ 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
}
+std::vector<UTF8Char> CText::StringToUTFCharList(const std::string &text) {
+ std::vector<UTF8Char> v;
+ unsigned int index = 0;
+ while (index < text.length())
+ {
+ 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];
+
+ index += len;
+
+ v.push_back(ch);
+ }
+ return v;
+}
+
void CText::DrawString(const std::string &text, FontType font,
float size, Math::Point pos, float width, int eol)
{
@@ -561,22 +575,9 @@ void CText::DrawString(const std::string &text, FontType font,
m_engine->SetState(ENG_RSTATE_TEXT);
- unsigned int index = 0;
- while (index < text.length())
- {
- 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];
-
- index += len;
-
- DrawChar(ch, font, size, pos);
+ std::vector<UTF8Char> chars = StringToUTFCharList(text);
+ for(auto it=chars.begin(); it != chars.end(); ++it){
+ DrawCharAndAdjustPos(*it, font, size, pos);
}
}
@@ -660,7 +661,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;
diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h
index e587609..0ecf7cd 100644
--- a/src/graphics/engine/text.h
+++ b/src/graphics/engine/text.h
@@ -292,7 +292,9 @@ protected:
void DrawString(const std::string &text, FontType font,
float size, Math::Point pos, float width, int eol);
void DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point size);
- void DrawChar(UTF8Char ch, FontType font, float size, Math::Point &pos);
+ void DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::Point &pos);
+ std::vector<UTF8Char>
+ StringToUTFCharList(const std::string &text);
protected:
CInstanceManager* m_iMan;