Support more buttonX.png files in other places than just buttons
parent
05bc65a90b
commit
12cf57409c
|
@ -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
|
// For whatever reason ch.c1 is a SIGNED char, we need to fix that
|
||||||
unsigned char icon = static_cast<unsigned char>(ch.c1);
|
unsigned char icon = static_cast<unsigned char>(ch.c1);
|
||||||
|
|
||||||
unsigned int texID;
|
// TODO: A bit of code duplication, see CControl::SetButtonTextureForIcon()
|
||||||
|
unsigned int texID = m_engine->LoadTexture("textures/interface/button" + StrUtils::ToString<int>((icon/64) + 1) + ".png").id;
|
||||||
if ( icon >= 128 )
|
icon = icon%64;
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Math::Point uv1, uv2;
|
Math::Point uv1, uv2;
|
||||||
uv1.x = (32.0f / 256.0f) * (icon%8);
|
uv1.x = (32.0f / 256.0f) * (icon%8);
|
||||||
|
|
|
@ -519,13 +519,7 @@ void CControl::Draw()
|
||||||
|
|
||||||
if ( m_state & STATE_DEAD ) return;
|
if ( m_state & STATE_DEAD ) return;
|
||||||
|
|
||||||
|
icon = SetButtonTextureForIcon(m_icon);
|
||||||
icon = m_icon%64;
|
|
||||||
buttonFile = (m_icon/64) + 1;
|
|
||||||
if ( buttonFile != 1 )
|
|
||||||
{
|
|
||||||
m_engine->SetTexture("textures/interface/button" + StrUtils::ToString<int>(buttonFile) + ".png");
|
|
||||||
}
|
|
||||||
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
|
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
|
||||||
if ( icon != -1 )
|
if ( icon != -1 )
|
||||||
{
|
{
|
||||||
|
@ -844,5 +838,13 @@ std::string CControl::GetResourceName(EventType eventType)
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CControl::SetButtonTextureForIcon(int icon)
|
||||||
|
{
|
||||||
|
int iconIdx = icon%64;
|
||||||
|
int buttonFile = (icon/64) + 1;
|
||||||
|
m_engine->SetTexture("textures/interface/button" + StrUtils::ToString<int>(buttonFile) + ".png");
|
||||||
|
return iconIdx;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,6 +116,13 @@ protected:
|
||||||
|
|
||||||
std::string GetResourceName(EventType eventType);
|
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:
|
protected:
|
||||||
Gfx::CEngine* m_engine;
|
Gfx::CEngine* m_engine;
|
||||||
Gfx::CParticle* m_particle;
|
Gfx::CParticle* m_particle;
|
||||||
|
|
|
@ -123,21 +123,7 @@ void CShortcut::Draw()
|
||||||
DrawVertex(icon, 0.95f);
|
DrawVertex(icon, 0.95f);
|
||||||
}
|
}
|
||||||
|
|
||||||
icon = m_icon;
|
icon = SetButtonTextureForIcon(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");
|
|
||||||
}
|
|
||||||
if (m_icon == 58)
|
if (m_icon == 58)
|
||||||
{
|
{
|
||||||
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
|
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
|
||||||
|
|
Loading…
Reference in New Issue