made DeckMenuItem a subclass of SimpleMenuItem

moved code to check on click position into base class from DeckMenuItem
TODO: apply same logic for standard menus
This commit is contained in:
techdragon.nguyen@gmail.com
2012-01-08 14:55:22 +00:00
parent 5ff2ac3123
commit 1cef5d690b
4 changed files with 49 additions and 41 deletions

View File

@@ -6,6 +6,11 @@
float SimpleMenuItem::mYOffset = 0;
SimpleMenuItem::SimpleMenuItem(int id): JGuiObject(id)
{
}
SimpleMenuItem::SimpleMenuItem(SimpleMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus, bool autoTranslate) :
JGuiObject(id), parent(_parent), fontId(fontId), mX(x), mY(y)
{
@@ -17,7 +22,8 @@ SimpleMenuItem::SimpleMenuItem(SimpleMenu* _parent, int id, int fontId, string t
mScale = 1.0f;
mTargetScale = 1.0f;
mXOffset = mX;
if (hasFocus) Entering();
}
@@ -47,6 +53,20 @@ void SimpleMenuItem::Update(float dt)
}
}
void SimpleMenuItem::checkUserClick()
{
int x1 = -1, y1 = -1;
if (mEngine->GetLeftClickCoordinates(x1, y1))
{
mIsValidSelection = false;
int x2 = mXOffset, y2 = static_cast<int>(mY + mYOffset);
if ( (x1 >= x2) && (x1 <= (x2 + 200)) && (y1 >= y2) && (y1 < (y2 + 30)))
mIsValidSelection = true;
}
else
mIsValidSelection = true;
}
void SimpleMenuItem::Entering()
{
mHasFocus = true;