X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fgui%2Fmenu.cpp;h=0045fbc77e1b3fda8c2c0c2d39bb7a01deff095b;hb=07ddaed2a657e4d2a3d038fed223fc5827159caf;hp=4e28ff27e77013fc57456491f606b346202e402b;hpb=f3e5e57c9996168a4889ae8e195be25f8b7e629b;p=supertux.git diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index 4e28ff27e..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 @@ -488,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]); @@ -667,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 @@ -699,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(