diff --git a/projects/mtg/include/SimpleButton.h b/projects/mtg/include/SimpleButton.h index 5a5791708..960b5b7c3 100644 --- a/projects/mtg/include/SimpleButton.h +++ b/projects/mtg/include/SimpleButton.h @@ -65,6 +65,7 @@ public: virtual void checkUserClick(); virtual float GetWidth(); + virtual float GetEnlargedWidth(); virtual void Relocate(float x, float y); virtual void RenderWithOffset(float yOffset); diff --git a/projects/mtg/src/SimpleButton.cpp b/projects/mtg/src/SimpleButton.cpp index d71509f33..64eb3f6da 100644 --- a/projects/mtg/src/SimpleButton.cpp +++ b/projects/mtg/src/SimpleButton.cpp @@ -29,8 +29,16 @@ JGuiObject(id), mX(x), mY(y), parent(_parent), mFontId(fontId) mHasFocus = hasFocus; - mScale = 1.0f; - mTargetScale = 1.0f; + mScale = (mText.size() < 20) ? SCALE_LARGE_NORMAL : SCALE_NORMAL; + + if (mHasFocus) { + mTargetScale = (mText.size() < 20) ? SCALE_SELECTED_LARGE : SCALE_SELECTED; + } + else + { + mTargetScale = (mText.size() < 20) ? SCALE_LARGE_NORMAL : SCALE_NORMAL; + } + mXOffset = mX; @@ -50,20 +58,8 @@ void SimpleButton::RenderWithOffset(float yOffset) { mYOffset = yOffset; WFont * mFont = WResourceManager::Instance()->GetWFont(mFontId); - if(mText.size() < 20) - { - if (mHasFocus) - mFont->SetScale(SCALE_SELECTED_LARGE); - else - mFont->SetScale(SCALE_LARGE_NORMAL); - } - else - { - if (mHasFocus) - mFont->SetScale(SCALE_SELECTED); - else - mFont->SetScale(SCALE_NORMAL); - } + + mFont->SetScale(mScale); mFont->DrawString(mText.c_str(), mX, mY + yOffset, JGETEXT_CENTER); } @@ -95,13 +91,13 @@ void SimpleButton::checkUserClick() void SimpleButton::Entering() { checkUserClick(); - mHasFocus = true; + setFocus(true); } bool SimpleButton::Leaving(JButton key) { checkUserClick(); - mHasFocus = false; + setFocus(false); return true; } @@ -167,6 +163,21 @@ bool SimpleButton::isSelectionValid() const void SimpleButton::setFocus(bool value) { mHasFocus = value; + + if (mHasFocus) { + if(mText.size() < 20) + mTargetScale = (SCALE_SELECTED_LARGE); + else + mTargetScale = (SCALE_SELECTED); + } + else + { + if(mText.size() < 20) + mTargetScale = (SCALE_LARGE_NORMAL); + else + mTargetScale = (SCALE_NORMAL); + } + } bool SimpleButton::hasFocus() const @@ -192,6 +203,17 @@ float SimpleButton::GetWidth() return mFont->GetStringWidth(mText.c_str()); } +float SimpleButton::GetEnlargedWidth() +{ + WFont * mFont = WResourceManager::Instance()->GetWFont(mFontId); + float backup = mFont->GetScale(); + mFont->SetScale(SCALE_SELECTED); + if(mText.size() < 20) + mFont->SetScale(SCALE_SELECTED_LARGE); + return mFont->GetStringWidth(mText.c_str()); + mFont->SetScale(backup); +} + ostream& SimpleButton::toString(ostream& out) const { return out << "SimpleButton ::: mHasFocus : " << hasFocus() diff --git a/projects/mtg/src/SimpleMenu.cpp b/projects/mtg/src/SimpleMenu.cpp index 4d5e1bb31..874a43cb3 100644 --- a/projects/mtg/src/SimpleMenu.cpp +++ b/projects/mtg/src/SimpleMenu.cpp @@ -134,8 +134,8 @@ void SimpleMenu::Render() for (int i = 0; i < mCount; ++i) { - float width = (static_cast (mObjects[i]))->GetWidth() + 15; - if (mWidth < width) mWidth = width * float(1.5); + float width = (static_cast (mObjects[i]))->GetEnlargedWidth() + 15; + if (mWidth < width) mWidth = width; } if ((!title.empty()) && (mWidth < titleFont->GetStringWidth(title.c_str()))) mWidth = titleFont->GetStringWidth(title.c_str());