From 449d1eecb7003eb7d5cbbe554b13fed9dc6753f1 Mon Sep 17 00:00:00 2001 From: "jean.chalard" Date: Sun, 4 Jan 2009 07:04:58 +0000 Subject: [PATCH] J : * Put the selected item in the menu in yellow. --- projects/mtg/include/SimpleMenuItem.h | 1 + projects/mtg/src/SimpleMenu.cpp | 30 +++++++-------------------- projects/mtg/src/SimpleMenuItem.cpp | 5 +++++ 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/projects/mtg/include/SimpleMenuItem.h b/projects/mtg/include/SimpleMenuItem.h index cef17b9a6..933f0581b 100644 --- a/projects/mtg/include/SimpleMenuItem.h +++ b/projects/mtg/include/SimpleMenuItem.h @@ -31,6 +31,7 @@ class SimpleMenuItem: public JGuiObject void Relocate(int x, int y); int GetWidth(); + bool hasFocus(); void RenderWithOffset(float yOffset); virtual void Render(); diff --git a/projects/mtg/src/SimpleMenu.cpp b/projects/mtg/src/SimpleMenu.cpp index 72a18630d..0e9d1898b 100644 --- a/projects/mtg/src/SimpleMenu.cpp +++ b/projects/mtg/src/SimpleMenu.cpp @@ -61,24 +61,6 @@ SimpleMenu::SimpleMenu(int id, JGuiListener* listener, JLBFont* font, int x, int stars->MoveTo(mX, mY); } -inline void SimpleMenu::MogrifyJewel() -{ - PIXEL_TYPE tmpBuf[sizeof(jewelGraphics)/sizeof(jewelGraphics[0])]; - if (!(random() & 0x7E)) - for (int i = sizeof(jewelGraphics) / sizeof(jewelGraphics[0]) - 1; i >= 0; --i) - { - unsigned int v = jewelGraphics[i]; - if (v & 0x80) tmpBuf[i] = 0xFF; else tmpBuf[i] = v & 0xFF; - if (v & 0x8000) tmpBuf[i] += 0xFF00; else tmpBuf[i] += (v & 0x7F00) << 1; - if (v & 0x800000) tmpBuf[i] += 0xFF0000; else tmpBuf[i] += (v & 0x7F0000) << 1; - tmpBuf[i] += v & 0xFF000000; - } - else - for (int i = sizeof(jewelGraphics) / sizeof(jewelGraphics[0]) - 1; i >= 0; --i) - tmpBuf[i] = jewelGraphics[i]; - jewel->mTex->UpdateBits(1, 1, 3, 3, tmpBuf); -} - void SimpleMenu::drawHorzPole(int x, int y, int width) { JRenderer* renderer = JRenderer::GetInstance(); @@ -89,8 +71,6 @@ void SimpleMenu::drawHorzPole(int x, int y, int width) renderer->RenderQuad(spadeR, x - 9, y - 6); renderer->RenderQuad(spadeL, x + width - 5, y - 6); - MogrifyJewel(); - renderer->RenderQuad(jewel, x, y - 1); renderer->RenderQuad(jewel, x + width - 1, y - 1); } @@ -104,8 +84,6 @@ void SimpleMenu::drawVertPole(int x, int y, int height) renderer->RenderQuad(spadeR, x - 6, y + 7, -M_PI/2); renderer->RenderQuad(spadeL, x - 6, y + height + 11, -M_PI/2); - MogrifyJewel(); - renderer->RenderQuad(jewel, x - 1, y - 1); renderer->RenderQuad(jewel, x - 1, y + height - 1); } @@ -149,7 +127,13 @@ void SimpleMenu::Render(){ for (int i = startId; i < startId + maxItems ; i++){ if (i > mCount-1) break; if ((static_cast(mObjects[i]))->mY - LINE_HEIGHT * startId < mY + height - LINE_HEIGHT + 7) - (static_cast(mObjects[i]))->RenderWithOffset(-LINE_HEIGHT*startId); + { + if (static_cast(mObjects[i])->hasFocus()) + mFont->SetColor(ARGB(255,255,255,0)); + else + mFont->SetColor(ARGB(255,255,255,255)); + (static_cast(mObjects[i]))->RenderWithOffset(-LINE_HEIGHT*startId); + } } drawHorzPole(mX - 25, mY + height, mWidth + 50); diff --git a/projects/mtg/src/SimpleMenuItem.cpp b/projects/mtg/src/SimpleMenuItem.cpp index 7c083e2a6..890947c24 100644 --- a/projects/mtg/src/SimpleMenuItem.cpp +++ b/projects/mtg/src/SimpleMenuItem.cpp @@ -75,3 +75,8 @@ int SimpleMenuItem::GetWidth() { return mFont->GetStringWidth(mText.c_str()); } + +bool SimpleMenuItem::hasFocus() +{ + return mHasFocus; +}