wok-4.x diff supertux/stuff/menu.h @ rev 9055

bluefish: fix genpkg_rules
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Mar 04 11:43:00 2011 +0100 (2011-03-04)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/supertux/stuff/menu.h	Fri Mar 04 11:43:00 2011 +0100
     1.3 @@ -0,0 +1,247 @@
     1.4 +//  $Id: menu.h 1053 2004-05-09 18:08:02Z tobgle $
     1.5 +// 
     1.6 +//  SuperTux
     1.7 +//  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
     1.8 +//
     1.9 +//  This program is free software; you can redistribute it and/or
    1.10 +//  modify it under the terms of the GNU General Public License
    1.11 +//  as published by the Free Software Foundation; either version 2
    1.12 +//  of the License, or (at your option) any later version.
    1.13 +//
    1.14 +//  This program is distributed in the hope that it will be useful,
    1.15 +//  but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16 +//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.17 +//  GNU General Public License for more details.
    1.18 +// 
    1.19 +//  You should have received a copy of the GNU General Public License
    1.20 +//  along with this program; if not, write to the Free Software
    1.21 +//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    1.22 +
    1.23 +#ifndef SUPERTUX_MENU_H
    1.24 +#define SUPERTUX_MENU_H
    1.25 +
    1.26 +#include <SDL.h>
    1.27 +#include <vector>
    1.28 +#include "texture.h"
    1.29 +#include "timer.h"
    1.30 +#include "type.h"
    1.31 +#include "mousecursor.h"
    1.32 +
    1.33 +/* IDs for menus */
    1.34 +
    1.35 +enum MainMenuIDs {
    1.36 +  MNID_STARTGAME,
    1.37 +  MNID_CONTRIB,
    1.38 +  MNID_OPTIONMENU,
    1.39 +  MNID_LEVELEDITOR,
    1.40 +  MNID_CREDITS,
    1.41 +  MNID_QUITMAINMENU
    1.42 +  };
    1.43 +
    1.44 +enum OptionsMenuIDs {
    1.45 +  MNID_OPENGL,
    1.46 +  MNID_FULLSCREEN,
    1.47 +  MNID_SOUND,
    1.48 +  MNID_MUSIC,
    1.49 +  MNID_SHOWFPS
    1.50 +  };
    1.51 +
    1.52 +enum GameMenuIDs {
    1.53 +  MNID_CONTINUE,
    1.54 +  MNID_ABORTLEVEL
    1.55 +  };
    1.56 +
    1.57 +enum WorldMapMenuIDs {
    1.58 +  MNID_RETURNWORLDMAP,
    1.59 +  MNID_QUITWORLDMAP
    1.60 +  };
    1.61 +
    1.62 +enum LevelEditorMainMenuIDs {
    1.63 +  MNID_RETURNLEVELEDITOR,
    1.64 +  MNID_SUBSETSETTINGS,
    1.65 +  MNID_QUITLEVELEDITOR
    1.66 +  };
    1.67 +  
    1.68 +enum LevelEditorSubsetSettingsIDs {
    1.69 +  MNID_SUBSETTITLE,
    1.70 +  MNID_SUBSETDESCRIPTION,
    1.71 +  MNID_SUBSETSAVECHANGES
    1.72 +  };
    1.73 +  
    1.74 +enum LevelEditorSubsetNewIDs {
    1.75 + MNID_SUBSETNAME,
    1.76 + MNID_CREATESUBSET
    1.77 +};
    1.78 +
    1.79 +enum LevelEditorSettingsMenuIDs {
    1.80 +  MNID_NAME,
    1.81 +  MNID_AUTHOR,
    1.82 +  MNID_SONG,
    1.83 +  MNID_BGIMG,
    1.84 +  MNID_PARTICLE,
    1.85 +  MNID_LENGTH,
    1.86 +  MNID_TIME,
    1.87 +  MNID_GRAVITY,
    1.88 +  MNID_BGSPEED,
    1.89 +  MNID_TopRed,
    1.90 +  MNID_TopGreen,
    1.91 +  MNID_TopBlue,
    1.92 +  MNID_BottomRed,
    1.93 +  MNID_BottomGreen,
    1.94 +  MNID_BottomBlue,
    1.95 +  MNID_APPLY
    1.96 +  };
    1.97 +
    1.98 +bool confirm_dialog(std::string text);
    1.99 +
   1.100 +/* Kinds of menu items */
   1.101 +enum MenuItemKind {
   1.102 +  MN_ACTION,
   1.103 +  MN_GOTO,
   1.104 +  MN_TOGGLE,
   1.105 +  MN_BACK,
   1.106 +  MN_DEACTIVE,
   1.107 +  MN_TEXTFIELD,
   1.108 +  MN_NUMFIELD,
   1.109 +  MN_CONTROLFIELD,
   1.110 +  MN_STRINGSELECT,
   1.111 +  MN_LABEL,
   1.112 +  MN_HL, /* horizontal line */
   1.113 +};
   1.114 +
   1.115 +class Menu;
   1.116 +
   1.117 +class MenuItem
   1.118 +{
   1.119 +public:
   1.120 +  MenuItemKind kind;
   1.121 +  int toggled;
   1.122 +  char *text;
   1.123 +  char *input;
   1.124 +  int *int_p;   // used for setting keys (can be used for more stuff...)
   1.125 +  int id;   // item id
   1.126 +  string_list_type* list;
   1.127 +  Menu* target_menu;
   1.128 +
   1.129 +  void change_text (const char *text);
   1.130 +  void change_input(const char *text);
   1.131 +
   1.132 +  static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu, int id, int* int_p);
   1.133 +
   1.134 +  std::string get_input_with_symbol(bool active_item);   // returns the text with an input symbol
   1.135 +private:
   1.136 +  bool input_flickering;
   1.137 +  Timer input_flickering_timer;
   1.138 +};
   1.139 +
   1.140 +class Menu
   1.141 +{
   1.142 +private:  
   1.143 +  static std::vector<Menu*> last_menus;
   1.144 +  static Menu* current_;
   1.145 +
   1.146 +  static void push_current(Menu* pmenu);
   1.147 +  static void pop_current();
   1.148 +
   1.149 +public:
   1.150 +  /** Set the current menu, if pmenu is NULL, hide the current menu */
   1.151 +  static void set_current(Menu* pmenu);
   1.152 +
   1.153 +  /** Return the current active menu or NULL if none is active */
   1.154 +  static Menu* current() { return current_; }
   1.155 +
   1.156 +private:
   1.157 +  /* Action done on the menu */
   1.158 +  enum MenuAction {
   1.159 +    MENU_ACTION_NONE = -1,
   1.160 +    MENU_ACTION_UP,
   1.161 +    MENU_ACTION_DOWN,
   1.162 +    MENU_ACTION_LEFT,
   1.163 +    MENU_ACTION_RIGHT,
   1.164 +    MENU_ACTION_HIT,
   1.165 +    MENU_ACTION_INPUT,
   1.166 +    MENU_ACTION_REMOVE
   1.167 +  };
   1.168 +
   1.169 +  /** Number of the item that got 'hit' (ie. pressed) in the last
   1.170 +      event()/action() call, -1 if none */
   1.171 +  int hit_item;
   1.172 +
   1.173 +  // position of the menu (ie. center of the menu, not top/left)
   1.174 +  int pos_x;
   1.175 +  int pos_y;
   1.176 +
   1.177 +  /** input event for the menu (up, down, left, right, etc.) */
   1.178 +  MenuAction menuaction;
   1.179 +
   1.180 +  /* input implementation variables */
   1.181 +  int delete_character;
   1.182 +  char mn_input_char;
   1.183 +  
   1.184 +public:
   1.185 +  Timer effect;
   1.186 +  int arrange_left;
   1.187 +  int active_item;
   1.188 +
   1.189 +  std::vector<MenuItem> item;
   1.190 +
   1.191 +  Menu();
   1.192 +  ~Menu();
   1.193 +
   1.194 +  void additem(MenuItem* pmenu_item);
   1.195 +  void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu, int id = -1, int *int_p = NULL);
   1.196 +  
   1.197 +  void  action ();
   1.198 +  
   1.199 +  /** Remove all entries from the menu */
   1.200 +  void clear();
   1.201 +
   1.202 +  /** Return the index of the menu item that was 'hit' (ie. the user
   1.203 +      clicked on it) in the last event() call */
   1.204 +  int  check  ();
   1.205 +
   1.206 +  MenuItem& get_item(int index) { return item[index]; }
   1.207 +  MenuItem& get_item_by_id(int id);
   1.208 +
   1.209 +  int get_active_item_id();
   1.210 +
   1.211 +  bool isToggled(int id);
   1.212 +
   1.213 +  void get_controlfield_key_into_input(MenuItem *item);
   1.214 +
   1.215 +  void draw   ();
   1.216 +  void draw_item(int index, int menu_width, int menu_height);
   1.217 +  void set_pos(int x, int y, float rw = 0, float rh = 0);
   1.218 +
   1.219 +  /** translate a SDL_Event into a menu_action */
   1.220 +  void event(SDL_Event& event);
   1.221 +
   1.222 +  int get_width() const;
   1.223 +  int get_height() const;
   1.224 +
   1.225 +  bool is_toggled(int id) const;
   1.226 +};
   1.227 +
   1.228 +extern Surface* checkbox;
   1.229 +extern Surface* checkbox_checked;
   1.230 +extern Surface* back;
   1.231 +extern Surface* arrow_left;
   1.232 +extern Surface* arrow_right;
   1.233 +
   1.234 +extern Menu* contrib_menu;
   1.235 +extern Menu* contrib_subset_menu;
   1.236 +extern Menu* main_menu;
   1.237 +extern Menu* game_menu;
   1.238 +extern Menu* worldmap_menu;
   1.239 +extern Menu* options_menu;
   1.240 +extern Menu* options_keys_menu;
   1.241 +extern Menu* options_joystick_menu;
   1.242 +extern Menu* highscore_menu;
   1.243 +extern Menu* load_game_menu;
   1.244 +extern Menu* save_game_menu;
   1.245 +
   1.246 +#endif /*SUPERTUX_MENU_H*/
   1.247 +
   1.248 +/* Local Variables: */
   1.249 +/* mode: c++ */
   1.250 +/* End: */