From 26e4e7aff315eea7119e5ccfe8cb38e347e19678 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Mon, 19 Apr 2004 21:54:34 +0000 Subject: [PATCH] - cleaned up my last_menu patch a bit more SVN-Revision: 581 --- src/menu.cpp | 50 ++++++++++++++++++++++++++++---------------------- src/menu.h | 3 +++ 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/menu.cpp b/src/menu.cpp index 044d94a23..8c5bc22d6 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -59,15 +59,33 @@ std::stack Menu::last_menus; Menu* Menu::current_ = 0; void -Menu::set_current(Menu* menu) +Menu::push_current(Menu* pmenu) { - if (menu) - { - if (last_menus.empty() || menu != last_menus.top()) - last_menus.push(current_); + if (current_) + last_menus.push(current_); + + set_current(pmenu); +} - menu->effect.start(500); +void +Menu::pop_current() +{ + if (!last_menus.empty()) + { + set_current(last_menus.top()); + last_menus.pop(); + } + else + { + set_current(0); } +} + +void +Menu::set_current(Menu* menu) +{ + if (menu) + menu->effect.start(500); current_ = menu; } @@ -234,7 +252,7 @@ Menu::action() { case MN_GOTO: if (item[active_item].target_menu != NULL) - Menu::set_current(item[active_item].target_menu); + Menu::push_current(item[active_item].target_menu); else puts("NULLL"); break; @@ -251,11 +269,7 @@ Menu::action() break; case MN_BACK: - if (!last_menus.empty()) - { - Menu::set_current(last_menus.top()); - last_menus.pop(); - } + Menu::pop_current(); break; default: break; @@ -591,16 +605,8 @@ Menu::event(SDL_Event& event) delete_character++; break; case SDLK_ESCAPE: - if(Menu::current()) - { - if (has_backitem == true && !last_menus.empty()) - { - Menu::set_current(last_menus.top()); - last_menus.pop(); - } - else - Menu::set_current(0); - } + Menu::pop_current(); + break; default: if( (key >= SDLK_0 && key <= SDLK_9) || (key >= SDLK_a && key <= SDLK_z) || (key >= SDLK_SPACE && key <= SDLK_SLASH)) { diff --git a/src/menu.h b/src/menu.h index 8c30c4400..36e533fc1 100644 --- a/src/menu.h +++ b/src/menu.h @@ -66,6 +66,9 @@ class Menu private: static std::stack last_menus; static Menu* current_; + + static void push_current(Menu* pmenu); + static void pop_current(); public: /** Set the current menu, if pmenu is NULL, hide the current menu */ static void set_current(Menu* pmenu); -- 2.11.0