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/menu/menu_storage.hpp"
25 #include "supertux/timer.hpp"
27 MenuManager* MenuManager::s_instance = 0;
30 MenuManager::instance()
36 MenuManager::MenuManager() :
45 MenuManager::~MenuManager()
51 MenuManager::draw(DrawingContext& context)
55 m_current->draw(context);
60 MenuManager::check_menu()
64 m_current->check_menu();
74 MenuManager::push_current(int id)
76 Menu* menu = MenuStorage::instance().create(static_cast<MenuStorage::MenuId>(id));
81 MenuManager::push_current_(Menu* menu)
83 m_previous = m_current;
87 m_last_menus.push_back(m_current);
91 m_current->effect_start_time = real_time;
92 m_current->effect_progress = 0.0f;
96 MenuManager::pop_current()
98 m_previous = m_current;
100 if (m_last_menus.size() >= 1)
102 m_current = m_last_menus.back();
103 m_current->effect_start_time = real_time;
104 m_current->effect_progress = 0.0f;
105 m_last_menus.pop_back();
109 set_current(MenuStorage::NO_MENU);
114 MenuManager::set_current(int id)
116 Menu* menu = MenuStorage::instance().create(static_cast<MenuStorage::MenuId>(id));
117 set_current_ptr(menu);
121 MenuManager::set_current_ptr(Menu* menu)
123 if (m_current && m_current->close == true)
129 m_previous = m_current;
133 menu->effect_start_time = real_time;
134 menu->effect_progress = 0.0f;
139 m_last_menus.clear(); //NULL new menu pointer => close all menus
140 m_current->effect_start_time = real_time;
141 m_current->effect_progress = 0.0f;
142 m_current->close = true;
145 // just to be sure...
146 g_input_manager->reset();
151 MenuManager::recalc_pos()
154 m_current->set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
156 for(auto i = m_all_menus.begin(); i != m_all_menus.end(); ++i)
158 // FIXME: This is of course not quite right, since it ignores any previous set_pos() calls
159 (*i)->set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);