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