diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 0ecd5820..045cdc4c 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -1004,22 +1004,9 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::I // For whatever reason ch.c1 is a SIGNED char, we need to fix that unsigned char icon = static_cast(ch.c1); - unsigned int texID; - - if ( icon >= 128 ) - { - icon -= 128; - texID = m_engine->LoadTexture("textures/interface/button3.png").id; - } - else if ( icon >= 64 ) - { - icon -= 64; - texID = m_engine->LoadTexture("textures/interface/button2.png").id; - } - else - { - texID = m_engine->LoadTexture("textures/interface/button1.png").id; - } + // TODO: A bit of code duplication, see CControl::SetButtonTextureForIcon() + unsigned int texID = m_engine->LoadTexture("textures/interface/button" + StrUtils::ToString((icon/64) + 1) + ".png").id; + icon = icon%64; Math::Point uv1, uv2; uv1.x = (32.0f / 256.0f) * (icon%8); diff --git a/src/ui/controls/control.cpp b/src/ui/controls/control.cpp index 0d1692ee..9c91f51c 100644 --- a/src/ui/controls/control.cpp +++ b/src/ui/controls/control.cpp @@ -519,13 +519,7 @@ void CControl::Draw() if ( m_state & STATE_DEAD ) return; - - icon = m_icon%64; - buttonFile = (m_icon/64) + 1; - if ( buttonFile != 1 ) - { - m_engine->SetTexture("textures/interface/button" + StrUtils::ToString(buttonFile) + ".png"); - } + icon = SetButtonTextureForIcon(m_icon); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); if ( icon != -1 ) { @@ -844,5 +838,13 @@ std::string CControl::GetResourceName(EventType eventType) return name; } +int CControl::SetButtonTextureForIcon(int icon) +{ + int iconIdx = icon%64; + int buttonFile = (icon/64) + 1; + m_engine->SetTexture("textures/interface/button" + StrUtils::ToString(buttonFile) + ".png"); + return iconIdx; +} + } diff --git a/src/ui/controls/control.h b/src/ui/controls/control.h index d3e6d5aa..a7166df8 100644 --- a/src/ui/controls/control.h +++ b/src/ui/controls/control.h @@ -116,6 +116,13 @@ protected: std::string GetResourceName(EventType eventType); + /** + * \brief Set texture in m_engine to correct buttonX.png for given icon + * \param icon Icon to draw + * \return Index inside the selected texture of the icon to draw + */ + int SetButtonTextureForIcon(int icon); + protected: Gfx::CEngine* m_engine; Gfx::CParticle* m_particle; diff --git a/src/ui/controls/shortcut.cpp b/src/ui/controls/shortcut.cpp index d85132d1..7d3ddd6d 100644 --- a/src/ui/controls/shortcut.cpp +++ b/src/ui/controls/shortcut.cpp @@ -123,21 +123,7 @@ void CShortcut::Draw() DrawVertex(icon, 0.95f); } - icon = m_icon; - if ( icon >= 128 ) - { - icon -= 128; - m_engine->SetTexture("textures/interface/button3.png"); - } - else if ( icon >= 64 ) - { - icon -= 64; - m_engine->SetTexture("textures/interface/button2.png"); - } - else - { - m_engine->SetTexture("textures/interface/button1.png"); - } + icon = SetButtonTextureForIcon(m_icon); if (m_icon == 58) { m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);