git repos / blockattack-game

commit 95ab6b0d

sago007 · 2016-11-12 16:11
95ab6b0dcd46d73c9273d1dfc1e9071eb79a85bf patch · browse files
parent 50fd2c5f3223f75962df40440aacae91922894d9

Now runs the main menu with the scene manager

Changed files

M source/code/MenuSystem.cpp before
M source/code/MenuSystem.h before
M source/code/menudef.cpp before
diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp index 6e78cfd..502d39f 100644 --- a/source/code/MenuSystem.cpp +++ b/source/code/MenuSystem.cpp
@@ -109,14 +109,14 @@ static bool isClicked(const Button &b, int x,int y) {
return false;
}
-void Menu::drawSelf() {
- DrawBackground(screen);
+void Menu::drawSelf(SDL_Renderer* target) {
+ DrawBackground(target);
for (const Button* b : buttons) {
drawToScreen(*b);
}
drawToScreen(exit);
- standardButton.thefont->draw(screen, 50, 50, "%s", title.c_str());
- globalData.mouse.Draw(screen, SDL_GetTicks(), mousex, mousey);
+ standardButton.thefont->draw(target, 50, 50, "%s", title.c_str());
+ globalData.mouse.Draw(target, SDL_GetTicks(), mousex, mousey);
}
@@ -301,8 +301,7 @@ bool Menu::IsActive() {
}
void Menu::Draw(SDL_Renderer* target) {
placeButtons();
- drawSelf();
- SDL_RenderPresent(target);
+ drawSelf(target);
}
void Menu::ProcessInput(const SDL_Event& event, bool &processed) {
UpdateMouseCoordinates(event, mousex, mousey);
@@ -398,5 +397,6 @@ void Menu::run() {
}
Update();
Draw(screen);
+ SDL_RenderPresent(screen);
}
}
diff --git a/source/code/MenuSystem.h b/source/code/MenuSystem.h index 409eb2e..16463f1 100644 --- a/source/code/MenuSystem.h +++ b/source/code/MenuSystem.h
@@ -94,7 +94,7 @@ private:
bool running = true; //The menu is running. The menu will terminate then this is false
SDL_Renderer *screen = nullptr; //Pointer to the screen to draw to
std::string title;
- void drawSelf(); //Private function to draw the screen
+ void drawSelf(SDL_Renderer* target); //Private function to draw the screen
void placeButtons(); //Rearanges the buttons to the correct place.
int oldmousex = 0;
int oldmousey = 0;
diff --git a/source/code/menudef.cpp b/source/code/menudef.cpp index 7d1d0f0..369b055 100644 --- a/source/code/menudef.cpp +++ b/source/code/menudef.cpp
@@ -295,5 +295,5 @@ void MainMenu() {
m.addButton(&bMulti);
m.addButton(&bConfigure);
m.addButton(&bHighscore);
- m.run();
+ RunGameState(m);
}