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 "math/vector.hpp"
25 #include "video/color.hpp"
26 #include "video/surface_ptr.hpp"
31 bool confirm_dialog(Surface* background, std::string text);
35 static Color default_color;
36 static Color active_color;
37 static Color inactive_color;
38 static Color label_color;
39 static Color field_color;
42 /* Action done on the menu */
44 MENU_ACTION_NONE = -1,
60 MenuItem* add_label(const std::string& text);
61 MenuItem* add_entry(int id, const std::string& text);
62 MenuItem* add_toggle(int id, const std::string& text, bool toggled = false);
63 MenuItem* add_inactive(int id, const std::string& text);
64 MenuItem* add_back(const std::string& text);
65 MenuItem* add_submenu(const std::string& text, int submenu);
66 MenuItem* add_controlfield(int id, const std::string& text,
67 const std::string& mapping = "");
68 MenuItem* add_string_select(int id, const std::string& text);
70 virtual void menu_action(MenuItem* item);
74 /** Perform actions to bring the menu up to date with configuration changes */
75 virtual void refresh() {}
77 /** Remove all entries from the menu */
80 virtual void check_menu() =0;
82 MenuItem& get_item(int index)
84 return *(items[index]);
87 MenuItem& get_item_by_id(int id);
88 const MenuItem& get_item_by_id(int id) const;
90 int get_active_item_id();
91 void set_active_item(int id);
93 void draw(DrawingContext& context);
94 Vector get_pos() const { return pos; }
95 void set_pos(float x, float y);
97 void event(const SDL_Event& event);
99 bool is_toggled(int id) const;
100 void set_toggled(int id, bool toggled);
102 float get_width() const;
103 float get_height() const;
106 /** Return the index of the menu item that was 'hit' (ie. the user
107 clicked on it) in the last event() call */
110 MenuItem* add_item(std::unique_ptr<MenuItem> menu_item);
113 void check_controlfield_change_event(const SDL_Event& event);
114 void draw_item(DrawingContext& context, int index);
117 /** Number of the item that got 'hit' (ie. pressed) in the last
118 event()/update() call, -1 if none */
121 // position of the menu (ie. center of the menu, not top/left)
124 /** input event for the menu (up, down, left, right, etc.) */
125 MenuAction menuaction;
127 /* input implementation variables */
128 int delete_character;
130 float menu_repeat_time;
133 std::vector<std::unique_ptr<MenuItem> > items;