- removed menu_process_current()
[supertux.git] / src / menu.h
1 /*
2   menu.h
3   
4   Super Tux - Menu
5   
6   by Tobias Glaesser
7   tobi.web@gmx.de
8   http://www.newbreedsoftware.com/supertux/
9   
10   December 20, 2003
11 */
12
13 #ifndef SUPERTUX_MENU_H
14 #define SUPERTUX_MENU_H
15
16 #include <SDL.h>
17 #include <vector>
18 #include "texture.h"
19 #include "timer.h"
20 #include "type.h"
21 #include "mousecursor.h"
22
23 /* Kinds of menu items */
24 enum MenuItemKind {
25   MN_ACTION,
26   MN_GOTO,
27   MN_TOGGLE,
28   MN_BACK,
29   MN_DEACTIVE,
30   MN_TEXTFIELD,
31   MN_NUMFIELD,
32   MN_CONTROLFIELD,
33   MN_STRINGSELECT,
34   MN_LABEL,
35   MN_HL, /* horizontal line */
36 };
37
38 class Menu;
39
40 class MenuItem
41 {
42 public:
43   MenuItemKind kind;
44   int toggled;
45   char *text;
46   char *input;
47   string_list_type* list;
48   Menu* target_menu;
49
50   void change_text (const char *text);
51   void change_input(const char *text);
52
53   static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu);
54 };
55
56 class Menu
57 {
58 private:
59   /* Action done on the menu */
60   enum MenuAction {
61     MENU_ACTION_NONE = -1,
62     MENU_ACTION_UP,
63     MENU_ACTION_DOWN,
64     MENU_ACTION_LEFT,
65     MENU_ACTION_RIGHT,
66     MENU_ACTION_HIT,
67     MENU_ACTION_INPUT,
68     MENU_ACTION_REMOVE
69   };
70
71   // position of the menu (ie. center of the menu, not top/left)
72   int pos_x;
73   int pos_y;
74   bool has_backitem;
75
76   /** input event for the menu */
77   MenuAction menuaction;
78
79   /* input implementation variables */
80   int delete_character;
81   char mn_input_char;
82   
83   Menu* last_menu;
84   int width();
85   int height();
86   
87   static Menu* current_;
88 public:
89   Timer effect;
90   int arrange_left;
91   int active_item;
92   std::vector<MenuItem> item;
93
94   /** Set the current menu, if pmenu is NULL, hide the current menu */
95   static void set_current(Menu* pmenu);
96   static Menu* current() { return current_; }
97
98   Menu();
99   ~Menu();
100
101   void additem(MenuItem* pmenu_item);
102   void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu);
103   void action ();
104   
105   /** Remove all entries from the menu */
106   void clear();
107
108   /** Check, if the value of the active menu item has changed. */
109   int  check  ();
110   void draw   ();
111   void draw_item(int index, int menu_width, int menu_height);
112   void set_pos(int x, int y, float rw = 0, float rh = 0);
113
114   /** translate a SDL_Event into a menu_action */
115   void event(SDL_Event& event);
116 };
117
118 extern Surface* checkbox;
119 extern Surface* checkbox_checked;
120 extern Surface* back;
121 extern Surface* arrow_left;
122 extern Surface* arrow_right;
123
124 extern Menu* contrib_menu;
125 extern Menu* contrib_subset_menu;
126 extern Menu* main_menu;
127 extern Menu* game_menu;
128 extern Menu* worldmap_menu;
129 extern Menu* options_menu;
130 extern Menu* options_controls_menu;
131 extern Menu* highscore_menu;
132 extern Menu* load_game_menu;
133 extern Menu* save_game_menu;
134
135 #endif /*SUPERTUX_MENU_H*/
136
137 /* Local Variables: */
138 /* mode: c++ */
139 /* End: */