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::draw(DrawingContext& context)
54 m_current->draw(context);
59 MenuManager::push_current(Menu* menu)
61 m_previous = m_current;
65 m_last_menus.push_back(m_current);
69 m_current->effect_start_time = real_time;
70 m_current->effect_progress = 0.0f;
74 MenuManager::pop_current()
76 m_previous = m_current;
78 if (m_last_menus.size() >= 1)
80 m_current = m_last_menus.back();
81 m_current->effect_start_time = real_time;
82 m_current->effect_progress = 0.0f;
83 m_last_menus.pop_back();
92 MenuManager::set_current(Menu* menu)
94 if (m_current && m_current->close == true)
100 m_previous = m_current;
104 menu->effect_start_time = real_time;
105 menu->effect_progress = 0.0f;
110 m_last_menus.clear(); //NULL new menu pointer => close all menus
111 m_current->effect_start_time = real_time;
112 m_current->effect_progress = 0.0f;
113 m_current->close = true;
116 // just to be sure...
117 g_input_manager->reset();
122 MenuManager::recalc_pos()
125 m_current->set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
127 for(auto i = m_all_menus.begin(); i != m_all_menus.end(); ++i)
129 // FIXME: This is of course not quite right, since it ignores any previous set_pos() calls
130 (*i)->set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);