commit 1b710a1e
The menu is now always centered.
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 652a3c8..af23f0d 100644
--- a/source/code/MenuSystem.cpp
+++ b/source/code/MenuSystem.cpp
@@ -116,10 +116,14 @@ void Button::setGfx(ButtonGfx* gfx) {
this->gfx = gfx;
}
-int Button::getHeight() {
+int Button::getHeight() const {
return this->gfx->ysize;
}
+int Button::getWidth() const {
+ return this->gfx->xsize;
+}
+
void Menu::drawSelf() {
DrawBackground(screen);
vector<Button*>::iterator it;
@@ -134,12 +138,12 @@ void Menu::drawSelf() {
void Menu::placeButtons() {
int nextY = 100;
- const int X = 50;
- vector<Button*>::iterator it;
- for (it = buttons.begin(); it < buttons.end(); it++) {
- (*it)->x = X;
- (*it)->y = nextY;
- nextY += (*it)->getHeight()+10;
+ int X = 50;
+ for (Button* it : buttons) {
+ X = (xsize - it->getWidth())/2;
+ it->x = X;
+ it->y = nextY;
+ nextY += it->getHeight()+10;
}
exit.x = X;
exit.y = nextY;
@@ -316,10 +320,7 @@ void Menu::run() {
if (!(highPriority)) {
SDL_Delay(10);
}
-
-
SDL_Event event;
-
while ( SDL_PollEvent(&event) ) {
if ( event.type == SDL_QUIT ) {
Config::getInstance()->setShuttingDown(5);
@@ -397,7 +398,7 @@ void Menu::run() {
running = false;
}
}
-
+ placeButtons();
drawSelf();
SDL_RenderPresent(screen);
}
diff --git a/source/code/MenuSystem.h b/source/code/MenuSystem.h
index 0a083d7..b9dea1c 100644
--- a/source/code/MenuSystem.h
+++ b/source/code/MenuSystem.h
@@ -82,7 +82,8 @@ public:
void setPopOnRun(bool popOnRun);
bool isPopOnRun() const;
void setGfx(ButtonGfx* gfx); //Draws to screen
- int getHeight();
+ int getHeight() const;
+ int getWidth() const;
//May hold any other information the callback might need
int iGeneric1 = 0;