This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch upstream/latest
in repository colobot.

commit ed0850ddb63bfa9544d8662f1f85567904f92c8e
Author: krzys-h <krzy...@interia.pl>
Date:   Tue Apr 7 12:26:44 2015 +0200

    Fixed buttons "eating" other characters in SatCom
---
 src/graphics/engine/text.cpp | 52 ++++++++++++++++++++++++++++++++++++++------
 src/graphics/engine/text.h   |  1 +
 2 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp
index b383a6b..9ee190a 100644
--- a/src/graphics/engine/text.cpp
+++ b/src/graphics/engine/text.cpp
@@ -350,8 +350,12 @@ float CText::GetStringWidth(std::string text, FontType 
font, float size)
 
 float CText::GetCharWidth(UTF8Char ch, FontType font, float size, float offset)
 {
-    // TODO: if (font == FONT_BUTTON)
-    if (font == FONT_BUTTON) return 0.0f;
+    if (font == FONT_BUTTON) {
+        Math::IntPoint windowSize = m_engine->GetWindowSize();
+        float height = GetHeight(FONT_COLOBOT, size);
+        float width = height*(static_cast<float>(windowSize.y)/windowSize.x);
+        return width;
+    }
 
     int width = 1;
     if (ch.c1 < 32 && ch.c1 >= 0)
@@ -614,7 +618,7 @@ void CText::DrawString(const std::string &text, 
std::vector<FontMetaChar>::itera
     unsigned int fmtIndex = 0;
 
     std::vector<UTF8Char> chars;
-    StringToUTFCharList(text, chars);
+    StringToUTFCharList(text, chars, format, end);
     for (auto it = chars.begin(); it != chars.end(); ++it)
     {
         FontType font = FONT_COLOBOT;
@@ -686,6 +690,42 @@ void CText::StringToUTFCharList(const std::string &text, 
std::vector<UTF8Char> &
     }
 }
 
+void CText::StringToUTFCharList(const std::string &text, std::vector<UTF8Char> 
&chars, std::vector<FontMetaChar>::iterator format, 
std::vector<FontMetaChar>::iterator end)
+{
+    unsigned int index = 0;
+    unsigned int totalLength = text.length();
+    while (index < totalLength)
+    {
+        UTF8Char ch;
+
+        FontType font = FONT_COLOBOT;
+        if(format + index != end)
+            font = static_cast<FontType>(*(format + index) & FONT_MASK_FONT);
+
+        int len;
+
+        if(font == FONT_BUTTON)
+        {
+            len = 1;
+        }
+        else
+        {
+            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;
+
+        chars.push_back(ch);
+    }
+}
+
 void CText::DrawString(const std::string &text, FontType font,
                        float size, Math::Point pos, float width, int eol, 
Color color)
 {
@@ -795,7 +835,7 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType 
font, float size, Math::P
         Math::Vector n(0.0f, 0.0f, -1.0f);  // normal
 
         // For whatever reason ch.c1 is a SIGNED char, we need to fix that
-        unsigned int icon = static_cast<unsigned char>(ch.c1);
+        unsigned char icon = static_cast<unsigned char>(ch.c1);
         if ( icon >= 192 )
         {
             icon -= 192;
@@ -843,9 +883,7 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType 
font, float size, Math::P
         m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, quad, 4, color);
         m_engine->AddStatisticTriangle(2);
 
-        // Don't ask my why but using height instead of width makes the 
buttons align perfectly with text without icons in category list in SatCom
-        // It's magic!
-        pos.x += height;
+        pos.x += width;
 
         // Don't forget to restore the state!
         m_engine->SetState(ENG_RSTATE_TEXT);
diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h
index 0551dcd..11f13c9 100644
--- a/src/graphics/engine/text.h
+++ b/src/graphics/engine/text.h
@@ -326,6 +326,7 @@ protected:
     void        DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point 
size);
     void        DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, 
Math::Point &pos, Color color);
     void        StringToUTFCharList(const std::string &text, 
std::vector<UTF8Char> &chars);
+    void        StringToUTFCharList(const std::string &text, 
std::vector<UTF8Char> &chars, std::vector<FontMetaChar>::iterator format, 
std::vector<FontMetaChar>::iterator end);
 
 protected:
     CEngine*       m_engine;

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-games/colobot.git

_______________________________________________
Pkg-games-commits mailing list
Pkg-games-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits

Reply via email to