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
32namespace M4 {
33
34namespace Burger {
35namespace GUI {
36
37enum 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
61namespace Riddle {
62namespace GUI {
63
64enum 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
85namespace GUI {
86
87#define _GM(X) ::M4::g_vars->_menu.X
88#define LockMouseSprite mouse_lock_sprite
89#define UnlockMouseSprite mouse_unlock_sprite
90
91enum 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
103struct menuItem;
104struct guiMenu;
105
106typedef bool (*ItemHandlerFunction)(menuItem *theItem, int32 eventType, int32 event, int32 x, int32 y, void **currItem);
107typedef void (*DrawFunction)(void *source, guiMenu *dest, int32 x1, int32 y1, int32 x2, int32 y2);
108typedef void (*DestroyFunction)(menuItem *theItem);
109typedef M4CALLBACK CALLBACK;
110
111typedef M4sprite Sprite;
112
113enum 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
124struct guiMenu;
125
126struct 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
165struct menuItemMsg : public menuItem {
166private:
167 static void drawMsg(menuItemMsg *myItem, guiMenu *myMenu, int32 x, int32 y, int32, int32);
168
169public:
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};
174
175struct menuItemButton : public menuItem {
176private:
177 static void drawButton(menuItemButton *myItem, guiMenu *myMenu,
178 int32 x, int32 y, int32, int32);
179
180public:
181 enum button_states {
182 BTN_STATE_NORM = 0,
183 BTN_STATE_OVER = 1,
184 BTN_STATE_PRESS = 2,
185 BTN_STATE_GREY = 3
186 };
187
188 enum button_types {
189 BTN_TYPE_GM_GENERIC,
190
191 // Burger
192 BTN_TYPE_SL_SAVE,
193 BTN_TYPE_SL_LOAD,
194 BTN_TYPE_SL_CANCEL,
195 BTN_TYPE_SL_TEXT,
196 BTN_TYPE_OM_DONE,
197 BTN_TYPE_OM_CANCEL,
198
199 // Riddle
200 BTN_TYPE_OM_SCROLLING_ON,
201 BTN_TYPE_OM_SCROLLING_OFF
202 };
203
204 int32 itemFlags = 0;
205 int32 buttonType = 0;
206 const char *prompt = nullptr;
207 menuItem *assocItem = nullptr;
208 int32 specialTag = 0;
209
210 static menuItemButton *add(guiMenu *myMenu, int32 tag, int32 x, int32 y, int32 w, int32 h, CALLBACK callback = nullptr,
211 int32 buttonType = 0, bool ghosted = false, bool transparent = false,
212 const char *prompt = nullptr, ItemHandlerFunction i_handler = (ItemHandlerFunction)handler);
213 static void disableButton(menuItemButton *myItem, int32 tag, guiMenu *myMenu);
214 static void enableButton(menuItemButton *myItem, int32 tag, guiMenu *myMenu);
215 static bool handler(menuItemButton *myItem, int32 eventType, int32 event,
216 int32 x, int32 y, void **currItem);
217};
218
219struct menuItemHSlider : public menuItem {
220private:
221 static void drawHSlider(menuItemHSlider *myItem, guiMenu *myMenu, int32 x, int32 y, int32, int32);
222 static bool handler(menuItemHSlider *myItem, int32 eventType, int32 event, int32 x, int32 y, void **currItem);
223
224public:
225 int32 itemFlags = 0;
226
227 int32 thumbW = 0, thumbH = 0;
228 int32 thumbX = 0, maxThumbX = 0;
229
230 int32 percent = 0;
231
232 enum {
233 H_THUMB_NORM = 0,
234 H_THUMB_OVER = 1,
235 H_THUMB_PRESS = 2
236 };
237
238 static menuItemHSlider *add(guiMenu *myMenu, int32 tag,
239 int32 x, int32 y, int32 w, int32 h, int32 initPercent = 0,
240 CALLBACK callback = nullptr, bool transparent = false);
241};
242
243struct menuItemVSlider : public menuItem {
244private:
245 static int32 whereIsCursor(menuItemVSlider *myVSlider, int32 y);
246
247public:
248 int32 itemFlags = 0;
249
250 int32 thumbW = 0, thumbH = 0;
251 int32 thumbY = 0, minThumbY = 0, maxThumbY = 0;
252
253 int32 percent = 0;
254
255 enum {
256 VS_NORM = 0x0000,
257 VS_OVER = 0x0001,
258 VS_PRESS = 0x0002,
259 VS_GREY = 0x0003,
260 VS_STATUS = 0x000f,
261 VS_UP = 0x0010,
262 VS_PAGE_UP = 0x0020,
263 VS_THUMB = 0x0030,
264 VS_PAGE_DOWN = 0x0040,
265 VS_DOWN = 0x0050,
266 VS_COMPONENT = 0x00f0
267 };
268
269 static menuItemVSlider *add(guiMenu *myMenu, int32 tag, int32 x, int32 y, int32 w, int32 h,
270 int32 initPercent = 0, CALLBACK callback = nullptr, bool transparent = false);
271 static void disableVSlider(menuItemVSlider *myItem, int32 tag, guiMenu *myMenu);
272 static void enableVSlider(menuItemVSlider *myItem, int32 tag, guiMenu *myMenu);
273 static void drawVSlider(menuItemVSlider *myItem, guiMenu *myMenu, int32 x, int32 y, int32, int32);
274 static bool handler(menuItemVSlider *myItem, int32 eventType, int32 event, int32 x, int32 y, void **currItem);
275};
276
278 int32 itemFlags = 0;
279
280 int32 specialTag = 0;
281 int32 pixWidth = 0;
282
283 char prompt[80] = { 0 };
284 char *promptEnd = nullptr;
285
286 char *cursor = nullptr;
287
288 enum {
289 TF_NORM = 0,
290 TF_OVER = 1,
291 TF_GREY = 2
292 };
293
294 static menuItemTextField *add(guiMenu *myMenu, int32 tag, int32 x, int32 y, int32 w, int32 h, int32 initFlags,
295 const char *prompt = nullptr, int32 specialtag = 0, CALLBACK callback = nullptr, bool transparent = false);
296 static bool handler(menuItemTextField *myItem, int32 eventType, int32 event, int32 x, int32 y, void **currItem);
297 static void drawTextField(menuItemTextField *myItem, guiMenu *myMenu, int32 x, int32 y, int32, int32);
298};
299
300struct guiMenu {
301private:
302 static void show(void *s, void *r, void *b, int32 destX, int32 destY);
303 static bool eventHandler(guiMenu *theMenu, int32 eventType, int32 parm1, int32 parm2, int32 parm3, bool *currScreen);
304
305public:
306 GrBuff *menuBuffer = nullptr;
307 menuItem *itemList = nullptr;
308 CALLBACK cb_return = nullptr;
309 CALLBACK cb_esc = nullptr;
310 EventHandler menuEventHandler = nullptr;
311
312 static bool initialize(RGB8 *myPalette);
313 static void shutdown(bool fadeToColor);
314 static guiMenu *create(Sprite *backgroundSprite, int32 x1, int32 y1, int32 scrnFlags);
315 static void destroy(guiMenu *myMenu);
316 static void configure(guiMenu *myMenu, CALLBACK cb_return, CALLBACK cb_esc);
317 static GrBuff *copyBackground(guiMenu *myMenu, int32 x, int32 y, int32 w, int32 h);
318 static menuItem *getItem(int32 tag, guiMenu *myMenu);
319 static void itemDelete(menuItem *myItem, int32 tag, guiMenu *myMenu);
320 static void itemRefresh(menuItem *myItem, int32 tag, guiMenu *myMenu);
321
322 static bool loadSprites(const char *series, int32 numSprites);
323 static void unloadSprites();
324};
325
327 //GLOBAL VARS
328 bool menuSystemInitialized = false;
329 bool buttonClosesDialog = false;
330 bool interfaceWasVisible = false;
331 RGB8 *menuPalette = nullptr;
332 bool dumpedCodes = false;
333 bool dumpedBackground = false;
334
335 menuItem *menuCurrItem = nullptr;
336
337 guiMenu *gameMenu = nullptr;
338 guiMenu *opMenu = nullptr;
339 guiMenu *slMenu = nullptr;
340 guiMenu *errMenu = nullptr;
341
342 //menu sprite series vars
343 char *menuSeriesResource = nullptr;
344 MemHandle menuSeriesHandle = nullptr;
345 int32 menuSeriesOffset = 0;
346 int32 menuSeriesPalOffset = 0;
347
348 Font *menuFont = nullptr;
349
350 // menu sprites array (used to hold all the sprites for the current menu, spriteCount is set tot he number of sprites in the series)
351 int32 spriteCount = 0;
352 Sprite **menuSprites = nullptr;
353
354 // VARS SPECIFIC TO THE GAME MENUS SYSTEM
355 // An array of slot titles used by the save/load menus
356 char **slotTitles = nullptr;
357 bool *slotInUse = nullptr;
358 int32 firstSlotIndex = 0; // Slot at the top of the list on menu
359 int32 slotSelected = -1; // Slot currently selected
360 bool deleteSaveDesc = false;
361
362 Sprite **thumbNails = nullptr;
363 Sprite *saveLoadThumbNail = nullptr; // Original used for menu display
364 Graphics::Surface _thumbnail; // ScummVM version used for savegame
365 int32 sizeofThumbData = -1;
366 int32 thumbIndex = 0;
367
368 bool currMenuIsSave = true; // Used to determine load or save menu
369 bool saveLoadFromHotkey = false; // Come from hotkey, not through game menu
370 bool gameMenuFromMain = false; // Come from main menu, not through escape
371
372 int32 remember_digi_volume = 0; // For cancelling out of the options menu
373 int32 remember_digestability = 0; // For cancelling out of the options menu
374
375 ~MenuGlobals() {
376 _thumbnail.free();
377 }
378};
379
380extern void gui_DrawSprite(Sprite *mySprite, Buffer *myBuff, int32 x, int32 y);
381
382//======================================
383//
384// gamemenu module defines
385//
386#define MENU_DEPTH 9 // video depth for menu popup boxes
387#define MAX_SLOTS 99 // number of save games you can have
388#define MAX_SLOTS_SHOWN 8 // number of slots in the scrolling field
389
390} // namespace GUI
391} // namespace M4
392
393#endif
Definition: gr_buff.h:30
Definition: database.h:28
Definition: surface.h:67
Definition: m4_types.h:54
Definition: gr_font.h:30
Definition: gui_menu_items.h:326
Definition: gui_menu_items.h:300
Definition: gui_menu_items.h:175
Definition: gui_menu_items.h:219
Definition: gui_menu_items.h:126
Definition: gui_menu_items.h:165
Definition: gui_menu_items.h:277
Definition: gui_menu_items.h:243
Definition: gui.h:31
Definition: m4_types.h:78