- turned menu_item_type into a class
[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 "texture.h"
18 #include "timer.h"
19 #include "type.h"
20 #include "mousecursor.h"
21
22 /* Kinds of menu items */
23 enum MenuItemKind {
24   MN_ACTION,
25   MN_GOTO,
26   MN_TOGGLE,
27   MN_BACK,
28   MN_DEACTIVE,
29   MN_TEXTFIELD,
30   MN_NUMFIELD,
31   MN_CONTROLFIELD,
32   MN_STRINGSELECT,
33   MN_LABEL,
34   MN_HL, /* horizontal line */
35 };
36
37 class Menu;
38
39 class MenuItem
40 {
41 public:
42   MenuItemKind kind;
43   int toggled;
44   char *text;
45   char *input;
46   string_list_type* list;
47   Menu* target_menu;
48
49   void change_text (const char *text);
50   void change_input(const char *text);
51
52   static MenuItem* create(MenuItemKind kind, char *text, int init_toggle, Menu* target_menu);
53 };
54
55 class Menu
56 {
57 private:
58   // position of the menu (ie. center of the menu, not top/left)
59   int pos_x;
60   int pos_y;
61   
62   int num_items;
63   Menu* last_menu;
64   int width();
65   int height();
66   
67 public:
68   Timer effect;
69   int arrange_left;
70   int active_item;
71   MenuItem* item;
72
73   static void set_current(Menu* pmenu);
74
75   Menu();
76   ~Menu();
77
78   void additem(MenuItem* pmenu_item);
79   void additem(MenuItemKind kind, char *text, int init_toggle, Menu* target_menu);
80   void action ();
81
82   /** Check, if the value of the active menu item has changed. */
83   int  check  ();
84   void draw   ();
85   void draw_item(int index, int menu_width, int menu_height);
86   void set_pos(int x, int y, float rw = 0, float rh = 0);
87
88   /* Check for a menu event */
89   void event(SDL_Event& event);
90 };
91
92
93 /* Action done on the menu */
94 enum MenuAction {
95   MENU_ACTION_NONE = -1,
96   MENU_ACTION_UP,
97   MENU_ACTION_DOWN,
98   MENU_ACTION_LEFT,
99   MENU_ACTION_RIGHT,
100   MENU_ACTION_HIT,
101   MENU_ACTION_INPUT,
102   MENU_ACTION_REMOVE
103 };
104
105 /* (global) menu variables */
106 extern MenuAction menuaction;
107 extern bool show_menu;
108 extern bool menu_change;
109
110 extern texture_type checkbox;
111 extern texture_type checkbox_checked;
112 extern texture_type back;
113 extern texture_type arrow_left;
114 extern texture_type arrow_right;
115
116 extern Menu* contrib_menu;
117 extern Menu* main_menu;
118 extern Menu* game_menu;
119 extern Menu* options_menu;
120 extern Menu* options_controls_menu;
121 extern Menu* highscore_menu;
122 extern Menu* load_game_menu;
123 extern Menu* save_game_menu;
124 extern Menu* current_menu;
125
126 /* input implementation variables */
127 extern int delete_character;
128 extern char mn_input_char;
129
130 /* Reset the global menu variables */
131 void menu_reset(void);
132
133 /* "Calculate" and draw the menu */
134 void menu_process_current(void);
135
136 #endif /*SUPERTUX_MENU_H*/
137
138 /* Local Variables: */
139 /* mode:c++ */
140 /* End */