This is an automated email from the git hooks/post-receive script. odyx pushed a commit to branch upstream/latest in repository colobot.
commit efe04be1c210c5d609df0d00bb784268033170b9 Author: krzys-h <krzy...@interia.pl> Date: Tue Apr 7 12:06:43 2015 +0200 Implemented button rendering in SatCom (#232) Finally! --- src/graphics/engine/text.cpp | 140 +++++++++++++++++++++++++++++++------------ src/ui/edit.cpp | 2 - 2 files changed, 102 insertions(+), 40 deletions(-) diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index bebf30c..b383a6b 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -621,9 +621,6 @@ void CText::DrawString(const std::string &text, std::vector<FontMetaChar>::itera if (format + fmtIndex != end) font = static_cast<FontType>(*(format + fmtIndex) & FONT_MASK_FONT); - // TODO: if (font == FONT_BUTTON) - if (font == FONT_BUTTON) continue; - UTF8Char ch = *it; float offset = pos.x - start; @@ -786,57 +783,124 @@ void CText::DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point size) void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::Point &pos, Color color) { - // TODO: if (font == FONT_BUTTON) - if (font == FONT_BUTTON) return; + 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); - CachedFont* cf = GetOrOpenFont(font, size); + Math::Point p1(pos.x, pos.y); + Math::Point p2(pos.x + width, pos.y + height); - if (cf == nullptr) - return; + Math::Vector n(0.0f, 0.0f, -1.0f); // normal - int width = 1; - if (ch.c1 > 0 && ch.c1 < 32) - { - if (ch.c1 == '\t') - width = m_tabSize; + // For whatever reason ch.c1 is a SIGNED char, we need to fix that + unsigned int icon = static_cast<unsigned char>(ch.c1); + if ( icon >= 192 ) + { + icon -= 192; + m_engine->SetTexture("textures/interface/text.png"); + m_engine->SetState(ENG_RSTATE_TTEXTURE_WHITE); + } + else if ( icon >= 128 ) + { + icon -= 128; + m_engine->SetTexture("textures/interface/button3.png"); + m_engine->SetState(ENG_RSTATE_TTEXTURE_WHITE); + } + else if ( icon >= 64 ) + { + icon -= 64; + m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetState(ENG_RSTATE_TTEXTURE_WHITE); + } + else + { + m_engine->SetTexture("textures/interface/button1.png"); + m_engine->SetState(ENG_RSTATE_TTEXTURE_WHITE); + } - ch = TranslateSpecialChar(ch.c1); - } + Math::Point uv1, uv2; + uv1.x = (32.0f / 256.0f) * (icon%8); + uv1.y = (32.0f / 256.0f) * (icon/8); + uv2.x = (32.0f / 256.0f) + uv1.x; + uv2.y = (32.0f / 256.0f) + uv1.y; - auto it = cf->cache.find(ch); - CharTexture tex; - if (it != cf->cache.end()) - { - tex = (*it).second; + float dp = 0.5f / 256.0f; + uv1.x += dp; + uv1.y += dp; + uv2.x -= dp; + uv2.y -= dp; + + Vertex quad[4] = + { + Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x, uv2.y)), + Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(uv1.x, uv1.y)), + Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(uv2.x, uv2.y)), + Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv2.x, uv1.y)) + }; + + 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; + + // Don't forget to restore the state! + m_engine->SetState(ENG_RSTATE_TEXT); } else { - tex = CreateCharTexture(ch, cf); + CachedFont* cf = GetOrOpenFont(font, size); - if (tex.id == 0) // invalid + if (cf == nullptr) return; - cf->cache[ch] = tex; - } + int width = 1; + if (ch.c1 > 0 && ch.c1 < 32) + { + if (ch.c1 == '\t') + width = m_tabSize; - Math::Point p1(pos.x, pos.y + tex.charSize.y - tex.texSize.y); - Math::Point p2(pos.x + tex.texSize.x, pos.y + tex.charSize.y); + ch = TranslateSpecialChar(ch.c1); + } - Math::Vector n(0.0f, 0.0f, -1.0f); // normal + auto it = cf->cache.find(ch); + CharTexture tex; + if (it != cf->cache.end()) + { + tex = (*it).second; + } + else + { + tex = CreateCharTexture(ch, cf); - Vertex quad[4] = - { - Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(0.0f, 1.0f)), - Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(0.0f, 0.0f)), - Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(1.0f, 1.0f)), - Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(1.0f, 0.0f)) - }; + if (tex.id == 0) // invalid + return; - m_device->SetTexture(0, tex.id); - m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, quad, 4, color); - m_engine->AddStatisticTriangle(2); + cf->cache[ch] = tex; + } + + Math::Point p1(pos.x, pos.y + tex.charSize.y - tex.texSize.y); + Math::Point p2(pos.x + tex.texSize.x, pos.y + tex.charSize.y); - pos.x += tex.charSize.x * width; + Math::Vector n(0.0f, 0.0f, -1.0f); // normal + + Vertex quad[4] = + { + Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(0.0f, 1.0f)), + Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(0.0f, 0.0f)), + Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(1.0f, 1.0f)), + Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(1.0f, 0.0f)) + }; + + m_device->SetTexture(0, tex.id); + m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, quad, 4, color); + m_engine->AddStatisticTriangle(2); + + pos.x += tex.charSize.x * width; + } } CachedFont* CText::GetOrOpenFont(FontType font, float size) diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index 35afd50..3ebc281 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -1662,14 +1662,12 @@ bool CEdit::ReadText(std::string filename, int addSize) buffer[i+6] == 'n' && buffer[i+7] == ' ' ) { - /* TODO: \button X; isn't working. Issue #232 if ( m_bSoluce || !bInSoluce ) { m_text[j] = GetValueParam(buffer+i+8, 0); m_format[j] = font|Gfx::FONT_BUTTON; j ++; } - */ i += strchr(buffer+i, ';')-(buffer+i)+1; } else if ( //m_format.size() > 0 && -- 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