forgot to check in the JGE changes from previous commit
This commit is contained in:
+4
-2
@@ -99,6 +99,8 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
vector<JGuiObject*> mObjects;
|
vector<JGuiObject*> mObjects;
|
||||||
|
|
||||||
|
vector<JGuiObject*> mButtons;
|
||||||
int mCount;
|
int mCount;
|
||||||
|
|
||||||
JGuiController(JGE* jge, int id, JGuiListener* listener);
|
JGuiController(JGE* jge, int id, JGuiListener* listener);
|
||||||
@@ -108,8 +110,8 @@ public:
|
|||||||
virtual void Update(float dt);
|
virtual void Update(float dt);
|
||||||
virtual bool CheckUserInput(JButton key);
|
virtual bool CheckUserInput(JButton key);
|
||||||
|
|
||||||
void Add(JGuiObject* ctrl);
|
void Add(JGuiObject* ctrl, bool isButton = false);
|
||||||
void RemoveAt(int i);
|
void RemoveAt(int i, bool isButton = false);
|
||||||
void Remove(int id);
|
void Remove(int id);
|
||||||
void Remove(JGuiObject* ctrl);
|
void Remove(JGuiObject* ctrl);
|
||||||
|
|
||||||
|
|||||||
+77
-23
@@ -78,6 +78,8 @@ JGuiController::~JGuiController()
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < mCount; i++)
|
for (int i = 0; i < mCount; i++)
|
||||||
if (mObjects[i] != NULL) delete mObjects[i];
|
if (mObjects[i] != NULL) delete mObjects[i];
|
||||||
|
for (size_t i = 0; i < mButtons.size(); i++)
|
||||||
|
if (mButtons[i] != NULL) delete mButtons[i];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,32 +158,46 @@ bool JGuiController::CheckUserInput(JButton key)
|
|||||||
int n = mCurr;
|
int n = mCurr;
|
||||||
if (mEngine->GetLeftClickCoordinates(x, y))
|
if (mEngine->GetLeftClickCoordinates(x, y))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < mCount; i++)
|
// first scan the buttons on the screen and then process the other gui elements
|
||||||
|
for (size_t i = 0; i < mButtons.size(); i++)
|
||||||
{
|
{
|
||||||
float top, left;
|
if (mButtons[i]->ButtonPressed())
|
||||||
if (mObjects[i]->getTopLeft(top, left))
|
|
||||||
{
|
{
|
||||||
distance2 = (top - y) * (top - y) + (left - x) * (left - x);
|
mEngine->LeftClickedProcessed();
|
||||||
if (distance2 < minDistance2)
|
return true;
|
||||||
{
|
|
||||||
minDistance2 = distance2;
|
|
||||||
n = i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN))
|
if (mObjects.size())
|
||||||
{
|
{
|
||||||
mCurr = n;
|
for (int i = 0; i < mCount; i++)
|
||||||
mObjects[mCurr]->Entering();
|
{
|
||||||
}
|
float top, left;
|
||||||
// if the same object was selected process click
|
if (mObjects[i]->getTopLeft(top, left))
|
||||||
else if (n == mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_OK))
|
{
|
||||||
{
|
distance2 = (top - y) * (top - y) + (left - x) * (left - x);
|
||||||
mObjects[mCurr]->Entering();
|
if (distance2 < minDistance2)
|
||||||
|
{
|
||||||
|
minDistance2 = distance2;
|
||||||
|
n = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN))
|
||||||
|
{
|
||||||
|
mCurr = n;
|
||||||
|
mObjects[mCurr]->Entering();
|
||||||
|
}
|
||||||
|
// if the same object was selected process click
|
||||||
|
else if (n == mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_OK))
|
||||||
|
{
|
||||||
|
mObjects[mCurr]->Entering();
|
||||||
|
}
|
||||||
|
mEngine->LeftClickedProcessed();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
mEngine->LeftClickedProcessed();
|
mEngine->LeftClickedProcessed();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -192,6 +208,9 @@ void JGuiController::Update(float dt)
|
|||||||
for (int i = 0; i < mCount; i++)
|
for (int i = 0; i < mCount; i++)
|
||||||
if (mObjects[i] != NULL)
|
if (mObjects[i] != NULL)
|
||||||
mObjects[i]->Update(dt);
|
mObjects[i]->Update(dt);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < mButtons.size(); i++ )
|
||||||
|
mButtons[i]->Update(dt);
|
||||||
|
|
||||||
if(mEngine)
|
if(mEngine)
|
||||||
{
|
{
|
||||||
@@ -200,14 +219,30 @@ void JGuiController::Update(float dt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JGuiController::Add(JGuiObject* ctrl)
|
void JGuiController::Add(JGuiObject* ctrl, bool isButton)
|
||||||
{
|
{
|
||||||
mObjects.push_back(ctrl);
|
if (!isButton)
|
||||||
mCount++;
|
{
|
||||||
|
mObjects.push_back(ctrl);
|
||||||
|
mCount++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mButtons.push_back(ctrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JGuiController::RemoveAt(int i)
|
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;
|
if (!mObjects[i]) return;
|
||||||
mObjects.erase(mObjects.begin() + i);
|
mObjects.erase(mObjects.begin() + i);
|
||||||
delete mObjects[i];
|
delete mObjects[i];
|
||||||
@@ -226,6 +261,15 @@ void JGuiController::Remove(int id)
|
|||||||
return;
|
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)
|
void JGuiController::Remove(JGuiObject* ctrl)
|
||||||
@@ -238,6 +282,16 @@ void JGuiController::Remove(JGuiObject* ctrl)
|
|||||||
return;
|
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)
|
void JGuiController::SetActionButton(JButton button)
|
||||||
|
|||||||
Reference in New Issue
Block a user