diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp index 502d39f..e515e6b 100644 --- a/source/code/MenuSystem.cpp +++ b/source/code/MenuSystem.cpp @@ -28,8 +28,8 @@ http://www.blockattack.net #include "gamecontroller.h" #include "BlockGame.hpp" -static int mousex; -static int mousey; +static int oldmousex = 0; +static int oldmousey = 0; using std::string; using std::cerr; @@ -116,7 +116,6 @@ void Menu::drawSelf(SDL_Renderer* target) { } drawToScreen(exit); standardButton.thefont->draw(target, 50, 50, "%s", title.c_str()); - globalData.mouse.Draw(target, SDL_GetTicks(), mousex, mousey); } @@ -304,7 +303,7 @@ void Menu::Draw(SDL_Renderer* target) { drawSelf(target); } void Menu::ProcessInput(const SDL_Event& event, bool &processed) { - UpdateMouseCoordinates(event, mousex, mousey); + UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey); if ( event.type == SDL_QUIT ) { Config::getInstance()->setShuttingDown(5); running = false; @@ -353,50 +352,34 @@ void Menu::Update() { bMouseUp=true; } - if (abs(mousex-oldmousex)>5 || abs(mousey-oldmousey)>5) { + if (abs(globalData.mousex-oldmousex)>5 || abs(globalData.mousey-oldmousey)>5) { for (int i=0; i< (int)buttons.size(); ++i) { - if (isClicked(*buttons.at(i),mousex,mousey)) { + if (isClicked(*buttons.at(i), globalData.mousex, globalData.mousey)) { marked = i; } } - if (isClicked(exit, mousex, mousey)) { + if (isClicked(exit, globalData.mousex, globalData.mousey)) { marked = buttons.size(); } - oldmousex = mousex; - oldmousey = mousey; + oldmousex = globalData.mousex; + oldmousey = globalData.mousey; } //mouse clicked if ( (buttonState&SDL_BUTTON(1) )==SDL_BUTTON(1) && bMouseUp) { bMouseUp = false; for (int i=0; i< (int)buttons.size(); ++i) { - if (isClicked(*buttons.at(i),mousex,mousey)) { + if (isClicked(*buttons.at(i), globalData.mousex, globalData.mousey)) { buttons.at(i)->doAction(); if (buttons.at(i)->isPopOnRun()) { running = false; } - mousex = 0; + globalData.mousex = 0; } } - if (isClicked(exit, mousex, mousey)) { + if (isClicked(exit, globalData.mousex, globalData.mousey)) { running = false; } } } -void Menu::run() { - running = true; - while (running && !Config::getInstance()->isShuttingDown()) { - if (!(globalData.highPriority)) { - SDL_Delay(10); - } - SDL_Event event; - bool processed = false; - while ( SDL_PollEvent(&event) ) { - ProcessInput(event,processed); - } - Update(); - Draw(screen); - SDL_RenderPresent(screen); - } -} diff --git a/source/code/MenuSystem.h b/source/code/MenuSystem.h index 16463f1..8e35941 100644 --- a/source/code/MenuSystem.h +++ b/source/code/MenuSystem.h @@ -96,8 +96,6 @@ private: std::string title; 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; bool bMouseUp = false; public: //numberOfItems is the expected numberOfItems for vector initialization @@ -109,9 +107,6 @@ public: //Add a button to the menu void addButton(Button *b); - - //Run the menu - void run(); bool IsActive() override; void Draw(SDL_Renderer* target) override; diff --git a/source/code/ScoresDisplay.cpp b/source/code/ScoresDisplay.cpp index 9b80fa2..d21c826 100644 --- a/source/code/ScoresDisplay.cpp +++ b/source/code/ScoresDisplay.cpp @@ -170,7 +170,7 @@ void ScoresDisplay::Draw(SDL_Renderer*) { void ScoresDisplay::ProcessInput(const SDL_Event& event, bool& processed) { - UpdateMouseCoordinates(event, mousex, mousey); + UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey); if (isLeftEvent(event)) { page++; @@ -204,12 +204,12 @@ void ScoresDisplay::Update() { bMouseUp = false; //The Score button: - if ((mousex>scoreX) && (mousexscoreY) && (mouseyscoreX) && (globalData.mousexscoreY) && (globalData.mouseybackX) && (mousexbackY) && (mouseybackX) && (globalData.mousexbackY) && (globalData.mouseynextX) && (mousexnextY) && (mouseynextX) && (globalData.mousexnextY) && (globalData.mousey=numberOfPages) { page = 0; diff --git a/source/code/ScoresDisplay.hpp b/source/code/ScoresDisplay.hpp index f8f5d3a..20922e7 100644 --- a/source/code/ScoresDisplay.hpp +++ b/source/code/ScoresDisplay.hpp @@ -43,8 +43,6 @@ public: int scoreY = 0; int buttonXsize = 0; int buttonYsize = 0; - int mousex = 0; - int mousey = 0; private: void DrawHighscores(int x, int y, bool endless); void DrawStats(); diff --git a/source/code/global.hpp b/source/code/global.hpp index c2eccc4..e18d029 100644 --- a/source/code/global.hpp +++ b/source/code/global.hpp @@ -66,6 +66,8 @@ struct GlobalData { //The xsize and ysize are updated everytime the background is drawn int xsize = 1024; int ysize = 768; + int mousex = 0; + int mousey = 0; }; extern GlobalData globalData; diff --git a/source/code/main.cpp b/source/code/main.cpp index 7174326..7870694 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -611,7 +611,6 @@ static string getKeyName(SDL_Keycode key) { void RunGameState(sago::GameStateInterface& state ) { - int mousex,mousey; bool done = false; //We are done! while (!done && !Config::getInstance()->isShuttingDown()) { state.Draw(globalData.screen); @@ -622,7 +621,7 @@ void RunGameState(sago::GameStateInterface& state ) { bool mustWriteScreenshot = false; while ( SDL_PollEvent(&event) ) { - UpdateMouseCoordinates(event, mousex, mousey); + UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey); if ( event.type == SDL_QUIT ) { Config::getInstance()->setShuttingDown(5); done = true; @@ -639,7 +638,7 @@ void RunGameState(sago::GameStateInterface& state ) { state.Update(); - globalData.mouse.Draw(globalData.screen, SDL_GetTicks(), mousex, mousey); + globalData.mouse.Draw(globalData.screen, SDL_GetTicks(), globalData.mousex, globalData.mousey); SDL_RenderPresent(globalData.screen); if (mustWriteScreenshot) { writeScreenShot(); @@ -886,7 +885,6 @@ int PuzzleLevelSelect(int Type) { const int xplace = 200; const int yplace = 300; int levelNr = 0; - int mousex, mousey; int oldmousex = 0; int oldmousey = 0; bool levelSelected = false; @@ -934,7 +932,7 @@ int PuzzleLevelSelect(int Type) { SDL_Event event; while ( SDL_PollEvent(&event) ) { - UpdateMouseCoordinates(event, mousex, mousey); + UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey); if ( event.type == SDL_QUIT ) { Config::getInstance()->setShuttingDown(5); @@ -977,25 +975,25 @@ int PuzzleLevelSelect(int Type) { SDL_GetKeyboardState(nullptr); - if (mousex != oldmousex || mousey != oldmousey) { + if (globalData.mousex != oldmousex || globalData.mousey != oldmousey) { int tmpSelected = -1; int j; for (j = 0; (tmpSelected == -1) && ( (j