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.
20 #ifndef SUPERTUX_MENU_H
21 #define SUPERTUX_MENU_H
30 #include "../video/surface.h"
31 #include "../video/font.h"
32 #include "../special/timer.h"
33 #include "../special/base.h"
34 #include "../gui/mousecursor.h"
39 /* Joystick menu delay */
40 #define JOYSTICK_MENU_DELAY 500
44 bool confirm_dialog(Surface* background, std::string text);
46 /* Kinds of menu items */
59 MN_HL, /* horizontal line */
71 int *int_p; // used for setting keys (can be used for more stuff...)
73 std::pair<std::set<std::string>, std::set<std::string>::iterator> list;
76 void change_text (const char *text);
77 void change_input(const char *text);
79 static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu, int id, int* int_p);
81 std::string get_input_with_symbol(bool active_item); // returns the text with an input symbol
83 bool input_flickering;
84 Timer input_flickering_timer;
90 static std::vector<Menu*> last_menus;
91 static Menu* current_;
93 static void push_current(Menu* pmenu);
94 static void pop_current();
97 /** Set the current menu, if pmenu is NULL, hide the current menu */
98 static void set_current(Menu* pmenu);
100 /** Return the current active menu or NULL if none is active */
101 static Menu* current()
107 /* Action done on the menu */
109 MENU_ACTION_NONE = -1,
119 /** Number of the item that got 'hit' (ie. pressed) in the last
120 event()/action() 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 Timer joystick_timer;
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;
146 std::vector<MenuItem> item;
151 void additem(MenuItem* pmenu_item);
152 void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu, int id = -1, int *int_p = NULL);
156 /** Remove all entries from the menu */
159 /** Return the index of the menu item that was 'hit' (ie. the user
160 clicked on it) in the last event() call */
163 MenuItem& get_item(int index)
167 MenuItem& get_item_by_id(int id);
169 int get_active_item_id();
171 bool isToggled(int id);
173 void Menu::get_controlfield_key_into_input(MenuItem *item);
174 void Menu::get_controlfield_js_into_input(MenuItem *item);
176 void draw(DrawingContext& context);
177 void draw_item(DrawingContext& context,
178 int index, int menu_width, int menu_height);
179 void set_pos(int x, int y, float rw = 0, float rh = 0);
181 /** translate a SDL_Event into a menu_action */
182 void event(SDL_Event& event);
184 int get_width() const;
185 int get_height() const;
187 bool is_toggled(int id) const;
190 extern Surface* checkbox;
191 extern Surface* checkbox_checked;
192 extern Surface* back;
193 extern Surface* arrow_left;
194 extern Surface* arrow_right;
196 } //namespace SuperTux
198 #endif /*SUPERTUX_MENU_H*/
200 /* Local Variables: */