From 4f033e38a7465768b6b9e67942278b067728cffb Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Sun, 16 Sep 2012 12:42:08 +0000 Subject: [PATCH] -draw button text the same way as labels to fix problems with displaying things like _ or ' (issue 97) --- source/gui/gui.cpp | 21 ++++++++++++++++----- source/gui/gui.hpp | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/source/gui/gui.cpp b/source/gui/gui.cpp index d8812aa6..fe861a46 100644 --- a/source/gui/gui.cpp +++ b/source/gui/gui.cpp @@ -38,7 +38,8 @@ s16 CButtonsMgr::addButton(SFont font, const wstringEx &text, int x, int y, u32 b->font = font; b->visible = false; - b->text = text; + //b->text = text; + b->text.setText(b->font, text); b->textColor = color; b->x = x + width / 2; b->y = y + height / 2; @@ -379,6 +380,7 @@ void CButtonsMgr::SButton::tick(void) CButtonsMgr::SElement::tick(); click += -click * 0.2f; if (click < 0.01f) click = 0.f; + text.tick(); } void CButtonsMgr::SProgressBar::tick(void) @@ -483,10 +485,13 @@ void CButtonsMgr::setText(s16 id, const wstringEx &text, bool unwrap) if (id < (s32)m_elts.size()) { CButtonsMgr::SLabel *lbl; + CButtonsMgr::SButton *btn; switch (m_elts[id]->t) { case CButtonsMgr::GUIELT_BUTTON: - ((CButtonsMgr::SButton *)m_elts[id].get())->text = text; + //((CButtonsMgr::SButton *)m_elts[id].get())->text = text; + btn = (CButtonsMgr::SButton *)m_elts[id].get(); + btn->text.setText(btn->font, text); break; case CButtonsMgr::GUIELT_LABEL: lbl = (CButtonsMgr::SLabel *)m_elts[id].get(); @@ -506,10 +511,13 @@ void CButtonsMgr::setText(s16 id, const wstringEx &text, u32 startline,bool unwr if (id < (s32)m_elts.size()) { CButtonsMgr::SLabel *lbl; + CButtonsMgr::SButton *btn; switch (m_elts[id]->t) { case CButtonsMgr::GUIELT_BUTTON: //((CButtonsMgr::SButton *)m_elts[id].get())->text = text; + btn = (CButtonsMgr::SButton *)m_elts[id].get(); + btn->text.setText(btn->font, text); break; case CButtonsMgr::GUIELT_LABEL: lbl = (CButtonsMgr::SLabel *)m_elts[id].get(); @@ -591,7 +599,7 @@ void CButtonsMgr::setProgress(s16 id, float f, bool instant) } } -void CButtonsMgr::_drawBtn(const CButtonsMgr::SButton &b, bool selected, bool click) +void CButtonsMgr::_drawBtn(CButtonsMgr::SButton &b, bool selected, bool click) { GXTexObj texObjLeft; GXTexObj texObjCenter; @@ -699,10 +707,13 @@ void CButtonsMgr::_drawBtn(const CButtonsMgr::SButton &b, bool selected, bool cl } if (!b.font.font) return; b.font.font->reset(); - CColor txtColor(b.textColor.r, b.textColor.g, b.textColor.b, (u8)((int)b.textColor.a * (int)alpha / 0xFF)); + //CColor txtColor(b.textColor.r, b.textColor.g, b.textColor.b, (u8)((int)b.textColor.a * (int)alpha / 0xFF)); b.font.font->setXScale(scaleX); b.font.font->setYScale(scaleY); - b.font.font->drawText(0, 0, b.text.c_str(), txtColor, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE); + //b.font.font->drawText(0, 0, b.text.c_str(), txtColor, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE); + b.text.setColor(CColor(b.textColor.r, b.textColor.g, b.textColor.b, (u8)((int)b.textColor.a * (int)alpha / 0xFF))); + b.text.setFrame(b.w, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE, true, true); + b.text.draw(); } void CButtonsMgr::_drawLbl(CButtonsMgr::SLabel &b) diff --git a/source/gui/gui.hpp b/source/gui/gui.hpp index f138dacc..59646d1a 100644 --- a/source/gui/gui.hpp +++ b/source/gui/gui.hpp @@ -108,7 +108,7 @@ private: { SFont font; SButtonTextureSet tex; - wstringEx text; + CText text; CColor textColor; float click; SmartGuiSound clickSound; @@ -152,7 +152,7 @@ private: bool m_mouse; CVideo m_vid; private: - void _drawBtn(const SButton &b, bool selected, bool click); + void _drawBtn(SButton &b, bool selected, bool click); void _drawLbl(SLabel &b); void _drawPBar(const SProgressBar &b); static STexture _noTexture;