From a581d1bba3aabf138c9eded3e87c8082d7427b85 Mon Sep 17 00:00:00 2001 From: "wagic.the.homebrew" Date: Wed, 21 Mar 2012 14:44:23 +0000 Subject: [PATCH] - Fixed some scaling issues with SimpleMenu - Fixed the animation for the menu fonts when selecting an item in the menu. mTargetScale and mScale in SimpleButton are here for a reason, people! -- Note: I'm not sure I actually like the "zoom on currently selected item" thing, not sure it brings much. -- we should definitely consider a hi resolution font because now it really doesn't look good, when it is scaled that much Why is the subtypes menu using a different font from all other simpleMenus ? --- projects/mtg/include/SimpleButton.h | 1 + projects/mtg/src/SimpleButton.cpp | 58 ++++++++++++++++++++--------- projects/mtg/src/SimpleMenu.cpp | 4 +- 3 files changed, 43 insertions(+), 20 deletions(-) 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());