X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=lib%2Fgui%2Fmenu.h;h=c9ef6ee7b218fc61e53bd3c9ff98f5a01ee55605;hb=133d94d5b145f325c38c8c15c9ea561bfffb092d;hp=e2113d0db665e53e955f5ec2d0913e18e8bfa2a5;hpb=9c511ea692d3a2339597211f08f18ea74fad35ec;p=supertux.git diff --git a/lib/gui/menu.h b/lib/gui/menu.h index e2113d0db..c9ef6ee7b 100644 --- a/lib/gui/menu.h +++ b/lib/gui/menu.h @@ -21,171 +21,186 @@ #define SUPERTUX_MENU_H #include +#include +#include +#include #include "SDL.h" #include "video/surface.h" +#include "video/font.h" #include "special/timer.h" -#include "special/base.h" -#include "special/stringlist.h" -#include "gui/mousecursor.h" +#include "mousecursor.h" +namespace SuperTux + { -/* Joystick menu delay */ + /* Joystick menu delay */ #define JOYSTICK_MENU_DELAY 500 -/* IDs for menus */ - -bool confirm_dialog(Surface* background, std::string text); - -/* Kinds of menu items */ -enum MenuItemKind { - MN_ACTION, - MN_GOTO, - MN_TOGGLE, - MN_BACK, - MN_DEACTIVE, - MN_TEXTFIELD, - MN_NUMFIELD, - MN_CONTROLFIELD_KB, - MN_CONTROLFIELD_JS, - MN_STRINGSELECT, - MN_LABEL, - MN_HL, /* horizontal line */ -}; - -class Menu; - -class MenuItem -{ -public: - MenuItemKind kind; - int toggled; - char *text; - char *input; - int *int_p; // used for setting keys (can be used for more stuff...) - int id; // item id - string_list_type* list; - Menu* target_menu; - - void change_text (const char *text); - void change_input(const char *text); - - static MenuItem* create(MenuItemKind kind, const char *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: - bool input_flickering; - Timer input_flickering_timer; -}; - -class Menu -{ -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 + /* IDs for menus */ + + bool confirm_dialog(Surface* background, std::string text); + + /* Kinds of menu items */ + enum MenuItemKind { + MN_ACTION, + MN_GOTO, + MN_TOGGLE, + MN_BACK, + MN_DEACTIVE, + MN_TEXTFIELD, + MN_NUMFIELD, + MN_CONTROLFIELD_KB, + MN_CONTROLFIELD_JS, + MN_STRINGSELECT, + MN_LABEL, + MN_HL, /* horizontal line */ }; - /** 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; - - /** input event for the menu (up, down, left, right, etc.) */ - MenuAction menuaction; - - /* input implementation variables */ - int delete_character; - char mn_input_char; - Timer joystick_timer; - -public: - Timer effect; - int arrange_left; - int active_item; - - std::vector item; - - Menu(); - ~Menu(); - - void additem(MenuItem* pmenu_item); - void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu, int id = -1, int *int_p = NULL); - - 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]; } - MenuItem& get_item_by_id(int id); - - int get_active_item_id(); - - bool isToggled(int id); - - void Menu::get_controlfield_key_into_input(MenuItem *item); - void Menu::get_controlfield_js_into_input(MenuItem *item); - - void draw(DrawingContext& context); - void draw_item(DrawingContext& context, - 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); - - int get_width() const; - int get_height() const; - - bool is_toggled(int id) const; -}; - -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* options_menu; -extern Menu* options_keys_menu; -extern Menu* options_joystick_menu; -extern Menu* highscore_menu; -extern Menu* load_game_menu; -extern Menu* save_game_menu; + class Menu; + + class MenuItem + { + public: + MenuItem() {}; + MenuItem(MenuItemKind kind, int id = -1); + MenuItem(MenuItemKind kind, int id, const std::string& text); + MenuItemKind kind; + int id; // item id + int toggled; + std::string text; + std::string input; + int *int_p; // used for setting keys (can be used for more stuff...) + + std::vector 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); + + std::string get_input_with_symbol(bool active_item); // returns the text with an input symbol + private: + bool input_flickering; + Timer input_flickering_timer; + }; + + class Menu + { + 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; + + /** input event for the menu (up, down, left, right, etc.) */ + MenuAction menuaction; + + /* input implementation variables */ + int delete_character; + char mn_input_char; + Timer joystick_timer; + + public: + static Font* default_font; + static Font* active_font; + static Font* deactive_font; + static Font* label_font; + static Font* field_font; + + Timer effect; + int arrange_left; + int active_item; + + std::vector item; + + Menu(); + ~Menu(); + + void additem(const MenuItem& menu_item); + void additem(MenuItem* pmenu_item); + void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu, int id = -1, int *int_p = NULL); + + 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]; + } + MenuItem& get_item_by_id(int id); + + int get_active_item_id(); + + bool isToggled(int id); + + void Menu::get_controlfield_key_into_input(MenuItem *item); + void Menu::get_controlfield_js_into_input(MenuItem *item); + + void draw(DrawingContext& context); + void draw_item(DrawingContext& context, + 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); + + int get_width() const; + int get_height() const; + + bool is_toggled(int id) const; + }; + + extern Surface* checkbox; + extern Surface* checkbox_checked; + extern Surface* back; + extern Surface* arrow_left; + extern Surface* arrow_right; + +} //namespace SuperTux #endif /*SUPERTUX_MENU_H*/