- converted text_type into a class
[supertux.git] / src / menu.h
index f459b5c..e8baf70 100644 (file)
 #define SUPERTUX_MENU_H
 
 #include <SDL.h>
+#include <vector>
 #include "texture.h"
 #include "timer.h"
 #include "type.h"
+#include "mousecursor.h"
 
 /* Kinds of menu items */
 enum MenuItemKind {
@@ -27,48 +29,69 @@ enum MenuItemKind {
   MN_DEACTIVE,
   MN_TEXTFIELD,
   MN_NUMFIELD,
+  MN_CONTROLFIELD,
   MN_STRINGSELECT,
   MN_LABEL,
-  MN_HL /* horizontal line */
+  MN_HL, /* horizontal line */
 };
 
-typedef struct menu_item_type
-  {
-    MenuItemKind kind;
-    int toggled;
-    char *text;
-    char *input;
-    string_list_type* list;
-    void* target_menu;
-  }
-menu_item_type;
-
-menu_item_type* menu_item_create(MenuItemKind kind, char *text, int init_toggle, void* 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);
-
-typedef struct menu_type
+class Menu;
+
+class MenuItem
 {
-  // center of the menu on the screen
-  int x;
-  int y;
+public:
+  MenuItemKind kind;
+  int toggled;
+  char *text;
+  char *input;
+  string_list_type* list;
+  Menu* target_menu;
+
+  void change_text (const char *text);
+  void change_input(const char *text);
+
+  static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu);
+};
 
-  int num_items;
-  int active_item;
+class Menu
+{
+private:
+  // position of the menu (ie. center of the menu, not top/left)
+  int pos_x;
+  int pos_y;
+  
+  Menu* last_menu;
+  int width();
+  int height();
+  
+public:
+  Timer effect;
   int arrange_left;
-  menu_item_type *item;
-  timer_type effect;
-}
-menu_type;
-
-void menu_init   (menu_type* pmenu);
-void menu_free   (menu_type* pmenu);
-void menu_additem(menu_type* pmenu, menu_item_type* pmenu_item);
-menu_item_type* menu_additem(menu_type* pmenu, MenuItemKind kind, char *text, int init_toggle, void* target_menu);
-void menu_action (menu_type* pmenu);
-int  menu_check  (menu_type* pmenu);
-void menu_draw   (menu_type* pmenu);
-void menu_set_current(menu_type* pmenu);
+  int active_item;
+  std::vector<MenuItem> item;
+
+  static void set_current(Menu* pmenu);
+
+  Menu();
+  ~Menu();
+
+  void additem(MenuItem* pmenu_item);
+  void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu);
+  void action ();
+  
+  /** Remove all entries from the menu */
+  void clear();
+
+  /** Check, if the value of the active menu item has changed. */
+  int  check  ();
+  void draw   ();
+  void draw_item(int index, int menu_width, int menu_height);
+  void set_pos(int x, int y, float rw = 0, float rh = 0);
+
+  /* Check for a menu event */
+  void event(SDL_Event& event);
+};
+
 
 /* Action done on the menu */
 enum MenuAction {
@@ -84,12 +107,26 @@ enum MenuAction {
 
 /* (global) menu variables */
 extern MenuAction menuaction;
-extern int show_menu;
-extern int menu_change;
-extern texture_type checkbox, checkbox_checked, back, arrow_left, arrow_right;
-
-extern menu_type main_menu, game_menu, options_menu, highscore_menu, load_game_menu, save_game_menu;
-extern menu_type* current_menu, * last_menu;
+extern bool show_menu;
+extern bool menu_change;
+
+extern Surface* checkbox;
+extern Surface* checkbox_checked;
+extern Surface* back;
+extern Surface* arrow_left;
+extern Surface* arrow_right;
+
+extern Menu* contrib_menu;
+extern Menu* contrib_subset_menu;
+extern Menu* main_menu;
+extern Menu* game_menu;
+extern Menu* worldmap_menu;
+extern Menu* options_menu;
+extern Menu* options_controls_menu;
+extern Menu* highscore_menu;
+extern Menu* load_game_menu;
+extern Menu* save_game_menu;
+extern Menu* current_menu;
 
 /* input implementation variables */
 extern int delete_character;
@@ -101,8 +138,8 @@ void menu_reset(void);
 /* "Calculate" and draw the menu */
 void menu_process_current(void);
 
-/* Check for a menu event */
-void menu_event(SDL_keysym* keysym);
-
 #endif /*SUPERTUX_MENU_H*/
 
+/* Local Variables: */
+/* mode: c++ */
+/* End: */