[Super-tux-commit] supertux/lib/gui menu.h,1.6,1.7 menu.cpp,1.15,1.16
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2004-11-18 15:10:06
|
Update of /cvsroot/super-tux/supertux/lib/gui In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23985 Modified Files: menu.h menu.cpp Log Message: change braindamaging usage of STL to something saner Index: menu.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/gui/menu.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- menu.cpp 9 Oct 2004 08:19:17 -0000 1.15 +++ menu.cpp 18 Nov 2004 15:09:53 -0000 1.16 @@ -18,6 +18,8 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef WIN32 +#include <config.h> + #include <sys/types.h> #include <ctype.h> #endif @@ -34,7 +36,6 @@ #include "../video/screen.h" #include "../video/drawing_context.h" #include "../app/setup.h" -#include "../special/timer.h" #include "../app/gettext.h" #include "../math/vector.h" @@ -152,14 +153,14 @@ current_ = menu; } -MenuItem::MenuItem(MenuItemKind _kind, int _id) : kind(_kind) , id(_id) +MenuItem::MenuItem(MenuItemKind _kind, int _id) + : kind(_kind) , id(_id) { - list.second = 0; } -MenuItem::MenuItem(MenuItemKind _kind, int _id, const std::string& _text) : kind(_kind) , id(_id) , text(_text) +MenuItem::MenuItem(MenuItemKind _kind, int _id, const std::string& _text) + : kind(_kind) , id(_id) , text(_text) { - list.second = 0; } /* Return a pointer to a new menu item */ @@ -178,8 +179,8 @@ pnew_item->target_menu = target_menu_; pnew_item->int_p = int_p_; - - pnew_item->list.second = 0; + + pnew_item->selected = 0; pnew_item->input_flickering = false; pnew_item->input_flickering_timer.init(true); @@ -286,19 +287,10 @@ item->change_input(oss.str().c_str()); } -/* Free a menu and all its items */ Menu::~Menu() { - if(item.size() != 0) - { - for(unsigned int i = 0; i < item.size(); ++i) - { - item[i].list.first.clear(); - } - } } - Menu::Menu() { hit_item = -1; @@ -394,25 +386,21 @@ break; case MENU_ACTION_LEFT: - if(item[active_item].kind == MN_STRINGSELECT - && item[active_item].list.first.size() != 0) - { - if(item[active_item].list.second != item[active_item].list.first.begin()) - --item[active_item].list.second; - else - item[active_item].list.second = item[active_item].list.first.end(); - } + if(item[active_item].kind == MN_STRINGSELECT) { + if(item[active_item].selected > 0) + item[active_item].selected--; + else + item[active_item].selected = item[active_item].list.size()-1; + } break; case MENU_ACTION_RIGHT: - if(item[active_item].kind == MN_STRINGSELECT - && item[active_item].list.first.size() != 0) - { - if(item[active_item].list.second != item[active_item].list.first.end()) - ++item[active_item].list.second; - else - item[active_item].list.second = item[active_item].list.first.begin(); - } + if(item[active_item].kind == MN_STRINGSELECT) { + if(item[active_item].selected+1 < item[active_item].list.size()) + item[active_item].selected++; + else + item[active_item].selected = 0; + } break; case MENU_ACTION_HIT: @@ -519,9 +507,9 @@ int text_width = int(text_font->get_text_width(pitem.text)); int input_width = int(text_font->get_text_width(pitem.input) + 10); int list_width = 0; - std::set<std::string>::iterator tmp = 0; - if(pitem.list.second != tmp) - list_width = int(text_font->get_text_width((*pitem.list.second))); + if(pitem.list.size() > 0) { + list_width = (int) text_font->get_text_width(pitem.list[pitem.selected]); + } if (arrange_left) x_pos += 24 - menu_width/2 + (text_width + input_width + list_width)/2; @@ -631,7 +619,7 @@ Vector(list_pos_2, 18), Color(0,0,0,128), LAYER_GUI - 5); - context.draw_text(text_font, (*pitem.list.second), + context.draw_text(text_font, pitem.list[pitem.selected], Vector(screen->w/2 + text_pos, y_pos - int(text_font->get_height()/2)), CENTER_ALLIGN, LAYER_GUI); context.draw_text(text_font, pitem.text, @@ -687,7 +675,7 @@ int menu_width = 0; for(unsigned int i = 0; i < item.size(); ++i) { - int w = item[i].text.size() + item[i].input.size() + 1; //+ ((item[i].list.second != item[i].list.first.end()) ? (strlen((*(item[i].list.second)).c_str())) : 0); + int w = item[i].text.size() + item[i].input.size() + 1; if( w > menu_width ) { menu_width = w; @@ -917,5 +905,3 @@ } } - -// EOF // Index: menu.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/gui/menu.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- menu.h 28 Jul 2004 23:06:11 -0000 1.6 +++ menu.h 18 Nov 2004 15:09:53 -0000 1.7 @@ -30,7 +30,6 @@ #include "../video/surface.h" #include "../video/font.h" #include "../special/timer.h" -#include "../special/base.h" #include "../gui/mousecursor.h" namespace SuperTux @@ -73,13 +72,17 @@ std::string text; std::string input; int *int_p; // used for setting keys (can be used for more stuff...) - std::pair<std::set<std::string>, std::set<std::string>::iterator> list; + + std::vector<std::string> list; // list of values for a STRINGSELECT item + size_t selected; // currently selected item + Menu* target_menu; void change_text (const std::string& text); void change_input(const std::string& text); - static MenuItem* create(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu, int id, int* int_p); + static MenuItem* create(MenuItemKind kind, const std::string& text, + int init_toggle, Menu* target_menu, int id, int* int_p); std::string get_input_with_symbol(bool active_item); // returns the text with an input symbol private: |