- turned menu into a class, still a lot of public variables around and menu_item...
[supertux.git] / src / menu.h
index 90a162d..1a36691 100644 (file)
 #define SUPERTUX_MENU_H
 
 #include <SDL.h>
+#include "texture.h"
+#include "timer.h"
+#include "type.h"
 
-/* (global) menu variables */
-int menuaction;
-int menuitem;
-int menumenu;
-int show_menu;
-int menu_change;
+/* Kinds of menu items */
+enum MenuItemKind {
+  MN_ACTION,
+  MN_GOTO,
+  MN_TOGGLE,
+  MN_BACK,
+  MN_DEACTIVE,
+  MN_TEXTFIELD,
+  MN_NUMFIELD,
+  MN_STRINGSELECT,
+  MN_LABEL,
+  MN_HL /* horizontal line */
+};
 
-#define MENU_MAIN_ITEM_MAX 3
-#define MENU_OPTIONS_ITEM_MAX 4
+class Menu;
 
-/* Action done on the menu */
-enum {
-  MN_UP,
-  MN_DOWN,
-  MN_HIT
+struct menu_item_type
+  {
+    MenuItemKind kind;
+    int toggled;
+    char *text;
+    char *input;
+    string_list_type* list;
+    Menu* target_menu;
 };
 
-/* Menus */
-enum {
-  MENU_MAIN,
-  MENU_OPTIONS
+menu_item_type* menu_item_create(MenuItemKind kind, char *text, int init_toggle, Menu* target_menu);
+void menu_item_change_text (menu_item_type* pmenu_item, const char *text);
+void menu_item_change_input(menu_item_type* pmenu_item, const char *text);
+
+class Menu
+{
+private:
+  // position of the menu (ie. center of the menu, not top/left)
+  int pos_x;
+  int pos_y;
+  
+  int num_items;
+
+public:
+  timer_type effect;
+  int arrange_left;
+  int active_item;
+  menu_item_type *item;
+
+  static void set_current(Menu* pmenu);
+
+  Menu();
+  ~Menu();
+
+  void additem(menu_item_type* pmenu_item);
+  void additem(MenuItemKind kind, char *text, int init_toggle, Menu* target_menu);
+  void action ();
+  int  check  ();
+  void draw   ();
+  void draw_item(int index, int menu_width, int menu_height);
 };
 
-/* Initialize the menu variables */
-void initmenu(void);
+
+/* Action done on the menu */
+enum MenuAction {
+  MENU_ACTION_NONE = -1,
+  MENU_ACTION_UP,
+  MENU_ACTION_DOWN,
+  MENU_ACTION_LEFT,
+  MENU_ACTION_RIGHT,
+  MENU_ACTION_HIT,
+  MENU_ACTION_INPUT,
+  MENU_ACTION_REMOVE
+};
+
+/* (global) menu variables */
+extern MenuAction menuaction;
+extern bool show_menu;
+extern bool menu_change;
+extern texture_type checkbox, checkbox_checked, back, arrow_left, arrow_right;
+
+extern Menu* main_menu;
+extern Menu* game_menu;
+extern Menu* options_menu;
+extern Menu* highscore_menu;
+extern Menu* load_game_menu;
+extern Menu* save_game_menu;
+extern Menu* current_menu;
+extern Menu* last_menu;
+
+/* input implementation variables */
+extern int delete_character;
+extern char mn_input_char;
+
+/* Reset the global menu variables */
+void menu_reset(void);
 
 /* "Calculate" and draw the menu */
-int drawmenu(void);
+void menu_process_current(void);
 
 /* Check for a menu event */
-void menu_event(SDLKey key);
+void menu_event(SDL_keysym* keysym);
 
 #endif /*SUPERTUX_MENU_H*/
 
+/* Local Variables: */
+/* mode:c++ */
+/* End */