commit 50fd2c5f
Changed the menu run slightly
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 e97fa1c..6e78cfd 100644
--- a/source/code/MenuSystem.cpp
+++ b/source/code/MenuSystem.cpp
@@ -305,6 +305,7 @@ void Menu::Draw(SDL_Renderer* target) {
SDL_RenderPresent(target);
}
void Menu::ProcessInput(const SDL_Event& event, bool &processed) {
+ UpdateMouseCoordinates(event, mousex, mousey);
if ( event.type == SDL_QUIT ) {
Config::getInstance()->setShuttingDown(5);
running = false;
@@ -342,96 +343,60 @@ void Menu::ProcessInput(const SDL_Event& event, bool &processed) {
}
}
-void Menu::run() {
- running = true;
- bool bMouseUp = false;
- int oldmousex = mousex;
- int oldmousey = mousey;
- while (running && !Config::getInstance()->isShuttingDown()) {
- if (!(globalData.highPriority)) {
- SDL_Delay(10);
- }
- SDL_Event event;
- while ( SDL_PollEvent(&event) ) {
- UpdateMouseCoordinates(event, mousex, mousey);
- if ( event.type == SDL_QUIT ) {
- Config::getInstance()->setShuttingDown(5);
- running = false;
- }
-
- if (isUpEvent(event)) {
- marked--;
- if (marked<0) {
- marked = buttons.size(); //not -1, since exit is after the last element in the list
- }
- }
-
- if (isDownEvent(event)) {
- marked++;
- if (marked> (int)buttons.size()) {
- marked = 0;
- }
- }
+void Menu::Update() {
+ for (int i=0; i<(int)buttons.size(); i++) {
+ buttons.at(i)->marked = (i == marked);
+ }
+ exit.marked = (marked == (int)buttons.size());
+ Uint8 buttonState = SDL_GetMouseState(nullptr,nullptr);
+ // If the mouse button is released, make bMouseUp equal true
+ if ( (buttonState&SDL_BUTTON(1))==0) {
+ bMouseUp=true;
+ }
- if (isEscapeEvent(event) && isSubmenu) {
- running = false;
+ if (abs(mousex-oldmousex)>5 || abs(mousey-oldmousey)>5) {
+ for (int i=0; i< (int)buttons.size(); ++i) {
+ if (isClicked(*buttons.at(i),mousex,mousey)) {
+ marked = i;
}
+ }
+ if (isClicked(exit, mousex, mousey)) {
+ marked = buttons.size();
+ }
+ oldmousex = mousex;
+ oldmousey = mousey;
+ }
- if (isConfirmEvent(event)) {
- if (marked < (int)buttons.size()) {
- buttons.at(marked)->doAction();
- if (buttons.at(marked)->isPopOnRun()) {
- running = false;
- }
- }
- if (marked == (int)buttons.size()) {
+ //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)) {
+ buttons.at(i)->doAction();
+ if (buttons.at(i)->isPopOnRun()) {
running = false;
}
+ mousex = 0;
}
-
- }
-
- for (int i=0; i<(int)buttons.size(); i++) {
- buttons.at(i)->marked = (i == marked);
}
- exit.marked = (marked == (int)buttons.size());
- Uint8 buttonState = SDL_GetMouseState(nullptr,nullptr);
- // If the mouse button is released, make bMouseUp equal true
- if ( (buttonState&SDL_BUTTON(1))==0) {
- bMouseUp=true;
+ if (isClicked(exit, mousex, mousey)) {
+ running = false;
}
+ }
+}
- if (abs(mousex-oldmousex)>5 || abs(mousey-oldmousey)>5) {
- for (int i=0; i< (int)buttons.size(); ++i) {
- if (isClicked(*buttons.at(i),mousex,mousey)) {
- marked = i;
- }
- }
- if (isClicked(exit, mousex, mousey)) {
- marked = buttons.size();
- }
- oldmousex = mousex;
- oldmousey = mousey;
+void Menu::run() {
+ running = true;
+ while (running && !Config::getInstance()->isShuttingDown()) {
+ if (!(globalData.highPriority)) {
+ SDL_Delay(10);
}
-
- //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)) {
- buttons.at(i)->doAction();
- if (buttons.at(i)->isPopOnRun()) {
- running = false;
- }
- mousex = 0;
- }
- }
- if (isClicked(exit, mousex, mousey)) {
- running = false;
- }
+ SDL_Event event;
+ bool processed = false;
+ while ( SDL_PollEvent(&event) ) {
+ ProcessInput(event,processed);
}
- placeButtons();
- drawSelf();
- SDL_RenderPresent(screen);
+ Update();
+ Draw(screen);
}
}
diff --git a/source/code/MenuSystem.h b/source/code/MenuSystem.h
index d893ddb..409eb2e 100644
--- a/source/code/MenuSystem.h
+++ b/source/code/MenuSystem.h
@@ -96,6 +96,9 @@ private:
std::string title;
void drawSelf(); //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
//SubMenu is true by default
@@ -113,6 +116,7 @@ public:
bool IsActive() override;
void Draw(SDL_Renderer* target) override;
void ProcessInput(const SDL_Event& event, bool &processed) override;
+ void Update() override;
};
class FileMenu