|
1 /* $Id$ */ |
|
2 |
|
3 #ifndef WINDOW_H |
|
4 #define WINDOW_H |
|
5 |
|
6 #include "macros.h" |
|
7 #include "string.h" |
|
8 #include "order.h" |
|
9 |
|
10 typedef struct WindowEvent WindowEvent; |
|
11 |
|
12 typedef void WindowProc(Window *w, WindowEvent *e); |
|
13 |
|
14 /* How the resize system works: |
|
15 First, you need to add a WWT_RESIZEBOX to the widgets, and you need |
|
16 to add the flag WDF_RESIZABLE to the window. Now the window is ready |
|
17 to resize itself. |
|
18 As you may have noticed, all widgets have a RESIZE_XXX in their line. |
|
19 This lines controls how the widgets behave on resize. RESIZE_NONE means |
|
20 it doesn't do anything. Any other option let's one of the borders |
|
21 move with the changed width/height. So if a widget has |
|
22 RESIZE_RIGHT, and the window is made 5 pixels wider by the user, |
|
23 the right of the window will also be made 5 pixels wider. |
|
24 Now, what if you want to clamp a widget to the bottom? Give it the flag |
|
25 RESIZE_TB. This is RESIZE_TOP + RESIZE_BOTTOM. Now if the window gets |
|
26 5 pixels bigger, both the top and bottom gets 5 bigger, so the whole |
|
27 widgets moves downwards without resizing, and appears to be clamped |
|
28 to the bottom. Nice aint it? |
|
29 You should know one more thing about this system. Most windows can't |
|
30 handle an increase of 1 pixel. So there is a step function, which |
|
31 let the windowsize only be changed by X pixels. You configure this |
|
32 after making the window, like this: |
|
33 w->resize.step_height = 10; |
|
34 Now the window will only change in height in steps of 10. |
|
35 You can also give a minimum width and height. The default value is |
|
36 the default height/width of the window itself. You can change this |
|
37 AFTER window-creation, with: |
|
38 w->resize.width or w->resize.height. |
|
39 That was all.. good luck, and enjoy :) -- TrueLight */ |
|
40 |
|
41 enum ResizeFlags { |
|
42 RESIZE_NONE = 0, |
|
43 |
|
44 RESIZE_LEFT = 1, |
|
45 RESIZE_RIGHT = 2, |
|
46 RESIZE_TOP = 4, |
|
47 RESIZE_BOTTOM = 8, |
|
48 |
|
49 RESIZE_LR = RESIZE_LEFT | RESIZE_RIGHT, |
|
50 RESIZE_RB = RESIZE_RIGHT | RESIZE_BOTTOM, |
|
51 RESIZE_TB = RESIZE_TOP | RESIZE_BOTTOM, |
|
52 RESIZE_LRB = RESIZE_LEFT | RESIZE_RIGHT | RESIZE_BOTTOM, |
|
53 RESIZE_LRTB = RESIZE_LEFT | RESIZE_RIGHT | RESIZE_TOP | RESIZE_BOTTOM, |
|
54 RESIZE_RTB = RESIZE_RIGHT | RESIZE_TOP | RESIZE_BOTTOM, |
|
55 |
|
56 /* The following flags are used by the system to specify what is disabled, hidden, or clicked |
|
57 * They are used in the same place as the above RESIZE_x flags, Widget visual_flags. |
|
58 * These states are used in exceptions. If nothing is specified, they will indicate |
|
59 * Enabled, visible or unclicked widgets*/ |
|
60 WIDG_DISABLED = 4, // widget is greyed out, not available |
|
61 WIDG_HIDDEN = 5, // widget is made invisible |
|
62 WIDG_LOWERED = 6, // widget is paint lowered, a pressed button in fact |
|
63 } ResizeFlag; |
|
64 |
|
65 /* used to indicate the end of widgets' list for vararg functions */ |
|
66 enum { |
|
67 WIDGET_LIST_END = -1, |
|
68 }; |
|
69 |
|
70 typedef struct Widget { |
|
71 byte type; ///< Widget type, see @WindowWidgetTypes |
|
72 byte display_flags; ///< Resize direction, alignment, etc. during resizing, see @ResizeFlags |
|
73 byte color; ///< Widget colour, see docs/ottd-colourtext-palette.png |
|
74 uint16 left, right, top, bottom; ///< The position offsets inside the window |
|
75 uint16 data; ///< The String/Image or special code (list-matrixes) of a widget |
|
76 StringID tooltips; ///< Tooltips that are shown when rightclicking on a widget |
|
77 } Widget; |
|
78 |
|
79 typedef enum FrameFlags { |
|
80 FR_TRANSPARENT = 0x01, ///< Makes the background transparent if set |
|
81 FR_BORDERONLY = 0x10, ///< Draw border only, no background |
|
82 FR_LOWERED = 0x20, ///< If set the frame is lowered and the background color brighter (ie. buttons when pressed) |
|
83 FR_DARKENED = 0x40, ///< If set the background is darker, allows for lowered frames with normal background color when used with FR_LOWERED (ie. dropdown boxes) |
|
84 } FrameFlags; |
|
85 |
|
86 void DrawFrameRect(int left, int top, int right, int bottom, int color, FrameFlags flags); |
|
87 |
|
88 enum WindowEventCodes { |
|
89 WE_CREATE, |
|
90 WE_DESTROY, |
|
91 WE_PAINT, |
|
92 WE_KEYPRESS, |
|
93 WE_CLICK, |
|
94 WE_RCLICK, |
|
95 WE_MOUSEOVER, |
|
96 WE_MOUSELOOP, |
|
97 WE_MOUSEWHEEL, |
|
98 WE_TICK, |
|
99 WE_4, |
|
100 WE_TIMEOUT, |
|
101 WE_PLACE_OBJ, |
|
102 WE_ABORT_PLACE_OBJ, |
|
103 WE_ON_EDIT_TEXT, |
|
104 WE_ON_EDIT_TEXT_CANCEL, |
|
105 WE_POPUPMENU_SELECT, |
|
106 WE_POPUPMENU_OVER, |
|
107 WE_DRAGDROP, |
|
108 WE_PLACE_DRAG, |
|
109 WE_PLACE_MOUSEUP, |
|
110 WE_PLACE_PRESIZE, |
|
111 WE_DROPDOWN_SELECT, |
|
112 WE_RESIZE, |
|
113 WE_MESSAGE, |
|
114 WE_SCROLL, |
|
115 WE_INVALIDATE_DATA, |
|
116 }; |
|
117 |
|
118 struct WindowEvent { |
|
119 byte event; |
|
120 union { |
|
121 struct{ |
|
122 Point pt; |
|
123 int widget; |
|
124 } click; |
|
125 |
|
126 struct { |
|
127 Point pt; |
|
128 TileIndex tile; |
|
129 TileIndex starttile; |
|
130 int userdata; |
|
131 } place; |
|
132 |
|
133 struct { |
|
134 Point pt; |
|
135 int widget; |
|
136 } dragdrop; |
|
137 |
|
138 struct { |
|
139 Point size; |
|
140 Point diff; |
|
141 } sizing; |
|
142 |
|
143 struct { |
|
144 char *str; |
|
145 } edittext; |
|
146 |
|
147 struct { |
|
148 Point pt; |
|
149 } popupmenu; |
|
150 |
|
151 struct { |
|
152 int button; |
|
153 int index; |
|
154 } dropdown; |
|
155 |
|
156 struct { |
|
157 Point pt; |
|
158 int widget; |
|
159 } mouseover; |
|
160 |
|
161 struct { |
|
162 bool cont; // continue the search? (default true) |
|
163 uint16 key; // 16-bit Unicode value of the key |
|
164 uint16 keycode;// untranslated key (including shift-state) |
|
165 } keypress; |
|
166 |
|
167 struct { |
|
168 uint msg; // message to be sent |
|
169 uint wparam; // additional message-specific information |
|
170 uint lparam; // additional message-specific information |
|
171 } message; |
|
172 |
|
173 struct { |
|
174 Point delta; // delta position against position of last call |
|
175 } scroll; |
|
176 |
|
177 struct { |
|
178 int wheel; // how much was 'wheel'd' |
|
179 } wheel; |
|
180 } we; |
|
181 }; |
|
182 |
|
183 enum WindowKeyCodes { |
|
184 WKC_SHIFT = 0x8000, |
|
185 WKC_CTRL = 0x4000, |
|
186 WKC_ALT = 0x2000, |
|
187 WKC_META = 0x1000, |
|
188 |
|
189 // Special ones |
|
190 WKC_NONE = 0, |
|
191 WKC_ESC = 1, |
|
192 WKC_BACKSPACE = 2, |
|
193 WKC_INSERT = 3, |
|
194 WKC_DELETE = 4, |
|
195 |
|
196 WKC_PAGEUP = 5, |
|
197 WKC_PAGEDOWN = 6, |
|
198 WKC_END = 7, |
|
199 WKC_HOME = 8, |
|
200 |
|
201 // Arrow keys |
|
202 WKC_LEFT = 9, |
|
203 WKC_UP = 10, |
|
204 WKC_RIGHT = 11, |
|
205 WKC_DOWN = 12, |
|
206 |
|
207 // Return & tab |
|
208 WKC_RETURN = 13, |
|
209 WKC_TAB = 14, |
|
210 |
|
211 // Numerical keyboard |
|
212 WKC_NUM_0 = 16, |
|
213 WKC_NUM_1 = 17, |
|
214 WKC_NUM_2 = 18, |
|
215 WKC_NUM_3 = 19, |
|
216 WKC_NUM_4 = 20, |
|
217 WKC_NUM_5 = 21, |
|
218 WKC_NUM_6 = 22, |
|
219 WKC_NUM_7 = 23, |
|
220 WKC_NUM_8 = 24, |
|
221 WKC_NUM_9 = 25, |
|
222 WKC_NUM_DIV = 26, |
|
223 WKC_NUM_MUL = 27, |
|
224 WKC_NUM_MINUS = 28, |
|
225 WKC_NUM_PLUS = 29, |
|
226 WKC_NUM_ENTER = 30, |
|
227 WKC_NUM_DECIMAL = 31, |
|
228 |
|
229 // Space |
|
230 WKC_SPACE = 32, |
|
231 |
|
232 // Function keys |
|
233 WKC_F1 = 33, |
|
234 WKC_F2 = 34, |
|
235 WKC_F3 = 35, |
|
236 WKC_F4 = 36, |
|
237 WKC_F5 = 37, |
|
238 WKC_F6 = 38, |
|
239 WKC_F7 = 39, |
|
240 WKC_F8 = 40, |
|
241 WKC_F9 = 41, |
|
242 WKC_F10 = 42, |
|
243 WKC_F11 = 43, |
|
244 WKC_F12 = 44, |
|
245 |
|
246 // backquote is the key left of "1" |
|
247 // we only store this key here, no matter what character is really mapped to it |
|
248 // on a particular keyboard. (US keyboard: ` and ~ ; German keyboard: ^ and °) |
|
249 WKC_BACKQUOTE = 45, |
|
250 WKC_PAUSE = 46, |
|
251 |
|
252 // 0-9 are mapped to 48-57 |
|
253 // A-Z are mapped to 65-90 |
|
254 // a-z are mapped to 97-122 |
|
255 }; |
|
256 |
|
257 typedef struct WindowDesc { |
|
258 int16 left, top, width, height; |
|
259 WindowClass cls; |
|
260 WindowClass parent_cls; |
|
261 uint32 flags; |
|
262 const Widget *widgets; |
|
263 WindowProc *proc; |
|
264 } WindowDesc; |
|
265 |
|
266 enum WindowDefaultFlag { |
|
267 WDF_STD_TOOLTIPS = 1, /* use standard routine when displaying tooltips */ |
|
268 WDF_DEF_WIDGET = 2, /* default widget control for some widgets in the on click event */ |
|
269 WDF_STD_BTN = 4, /* default handling for close and drag widgets (widget no 0 and 1) */ |
|
270 |
|
271 WDF_UNCLICK_BUTTONS = 16, /* Unclick buttons when the window event times out */ |
|
272 WDF_STICKY_BUTTON = 32, /* Set window to sticky mode; they are not closed unless closed with 'X' (widget 2) */ |
|
273 WDF_RESIZABLE = 64, /* A window can be resized */ |
|
274 WDF_MODAL = 128, /* The window is a modal child of some other window, meaning the parent is 'inactive' */ |
|
275 }; |
|
276 |
|
277 /* can be used as x or y coordinates to cause a specific placement */ |
|
278 enum WindowDefaultPosition { |
|
279 WDP_AUTO = -1, ///< Find a place automatically |
|
280 WDP_CENTER = -2, ///< Center the window (left/right or top/bottom) |
|
281 WDP_ALIGN_TBR = -3, ///< Align the right side of the window with the right side of the main toolbar |
|
282 WDP_ALIGN_TBL = -4, ///< Align the left side of the window with the left side of the main toolbar |
|
283 }; |
|
284 |
|
285 typedef struct Textbuf { |
|
286 char *buf; /* buffer in which text is saved */ |
|
287 uint16 maxlength, maxwidth; /* the maximum size of the buffer. Maxwidth specifies screensize in pixels, maxlength is in bytes */ |
|
288 uint16 length, width; /* the current size of the string. Width specifies screensize in pixels, length is in bytes */ |
|
289 bool caret; /* is the caret ("_") visible or not */ |
|
290 uint16 caretpos; /* the current position of the caret in the buffer, in bytes */ |
|
291 uint16 caretxoffs; /* the current position of the caret in pixels */ |
|
292 } Textbuf; |
|
293 |
|
294 #define WP(ptr,str) (*(str*)(ptr)->custom) |
|
295 /* You cannot 100% reliably calculate the biggest custom struct as |
|
296 * the number of pointers in it and alignment will have a huge impact. |
|
297 * 96 is the largest window-size for 64-bit machines currently */ |
|
298 #define WINDOW_CUSTOM_SIZE 96 |
|
299 |
|
300 typedef struct Scrollbar { |
|
301 uint16 count, cap, pos; |
|
302 } Scrollbar; |
|
303 |
|
304 typedef struct ResizeInfo { |
|
305 uint width; /* Minimum width and height */ |
|
306 uint height; |
|
307 |
|
308 uint step_width; /* In how big steps the width and height go */ |
|
309 uint step_height; |
|
310 } ResizeInfo; |
|
311 |
|
312 typedef struct WindowMessage { |
|
313 int msg; |
|
314 int wparam; |
|
315 int lparam; |
|
316 } WindowMessage; |
|
317 |
|
318 struct Window { |
|
319 uint16 flags4; |
|
320 WindowClass window_class; |
|
321 WindowNumber window_number; |
|
322 |
|
323 int left, top; |
|
324 int width, height; |
|
325 |
|
326 Scrollbar hscroll, vscroll, vscroll2; |
|
327 ResizeInfo resize; |
|
328 |
|
329 byte caption_color; |
|
330 |
|
331 WindowProc *wndproc; |
|
332 ViewPort *viewport; |
|
333 const Widget *original_widget; |
|
334 Widget *widget; |
|
335 uint widget_count; |
|
336 uint32 desc_flags; |
|
337 |
|
338 WindowMessage message; |
|
339 Window *parent; |
|
340 byte custom[WINDOW_CUSTOM_SIZE]; |
|
341 }; |
|
342 |
|
343 typedef struct querystr_d { |
|
344 StringID caption; |
|
345 Textbuf text; |
|
346 const char *orig; |
|
347 CharSetFilter afilter; |
|
348 bool handled; |
|
349 } querystr_d; |
|
350 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(querystr_d)); |
|
351 |
|
352 typedef struct { |
|
353 byte item_count; /* follow_vehicle */ |
|
354 byte sel_index; /* scrollpos_x */ |
|
355 byte main_button; /* scrollpos_y */ |
|
356 byte action_id; |
|
357 StringID string_id; /* unk30 */ |
|
358 uint16 checked_items; /* unk32 */ |
|
359 byte disabled_items; |
|
360 } menu_d; |
|
361 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(menu_d)); |
|
362 |
|
363 typedef struct { |
|
364 int16 data_1, data_2, data_3; |
|
365 int16 data_4, data_5; |
|
366 bool close; |
|
367 byte byte_1; |
|
368 } def_d; |
|
369 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(def_d)); |
|
370 |
|
371 typedef struct { |
|
372 void *data; |
|
373 } void_d; |
|
374 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(void_d)); |
|
375 |
|
376 typedef struct { |
|
377 uint16 base; |
|
378 uint16 count; |
|
379 } tree_d; |
|
380 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(tree_d)); |
|
381 |
|
382 typedef struct { |
|
383 StringID string_id; |
|
384 byte paramcount; |
|
385 uint32 params[5]; |
|
386 } tooltips_d; |
|
387 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(tooltips_d)); |
|
388 |
|
389 typedef struct { |
|
390 byte vehicle_type; |
|
391 union { |
|
392 byte railtype; |
|
393 byte acc_planes; // AIRCRAFT_ONLY, ALL, HELICOPTERS_ONLY |
|
394 } filter; |
|
395 byte sel_index; // deprecated value, used for 'unified' ship and road |
|
396 bool descending_sort_order; |
|
397 byte sort_criteria; |
|
398 EngineID sel_engine; |
|
399 EngineID rename_engine; |
|
400 EngineList eng_list; |
|
401 } buildvehicle_d; |
|
402 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(buildvehicle_d)); |
|
403 |
|
404 typedef struct { |
|
405 byte vehicletype; |
|
406 byte sel_index[2]; |
|
407 EngineID sel_engine[2]; |
|
408 uint16 count[2]; |
|
409 bool wagon_btnstate; // true means engine is selected |
|
410 } replaceveh_d; |
|
411 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(replaceveh_d)); |
|
412 |
|
413 typedef struct { |
|
414 VehicleID sel; |
|
415 byte type; |
|
416 bool generate_list; |
|
417 uint16 engine_list_length; |
|
418 uint16 wagon_list_length; |
|
419 uint16 engine_count; |
|
420 uint16 wagon_count; |
|
421 Vehicle **vehicle_list; |
|
422 Vehicle **wagon_list; |
|
423 } depot_d; |
|
424 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(depot_d)); |
|
425 |
|
426 typedef struct { |
|
427 int sel; |
|
428 } order_d; |
|
429 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(order_d)); |
|
430 |
|
431 typedef struct { |
|
432 byte tab; |
|
433 } traindetails_d; |
|
434 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(traindetails_d)); |
|
435 |
|
436 typedef struct { |
|
437 int32 scroll_x; |
|
438 int32 scroll_y; |
|
439 int32 subscroll; |
|
440 } smallmap_d; |
|
441 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(smallmap_d)); |
|
442 |
|
443 typedef struct { |
|
444 uint32 face; |
|
445 byte gender; |
|
446 } facesel_d; |
|
447 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(facesel_d)); |
|
448 |
|
449 typedef struct { |
|
450 int sel; |
|
451 struct RefitOption *cargo; |
|
452 struct RefitList *list; |
|
453 uint length; |
|
454 VehicleOrderID order; |
|
455 } refit_d; |
|
456 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(refit_d)); |
|
457 |
|
458 typedef struct { |
|
459 VehicleID follow_vehicle; |
|
460 int32 scrollpos_x; |
|
461 int32 scrollpos_y; |
|
462 } vp_d; |
|
463 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vp_d)); |
|
464 |
|
465 // vp2_d is the same as vp_d, except for the data_# values.. |
|
466 typedef struct { |
|
467 VehicleID follow_vehicle; |
|
468 int32 scrollpos_x; |
|
469 int32 scrollpos_y; |
|
470 byte data_1; |
|
471 byte data_2; |
|
472 byte data_3; |
|
473 } vp2_d; |
|
474 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vp2_d)); |
|
475 |
|
476 typedef struct { |
|
477 uint16 follow_vehicle; |
|
478 int32 scrollpos_x; |
|
479 int32 scrollpos_y; |
|
480 NewsItem *ni; |
|
481 } news_d; |
|
482 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(news_d)); |
|
483 |
|
484 typedef struct { |
|
485 uint32 background_img; |
|
486 int8 rank; |
|
487 } highscore_d; |
|
488 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(highscore_d)); |
|
489 |
|
490 typedef struct { |
|
491 int height; |
|
492 uint16 counter; |
|
493 } scroller_d; |
|
494 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(scroller_d)); |
|
495 |
|
496 typedef enum SortListFlags { |
|
497 VL_DESC = 0x01, // sort descending or ascending |
|
498 VL_RESORT = 0x02, // instruct the code to resort the list in the next loop |
|
499 VL_REBUILD = 0x04 // create sort-listing to use for qsort and friends |
|
500 } SortListFlags; |
|
501 |
|
502 typedef struct Listing { |
|
503 bool order; // Ascending/descending |
|
504 byte criteria; // Sorting criteria |
|
505 } Listing; |
|
506 |
|
507 typedef struct list_d { |
|
508 uint16 list_length; // length of the list being sorted |
|
509 byte sort_type; // what criteria to sort on |
|
510 SortListFlags flags; // used to control sorting/resorting/etc. |
|
511 uint16 resort_timer; // resort list after a given amount of ticks if set |
|
512 } list_d; |
|
513 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(list_d)); |
|
514 |
|
515 typedef struct message_d { |
|
516 int msg; |
|
517 int wparam; |
|
518 int lparam; |
|
519 } message_d; |
|
520 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(message_d)); |
|
521 |
|
522 typedef struct dropdown_d { |
|
523 uint32 disabled_state; |
|
524 uint32 hidden_state; |
|
525 WindowClass parent_wnd_class; |
|
526 WindowNumber parent_wnd_num; |
|
527 byte parent_button; |
|
528 byte num_items; |
|
529 byte selected_index; |
|
530 const StringID *items; |
|
531 byte click_delay; |
|
532 bool drag_mode; |
|
533 } dropdown_d; |
|
534 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(dropdown_d)); |
|
535 |
|
536 |
|
537 /****************** THESE ARE NOT WIDGET TYPES!!!!! *******************/ |
|
538 enum WindowWidgetBehaviours { |
|
539 WWB_PUSHBUTTON = 1 << 5, |
|
540 |
|
541 WWB_MASK = 0xE0, |
|
542 }; |
|
543 |
|
544 |
|
545 enum WindowWidgetTypes { |
|
546 WWT_EMPTY, |
|
547 |
|
548 WWT_PANEL, /* simple depressed panel */ |
|
549 WWT_INSET, /* pressed (inset) panel, most commonly used as combo box _text_ area */ |
|
550 WWT_IMGBTN, /* button with image */ |
|
551 WWT_IMGBTN_2, /* button with diff image when clicked */ |
|
552 |
|
553 WWT_TEXTBTN, /* button with text */ |
|
554 WWT_TEXTBTN_2, /* button with diff text when clicked */ |
|
555 WWT_LABEL, /* centered label */ |
|
556 WWT_MATRIX, |
|
557 WWT_SCROLLBAR, |
|
558 WWT_FRAME, /* frame */ |
|
559 WWT_CAPTION, |
|
560 |
|
561 WWT_HSCROLLBAR, |
|
562 WWT_STICKYBOX, |
|
563 WWT_SCROLL2BAR, /* 2nd vertical scrollbar*/ |
|
564 WWT_RESIZEBOX, |
|
565 WWT_CLOSEBOX, |
|
566 WWT_LAST, /* Last Item. use WIDGETS_END to fill up padding!! */ |
|
567 |
|
568 WWT_MASK = 0x1F, |
|
569 |
|
570 WWT_PUSHBTN = WWT_PANEL | WWB_PUSHBUTTON, |
|
571 WWT_PUSHTXTBTN = WWT_TEXTBTN | WWB_PUSHBUTTON, |
|
572 WWT_PUSHIMGBTN = WWT_IMGBTN | WWB_PUSHBUTTON, |
|
573 }; |
|
574 |
|
575 #define WIDGETS_END WWT_LAST, RESIZE_NONE, 0, 0, 0, 0, 0, 0, STR_NULL |
|
576 |
|
577 enum WindowFlags { |
|
578 WF_TIMEOUT_SHL = 0, |
|
579 WF_TIMEOUT_MASK = 7, |
|
580 WF_DRAGGING = 1 << 3, |
|
581 WF_SCROLL_UP = 1 << 4, |
|
582 WF_SCROLL_DOWN = 1 << 5, |
|
583 WF_SCROLL_MIDDLE = 1 << 6, |
|
584 WF_HSCROLL = 1 << 7, |
|
585 WF_SIZING = 1 << 8, |
|
586 WF_STICKY = 1 << 9, |
|
587 |
|
588 WF_DISABLE_VP_SCROLL = 1 << 10, |
|
589 |
|
590 WF_WHITE_BORDER_ONE = 1 << 11, |
|
591 WF_WHITE_BORDER_MASK = 1 << 12 | WF_WHITE_BORDER_ONE, |
|
592 WF_SCROLL2 = 1 << 13, |
|
593 }; |
|
594 |
|
595 /* window.c */ |
|
596 void CallWindowEventNP(Window *w, int event); |
|
597 void CallWindowTickEvent(void); |
|
598 void SetWindowDirty(const Window *w); |
|
599 void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, uint msg, uint wparam, uint lparam); |
|
600 void SendWindowMessageClass(WindowClass wnd_class, uint msg, uint wparam, uint lparam); |
|
601 |
|
602 Window *FindWindowById(WindowClass cls, WindowNumber number); |
|
603 void DeleteWindow(Window *w); |
|
604 void DeletePlayerWindows(PlayerID pi); |
|
605 void ChangeWindowOwner(PlayerID old_player, PlayerID new_player); |
|
606 Window *BringWindowToFrontById(WindowClass cls, WindowNumber number); |
|
607 Window *FindWindowFromPt(int x, int y); |
|
608 |
|
609 bool IsWindowOfPrototype(const Window *w, const Widget *widget); |
|
610 void AssignWidgetToWindow(Window *w, const Widget *widget); |
|
611 Window *AllocateWindow( |
|
612 int x, |
|
613 int y, |
|
614 int width, |
|
615 int height, |
|
616 WindowProc *proc, |
|
617 WindowClass cls, |
|
618 const Widget *widget); |
|
619 |
|
620 Window *AllocateWindowDesc(const WindowDesc *desc); |
|
621 Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number); |
|
622 |
|
623 void DrawWindowViewport(const Window *w); |
|
624 void ResizeWindow(Window *w, int x, int y); |
|
625 |
|
626 /** |
|
627 * Sets the enabled/disabled status of a widget. |
|
628 * By default, widgets are enabled. |
|
629 * On certain conditions, they have to be disabled. |
|
630 * @param w : Window on which the widget is located |
|
631 * @param widget_index : index of this widget in the window |
|
632 * @param disab_stat : status to use ie: disabled = true, enabled = false |
|
633 */ |
|
634 static inline void SetWindowWidgetDisabledState(Window *w, byte widget_index, bool disab_stat) |
|
635 { |
|
636 assert(widget_index < w->widget_count); |
|
637 SB(w->widget[widget_index].display_flags, WIDG_DISABLED, 1, !!disab_stat); |
|
638 } |
|
639 |
|
640 /** |
|
641 * Sets a widget to disabled. |
|
642 * @param w : Window on which the widget is located |
|
643 * @param widget_index : index of this widget in the window |
|
644 */ |
|
645 static inline void DisableWindowWidget(Window *w, byte widget_index) |
|
646 { |
|
647 SetWindowWidgetDisabledState(w, widget_index, true); |
|
648 } |
|
649 |
|
650 /** |
|
651 * Sets a widget to Enabled. |
|
652 * @param w : Window on which the widget is located |
|
653 * @param widget_index : index of this widget in the window |
|
654 */ |
|
655 static inline void EnableWindowWidget(Window *w, byte widget_index) |
|
656 { |
|
657 SetWindowWidgetDisabledState(w, widget_index, false); |
|
658 } |
|
659 |
|
660 /** |
|
661 * Gets the enabled/disabled status of a widget. |
|
662 * @param w : Window on which the widget is located |
|
663 * @param widget_index : index of this widget in the window |
|
664 * @return status of the widget ie: disabled = true, enabled = false |
|
665 */ |
|
666 static inline bool IsWindowWidgetDisabled(const Window *w, byte widget_index) |
|
667 { |
|
668 assert(widget_index < w->widget_count); |
|
669 return HASBIT(w->widget[widget_index].display_flags, WIDG_DISABLED); |
|
670 } |
|
671 |
|
672 /** |
|
673 * Sets the hidden/shown status of a widget. |
|
674 * By default, widgets are visible. |
|
675 * On certain conditions, they have to be hidden. |
|
676 * @param w Window on which the widget is located |
|
677 * @param widget_index index of this widget in the window |
|
678 * @param hidden_stat status to use ie. hidden = true, visible = false |
|
679 */ |
|
680 static inline void SetWindowWidgetHiddenState(Window *w, byte widget_index, bool hidden_stat) |
|
681 { |
|
682 assert(widget_index < w->widget_count); |
|
683 SB(w->widget[widget_index].display_flags, WIDG_HIDDEN, 1, !!hidden_stat); |
|
684 } |
|
685 |
|
686 /** |
|
687 * Sets a widget hidden. |
|
688 * @param w : Window on which the widget is located |
|
689 * @param widget_index : index of this widget in the window |
|
690 */ |
|
691 static inline void HideWindowWidget(Window *w, byte widget_index) |
|
692 { |
|
693 SetWindowWidgetHiddenState(w, widget_index, true); |
|
694 } |
|
695 |
|
696 /** |
|
697 * Sets a widget visible. |
|
698 * @param w : Window on which the widget is located |
|
699 * @param widget_index : index of this widget in the window |
|
700 */ |
|
701 static inline void ShowWindowWidget(Window *w, byte widget_index) |
|
702 { |
|
703 SetWindowWidgetHiddenState(w, widget_index, false); |
|
704 } |
|
705 |
|
706 /** |
|
707 * Gets the visibility of a widget. |
|
708 * @param w : Window on which the widget is located |
|
709 * @param widget_index : index of this widget in the window |
|
710 * @return status of the widget ie: hidden = true, visible = false |
|
711 */ |
|
712 static inline bool IsWindowWidgetHidden(const Window *w, byte widget_index) |
|
713 { |
|
714 assert(widget_index < w->widget_count); |
|
715 return HASBIT(w->widget[widget_index].display_flags, WIDG_HIDDEN); |
|
716 } |
|
717 |
|
718 /** |
|
719 * Sets the lowered/raised status of a widget. |
|
720 * @param w : Window on which the widget is located |
|
721 * @param widget_index : index of this widget in the window |
|
722 * @param hidden_stat : status to use ie: lowered = true, raised = false |
|
723 */ |
|
724 static inline void SetWindowWidgetLoweredState(Window *w, byte widget_index, bool lowered_stat) |
|
725 { |
|
726 assert(widget_index < w->widget_count); |
|
727 SB(w->widget[widget_index].display_flags, WIDG_LOWERED, 1, !!lowered_stat); |
|
728 } |
|
729 |
|
730 /** |
|
731 * Invert the lowered/raised status of a widget. |
|
732 * @param w : Window on which the widget is located |
|
733 * @param widget_index : index of this widget in the window |
|
734 */ |
|
735 static inline void ToggleWidgetLoweredState(Window *w, byte widget_index) |
|
736 { |
|
737 assert(widget_index < w->widget_count); |
|
738 TOGGLEBIT(w->widget[widget_index].display_flags, WIDG_LOWERED); |
|
739 } |
|
740 |
|
741 /** |
|
742 * Marks a widget as lowered. |
|
743 * @param w : Window on which the widget is located |
|
744 * @param widget_index : index of this widget in the window |
|
745 */ |
|
746 static inline void LowerWindowWidget(Window *w, byte widget_index) |
|
747 { |
|
748 SetWindowWidgetLoweredState(w, widget_index, true); |
|
749 } |
|
750 |
|
751 /** |
|
752 * Marks a widget as raised. |
|
753 * @param w : Window on which the widget is located |
|
754 * @param widget_index : index of this widget in the window |
|
755 */ |
|
756 static inline void RaiseWindowWidget(Window *w, byte widget_index) |
|
757 { |
|
758 SetWindowWidgetLoweredState(w, widget_index, false); |
|
759 } |
|
760 |
|
761 /** |
|
762 * Gets the lowered state of a widget. |
|
763 * @param w : Window on which the widget is located |
|
764 * @param widget_index : index of this widget in the window |
|
765 * @return status of the widget ie: lowered = true, raised= false |
|
766 */ |
|
767 static inline bool IsWindowWidgetLowered(const Window *w, byte widget_index) |
|
768 { |
|
769 assert(widget_index < w->widget_count); |
|
770 return HASBIT(w->widget[widget_index].display_flags, WIDG_LOWERED); |
|
771 } |
|
772 |
|
773 void InitWindowSystem(void); |
|
774 void UnInitWindowSystem(void); |
|
775 void ResetWindowSystem(void); |
|
776 int GetMenuItemIndex(const Window *w, int x, int y); |
|
777 void InputLoop(void); |
|
778 void HandleKeypress(uint32 key); |
|
779 void HandleMouseEvents(void); |
|
780 void UpdateWindows(void); |
|
781 void InvalidateWidget(const Window *w, byte widget_index); |
|
782 void InvalidateThisWindowData(Window *w); |
|
783 void InvalidateWindowData(WindowClass cls, WindowNumber number); |
|
784 void RaiseWindowButtons(Window *w); |
|
785 void RelocateAllWindows(int neww, int newh); |
|
786 int PositionMainToolbar(Window *w); |
|
787 void CDECL SetWindowWidgetsDisabledState(Window *w, bool disab_stat, int widgets, ...); |
|
788 void CDECL SetWindowWidgetsHiddenState(Window *w, bool hidden_stat, int widgets, ...); |
|
789 void CDECL SetWindowWidgetsLoweredState(Window *w, bool lowered_stat, int widgets, ...); |
|
790 |
|
791 /* misc_gui.c*/ |
|
792 void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint params[]); |
|
793 static inline void GuiShowTooltips(StringID str) |
|
794 { |
|
795 GuiShowTooltipsWithArgs(str, 0, NULL); |
|
796 } |
|
797 |
|
798 /* widget.c */ |
|
799 int GetWidgetFromPos(const Window *w, int x, int y); |
|
800 void DrawWindowWidgets(const Window *w); |
|
801 void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask); |
|
802 |
|
803 void HandleButtonClick(Window *w, byte widget); |
|
804 |
|
805 Window *GetCallbackWnd(void); |
|
806 void DeleteNonVitalWindows(void); |
|
807 void DeleteAllNonVitalWindows(void); |
|
808 void HideVitalWindows(void); |
|
809 void ShowVitalWindows(void); |
|
810 Window **FindWindowZPosition(const Window *w); |
|
811 |
|
812 /* window.c */ |
|
813 extern Window *_z_windows[]; |
|
814 extern Window **_last_z_window; |
|
815 #define FOR_ALL_WINDOWS(wz) for (wz = _z_windows; wz != _last_z_window; wz++) |
|
816 |
|
817 VARDEF Point _cursorpos_drag_start; |
|
818 |
|
819 VARDEF bool _left_button_down; |
|
820 VARDEF bool _left_button_clicked; |
|
821 |
|
822 VARDEF bool _right_button_down; |
|
823 VARDEF bool _right_button_clicked; |
|
824 |
|
825 VARDEF int _scrollbar_start_pos; |
|
826 VARDEF int _scrollbar_size; |
|
827 VARDEF byte _scroller_click_timeout; |
|
828 |
|
829 VARDEF bool _scrolling_scrollbar; |
|
830 VARDEF bool _scrolling_viewport; |
|
831 VARDEF bool _popup_menu_active; |
|
832 |
|
833 VARDEF byte _special_mouse_mode; |
|
834 enum SpecialMouseMode { |
|
835 WSM_NONE = 0, |
|
836 WSM_DRAGDROP = 1, |
|
837 WSM_SIZING = 2, |
|
838 WSM_PRESIZE = 3, |
|
839 }; |
|
840 |
|
841 void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y); |
|
842 |
|
843 #endif /* WINDOW_H */ |