- fixed bug in live counting
[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   // position of the menu (ie. center of the menu, not top/left)
60   int pos_x;
61   int pos_y;
62   bool has_backitem;
63   
64   Menu* last_menu;
65   int width();
66   int height();
67   
68 public:
69   Timer effect;
70   int arrange_left;
71   int active_item;
72   std::vector<MenuItem> item;
73
74   static void set_current(Menu* pmenu);
75
76   Menu();
77   ~Menu();
78
79   void additem(MenuItem* pmenu_item);
80   void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu);
81   void action ();
82   
83   /** Remove all entries from the menu */
84   void clear();
85
86   /** Check, if the value of the active menu item has changed. */
87   int  check  ();
88   void draw   ();
89   void draw_item(int index, int menu_width, int menu_height);
90   void set_pos(int x, int y, float rw = 0, float rh = 0);
91
92   /* Check for a menu event */
93   void event(SDL_Event& event);
94 };
95
96
97 /* Action done on the menu */
98 enum MenuAction {
99   MENU_ACTION_NONE = -1,
100   MENU_ACTION_UP,
101   MENU_ACTION_DOWN,
102   MENU_ACTION_LEFT,
103   MENU_ACTION_RIGHT,
104   MENU_ACTION_HIT,
105   MENU_ACTION_INPUT,
106   MENU_ACTION_REMOVE
107 };
108
109 /* (global) menu variables */
110 extern MenuAction menuaction;
111 extern bool show_menu;
112 extern bool menu_change;
113
114 extern Surface* checkbox;
115 extern Surface* checkbox_checked;
116 extern Surface* back;
117 extern Surface* arrow_left;
118 extern Surface* arrow_right;
119
120 extern Menu* contrib_menu;
121 extern Menu* contrib_subset_menu;
122 extern Menu* main_menu;
123 extern Menu* game_menu;
124 extern Menu* worldmap_menu;
125 extern Menu* options_menu;
126 extern Menu* options_controls_menu;
127 extern Menu* highscore_menu;
128 extern Menu* load_game_menu;
129 extern Menu* save_game_menu;
130 extern Menu* current_menu;
131
132 /* input implementation variables */
133 extern int delete_character;
134 extern char mn_input_char;
135
136 /* Reset the global menu variables */
137 void menu_reset(void);
138
139 /* "Calculate" and draw the menu */
140 void menu_process_current(void);
141
142 #endif /*SUPERTUX_MENU_H*/
143
144 /* Local Variables: */
145 /* mode: c++ */
146 /* End: */