diff options
author | Piotr Dziwinski <piotrdz@gmail.com> | 2012-09-29 10:40:11 +0200 |
---|---|---|
committer | Piotr Dziwinski <piotrdz@gmail.com> | 2012-09-29 10:40:11 +0200 |
commit | 677ce3960cd13cbf994311c76d75b343b22fd480 (patch) | |
tree | ee2bab43ec29cdf94d8c1173ee022fe95c2a0222 /src/graphics/engine/text.cpp | |
parent | 77952a85e63ca13dd9cfc93c7b6a271d7c91e59a (diff) | |
download | colobot-677ce3960cd13cbf994311c76d75b343b22fd480.tar.gz colobot-677ce3960cd13cbf994311c76d75b343b22fd480.tar.bz2 colobot-677ce3960cd13cbf994311c76d75b343b22fd480.zip |
Some fixes and optimizations
- fixed 2nd texture setting
- added padding to some structs for faster access
- changed rendering primitives to glDrawArrays()
- optimized texture modesetting calls
- fixed some valgrind errors
Diffstat (limited to 'src/graphics/engine/text.cpp')
-rw-r--r-- | src/graphics/engine/text.cpp | 42 |
1 files changed, 13 insertions, 29 deletions
diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index a77a6fd..4deeb53 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -279,18 +279,14 @@ float CText::GetHeight(FontType font, float size) float CText::GetStringWidth(const std::string &text, std::map<unsigned int, FontMetaChar> &format, float size) { - // TODO assert was commented as new code uses map not vector and if's size doesn't have to match text length - // this has to be tested if it's correct - //assert(StrUtils::Utf8StringLength(text) == format.size()); - float width = 0.0f; unsigned int index = 0; unsigned int fmtIndex = 0; while (index < text.length()) { FontType font = FONT_COLOBOT; - if (format.count(fmtIndex)) - font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT); + if (format.count(fmtIndex)) + font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT); UTF8Char ch; @@ -350,10 +346,6 @@ float CText::GetCharWidth(UTF8Char ch, FontType font, float size, float offset) int CText::Justify(const std::string &text, std::map<unsigned int, FontMetaChar> &format, float size, float width) { - // TODO assert was commented as new code uses map not vector and if's size doesn't have to match text length - // this has to be tested if it's correct - //assert(StrUtils::Utf8StringLength(text) == format.size()); - float pos = 0.0f; int cut = 0; unsigned int index = 0; @@ -361,8 +353,8 @@ int CText::Justify(const std::string &text, std::map<unsigned int, FontMetaChar> while (index < text.length()) { FontType font = FONT_COLOBOT; - if (format.count(fmtIndex)) - font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT); + if (format.count(fmtIndex)) + font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT); UTF8Char ch; @@ -437,18 +429,14 @@ int CText::Justify(const std::string &text, FontType font, float size, float wid int CText::Detect(const std::string &text, std::map<unsigned int, FontMetaChar> &format, float size, float offset) { - // TODO assert was commented as new code uses map not vector and if's size doesn't have to match text length - // this has to be tested if it's correct - //assert(StrUtils::Utf8StringLength(text) == format.size()); - float pos = 0.0f; unsigned int index = 0; unsigned int fmtIndex = 0; while (index < text.length()) { FontType font = FONT_COLOBOT; - if (format.count(fmtIndex)) - font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT); + if (format.count(fmtIndex)) + font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT); // TODO: if (font == FONT_BUTTON) if (font == FONT_BUTTON) continue; @@ -514,13 +502,8 @@ int CText::Detect(const std::string &text, FontType font, float size, float offs void CText::DrawString(const std::string &text, std::map<unsigned int, FontMetaChar> &format, float size, Math::Point pos, float width, int eol) { - // TODO assert was commented as new code uses map not vector and if's size doesn't have to match text length - // this has to be tested if it's correct - //assert(StrUtils::Utf8StringLength(text) == format.size()); - m_engine->SetState(ENG_RSTATE_TEXT); - FontType font = FONT_COLOBOT; float start = pos.x; unsigned int fmtIndex = 0; @@ -530,8 +513,8 @@ void CText::DrawString(const std::string &text, std::map<unsigned int, FontMetaC for (auto it = chars.begin(); it != chars.end(); ++it) { FontType font = FONT_COLOBOT; - if (format.count(fmtIndex)) - font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT); + if (format.count(fmtIndex)) + font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT); // TODO: if (font == FONT_BUTTON) if (font == FONT_BUTTON) continue; @@ -566,17 +549,18 @@ void CText::DrawString(const std::string &text, std::map<unsigned int, FontMetaC void CText::StringToUTFCharList(const std::string &text, std::vector<UTF8Char> &chars) { unsigned int index = 0; - while (index < text.length()) + unsigned int totalLength = text.length(); + while (index < totalLength) { UTF8Char ch; 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; |