- 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 ?
This commit is contained in:
wagic.the.homebrew
2012-03-21 14:44:23 +00:00
parent 3ba22cd615
commit a581d1bba3
3 changed files with 43 additions and 20 deletions

View File

@@ -65,6 +65,7 @@ public:
virtual void checkUserClick(); virtual void checkUserClick();
virtual float GetWidth(); virtual float GetWidth();
virtual float GetEnlargedWidth();
virtual void Relocate(float x, float y); virtual void Relocate(float x, float y);
virtual void RenderWithOffset(float yOffset); virtual void RenderWithOffset(float yOffset);

View File

@@ -29,8 +29,16 @@ JGuiObject(id), mX(x), mY(y), parent(_parent), mFontId(fontId)
mHasFocus = hasFocus; mHasFocus = hasFocus;
mScale = 1.0f; mScale = (mText.size() < 20) ? SCALE_LARGE_NORMAL : SCALE_NORMAL;
mTargetScale = 1.0f;
if (mHasFocus) {
mTargetScale = (mText.size() < 20) ? SCALE_SELECTED_LARGE : SCALE_SELECTED;
}
else
{
mTargetScale = (mText.size() < 20) ? SCALE_LARGE_NORMAL : SCALE_NORMAL;
}
mXOffset = mX; mXOffset = mX;
@@ -50,20 +58,8 @@ void SimpleButton::RenderWithOffset(float yOffset)
{ {
mYOffset = yOffset; mYOffset = yOffset;
WFont * mFont = WResourceManager::Instance()->GetWFont(mFontId); WFont * mFont = WResourceManager::Instance()->GetWFont(mFontId);
if(mText.size() < 20)
{ mFont->SetScale(mScale);
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->DrawString(mText.c_str(), mX, mY + yOffset, JGETEXT_CENTER); mFont->DrawString(mText.c_str(), mX, mY + yOffset, JGETEXT_CENTER);
} }
@@ -95,13 +91,13 @@ void SimpleButton::checkUserClick()
void SimpleButton::Entering() void SimpleButton::Entering()
{ {
checkUserClick(); checkUserClick();
mHasFocus = true; setFocus(true);
} }
bool SimpleButton::Leaving(JButton key) bool SimpleButton::Leaving(JButton key)
{ {
checkUserClick(); checkUserClick();
mHasFocus = false; setFocus(false);
return true; return true;
} }
@@ -167,6 +163,21 @@ bool SimpleButton::isSelectionValid() const
void SimpleButton::setFocus(bool value) void SimpleButton::setFocus(bool value)
{ {
mHasFocus = 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 bool SimpleButton::hasFocus() const
@@ -192,6 +203,17 @@ float SimpleButton::GetWidth()
return mFont->GetStringWidth(mText.c_str()); 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 ostream& SimpleButton::toString(ostream& out) const
{ {
return out << "SimpleButton ::: mHasFocus : " << hasFocus() return out << "SimpleButton ::: mHasFocus : " << hasFocus()

View File

@@ -134,8 +134,8 @@ void SimpleMenu::Render()
for (int i = 0; i < mCount; ++i) for (int i = 0; i < mCount; ++i)
{ {
float width = (static_cast<SimpleMenuItem*> (mObjects[i]))->GetWidth() + 15; float width = (static_cast<SimpleMenuItem*> (mObjects[i]))->GetEnlargedWidth() + 15;
if (mWidth < width) mWidth = width * float(1.5); if (mWidth < width) mWidth = width;
} }
if ((!title.empty()) && (mWidth < titleFont->GetStringWidth(title.c_str()))) if ((!title.empty()) && (mWidth < titleFont->GetStringWidth(title.c_str())))
mWidth = titleFont->GetStringWidth(title.c_str()); mWidth = titleFont->GetStringWidth(title.c_str());