4 // Copyright (C) 2006 Matthias Braun <matze@braunis.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.
20 #ifndef SUPERTUX_MENU_H
21 #define SUPERTUX_MENU_H
32 #include "video/surface.hpp"
33 #include "video/font.hpp"
34 #include "mousecursor.hpp"
36 bool confirm_dialog(Surface* background, std::string text);
38 /* Kinds of menu items */
50 MN_HL, /* horizontal line */
58 MenuItem(MenuItemKind kind, int id = -1);
66 std::vector<std::string> list; // list of values for a STRINGSELECT item
67 size_t selected; // currently selected item
71 void set_help(const std::string& help_text);
73 void change_text (const std::string& text);
74 void change_input(const std::string& text);
76 static MenuItem* create(MenuItemKind kind, const std::string& text,
77 int init_toggle, Menu* target_menu, int id, int key);
79 std::string get_input_with_symbol(bool active_item); // returns the text with an input symbol
82 /// copy-construction not allowed
83 MenuItem(const MenuItem& ) { assert(false); }
84 /// assignment not allowed
85 void operator= (const MenuItem& ) { assert(false); }
87 /// keyboard key or joystick button
88 bool input_flickering;
94 static std::vector<Menu*> last_menus;
95 static Menu* previous;
96 static Menu* current_;
98 static void pop_current();
101 /** Set the current menu, if pmenu is NULL, hide the current menu */
102 static void set_current(Menu* pmenu);
104 static void push_current(Menu* pmenu);
106 static void recalc_pos();
108 /** Return the current active menu or NULL if none is active */
109 static Menu* current()
115 /* Action done on the menu */
117 MENU_ACTION_NONE = -1,
128 /** Number of the item that got 'hit' (ie. pressed) in the last
129 event()/update() call, -1 if none */
132 // position of the menu (ie. center of the menu, not top/left)
136 /** input event for the menu (up, down, left, right, etc.) */
137 MenuAction menuaction;
139 /* input implementation variables */
140 int delete_character;
142 float menu_repeat_time;
145 static Font* default_font;
146 static Font* active_font;
147 static Font* deactive_font;
148 static Font* label_font;
149 static Font* field_font;
151 std::vector<MenuItem*> items;
157 MenuItem* add_label(const std::string& text);
158 MenuItem* add_entry(int id, const std::string& text);
159 MenuItem* add_toggle(int id, const std::string& text, bool toggled = false);
160 MenuItem* add_deactive(int id, const std::string& text);
161 MenuItem* add_back(const std::string& text);
162 MenuItem* add_submenu(const std::string& text, Menu* submenu, int id = -1);
163 MenuItem* add_controlfield(int id, const std::string& text,
164 const std::string& mapping = "");
165 MenuItem* add_string_select(int id, const std::string& text);
167 virtual void menu_action(MenuItem* item);
171 /** Remove all entries from the menu */
174 /** Return the index of the menu item that was 'hit' (ie. the user
175 clicked on it) in the last event() call */
178 MenuItem& get_item(int index)
180 return *(items[index]);
182 MenuItem& get_item_by_id(int id);
183 const MenuItem& get_item_by_id(int id) const;
185 int get_active_item_id();
186 void set_active_item(int id);
188 void draw(DrawingContext& context);
189 void set_pos(float x, float y, float rw = 0, float rh = 0);
191 void event(const SDL_Event& event);
193 bool is_toggled(int id) const;
194 void set_toggled(int id, bool toggled);
196 Menu* get_parent() const;
199 void additem(MenuItem* pmenu_item);
200 float get_width() const;
201 float get_height() const;
204 void check_controlfield_change_event(const SDL_Event& event);
205 void draw_item(DrawingContext& context, int index);
206 float effect_progress;
207 float effect_start_time;
211 std::auto_ptr<Surface> checkbox;
212 std::auto_ptr<Surface> checkbox_checked;
213 std::auto_ptr<Surface> back;
214 std::auto_ptr<Surface> arrow_left;
215 std::auto_ptr<Surface> arrow_right;