X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fmenu.h;h=56e1a360fc215cf8772ffe3158771c651e630277;hb=b6543ef22bd7e4193d03cadac0c6e0dc75e3bd66;hp=3da7a974032be1046df49182c5b8c106c9fced69;hpb=ed8b08f0568d887c3459568b6a479356af09e36f;p=supertux.git diff --git a/src/menu.h b/src/menu.h index 3da7a9740..56e1a360f 100644 --- a/src/menu.h +++ b/src/menu.h @@ -1,19 +1,27 @@ -/* - menu.h - - Super Tux - Menu - - by Tobias Glaesser - tobi.web@gmx.de - http://www.newbreedsoftware.com/supertux/ - - December 20, 2003 -*/ +// $Id$ +// +// SuperTux +// Copyright (C) 2004 Tobias Glaesser +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// 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. #ifndef SUPERTUX_MENU_H #define SUPERTUX_MENU_H #include +#include #include "texture.h" #include "timer.h" #include "type.h" @@ -36,96 +44,120 @@ enum MenuItemKind { class Menu; -struct menu_item_type - { - MenuItemKind kind; - int toggled; - char *text; - char *input; - string_list_type* list; - Menu* target_menu; -}; +class MenuItem +{ +public: + MenuItemKind kind; + int toggled; + char *text; + char *input; + string_list_type* list; + Menu* target_menu; + + void change_text (const char *text); + void change_input(const char *text); -menu_item_type* menu_item_create(MenuItemKind kind, char *text, int init_toggle, Menu* target_menu); -void menu_item_change_text (menu_item_type* pmenu_item, const char *text); -void menu_item_change_input(menu_item_type* pmenu_item, const char *text); + static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu); +}; class Menu { -friend void menu_event(SDL_Event& event); +private: + static std::vector last_menus; + static Menu* current_; + + static void push_current(Menu* pmenu); + static void pop_current(); +public: + /** Set the current menu, if pmenu is NULL, hide the current menu */ + static void set_current(Menu* pmenu); + + /** Return the current active menu or NULL if none is active */ + static Menu* current() { return current_; } private: + /* Action done on the menu */ + enum MenuAction { + MENU_ACTION_NONE = -1, + MENU_ACTION_UP, + MENU_ACTION_DOWN, + MENU_ACTION_LEFT, + MENU_ACTION_RIGHT, + MENU_ACTION_HIT, + MENU_ACTION_INPUT, + MENU_ACTION_REMOVE + }; + + /** Number of the item that got 'hit' (ie. pressed) in the last + event()/action() call, -1 if none */ + int hit_item; + // position of the menu (ie. center of the menu, not top/left) int pos_x; int pos_y; - - int num_items; - Menu* last_menu; - int width(); - int height(); + bool has_backitem; + /** input event for the menu (up, down, left, right, etc.) */ + MenuAction menuaction; + + /* input implementation variables */ + int delete_character; + char mn_input_char; + public: - timer_type effect; + Timer effect; int arrange_left; int active_item; - menu_item_type *item; - static void set_current(Menu* pmenu); + std::vector item; Menu(); ~Menu(); - void additem(menu_item_type* pmenu_item); - void additem(MenuItemKind kind, char *text, int init_toggle, Menu* target_menu); - void action (); + void additem(MenuItem* pmenu_item); + void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu); + + void action (); + + /** Remove all entries from the menu */ + void clear(); + + /** Return the index of the menu item that was 'hit' (ie. the user + clicked on it) in the last event() call */ int check (); + + MenuItem& get_item(int index) { return item[index]; } + void draw (); void draw_item(int index, int menu_width, int menu_height); -}; + void set_pos(int x, int y, float rw = 0, float rh = 0); + /** translate a SDL_Event into a menu_action */ + void event(SDL_Event& event); -/* Action done on the menu */ -enum MenuAction { - MENU_ACTION_NONE = -1, - MENU_ACTION_UP, - MENU_ACTION_DOWN, - MENU_ACTION_LEFT, - MENU_ACTION_RIGHT, - MENU_ACTION_HIT, - MENU_ACTION_INPUT, - MENU_ACTION_REMOVE + int get_width() const; + int get_height() const; }; -/* (global) menu variables */ -extern MenuAction menuaction; -extern bool show_menu; -extern bool menu_change; -extern texture_type checkbox, checkbox_checked, back, arrow_left, arrow_right; +extern Surface* checkbox; +extern Surface* checkbox_checked; +extern Surface* back; +extern Surface* arrow_left; +extern Surface* arrow_right; +extern Menu* contrib_menu; +extern Menu* contrib_subset_menu; extern Menu* main_menu; extern Menu* game_menu; +extern Menu* worldmap_menu; extern Menu* options_menu; extern Menu* options_controls_menu; extern Menu* highscore_menu; extern Menu* load_game_menu; extern Menu* save_game_menu; -extern Menu* current_menu; - -/* input implementation variables */ -extern int delete_character; -extern char mn_input_char; - -/* Reset the global menu variables */ -void menu_reset(void); - -/* "Calculate" and draw the menu */ -void menu_process_current(void); - -/* Check for a menu event */ -void menu_event(SDL_Event& event); #endif /*SUPERTUX_MENU_H*/ /* Local Variables: */ -/* mode:c++ */ -/* End */ +/* mode: c++ */ +/* End: */