wok annotate supertux/stuff/menu.h @ rev 6835

Forgot patch for freeimage to compile with gcc 4.5.
author Christopher Rogers <slaxemulator@gmail.com>
date Tue Oct 19 21:25:15 2010 +0000 (2010-10-19)
parents
children
rev   line source
mallory@2114 1 // $Id: menu.h 1053 2004-05-09 18:08:02Z tobgle $
mallory@2114 2 //
mallory@2114 3 // SuperTux
mallory@2114 4 // Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
mallory@2114 5 //
mallory@2114 6 // This program is free software; you can redistribute it and/or
mallory@2114 7 // modify it under the terms of the GNU General Public License
mallory@2114 8 // as published by the Free Software Foundation; either version 2
mallory@2114 9 // of the License, or (at your option) any later version.
mallory@2114 10 //
mallory@2114 11 // This program is distributed in the hope that it will be useful,
mallory@2114 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
mallory@2114 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
mallory@2114 14 // GNU General Public License for more details.
mallory@2114 15 //
mallory@2114 16 // You should have received a copy of the GNU General Public License
mallory@2114 17 // along with this program; if not, write to the Free Software
mallory@2114 18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
mallory@2114 19
mallory@2114 20 #ifndef SUPERTUX_MENU_H
mallory@2114 21 #define SUPERTUX_MENU_H
mallory@2114 22
mallory@2114 23 #include <SDL.h>
mallory@2114 24 #include <vector>
mallory@2114 25 #include "texture.h"
mallory@2114 26 #include "timer.h"
mallory@2114 27 #include "type.h"
mallory@2114 28 #include "mousecursor.h"
mallory@2114 29
mallory@2114 30 /* IDs for menus */
mallory@2114 31
mallory@2114 32 enum MainMenuIDs {
mallory@2114 33 MNID_STARTGAME,
mallory@2114 34 MNID_CONTRIB,
mallory@2114 35 MNID_OPTIONMENU,
mallory@2114 36 MNID_LEVELEDITOR,
mallory@2114 37 MNID_CREDITS,
mallory@2114 38 MNID_QUITMAINMENU
mallory@2114 39 };
mallory@2114 40
mallory@2114 41 enum OptionsMenuIDs {
mallory@2114 42 MNID_OPENGL,
mallory@2114 43 MNID_FULLSCREEN,
mallory@2114 44 MNID_SOUND,
mallory@2114 45 MNID_MUSIC,
mallory@2114 46 MNID_SHOWFPS
mallory@2114 47 };
mallory@2114 48
mallory@2114 49 enum GameMenuIDs {
mallory@2114 50 MNID_CONTINUE,
mallory@2114 51 MNID_ABORTLEVEL
mallory@2114 52 };
mallory@2114 53
mallory@2114 54 enum WorldMapMenuIDs {
mallory@2114 55 MNID_RETURNWORLDMAP,
mallory@2114 56 MNID_QUITWORLDMAP
mallory@2114 57 };
mallory@2114 58
mallory@2114 59 enum LevelEditorMainMenuIDs {
mallory@2114 60 MNID_RETURNLEVELEDITOR,
mallory@2114 61 MNID_SUBSETSETTINGS,
mallory@2114 62 MNID_QUITLEVELEDITOR
mallory@2114 63 };
mallory@2114 64
mallory@2114 65 enum LevelEditorSubsetSettingsIDs {
mallory@2114 66 MNID_SUBSETTITLE,
mallory@2114 67 MNID_SUBSETDESCRIPTION,
mallory@2114 68 MNID_SUBSETSAVECHANGES
mallory@2114 69 };
mallory@2114 70
mallory@2114 71 enum LevelEditorSubsetNewIDs {
mallory@2114 72 MNID_SUBSETNAME,
mallory@2114 73 MNID_CREATESUBSET
mallory@2114 74 };
mallory@2114 75
mallory@2114 76 enum LevelEditorSettingsMenuIDs {
mallory@2114 77 MNID_NAME,
mallory@2114 78 MNID_AUTHOR,
mallory@2114 79 MNID_SONG,
mallory@2114 80 MNID_BGIMG,
mallory@2114 81 MNID_PARTICLE,
mallory@2114 82 MNID_LENGTH,
mallory@2114 83 MNID_TIME,
mallory@2114 84 MNID_GRAVITY,
mallory@2114 85 MNID_BGSPEED,
mallory@2114 86 MNID_TopRed,
mallory@2114 87 MNID_TopGreen,
mallory@2114 88 MNID_TopBlue,
mallory@2114 89 MNID_BottomRed,
mallory@2114 90 MNID_BottomGreen,
mallory@2114 91 MNID_BottomBlue,
mallory@2114 92 MNID_APPLY
mallory@2114 93 };
mallory@2114 94
mallory@2114 95 bool confirm_dialog(std::string text);
mallory@2114 96
mallory@2114 97 /* Kinds of menu items */
mallory@2114 98 enum MenuItemKind {
mallory@2114 99 MN_ACTION,
mallory@2114 100 MN_GOTO,
mallory@2114 101 MN_TOGGLE,
mallory@2114 102 MN_BACK,
mallory@2114 103 MN_DEACTIVE,
mallory@2114 104 MN_TEXTFIELD,
mallory@2114 105 MN_NUMFIELD,
mallory@2114 106 MN_CONTROLFIELD,
mallory@2114 107 MN_STRINGSELECT,
mallory@2114 108 MN_LABEL,
mallory@2114 109 MN_HL, /* horizontal line */
mallory@2114 110 };
mallory@2114 111
mallory@2114 112 class Menu;
mallory@2114 113
mallory@2114 114 class MenuItem
mallory@2114 115 {
mallory@2114 116 public:
mallory@2114 117 MenuItemKind kind;
mallory@2114 118 int toggled;
mallory@2114 119 char *text;
mallory@2114 120 char *input;
mallory@2114 121 int *int_p; // used for setting keys (can be used for more stuff...)
mallory@2114 122 int id; // item id
mallory@2114 123 string_list_type* list;
mallory@2114 124 Menu* target_menu;
mallory@2114 125
mallory@2114 126 void change_text (const char *text);
mallory@2114 127 void change_input(const char *text);
mallory@2114 128
mallory@2114 129 static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu, int id, int* int_p);
mallory@2114 130
mallory@2114 131 std::string get_input_with_symbol(bool active_item); // returns the text with an input symbol
mallory@2114 132 private:
mallory@2114 133 bool input_flickering;
mallory@2114 134 Timer input_flickering_timer;
mallory@2114 135 };
mallory@2114 136
mallory@2114 137 class Menu
mallory@2114 138 {
mallory@2114 139 private:
mallory@2114 140 static std::vector<Menu*> last_menus;
mallory@2114 141 static Menu* current_;
mallory@2114 142
mallory@2114 143 static void push_current(Menu* pmenu);
mallory@2114 144 static void pop_current();
mallory@2114 145
mallory@2114 146 public:
mallory@2114 147 /** Set the current menu, if pmenu is NULL, hide the current menu */
mallory@2114 148 static void set_current(Menu* pmenu);
mallory@2114 149
mallory@2114 150 /** Return the current active menu or NULL if none is active */
mallory@2114 151 static Menu* current() { return current_; }
mallory@2114 152
mallory@2114 153 private:
mallory@2114 154 /* Action done on the menu */
mallory@2114 155 enum MenuAction {
mallory@2114 156 MENU_ACTION_NONE = -1,
mallory@2114 157 MENU_ACTION_UP,
mallory@2114 158 MENU_ACTION_DOWN,
mallory@2114 159 MENU_ACTION_LEFT,
mallory@2114 160 MENU_ACTION_RIGHT,
mallory@2114 161 MENU_ACTION_HIT,
mallory@2114 162 MENU_ACTION_INPUT,
mallory@2114 163 MENU_ACTION_REMOVE
mallory@2114 164 };
mallory@2114 165
mallory@2114 166 /** Number of the item that got 'hit' (ie. pressed) in the last
mallory@2114 167 event()/action() call, -1 if none */
mallory@2114 168 int hit_item;
mallory@2114 169
mallory@2114 170 // position of the menu (ie. center of the menu, not top/left)
mallory@2114 171 int pos_x;
mallory@2114 172 int pos_y;
mallory@2114 173
mallory@2114 174 /** input event for the menu (up, down, left, right, etc.) */
mallory@2114 175 MenuAction menuaction;
mallory@2114 176
mallory@2114 177 /* input implementation variables */
mallory@2114 178 int delete_character;
mallory@2114 179 char mn_input_char;
mallory@2114 180
mallory@2114 181 public:
mallory@2114 182 Timer effect;
mallory@2114 183 int arrange_left;
mallory@2114 184 int active_item;
mallory@2114 185
mallory@2114 186 std::vector<MenuItem> item;
mallory@2114 187
mallory@2114 188 Menu();
mallory@2114 189 ~Menu();
mallory@2114 190
mallory@2114 191 void additem(MenuItem* pmenu_item);
mallory@2114 192 void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu, int id = -1, int *int_p = NULL);
mallory@2114 193
mallory@2114 194 void action ();
mallory@2114 195
mallory@2114 196 /** Remove all entries from the menu */
mallory@2114 197 void clear();
mallory@2114 198
mallory@2114 199 /** Return the index of the menu item that was 'hit' (ie. the user
mallory@2114 200 clicked on it) in the last event() call */
mallory@2114 201 int check ();
mallory@2114 202
mallory@2114 203 MenuItem& get_item(int index) { return item[index]; }
mallory@2114 204 MenuItem& get_item_by_id(int id);
mallory@2114 205
mallory@2114 206 int get_active_item_id();
mallory@2114 207
mallory@2114 208 bool isToggled(int id);
mallory@2114 209
mallory@2114 210 void get_controlfield_key_into_input(MenuItem *item);
mallory@2114 211
mallory@2114 212 void draw ();
mallory@2114 213 void draw_item(int index, int menu_width, int menu_height);
mallory@2114 214 void set_pos(int x, int y, float rw = 0, float rh = 0);
mallory@2114 215
mallory@2114 216 /** translate a SDL_Event into a menu_action */
mallory@2114 217 void event(SDL_Event& event);
mallory@2114 218
mallory@2114 219 int get_width() const;
mallory@2114 220 int get_height() const;
mallory@2114 221
mallory@2114 222 bool is_toggled(int id) const;
mallory@2114 223 };
mallory@2114 224
mallory@2114 225 extern Surface* checkbox;
mallory@2114 226 extern Surface* checkbox_checked;
mallory@2114 227 extern Surface* back;
mallory@2114 228 extern Surface* arrow_left;
mallory@2114 229 extern Surface* arrow_right;
mallory@2114 230
mallory@2114 231 extern Menu* contrib_menu;
mallory@2114 232 extern Menu* contrib_subset_menu;
mallory@2114 233 extern Menu* main_menu;
mallory@2114 234 extern Menu* game_menu;
mallory@2114 235 extern Menu* worldmap_menu;
mallory@2114 236 extern Menu* options_menu;
mallory@2114 237 extern Menu* options_keys_menu;
mallory@2114 238 extern Menu* options_joystick_menu;
mallory@2114 239 extern Menu* highscore_menu;
mallory@2114 240 extern Menu* load_game_menu;
mallory@2114 241 extern Menu* save_game_menu;
mallory@2114 242
mallory@2114 243 #endif /*SUPERTUX_MENU_H*/
mallory@2114 244
mallory@2114 245 /* Local Variables: */
mallory@2114 246 /* mode: c++ */
mallory@2114 247 /* End: */