From 945c2601d0dcf577bc86a1f40f21700016955950 Mon Sep 17 00:00:00 2001 From: "wrenczes@gmail.com" Date: Thu, 2 Jun 2011 18:27:00 +0000 Subject: [PATCH] Fixed the SimpleMenu to recenter itself as its default behaviour during construction. (You can still override it to position it explicitly if needed.) This fixes the bad alignment of the menu when you'd select single player & the hermit mode was unlocked. --- projects/mtg/include/SimpleMenu.h | 7 ++++++- projects/mtg/src/SimpleMenu.cpp | 11 +++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/projects/mtg/include/SimpleMenu.h b/projects/mtg/include/SimpleMenu.h index 540cf08fd..2bca69d7b 100644 --- a/projects/mtg/include/SimpleMenu.h +++ b/projects/mtg/include/SimpleMenu.h @@ -23,6 +23,9 @@ private: float timeOpen; bool mClosed; + bool mCenterHorizontal; + bool mCenterVertical; + static JQuadPtr spadeR, spadeL, jewel, side; static JTexture *spadeRTex, *spadeLTex, *jewelTex, *sideTex; static WFont* titleFont; @@ -34,13 +37,15 @@ private: public: bool autoTranslate; - SimpleMenu(int id, JGuiListener* listener, int fontId, float x, float y, const char * _title = "", int _maxItems = 7); + SimpleMenu(int id, JGuiListener* listener, int fontId, float x, float y, const char * _title = "", int _maxItems = 7, bool centerHorizontal = true, bool centerVertical = true); virtual ~SimpleMenu(); void Render(); void Update(float dt); void Add(int id, const char * Text, string desc = "", bool forceFocus = false); void Close(); + void RecenterMenu(); + float selectionTargetY; bool isClosed() { diff --git a/projects/mtg/src/SimpleMenu.cpp b/projects/mtg/src/SimpleMenu.cpp index 84f5d888f..efebfe375 100644 --- a/projects/mtg/src/SimpleMenu.cpp +++ b/projects/mtg/src/SimpleMenu.cpp @@ -30,8 +30,8 @@ JTexture* SimpleMenu::sideTex = NULL; WFont* SimpleMenu::titleFont = NULL; hgeParticleSystem* SimpleMenu::stars = NULL; -SimpleMenu::SimpleMenu(int id, JGuiListener* listener, int fontId, float x, float y, const char * _title, int _maxItems) : - JGuiController(id, listener), fontId(fontId) +SimpleMenu::SimpleMenu(int id, JGuiListener* listener, int fontId, float x, float y, const char * _title, int _maxItems, bool centerHorizontal, bool centerVertical) + : JGuiController(id, listener), fontId(fontId), mCenterHorizontal(centerHorizontal), mCenterVertical(centerVertical) { autoTranslate = true; mHeight = 2 * kVerticalMargin; @@ -137,6 +137,13 @@ void SimpleMenu::Render() if ((!title.empty()) && (mWidth < titleFont->GetStringWidth(title.c_str()))) mWidth = titleFont->GetStringWidth(title.c_str()); mWidth += 2 * kHorizontalMargin; + + if (mCenterHorizontal) + mX = (JRenderer::GetInstance()->GetActualWidth() - mWidth) / 2; + + if (mCenterVertical) + mY = (JRenderer::GetInstance()->GetActualHeight() - mHeight) / 2; + for (int i = 0; i < mCount; ++i) { float y = mY + kVerticalMargin + i * kLineHeight;