Removing unused var 'slotfile'
[supertux.git] / src / gui / menu.hpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
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.
8 //
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.
13 //
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/>.
16
17 #ifndef HEADER_SUPERTUX_GUI_MENU_HPP
18 #define HEADER_SUPERTUX_GUI_MENU_HPP
19
20 #include <list>
21 #include <memory>
22 #include <SDL.h>
23
24 #include "math/vector.hpp"
25 #include "video/color.hpp"
26 #include "video/surface_ptr.hpp"
27
28 class DrawingContext;
29 class MenuItem;
30
31 class Menu
32 {
33 private:
34   /* Action done on the menu */
35   enum MenuAction {
36     MENU_ACTION_NONE = -1,
37     MENU_ACTION_UP,
38     MENU_ACTION_DOWN,
39     MENU_ACTION_LEFT,
40     MENU_ACTION_RIGHT,
41     MENU_ACTION_HIT,
42     MENU_ACTION_INPUT,
43     MENU_ACTION_REMOVE,
44     MENU_ACTION_BACK
45   };
46
47 public:
48   Menu();
49   virtual ~Menu();
50
51   MenuItem* add_hl();
52   MenuItem* add_label(const std::string& text);
53   MenuItem* add_entry(int id, const std::string& text);
54   MenuItem* add_toggle(int id, const std::string& text, bool toggled = false);
55   MenuItem* add_inactive(int id, const std::string& text);
56   MenuItem* add_back(const std::string& text);
57   MenuItem* add_submenu(const std::string& text, int submenu);
58   MenuItem* add_controlfield(int id, const std::string& text,
59                              const std::string& mapping = "");
60   MenuItem* add_string_select(int id, const std::string& text);
61
62   virtual void menu_action(MenuItem* item) = 0;
63
64   void process_input();
65
66   /** Perform actions to bring the menu up to date with configuration changes */
67   virtual void refresh() {}
68
69   /** Remove all entries from the menu */
70   void clear();
71
72   MenuItem& get_item(int index)
73   {
74     return *(items[index]);
75   }
76
77   MenuItem& get_item_by_id(int id);
78   const MenuItem& get_item_by_id(int id) const;
79
80   int get_active_item_id();
81   void set_active_item(int id);
82
83   void draw(DrawingContext& context);
84   Vector get_center_pos() const { return pos; }
85   void set_center_pos(float x, float y);
86
87   void event(const SDL_Event& event);
88
89   bool is_toggled(int id) const;
90   void set_toggled(int id, bool toggled);
91
92   float get_width() const;
93   float get_height() const;
94
95   virtual void on_window_resize();
96
97 protected:
98   MenuItem* add_item(std::unique_ptr<MenuItem> menu_item);
99
100 private:
101   void process_action(MenuAction menuaction);
102   void check_controlfield_change_event(const SDL_Event& event);
103   void draw_item(DrawingContext& context, int index);
104
105 private:
106   // position of the menu (ie. center of the menu, not top/left)
107   Vector pos;
108
109   /* input implementation variables */
110   int   delete_character;
111   char  mn_input_char;
112   float menu_repeat_time;
113
114 public:
115   std::vector<std::unique_ptr<MenuItem> > items;
116
117 private:
118   int arrange_left;
119   int active_item;
120 };
121
122 #endif
123
124 /* EOF */