ScummVM API documentation
popup.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef MADS_CORE_POPUP_H
23#define MADS_CORE_POPUP_H
24
25#include "mads/core/general.h"
26#include "mads/core/font.h"
27#include "mads/core/sprite.h"
28#include "mads/core/heap.h"
29
30namespace MADS {
31
32#define POPUP_UPPER_LEFT 1 /* Pieces of border box */
33#define POPUP_UPPER_RIGHT 2
34#define POPUP_LOWER_LEFT 3
35#define POPUP_LOWER_RIGHT 4
36#define POPUP_LEFT 5
37#define POPUP_RIGHT 6
38#define POPUP_TOP 7
39#define POPUP_BOTTOM 8
40#define POPUP_UPPER_CENTER 9
41
42#define pop_xs(piece) (box_param.series->index[piece-1].xs)
43#define pop_ys(piece) (box_param.series->index[piece-1].ys)
44
45#define pop_y2(piece) (box_param.series->index[piece-1].y)
46#define pop_y(piece) (pop_y2(piece) - pop_ys(piece) + 1)
47
48#define pop_m(piece) (box_param.series->index[piece-1].x)
49#define pop_x(piece) (pop_m(piece) - (pop_xs(piece) >> 1))
50#define pop_x2(piece) (pop_x(piece) + pop_xs(piece) - 1)
51
52#define POPUP_BASE_COLOR 18 /* Popup palette location */
53#define POPUP_NUM_COLORS 8
54
55#define POPUP_FILL_COLOR popup_colors[8] /* Popup fill color */
56#define POPUP_FILL_COLOR_2 popup_colors[9]
57#define POPUP_TEXT_COLOR popup_colors[10]
58#define POPUP_HILITE_COLOR popup_colors[11]
59#define POPUP_HILITE_COLOR_2 popup_colors[12]
60#define POPUP_ASK_COLOR popup_colors[13]
61
62#define popup_normal_color_1 popup_colors[0]
63#define popup_normal_color_2 popup_colors[1]
64#define popup_shadow_color_1 popup_colors[2]
65#define popup_shadow_color_2 popup_colors[3]
66#define popup_hilite_color_1 popup_colors[4]
67#define popup_hilite_color_2 popup_colors[5]
68#define popup_ask_color popup_colors[6]
69#define popup_text_color popup_colors[7]
70
71#define POPUP_DIALOG_TEXT_COLOR popup_colors[14]
72#define POPUP_DIALOG_BUTTON_COLOR_1 popup_colors[15]
73#define POPUP_DIALOG_BUTTON_COLOR_2 popup_colors[16]
74#define POPUP_DIALOG_BORDER_COLOR_1 popup_colors[17]
75#define POPUP_DIALOG_BORDER_COLOR_2 popup_colors[18]
76#define POPUP_DIALOG_SELECT_COLOR popup_colors[19]
77#define POPUP_DIALOG_STRING_COLOR popup_colors[20]
78
79#define POPUP_DIALOG_MENU_TEXT_1 popup_colors[21]
80#define POPUP_DIALOG_MENU_TEXT_2 popup_colors[22]
81#define POPUP_DIALOG_MENU_TEXT_3 popup_colors[23]
82
83#define POPUP_MAX_LINES 20
84#define POPUP_SPACING 1
85
86#define POPUP_CENTER 0x8000 /* General centering */
87#define POPUP_BUTTON_ROW 0x4000 /* Popup buttons only */
88#define POPUP_RIGHT_JUST 0x2000 /* Right side */
89
90#define POPUP_BUTTON_RIGHT 0x0800
91#define POPUP_BUTTON_LEFT 0x0400
92
93#define POPUP_FILL -1 /* Fill on next line */
94
95#define POPUP_BAR 0xffff /* Bar across line */
96#define POPUP_UNDERLINE 0x8000 /* Underline text */
97#define POPUP_DOWNPIXEL 0x4000 /* Down a pixel */
98
99
100#define popup_padding_width 3 /* Extra space on each side */
101
102struct BoxParam {
103 SeriesPtr series; /* Sprite series for popup box */
104
105 char name[16]; /* Sprite series name */
106
107 FontPtr font; /* Box font */
108 int font_spacing; /* Box font spacing */
109
110 int top_adjust_y; /* Coordinate adjustments for */
111 int center_adjust_y; /* box pieces (to get them in */
112 int upper_right_adjust_y; /* line). */
113 int left_adjust_x;
114 int lower_left_adjust_x;
115 int bottom_adjust_y;
116 int lower_right_adjust_y;
117 int right_adjust_x;
118
119 int offset_x; /* Window offset within box */
120 int offset_y;
121
122 int extra_x; /* Extra width/height provided by */
123 int extra_y; /* corner pieces */
124
125 int pieces_per_center; /* Number of bottom pieces in center */
126
127 int erase_on_first; /* If true, erases default during ask */
128
129 SeriesPtr logo; /* Logo sprite series, if any */
130 SeriesPtr menu; /* Menu sprite series, if any */
131 FontPtr menu_font; /* Menu font */
132 int menu_font_spacing; /* Menu font spacing */
133
134 int menu_left_width; /* Menu sprite series size */
135 int menu_right_width;
136 int menu_middle_width;
137
138 int menu_text_x_offset; /* Menu text offsets */
139 int menu_text_y_offset;
140 int menu_text_x_bonus; /* Bonus offsets when selected */
141 int menu_text_y_bonus;
142};
143
144struct Box {
145 int active;
146
147 int base_x, base_y; /* Box base screen location */
148
149 int x, y; /* Box upper left extremity */
150 int xs, ys; /* Box size */
151
152 int window_x, window_y; /* Window screen location */
153 int window_xs, window_ys; /* Window size */
154
155 int text_xs; /* Horizontal size of actual text */
156 int text_extra; /* Extra padding space (total) */
157
158 int depth_x, depth_xs; /* Depth preserve coordinates */
159
160 int horiz_pieces; /* # of horiz pieces each side */
161 int vert_pieces; /* # of vertical pieces */
162
163 int text_width;
164 int text_x, text_y;
165 int ask_x, ask_y;
166 int cursor_x;
167 word tab[POPUP_MAX_LINES];
168 char *text[POPUP_MAX_LINES];
169
170 int dont_add_space;
171
172 int preserve_handle;
173 int depth_preserve_handle;
174
175 Buffer screen_buffer; /* scr_main copy covering the full popup rect */
176 Buffer orig_buffer; /* scr_orig copy for the game-area portion (depth) */
177 Buffer depth_buffer; /* scr_depth copy (clipped to depth-buffer height) */
178
179 int screen_saved;
180 int orig_saved;
181 int depth_saved;
182
183 word fill_accum;
184
185 SeriesPtr icon; /* Sprite displayed in box */
186 int icon_id;
187 int icon_width;
188 int icon_height;
189
190 int dialog_system; /* Dialog system hooks */
191 long request_y_size;
192
193 int icon_center;
194};
195
196
197/* Item types defined so */
198#define ITEM_BLANK 0 /* Null item */
199#define ITEM_BUTTON 1 /* Button */
200#define ITEM_MESSAGE 2 /* String message */
201#define ITEM_SAVELIST 3 /* Saved game list*/
202#define ITEM_SPRITE 4 /* Static sprite */
203#define ITEM_MENU 5 /* Menu item */
204
205
207 char *data; /* Heap pointer for buffer space */
208 int max_length; /* Buffer max string width */
209 int width; /* Buffer width in pixels */
210 int base_x; /* Buffer base position */
211 int text_x; /* Buffer base text position */
212 int cursor; /* Buffer cursor location */
213 int select_base;
214 int select_target;
215};
216
217
218#define SCROLL_AXIS_HORIZONTAL 0
219#define SCROLL_AXIS_VERTICAL 1
220
221#define SCROLL_STATUS_UP 0x80
222#define SCROLL_STATUS_DOWN 0x40
223
225 int axis;
226
227 int status;
228
229 int x, y;
230 int xs, ys;
231
232 int arrow_size;
233 int arrow_1_base;
234 int arrow_2_base;
235
236 int thumb_base;
237 int thumb_item;
238 int thumb_size;
239};
240
241struct PopupList {
242 int box_x, box_y; /* Size of box around list */
243 int box_xs, box_ys;
244
245 int list_x, list_y; /* List item base location */
246 int list_xs, list_ys; /* List item size */
247 int list_xw, list_yw; /* List item width of entry */
248
249 int font_x, font_y; /* Font base location */
250
251 int extra_x, extra_y; /* Extra item (number list) */
252 int extra_xs, extra_ys;
253
254 int rows, columns; /* List rows and columnts */
255 int element_max_length; /* List text length of entry */
256
257 int elements; /* List # of elements */
258 int element_offset; /* List offset to elements */
259
260 int base_element; /* Upper left element */
261 int picked_element; /* Selected element */
262
263 PopupScrollBar scroll; /* ScrollBar info */
264
265 char *data; /* List string data */
266
267 long double_clock; /* Double click clock */
268 int double_element; /* Double click element */
269
270};
271
272#define POPUP_DOUBLE_CLICK_THRESHOLD 20
273
274
275#define POPUP_ITEM_VECTORS 7 /* Item-specific function vectors */
276
277#define VECTOR_X_SIZE 0 /* Compute item X size */
278#define VECTOR_Y_SIZE 1 /* Compute item Y size */
279#define VECTOR_ADJUST 2 /* Adjust coordinates to absolute */
280#define VECTOR_DRAW 3 /* Draw item */
281#define VECTOR_UPDATE 4 /* Update item */
282#define VECTOR_MOUSE 5 /* Accept mouse input */
283#define VECTOR_KEY 6 /* Accept keyboard input */
284
285#define ITEM_STATUS_ACTIVE 0x01
286#define ITEM_STATUS_CLOCK 0x02
287#define ITEM_STATUS_FORCED 0x04
288#define ITEM_STATUS_IN_RANGE 0x08
289
290#define ITEM_STATUS_STRING 0x10
291
292#define ITEM_STATUS_VIRGIN 0x20
293#define ITEM_STATUS_DIRTY 0x40
294#define ITEM_STATUS_INPUT 0x80
295
296#define ITEM_STATUS_INERT 0x100
297
298struct PopupItem {
299 byte type; /* Type of item */
300
301 word status; /* Status of item */
302
303 int misc[10]; /* Item specific */
304
305 int x, y; /* Item location */
306 int xs, ys; /* Item base size */
307
308 int font_x; /* Font X base */
309 int font_y; /* Font Y base */
310
311 int keystroke; /* Hotkey for item */
312
313 long mouse_interval; /* Mouse interval */
314
315 char *prompt; /* Item label */
316
317 PopupBuffer *buffer; /* Item buffer */
318 PopupList *list; /* Item list */
319
320 SeriesPtr series; /* Sprite series */
321 int sprite; /* Sprite id */
322
323 int (*vector[POPUP_ITEM_VECTORS])(PopupItem *item); /* Vectors */
324};
325
326
327#define POPUP_MOUSE_SCROLL 0x8000 /* Mouse in scroll bar */
328#define POPUP_MOUSE_UP 0x4000 /* Mouse scrolling up */
329#define POPUP_MOUSE_DOWN 0x2000 /* Mouse scrolling down */
330
331
332#define POPUP_STATUS_DYNAMIC 0x8000 /* Popup created dynamically */
333#define POPUP_STATUS_VALID 0x4000 /* Popup valid */
334#define POPUP_STATUS_EXIT 0x2000 /* Popup ready to exit */
335
336#define POPUP_STATUS_BAR 0x0004 /* Popup bar should be drawn */
337#define POPUP_STATUS_STEAL 0x0002 /* Popup bar should steal color */
338#define POPUP_STATUS_BUTTON 0x0001 /* Popup button row in use */
339
340
341struct Popup {
342 Heap heap; /* Popup heap space */
343
344 word status; /* Popup status flags */
345
346 uint16 x, y; /* X location */
347 int16 width; /* X minimum width */
348 int16 y_position; /* Y current usage */
349 int16 y_spacing; /* Y spacing */
350 int16 xs, ys; /* Window size information */
351
352 int16 button_y; /* Button Y location */
353 int16 button_spacing; /* Button spacing */
354 int16 button_left_fill; /* Button row left fill */
355 int16 button_right_fill; /* Button row right fill */
356 int16 button_bar_color; /* Button bar color */
357
358 uint32 key; /* Last keyboard input */
359 int16 key_handled; /* Flag if key handled */
360
361 int16 mouse_status; /* Mouse status word */
362 long mouse_clock; /* Mouse action clock */
363
364 PopupItem *enter_item; /* ENTER key button */
365 PopupItem *cancel_item; /* CANCEL (ESC key) item */
366
367 PopupItem *string_item; /* STRING item, if any */
368
369 PopupItem *mouse_item; /* Mouse active item */
370 PopupItem *active_item; /* Active item */
371
372 PopupItem *list_item; /* List item */
373 PopupItem *clear_item; /* Clear list item */
374
375 int16 max_items; /* Maximum # of items */
376 int16 num_items; /* Number of items in popup */
377
378 PopupItem *item; /* Item list */
379};
380
381
382extern Box text_box;
383extern Box *box;
384
385extern int popup_key;
386extern int popup_esc_key;
387extern int popup_asking_number;
388
389extern int popup_available;
390
391extern int popup_preserve_initiator[3];
392
393extern byte popup_colors[24];
394extern byte popup_num_colors;
395
396extern BoxParam box_param;
397
398extern void init_popup();
399
400extern int popup_create(int horiz_pieces, int x, int y);
401extern void popup_add_icon(SeriesPtr series, int id, int center);
402extern int popup_draw(int save_screen, int depth_code);
403extern void popup_destroy();
404
405extern void popup_next_line();
406extern void popup_set_ask();
407extern void popup_add_string(const char *string);
408extern void popup_write_string(const char *string);
409extern void popup_bar();
410extern void popup_underline();
411extern void popup_downpixel();
412extern void popup_tab(int tab_level);
413extern void popup_center_string(const char *string, int underline);
414
415extern int popup_and_wait(int save_screen);
416extern int popup_and_dont_wait(int save_screen);
417
418extern void popup_update_ask(char *string, int maxlen);
419extern int popup_ask_string(char *target, int maxlen, int save_screen);
420extern int popup_ask_number(long *value, int maxlen, int save_screen);
421
422extern int popup_estimate_pieces(int maxlen);
423extern int popup_get_string(char *target, const char *top, const char *left, int maxlen);
424extern int popup_get_long(long *value, const char *top, const char *left, int maxlen);
425extern int popup_get_number(int16 *value, const char *top, const char *left, int maxlen);
426
427extern int popup_alert(int width, const char *message_line, ...);
428
429extern int popup_box_load();
430
431/*
432 * popup_dialog_create()
433 * Sets up popup dialog structure, allocating memory dynamically
434 * if necessary.
435 *
436 * @param memory
437 * @param heap_size
438 * @param max_items
439 * @return
440 */
441Popup *popup_dialog_create(void *memory, long heap_size, int max_items);
442/*
443 * popup_dialog_destroy()
444 * Destroys a popup dialog, deallocating any dynamic memory.
445 *
446 * @return
447 */
448extern Popup *popup_dialog_destroy();
449
450extern PopupItem *popup_button(const char *prompt, int x);
451extern PopupItem *popup_cancel_button(const char *prompt);
452extern PopupItem *popup_message(const char *prompt, int x, int y);
453extern PopupItem *popup_execute();
454
455extern PopupItem *popup_savelist(char *data, char *empty_string,
456 int elements, int element_offset, int element_max_length,
457 int pixel_width, int rows, int accept_input, int default_element);
458
459extern void popup_blank(int num_lines);
460extern void popup_blank_line();
461extern void popup_width_force(int width);
462
463
464extern void popup_menu_option(PopupItem *item, char *option);
465extern PopupItem *popup_menu(const char *prompt,
466 int x, int y, int pixel_width,
467 int off_center_x,
468 int elements, int element_max_length,
469 int default_element);
470
471extern PopupItem *popup_sprite(SeriesPtr series, int sprite, int x, int y);
472
473} // namespace MADS
474
475#endif
Definition: popup.h:144
Definition: popup.h:102
Definition: general.h:57
Definition: font.h:33
Definition: heap.h:29
Definition: popup.h:206
Definition: popup.h:341
Definition: popup.h:298
Definition: popup.h:241
Definition: popup.h:224
Definition: sprite.h:244