2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef HEADER_SUPERTUX_GUI_MENU_HPP
18 #define HEADER_SUPERTUX_GUI_MENU_HPP
24 #include "gui/mousecursor.hpp"
25 #include "video/font.hpp"
27 bool confirm_dialog(Surface* background, std::string text);
29 /* Kinds of menu items */
41 MN_HL /* horizontal line */
49 MenuItem(MenuItemKind kind, int id = -1);
57 std::vector<std::string> list; // list of values for a STRINGSELECT item
58 size_t selected; // currently selected item
62 void set_help(const std::string& help_text);
64 void change_text (const std::string& text);
65 void change_input(const std::string& text);
67 static MenuItem* create(MenuItemKind kind, const std::string& text,
68 int init_toggle, Menu* target_menu, int id, int key);
70 std::string get_input_with_symbol(bool active_item); // returns the text with an input symbol
73 /// keyboard key or joystick button
74 bool input_flickering;
77 MenuItem(const MenuItem&);
78 MenuItem& operator=(const MenuItem&);
83 static Color default_color;
84 static Color active_color;
85 static Color inactive_color;
86 static Color label_color;
87 static Color field_color;
89 static std::vector<Menu*> last_menus;
91 /** Pointers to all currently available menus, used to handle repositioning on window resize */
92 static std::list<Menu*> all_menus;
94 static Menu* previous;
95 static Menu* current_;
98 /** Set the current menu, if pmenu is NULL, hide the current menu */
99 static void set_current(Menu* pmenu);
101 static void push_current(Menu* pmenu);
102 static void pop_current();
104 static void recalc_pos();
106 /** Return the current active menu or NULL if none is active */
107 static Menu* current()
113 /* Action done on the menu */
115 MENU_ACTION_NONE = -1,
126 /** Number of the item that got 'hit' (ie. pressed) in the last
127 event()/update() call, -1 if none */
130 // position of the menu (ie. center of the menu, not top/left)
134 /** input event for the menu (up, down, left, right, etc.) */
135 MenuAction menuaction;
137 /* input implementation variables */
138 int delete_character;
140 float menu_repeat_time;
145 std::vector<MenuItem*> items;
151 MenuItem* add_label(const std::string& text);
152 MenuItem* add_entry(int id, const std::string& text);
153 MenuItem* add_toggle(int id, const std::string& text, bool toggled = false);
154 MenuItem* add_inactive(int id, const std::string& text);
155 MenuItem* add_back(const std::string& text);
156 MenuItem* add_submenu(const std::string& text, Menu* submenu, int id = -1);
157 MenuItem* add_controlfield(int id, const std::string& text,
158 const std::string& mapping = "");
159 MenuItem* add_string_select(int id, const std::string& text);
161 virtual void menu_action(MenuItem* item);
165 /** Remove all entries from the menu */
168 /** Return the index of the menu item that was 'hit' (ie. the user
169 clicked on it) in the last event() call */
172 MenuItem& get_item(int index)
174 return *(items[index]);
176 MenuItem& get_item_by_id(int id);
177 const MenuItem& get_item_by_id(int id) const;
179 int get_active_item_id();
180 void set_active_item(int id);
182 void draw(DrawingContext& context);
183 void set_pos(float x, float y, float rw = 0, float rh = 0);
185 void event(const SDL_Event& event);
187 bool is_toggled(int id) const;
188 void set_toggled(int id, bool toggled);
190 Menu* get_parent() const;
193 void additem(MenuItem* pmenu_item);
194 float get_width() const;
195 float get_height() const;
198 void check_controlfield_change_event(const SDL_Event& event);
199 void draw_item(DrawingContext& context, int index);
200 float effect_progress;
201 float effect_start_time;
205 std::auto_ptr<Surface> checkbox;
206 std::auto_ptr<Surface> checkbox_checked;
207 std::auto_ptr<Surface> back;
208 std::auto_ptr<Surface> arrow_left;
209 std::auto_ptr<Surface> arrow_right;