4 // Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #ifndef SUPERTUX_MENU_H
20 #define SUPERTUX_MENU_H
30 #include "video/surface.hpp"
31 #include "video/font.hpp"
32 #include "mousecursor.hpp"
34 bool confirm_dialog(Surface* background, std::string text);
36 /* Kinds of menu items */
48 MN_HL, /* horizontal line */
56 MenuItem(MenuItemKind kind, int id = -1);
63 std::vector<std::string> list; // list of values for a STRINGSELECT item
64 size_t selected; // currently selected item
68 void change_text (const std::string& text);
69 void change_input(const std::string& text);
71 static MenuItem* create(MenuItemKind kind, const std::string& text,
72 int init_toggle, Menu* target_menu, int id, int key);
74 std::string get_input_with_symbol(bool active_item); // returns the text with an input symbol
77 /// copy-construction not allowed
78 MenuItem(const MenuItem& ) { assert(false); }
79 /// assignment not allowed
80 void operator= (const MenuItem& ) { assert(false); }
82 /// keyboard key or joystick button
83 bool input_flickering;
89 static std::vector<Menu*> last_menus;
90 static Menu* current_;
92 static void push_current(Menu* pmenu);
93 static void pop_current();
96 /** Set the current menu, if pmenu is NULL, hide the current menu */
97 static void set_current(Menu* pmenu);
99 /** Return the current active menu or NULL if none is active */
100 static Menu* current()
106 /* Action done on the menu */
108 MENU_ACTION_NONE = -1,
119 /** Number of the item that got 'hit' (ie. pressed) in the last
120 event()/update() call, -1 if none */
123 // position of the menu (ie. center of the menu, not top/left)
127 /** input event for the menu (up, down, left, right, etc.) */
128 MenuAction menuaction;
130 /* input implementation variables */
131 int delete_character;
133 Uint32 menu_repeat_ticks;
136 static Font* default_font;
137 static Font* active_font;
138 static Font* deactive_font;
139 static Font* label_font;
140 static Font* field_font;
142 std::vector<MenuItem*> items;
148 void add_label(const std::string& text);
149 void add_entry(int id, const std::string& text);
150 void add_toggle(int id, const std::string& text, bool toggled = false);
151 void add_deactive(int id, const std::string& text);
152 void add_back(const std::string& text);
153 void add_submenu(const std::string& text, Menu* submenu, int id = -1);
154 void add_controlfield(int id, const std::string& text,
155 const std::string& mapping = "");
157 virtual void menu_action(MenuItem* item);
161 /** Remove all entries from the menu */
164 /** Return the index of the menu item that was 'hit' (ie. the user
165 clicked on it) in the last event() call */
168 MenuItem& get_item(int index)
170 return *(items[index]);
172 MenuItem& get_item_by_id(int id);
173 const MenuItem& get_item_by_id(int id) const;
175 int get_active_item_id();
176 void set_active_item(int id);
178 void draw(DrawingContext& context);
179 void set_pos(int x, int y, float rw = 0, float rh = 0);
181 void event(const SDL_Event& event);
183 bool is_toggled(int id) const;
186 void additem(MenuItem* pmenu_item);
187 int get_width() const;
188 int get_height() const;
191 void check_controlfield_change_event(const SDL_Event& event);
192 void draw_item(DrawingContext& context, int index);
198 extern Surface* checkbox;
199 extern Surface* checkbox_checked;
200 extern Surface* back;
201 extern Surface* arrow_left;
202 extern Surface* arrow_right;