commit 7b384c3f
Moved the isClicked out.
Changed files
| M | source/code/MenuSystem.cpp before |
| M | source/code/MenuSystem.h before |
diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp
index 6fda7c3..eb597d5 100644
--- a/source/code/MenuSystem.cpp
+++ b/source/code/MenuSystem.cpp
@@ -74,13 +74,6 @@ void Button::setAction(void (*action2run)(Button*)) {
action = action2run;
}
-bool Button::isClicked(int x,int y) {
- if ( x >= this->x && y >= this->y && x<= this->x+standardButton.xsize && y <= this->y + standardButton.ysize) {
- return true;
- }
- return false;
-}
-
void Button::doAction() {
if (action) {
action(this);
@@ -117,6 +110,14 @@ static void drawToScreen(const Button &b) {
standardButton.thefont->draw(screen, b.x+standardButton.xsize/2,b.y+standardButton.ysize/2-standardButton.thefont->getHeight("%s", b.label.c_str())/2, NFont::CENTER, "%s", b.label.c_str());
}
+
+static bool isClicked(const Button &b, int x,int y) {
+ if ( x >= b.x && y >= b.y && x<= b.x+standardButton.xsize && y <= b.y + standardButton.ysize) {
+ return true;
+ }
+ return false;
+}
+
void Menu::drawSelf() {
DrawBackground(screen);
for (const Button* b : buttons) {
@@ -363,11 +364,11 @@ void Menu::run() {
if (abs(mousex-oldmousex)>5 || abs(mousey-oldmousey)>5) {
for (int i=0; i< (int)buttons.size(); ++i) {
- if (buttons.at(i)->isClicked(mousex,mousey)) {
+ if (isClicked(*buttons.at(i),mousex,mousey)) {
marked = i;
}
}
- if (exit.isClicked(mousex,mousey)) {
+ if (isClicked(exit, mousex, mousey)) {
marked = buttons.size();
}
oldmousex = mousex;
@@ -378,7 +379,7 @@ void Menu::run() {
if ( (buttonState&SDL_BUTTON(1) )==SDL_BUTTON(1) && bMouseUp) {
bMouseUp = false;
for (int i=0; i< (int)buttons.size(); ++i) {
- if (buttons.at(i)->isClicked(mousex,mousey)) {
+ if (isClicked(*buttons.at(i),mousex,mousey)) {
buttons.at(i)->doAction();
if (buttons.at(i)->isPopOnRun()) {
running = false;
@@ -386,7 +387,7 @@ void Menu::run() {
mousex = 0;
}
}
- if (exit.isClicked(mousex,mousey)) {
+ if (isClicked(exit, mousex, mousey)) {
running = false;
}
}
diff --git a/source/code/MenuSystem.h b/source/code/MenuSystem.h
index 85f3f43..cf0e763 100644
--- a/source/code/MenuSystem.h
+++ b/source/code/MenuSystem.h
@@ -74,7 +74,6 @@ public:
//Set the action to run
void setAction(void (*action2run)(Button*));
- bool isClicked(int x,int y); //Returns true if (x,y) is within the borders of the button
virtual void doAction(); //Run the callback function
void setPopOnRun(bool popOnRun);
bool isPopOnRun() const;