src/gui/menu_item.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.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_item.hpp"
00018 
00019 #include "supertux/resources.hpp"
00020 #include "supertux/timer.hpp"
00021 #include "video/font.hpp"
00022 
00023 static const float FLICK_CURSOR_TIME   = 0.5f;
00024 
00025 MenuItem::MenuItem(MenuItemKind _kind, int _id) :
00026   kind(_kind),
00027   id(_id),
00028   toggled(),
00029   text(),
00030   input(),
00031   help(),
00032   list(),
00033   selected(),
00034   target_menu(),
00035   input_flickering()
00036 {
00037   toggled = false;
00038   selected = false;
00039   target_menu = 0;
00040 }
00041 
00042 void
00043 MenuItem::change_text(const  std::string& text_)
00044 {
00045   text = text_;
00046 }
00047 
00048 void
00049 MenuItem::change_input(const  std::string& text_)
00050 {
00051   input = text_;
00052 }
00053 
00054 void
00055 MenuItem::set_help(const std::string& help_text)
00056 {
00057   std::string overflow;
00058   help = Resources::normal_font->wrap_to_width(help_text, 600, &overflow);
00059   while (!overflow.empty())
00060   {
00061     help += "\n";
00062     help += Resources::normal_font->wrap_to_width(overflow, 600, &overflow);
00063   }
00064 }
00065 
00066 std::string
00067 MenuItem::get_input_with_symbol(bool active_item)
00068 {
00069   if(!active_item) {
00070     input_flickering = true;
00071   } else {
00072     input_flickering = ((int) (real_time / FLICK_CURSOR_TIME)) % 2;
00073   }
00074 
00075   char str[1024];
00076   if(input_flickering)
00077     snprintf(str, sizeof(str), "%s ",input.c_str());
00078   else
00079     snprintf(str, sizeof(str), "%s_",input.c_str());
00080 
00081   std::string string = str;
00082 
00083   return string;
00084 }
00085 
00086 /* EOF */

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