X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fgui%2Fmenu.cpp;h=0045fbc77e1b3fda8c2c0c2d39bb7a01deff095b;hb=07ddaed2a657e4d2a3d038fed223fc5827159caf;hp=052a54d131e2ac93dd9fcaf666171d07270ee9a8;hpb=1486ceaaf9dd7a9d2d7e3654550b9a2768df2a56;p=supertux.git diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index 052a54d13..0045fbc77 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -1,7 +1,7 @@ // $Id$ // // SuperTux -// Copyright (C) 2004 Tobias Glaesser +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -16,6 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + #include #include @@ -30,6 +31,7 @@ #include #include "menu.hpp" +#include "mainloop.hpp" #include "video/screen.hpp" #include "video/drawing_context.hpp" #include "gettext.hpp" @@ -37,7 +39,6 @@ #include "main.hpp" #include "resources.hpp" #include "control/joystickkeyboardcontroller.hpp" -#include "exceptions.hpp" static const int MENU_REPEAT_INITIAL = 400; static const int MENU_REPEAT_RATE = 200; @@ -68,12 +69,13 @@ bool confirm_dialog(Surface *background, std::string text) DrawingContext context; + // TODO make this a screen and not another mainloop... while(true) { SDL_Event event; while (SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) - throw graceful_shutdown(); + main_loop->quit(); main_controller->process_event(event); dialog->event(event); } @@ -487,8 +489,8 @@ Menu::menu_action(MenuItem* ) void Menu::draw_item(DrawingContext& context, int index) { - int menu_height = get_height(); - int menu_width = get_width(); + float menu_height = get_height(); + float menu_width = get_width(); MenuItem& pitem = *(items[index]); @@ -666,29 +668,33 @@ Menu::draw_item(DrawingContext& context, int index) } } -int Menu::get_width() const +float Menu::get_width() const +{ + /* The width of the menu has to be more than the width of the text + with the most characters */ + float menu_width = 0; + for(unsigned int i = 0; i < items.size(); ++i) { - /* The width of the menu has to be more than the width of the text - with the most characters */ - int menu_width = 0; - for(unsigned int i = 0; i < items.size(); ++i) - { - int w = items[i]->text.size() + items[i]->input.size() + 1; - if(w > menu_width) - { - menu_width = w; - if( items[i]->kind == MN_TOGGLE) - menu_width += 2; - } - } - - return (menu_width * 16 + 24); + Font* font = default_font; + if(items[i]->kind == MN_LABEL) + font = label_font; + + float w = font->get_text_width(items[i]->text) + + label_font->get_text_width(items[i]->input) + 16; + if(items[i]->kind == MN_TOGGLE) + w += 32; + + if(w > menu_width) + menu_width = w; } + + return menu_width + 24; +} -int Menu::get_height() const - { - return items.size() * 24; - } +float Menu::get_height() const +{ + return items.size() * 24; +} /* Draw the current menu. */ void @@ -698,8 +704,8 @@ Menu::draw(DrawingContext& context) MouseCursor::current()->draw(context); } - int menu_height = get_height(); - int menu_width = get_width(); + float menu_height = get_height(); + float menu_width = get_width(); /* Draw a transparent background */ context.draw_filled_rect(