forgot to check in the JGE changes from previous commit

This commit is contained in:
techdragon.nguyen@gmail.com
2012-01-25 22:31:58 +00:00
parent a36d886dd5
commit dda048c616
2 changed files with 81 additions and 25 deletions
+4 -2
View File
@@ -99,6 +99,8 @@ protected:
public:
vector<JGuiObject*> mObjects;
vector<JGuiObject*> mButtons;
int mCount;
JGuiController(JGE* jge, int id, JGuiListener* listener);
@@ -108,8 +110,8 @@ public:
virtual void Update(float dt);
virtual bool CheckUserInput(JButton key);
void Add(JGuiObject* ctrl);
void RemoveAt(int i);
void Add(JGuiObject* ctrl, bool isButton = false);
void RemoveAt(int i, bool isButton = false);
void Remove(int id);
void Remove(JGuiObject* ctrl);
+57 -3
View File
@@ -78,6 +78,8 @@ JGuiController::~JGuiController()
{
for (int i = 0; i < mCount; i++)
if (mObjects[i] != NULL) delete mObjects[i];
for (size_t i = 0; i < mButtons.size(); i++)
if (mButtons[i] != NULL) delete mButtons[i];
}
@@ -155,6 +157,18 @@ bool JGuiController::CheckUserInput(JButton key)
unsigned int minDistance2 = -1;
int n = mCurr;
if (mEngine->GetLeftClickCoordinates(x, y))
{
// first scan the buttons on the screen and then process the other gui elements
for (size_t i = 0; i < mButtons.size(); i++)
{
if (mButtons[i]->ButtonPressed())
{
mEngine->LeftClickedProcessed();
return true;
}
}
if (mObjects.size())
{
for (int i = 0; i < mCount; i++)
{
@@ -183,6 +197,8 @@ bool JGuiController::CheckUserInput(JButton key)
mEngine->LeftClickedProcessed();
return true;
}
mEngine->LeftClickedProcessed();
}
}
return false;
}
@@ -193,6 +209,9 @@ void JGuiController::Update(float dt)
if (mObjects[i] != NULL)
mObjects[i]->Update(dt);
for (size_t i = 0; i < mButtons.size(); i++ )
mButtons[i]->Update(dt);
if(mEngine)
{
JButton key = mEngine->ReadButton();
@@ -200,14 +219,30 @@ void JGuiController::Update(float dt)
}
}
void JGuiController::Add(JGuiObject* ctrl)
void JGuiController::Add(JGuiObject* ctrl, bool isButton)
{
if (!isButton)
{
mObjects.push_back(ctrl);
mCount++;
}
void JGuiController::RemoveAt(int i)
else
{
mButtons.push_back(ctrl);
}
}
void JGuiController::RemoveAt(int i, bool isButton)
{
if (isButton)
{
if (!mButtons[i]) return;
mButtons.erase(mButtons.begin() + i);
delete mButtons[i];
return;
}
if (!mObjects[i]) return;
mObjects.erase(mObjects.begin() + i);
delete mObjects[i];
@@ -226,6 +261,15 @@ void JGuiController::Remove(int id)
return;
}
}
for (size_t i = 0; i < mButtons.size(); i++)
{
if (mButtons[i] != NULL && mButtons[i]->GetId() == id)
{
RemoveAt(i, true);
return;
}
}
}
void JGuiController::Remove(JGuiObject* ctrl)
@@ -238,6 +282,16 @@ void JGuiController::Remove(JGuiObject* ctrl)
return;
}
}
for (size_t i = 0; i < mButtons.size(); i++)
{
if (mButtons[i] != NULL && mButtons[i] == ctrl)
{
RemoveAt(i, true);
return;
}
}
}
void JGuiController::SetActionButton(JButton button)