src/gui/menu_manager.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "gui/menu_manager.hpp"
00018 
00019 #include "control/joystickkeyboardcontroller.hpp"
00020 #include "gui/menu.hpp"
00021 #include "supertux/globals.hpp"
00022 #include "supertux/timer.hpp"
00023 
00024 std::vector<Menu*> MenuManager::last_menus;
00025 std::list<Menu*> MenuManager::all_menus;
00026 Menu* MenuManager::current_ = 0;
00027 Menu* MenuManager::previous = 0;
00028 
00029 void
00030 MenuManager::push_current(Menu* pmenu)
00031 {
00032   previous = current_;
00033 
00034   if (current_)
00035     last_menus.push_back(current_);
00036 
00037   current_ = pmenu;
00038   current_->effect_start_time = real_time;
00039   current_->effect_progress   = 0.0f;
00040 }
00041 
00042 void
00043 MenuManager::pop_current()
00044 {
00045   previous = current_;
00046 
00047   if (last_menus.size() >= 1) {
00048     current_ = last_menus.back();
00049     current_->effect_start_time = real_time;
00050     current_->effect_progress   = 0.0f;
00051     last_menus.pop_back();
00052   } else {
00053     set_current(NULL);
00054   }
00055 }
00056 
00057 void
00058 MenuManager::set_current(Menu* menu)
00059 {
00060   if (current_ && current_->close == true)
00061     return;
00062 
00063   previous = current_;
00064 
00065   if (menu) {
00066     menu->effect_start_time = real_time;
00067     menu->effect_progress = 0.0f;
00068     current_ = menu;
00069   }
00070   else if (current_) {
00071     last_menus.clear();                         //NULL new menu pointer => close all menus
00072     current_->effect_start_time = real_time;
00073     current_->effect_progress = 0.0f;
00074     current_->close = true;
00075   }
00076 
00077   // just to be sure...
00078   g_jk_controller->reset();
00079 }
00080 
00081 void
00082 MenuManager::recalc_pos()
00083 {
00084   if (current_)
00085     current_->set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
00086 
00087   for(std::list<Menu*>::iterator i = all_menus.begin(); i != all_menus.end(); ++i)
00088   {
00089     // FIXME: This is of course not quite right, since it ignores any previous set_pos() calls
00090     (*i)->set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
00091   }
00092 }
00093 
00094 /* EOF */

Generated on Mon Jun 9 03:38:18 2014 for SuperTux by  doxygen 1.5.1