ScummVM API documentation
gui_menu_items.h
1 
2 /* ScummVM - Graphic Adventure Engine
3  *
4  * ScummVM is the legal property of its developers, whose names
5  * are too numerous to list here. Please refer to the COPYRIGHT
6  * file distributed with this source distribution.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef M4_GUI_GUI_MENU_ITEMS_H
24 #define M4_GUI_GUI_MENU_ITEMS_H
25 
26 #include "graphics/surface.h"
27 #include "m4/m4_types.h"
28 #include "m4/graphics/gr_buff.h"
29 #include "m4/gui/gui_univ.h"
30 #include "m4/graphics/gr_font.h"
31 
32 namespace M4 {
33 
34 namespace Burger {
35 namespace GUI {
36 
37 enum options_menu_sprites {
38  OM_DIALOG_BOX,
39 
40  OM_SLIDER_BTN_NORM,
41  OM_SLIDER_BTN_OVER,
42  OM_SLIDER_BTN_PRESS,
43 
44  OM_SLIDER_BAR,
45 
46  OM_DONE_BTN_GREY,
47  OM_DONE_BTN_NORM,
48  OM_DONE_BTN_OVER,
49  OM_DONE_BTN_PRESS,
50 
51  OM_CANCEL_BTN_NORM,
52  OM_CANCEL_BTN_OVER,
53  OM_CANCEL_BTN_PRESS,
54 
55  OM_TOTAL_SPRITES
56 };
57 
58 } // namespace GUI
59 } // namespace Burger
60 
61 namespace Riddle {
62 namespace GUI {
63 
64 enum options_menu_sprites {
65  OM_DIALOG_BOX,
66 
67  OM_SLIDER_BTN_NORM = 5,
68  OM_SLIDER_BTN_OVER = 6,
69  OM_SLIDER_BTN_PRESS = 7,
70 
71  OM_SCROLLING_ON_BTN_NORM = 8,
72  OM_SCROLLING_ON_BTN_OVER = 9,
73  OM_SCROLLING_ON_BTN_PRESS = 13,
74 
75  OM_SCROLLING_OFF_BTN_NORM = 11,
76  OM_SCROLLING_OFF_BTN_OVER = 12,
77  OM_SCROLLING_OFF_BTN_PRESS = 10,
78 
79  OM_TOTAL_SPRITES = 14
80 };
81 
82 } // namespace GUI
83 } // namespace Riddle
84 
85 namespace GUI {
86 
87 #define _GM(X) ::M4::g_vars->_menu.X
88 #define LockMouseSprite mouse_lock_sprite
89 #define UnlockMouseSprite mouse_unlock_sprite
90 
91 enum save_load_menu_item_tags {
92  SL_TAG_SAVE = 100,
93  SL_TAG_SAVE_LABEL,
94  SL_TAG_LOAD,
95  SL_TAG_LOAD_LABEL,
96  SL_TAG_CANCEL,
97  SL_TAG_SAVE_TITLE_LABEL,
98  SL_TAG_LOAD_TITLE_LABEL,
99  SL_TAG_VSLIDER,
100  SL_TAG_THUMBNAIL
101 };
102 
103 struct menuItem;
104 struct guiMenu;
105 
106 typedef bool (*ItemHandlerFunction)(menuItem *theItem, int32 eventType, int32 event, int32 x, int32 y, void **currItem);
107 typedef void (*DrawFunction)(void *source, guiMenu *dest, int32 x1, int32 y1, int32 x2, int32 y2);
108 typedef void (*DestroyFunction)(menuItem *theItem);
109 typedef M4CALLBACK CALLBACK;
110 
111 typedef M4sprite Sprite;
112 
113 enum game_menu_sprites {
114  GM_DIALOG_BOX,
115 
116  GM_BUTTON_GREY,
117  GM_BUTTON_NORM,
118  GM_BUTTON_OVER,
119  GM_BUTTON_PRESS,
120 
121  GM_TOTAL_SPRITES
122 };
123 
124 struct guiMenu;
125 
126 struct menuItem {
127  enum {
128  TEXT_COLOR_GREY_HILITE = 192,
129  TEXT_COLOR_GREY_FOREGROUND = 210,
130  TEXT_COLOR_GREY_SHADOW = 229,
131 
132  TEXT_COLOR_NORM_HILITE = 3,
133  TEXT_COLOR_NORM_FOREGROUND = 2,
134  TEXT_COLOR_NORM_SHADOW = 1,
135 
136  TEXT_COLOR_OVER_HILITE = 3,
137  TEXT_COLOR_OVER_FOREGROUND = 2,
138  TEXT_COLOR_OVER_SHADOW = 1,
139 
140  TEXT_COLOR_PRESS_HILITE = 3,
141  TEXT_COLOR_PRESS_FOREGROUND = 2,
142  TEXT_COLOR_PRESS_SHADOW = 1,
143  };
144 
145  menuItem *next = nullptr;
146  menuItem *prev = nullptr;
147 
148  guiMenu *myMenu = nullptr;
149  int32 tag = 0;
150 
151  int32 x1 = 0, y1 = 0, x2 = 0, y2 = 0;
152 
153  bool transparent = false;
154  GrBuff *background = nullptr;
155 
156  CALLBACK callback = nullptr;
157  DrawFunction redraw = nullptr;
158  DestroyFunction destroy = nullptr;
159  ItemHandlerFunction itemEventHandler = nullptr;
160 
161  static void destroyItem(menuItem *theItem);
162  static bool cursorInsideItem(menuItem *myItem, int32 cursorX, int32 cursorY);
163 };
164 
165 struct menuItemMsg : public menuItem {
166 private:
167  static void drawMsg(menuItemMsg *myItem, guiMenu *myMenu, int32 x, int32 y, int32, int32);
168 
169 public:
170  int32 itemFlags = 0;
171 
172  static menuItemMsg *msgAdd(guiMenu *myMenu, int32 tag, int32 x, int32 y, int32 w, int32 h, bool transparent = false);
173  static void disableMsg(menuItemMsg *myItem, int32 tag, guiMenu *myMenu);
174  static void enableMsg(menuItemMsg *myItem, int32 tag, guiMenu *myMenu);
175 };
176 
177 struct menuItemButton : public menuItem {
178 private:
179  static void drawButton(menuItemButton *myItem, guiMenu *myMenu,
180  int32 x, int32 y, int32, int32);
181 
182 public:
183  enum button_states {
184  BTN_STATE_NORM = 0,
185  BTN_STATE_OVER = 1,
186  BTN_STATE_PRESS = 2,
187  BTN_STATE_GREY = 3
188  };
189 
190  enum button_types {
191  BTN_TYPE_GM_GENERIC,
192 
193  // Burger
194  BTN_TYPE_SL_SAVE,
195  BTN_TYPE_SL_LOAD,
196  BTN_TYPE_SL_CANCEL,
197  BTN_TYPE_SL_TEXT,
198  BTN_TYPE_OM_DONE,
199  BTN_TYPE_OM_CANCEL,
200 
201  // Riddle
202  BTN_TYPE_OM_SCROLLING_ON,
203  BTN_TYPE_OM_SCROLLING_OFF
204  };
205 
206  int32 itemFlags = 0;
207  int32 buttonType = 0;
208  const char *prompt = nullptr;
209  menuItem *assocItem = nullptr;
210  int32 specialTag = 0;
211 
212  static menuItemButton *add(guiMenu *myMenu, int32 tag, int32 x, int32 y, int32 w, int32 h, CALLBACK callback = nullptr,
213  int32 buttonType = 0, bool ghosted = false, bool transparent = false,
214  const char *prompt = nullptr, ItemHandlerFunction i_handler = (ItemHandlerFunction)handler);
215  static void disableButton(menuItemButton *myItem, int32 tag, guiMenu *myMenu);
216  static void enableButton(menuItemButton *myItem, int32 tag, guiMenu *myMenu);
217  static bool handler(menuItemButton *theItem, int32 eventType, int32 event,
218  int32 x, int32 y, void **currItem);
219 };
220 
221 struct menuItemHSlider : public menuItem {
222 private:
223  static void drawHSlider(menuItemHSlider *myItem, guiMenu *myMenu, int32 x, int32 y, int32, int32);
224  static bool handler(menuItemHSlider *myItem, int32 eventType, int32 event, int32 x, int32 y, void **currItem);
225 
226 public:
227  int32 itemFlags = 0;
228 
229  int32 thumbW = 0, thumbH = 0;
230  int32 thumbX = 0, maxThumbX = 0;
231 
232  int32 percent = 0;
233 
234  enum {
235  H_THUMB_NORM = 0,
236  H_THUMB_OVER = 1,
237  H_THUMB_PRESS = 2
238  };
239 
240  static menuItemHSlider *add(guiMenu *myMenu, int32 tag,
241  int32 x, int32 y, int32 w, int32 h, int32 initPercent = 0,
242  CALLBACK callback = nullptr, bool transparent = false);
243 };
244 
245 struct menuItemVSlider : public menuItem {
246 private:
247  static int32 whereIsCursor(menuItemVSlider *myVSlider, int32 y);
248 
249 public:
250  int32 itemFlags = 0;
251 
252  int32 thumbW = 0, thumbH = 0;
253  int32 thumbY = 0, minThumbY = 0, maxThumbY = 0;
254 
255  int32 percent = 0;
256 
257  enum {
258  VS_NORM = 0x0000,
259  VS_OVER = 0x0001,
260  VS_PRESS = 0x0002,
261  VS_GREY = 0x0003,
262  VS_STATUS = 0x000f,
263  VS_UP = 0x0010,
264  VS_PAGE_UP = 0x0020,
265  VS_THUMB = 0x0030,
266  VS_PAGE_DOWN = 0x0040,
267  VS_DOWN = 0x0050,
268  VS_COMPONENT = 0x00f0
269  };
270 
271  static menuItemVSlider *add(guiMenu *myMenu, int32 tag, int32 x, int32 y, int32 w, int32 h,
272  int32 initPercent = 0, CALLBACK callback = nullptr, bool transparent = false);
273  static void disableVSlider(menuItemVSlider *myItem, int32 tag, guiMenu *myMenu);
274  static void enableVSlider(menuItemVSlider *myItem, int32 tag, guiMenu *myMenu);
275  static void drawVSlider(menuItemVSlider *myItem, guiMenu *myMenu, int32 x, int32 y, int32, int32);
276  static bool handler(menuItemVSlider *myItem, int32 eventType, int32 event, int32 x, int32 y, void **currItem);
277 };
278 
279 struct menuItemTextField : public menuItem {
280  int32 itemFlags = 0;
281 
282  int32 specialTag = 0;
283  int32 pixWidth = 0;
284 
285  char prompt[80] = { 0 };
286  char *promptEnd = nullptr;
287 
288  char *cursor = nullptr;
289 
290  enum {
291  TF_NORM = 0,
292  TF_OVER = 1,
293  TF_GREY = 2
294  };
295 
296  static menuItemTextField *add(guiMenu *myMenu, int32 tag, int32 x, int32 y, int32 w, int32 h, int32 initFlags,
297  const char *prompt = nullptr, int32 specialtag = 0, CALLBACK callback = nullptr, bool transparent = false);
298  static bool handler(menuItemTextField *myItem, int32 eventType, int32 event, int32 x, int32 y, void **currItem);
299  static void drawTextField(menuItemTextField *myItem, guiMenu *myMenu, int32 x, int32 y, int32, int32);
300 };
301 
302 struct guiMenu {
303 private:
304  static void show(void *s, void *r, void *b, int32 destX, int32 destY);
305  static bool eventHandler(guiMenu *theMenu, int32 eventType, int32 parm1, int32 parm2, int32 parm3, bool *currScreen);
306 
307 public:
308  GrBuff *menuBuffer = nullptr;
309  menuItem *itemList = nullptr;
310  CALLBACK cb_return = nullptr;
311  CALLBACK cb_esc = nullptr;
312  EventHandler menuEventHandler = nullptr;
313 
314  static bool initialize(RGB8 *myPalette);
315  static void shutdown(bool fadeToColor);
316  static guiMenu *create(Sprite *backgroundSprite, int32 x1, int32 y1, int32 scrnFlags);
317  static void destroy(guiMenu *myMenu);
318  static void configure(guiMenu *myMenu, CALLBACK cb_return, CALLBACK cb_esc);
319  static GrBuff *copyBackground(guiMenu *myMenu, int32 x, int32 y, int32 w, int32 h);
320  static menuItem *getItem(int32 tag, guiMenu *myMenu);
321  static void itemDelete(menuItem *myItem, int32 tag, guiMenu *myMenu);
322  static void itemRefresh(menuItem *myItem, int32 tag, guiMenu *myMenu);
323 
324  static bool loadSprites(const char *series, int32 numSprites);
325  static void unloadSprites();
326 };
327 
328 struct MenuGlobals {
329  //GLOBAL VARS
330  bool menuSystemInitialized = false;
331  bool buttonClosesDialog = false;
332  bool interfaceWasVisible = false;
333  RGB8 *menuPalette = nullptr;
334  bool dumpedCodes = false;
335  bool dumpedBackground = false;
336 
337  menuItem *menuCurrItem = nullptr;
338 
339  guiMenu *gameMenu = nullptr;
340  guiMenu *opMenu = nullptr;
341  guiMenu *slMenu = nullptr;
342  guiMenu *errMenu = nullptr;
343 
344  //menu sprite series vars
345  char *menuSeriesResource = nullptr;
346  MemHandle menuSeriesHandle = nullptr;
347  int32 menuSeriesOffset = 0;
348  int32 menuSeriesPalOffset = 0;
349 
350  Font *menuFont = nullptr;
351 
352  // menu sprites array (used to hold all the sprites for the current menu, spriteCount is set tot he number of sprites in the series)
353  int32 spriteCount = 0;
354  Sprite **menuSprites = nullptr;
355 
356  // VARS SPECIFIC TO THE GAME MENUS SYSTEM
357  // An array of slot titles used by the save/load menus
358  char **slotTitles = nullptr;
359  bool *slotInUse = nullptr;
360  int32 firstSlotIndex = 0; // Slot at the top of the list on menu
361  int32 slotSelected = -1; // Slot currently selected
362  bool deleteSaveDesc = false;
363 
364  Sprite **thumbNails = nullptr;
365  Sprite *saveLoadThumbNail = nullptr; // Original used for menu display
366  Graphics::Surface _thumbnail; // ScummVM version used for savegame
367  int32 sizeofThumbData = -1;
368  int32 thumbIndex = 0;
369 
370  bool currMenuIsSave = true; // Used to determine load or save menu
371  bool saveLoadFromHotkey = false; // Come from hotkey, not through game menu
372  bool gameMenuFromMain = false; // Come from main menu, not through escape
373 
374  int32 remember_digi_volume = 0; // For cancelling out of the options menu
375  int32 remember_digestability = 0; // For cancelling out of the options menu
376 
377  ~MenuGlobals() {
378  _thumbnail.free();
379  }
380 };
381 
382 extern void gui_DrawSprite(Sprite *mySprite, Buffer *myBuff, int32 x, int32 y);
383 
384 //======================================
385 //
386 // gamemenu module defines
387 //
388 #define MENU_DEPTH 9 // video depth for menu popup boxes
389 #define MAX_SLOTS 99 // number of save games you can have
390 #define MAX_SLOTS_SHOWN 8 // number of slots in the scrolling field
391 
392 } // namespace GUI
393 } // namespace M4
394 
395 #endif
Definition: surface.h:67
Definition: gr_font.h:30
Definition: gui_menu_items.h:126
Definition: gui_menu_items.h:302
Definition: system.h:46
Definition: m4_types.h:88
Definition: gui_menu_items.h:328
Definition: gui_menu_items.h:165
Definition: gui_menu_items.h:221
Definition: m4_types.h:67
Definition: database.h:28
Definition: gr_buff.h:30
Definition: gui_menu_items.h:279
Definition: gui_menu_items.h:245
Definition: gui_menu_items.h:177