2 // Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "gui/menu_manager.hpp"
21 #include "control/input_manager.hpp"
22 #include "gui/menu.hpp"
23 #include "supertux/globals.hpp"
24 #include "supertux/timer.hpp"
26 MenuManager* MenuManager::s_instance = 0;
29 MenuManager::instance()
35 MenuManager::MenuManager() :
44 MenuManager::~MenuManager()
50 MenuManager::push_current(Menu* menu)
52 m_previous = m_current;
56 m_last_menus.push_back(m_current);
60 m_current->effect_start_time = real_time;
61 m_current->effect_progress = 0.0f;
65 MenuManager::pop_current()
67 m_previous = m_current;
69 if (m_last_menus.size() >= 1)
71 m_current = m_last_menus.back();
72 m_current->effect_start_time = real_time;
73 m_current->effect_progress = 0.0f;
74 m_last_menus.pop_back();
83 MenuManager::set_current(Menu* menu)
85 if (m_current && m_current->close == true)
91 m_previous = m_current;
95 menu->effect_start_time = real_time;
96 menu->effect_progress = 0.0f;
101 m_last_menus.clear(); //NULL new menu pointer => close all menus
102 m_current->effect_start_time = real_time;
103 m_current->effect_progress = 0.0f;
104 m_current->close = true;
107 // just to be sure...
108 g_input_manager->reset();
113 MenuManager::recalc_pos()
116 m_current->set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
118 for(auto i = m_all_menus.begin(); i != m_all_menus.end(); ++i)
120 // FIXME: This is of course not quite right, since it ignores any previous set_pos() calls
121 (*i)->set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);