author | rubidium |
Fri, 28 Mar 2008 10:32:55 +0000 | |
branch | noai |
changeset 9826 | 9707ad4c9b60 |
parent 9732 | f8eb3e208514 |
child 9837 | c9ec4f82e0d0 |
permissions | -rw-r--r-- |
9723 | 1 |
/* $Id$ */ |
2 |
||
3 |
/** @file window_gui.h Functions, definitions and such used only by the GUI. */ |
|
4 |
||
5 |
#ifndef WINDOW_GUI_H |
|
6 |
#define WINDOW_GUI_H |
|
7 |
||
8 |
#include "core/bitmath_func.hpp" |
|
9 |
#include "vehicle_type.h" |
|
10 |
#include "viewport_type.h" |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
11 |
#include "player_type.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
12 |
#include "strings_type.h" |
9723 | 13 |
|
14 |
/** |
|
15 |
* The maximum number of windows that can be opened. |
|
16 |
*/ |
|
17 |
static const int MAX_NUMBER_OF_WINDOWS = 25; |
|
18 |
||
19 |
typedef void WindowProc(Window *w, WindowEvent *e); |
|
20 |
||
21 |
/* How the resize system works: |
|
22 |
First, you need to add a WWT_RESIZEBOX to the widgets, and you need |
|
23 |
to add the flag WDF_RESIZABLE to the window. Now the window is ready |
|
24 |
to resize itself. |
|
25 |
As you may have noticed, all widgets have a RESIZE_XXX in their line. |
|
26 |
This lines controls how the widgets behave on resize. RESIZE_NONE means |
|
27 |
it doesn't do anything. Any other option let's one of the borders |
|
28 |
move with the changed width/height. So if a widget has |
|
29 |
RESIZE_RIGHT, and the window is made 5 pixels wider by the user, |
|
30 |
the right of the window will also be made 5 pixels wider. |
|
31 |
Now, what if you want to clamp a widget to the bottom? Give it the flag |
|
32 |
RESIZE_TB. This is RESIZE_TOP + RESIZE_BOTTOM. Now if the window gets |
|
33 |
5 pixels bigger, both the top and bottom gets 5 bigger, so the whole |
|
34 |
widgets moves downwards without resizing, and appears to be clamped |
|
35 |
to the bottom. Nice aint it? |
|
36 |
You should know one more thing about this system. Most windows can't |
|
37 |
handle an increase of 1 pixel. So there is a step function, which |
|
38 |
let the windowsize only be changed by X pixels. You configure this |
|
39 |
after making the window, like this: |
|
40 |
w->resize.step_height = 10; |
|
41 |
Now the window will only change in height in steps of 10. |
|
42 |
You can also give a minimum width and height. The default value is |
|
43 |
the default height/width of the window itself. You can change this |
|
44 |
AFTER window-creation, with: |
|
45 |
w->resize.width or w->resize.height. |
|
46 |
That was all.. good luck, and enjoy :) -- TrueLight */ |
|
47 |
||
48 |
enum ResizeFlag { |
|
49 |
RESIZE_NONE = 0, ///< no resize required |
|
50 |
||
51 |
RESIZE_LEFT = 1, ///< left resize flag |
|
52 |
RESIZE_RIGHT = 2, ///< rigth resize flag |
|
53 |
RESIZE_TOP = 4, ///< top resize flag |
|
54 |
RESIZE_BOTTOM = 8, ///< bottom resize flag |
|
55 |
||
56 |
RESIZE_LR = RESIZE_LEFT | RESIZE_RIGHT, ///< combination of left and right resize flags |
|
57 |
RESIZE_RB = RESIZE_RIGHT | RESIZE_BOTTOM, ///< combination of right and bottom resize flags |
|
58 |
RESIZE_TB = RESIZE_TOP | RESIZE_BOTTOM, ///< combination of top and bottom resize flags |
|
59 |
RESIZE_LRB = RESIZE_LEFT | RESIZE_RIGHT | RESIZE_BOTTOM, ///< combination of left, right and bottom resize flags |
|
60 |
RESIZE_LRTB = RESIZE_LEFT | RESIZE_RIGHT | RESIZE_TOP | RESIZE_BOTTOM, ///< combination of all resize flags |
|
61 |
RESIZE_RTB = RESIZE_RIGHT | RESIZE_TOP | RESIZE_BOTTOM, ///< combination of right, top and bottom resize flag |
|
62 |
||
63 |
/* The following flags are used by the system to specify what is disabled, hidden, or clicked |
|
64 |
* They are used in the same place as the above RESIZE_x flags, Widget visual_flags. |
|
65 |
* These states are used in exceptions. If nothing is specified, they will indicate |
|
66 |
* Enabled, visible or unclicked widgets*/ |
|
67 |
WIDG_DISABLED = 4, ///< widget is greyed out, not available |
|
68 |
WIDG_HIDDEN = 5, ///< widget is made invisible |
|
69 |
WIDG_LOWERED = 6, ///< widget is paint lowered, a pressed button in fact |
|
70 |
}; |
|
71 |
||
72 |
enum { |
|
73 |
WIDGET_LIST_END = -1, ///< indicate the end of widgets' list for vararg functions |
|
74 |
}; |
|
75 |
||
76 |
struct Widget { |
|
77 |
byte type; ///< Widget type, see WindowWidgetTypes |
|
78 |
byte display_flags; ///< Resize direction, alignment, etc. during resizing, see ResizeFlags |
|
79 |
byte color; ///< Widget colour, see docs/ottd-colourtext-palette.png |
|
80 |
int16 left, right, top, bottom; ///< The position offsets inside the window |
|
81 |
uint16 data; ///< The String/Image or special code (list-matrixes) of a widget |
|
82 |
StringID tooltips; ///< Tooltips that are shown when rightclicking on a widget |
|
83 |
}; |
|
84 |
||
85 |
enum FrameFlags { |
|
86 |
FR_NONE = 0, |
|
87 |
FR_TRANSPARENT = 1 << 0, ///< Makes the background transparent if set |
|
88 |
FR_BORDERONLY = 1 << 4, ///< Draw border only, no background |
|
89 |
FR_LOWERED = 1 << 5, ///< If set the frame is lowered and the background color brighter (ie. buttons when pressed) |
|
90 |
FR_DARKENED = 1 << 6, ///< If set the background is darker, allows for lowered frames with normal background color when used with FR_LOWERED (ie. dropdown boxes) |
|
91 |
}; |
|
92 |
||
93 |
DECLARE_ENUM_AS_BIT_SET(FrameFlags); |
|
94 |
||
95 |
void DrawFrameRect(int left, int top, int right, int bottom, int color, FrameFlags flags); |
|
96 |
||
97 |
enum WindowEventCodes { |
|
98 |
WE_CREATE, |
|
99 |
WE_DESTROY, |
|
100 |
WE_PAINT, |
|
101 |
WE_KEYPRESS, |
|
102 |
WE_CLICK, |
|
103 |
WE_DOUBLE_CLICK, |
|
104 |
WE_RCLICK, |
|
105 |
WE_MOUSEOVER, |
|
106 |
WE_MOUSELOOP, |
|
107 |
WE_MOUSEWHEEL, |
|
108 |
WE_TICK, |
|
109 |
WE_4, |
|
110 |
WE_TIMEOUT, |
|
111 |
WE_PLACE_OBJ, |
|
112 |
WE_ABORT_PLACE_OBJ, |
|
113 |
WE_ON_EDIT_TEXT, |
|
114 |
WE_ON_EDIT_TEXT_CANCEL, |
|
115 |
WE_POPUPMENU_SELECT, |
|
116 |
WE_POPUPMENU_OVER, |
|
117 |
WE_DRAGDROP, |
|
118 |
WE_PLACE_DRAG, |
|
119 |
WE_PLACE_MOUSEUP, |
|
120 |
WE_PLACE_PRESIZE, |
|
121 |
WE_DROPDOWN_SELECT, |
|
122 |
WE_RESIZE, |
|
123 |
WE_MESSAGE, |
|
124 |
WE_SCROLL, |
|
125 |
WE_INVALIDATE_DATA, |
|
9732 | 126 |
WE_CTRL_CHANGED, |
9723 | 127 |
}; |
128 |
||
129 |
struct WindowEvent { |
|
130 |
byte event; |
|
131 |
union { |
|
132 |
struct { |
|
133 |
void *data; |
|
134 |
} create; |
|
135 |
||
136 |
struct { |
|
137 |
Point pt; |
|
138 |
int widget; |
|
139 |
} click; |
|
140 |
||
141 |
struct { |
|
142 |
Point pt; |
|
143 |
TileIndex tile; |
|
144 |
TileIndex starttile; |
|
145 |
ViewportPlaceMethod select_method; |
|
146 |
byte select_proc; |
|
147 |
} place; |
|
148 |
||
149 |
struct { |
|
150 |
Point pt; |
|
151 |
int widget; |
|
152 |
} dragdrop; |
|
153 |
||
154 |
struct { |
|
155 |
Point size; |
|
156 |
Point diff; |
|
157 |
} sizing; |
|
158 |
||
159 |
struct { |
|
160 |
char *str; |
|
161 |
} edittext; |
|
162 |
||
163 |
struct { |
|
164 |
Point pt; |
|
165 |
} popupmenu; |
|
166 |
||
167 |
struct { |
|
168 |
int button; |
|
169 |
int index; |
|
170 |
} dropdown; |
|
171 |
||
172 |
struct { |
|
173 |
Point pt; |
|
174 |
int widget; |
|
175 |
} mouseover; |
|
176 |
||
177 |
struct { |
|
178 |
bool cont; ///< continue the search? (default true) |
|
179 |
uint16 key; ///< 16-bit Unicode value of the key |
|
180 |
uint16 keycode; ///< untranslated key (including shift-state) |
|
181 |
} keypress; |
|
182 |
||
183 |
struct { |
|
184 |
int msg; ///< message to be sent |
|
185 |
int wparam; ///< additional message-specific information |
|
186 |
int lparam; ///< additional message-specific information |
|
187 |
} message; |
|
188 |
||
189 |
struct { |
|
190 |
Point delta; ///< delta position against position of last call |
|
191 |
} scroll; |
|
192 |
||
193 |
struct { |
|
194 |
int wheel; ///< how much was 'wheel'd' |
|
195 |
} wheel; |
|
9732 | 196 |
|
197 |
struct { |
|
198 |
bool cont; ///< continue the search? (default true) |
|
199 |
} ctrl; |
|
9723 | 200 |
} we; |
201 |
}; |
|
202 |
||
203 |
struct WindowDesc { |
|
204 |
int16 left, top, minimum_width, minimum_height, default_width, default_height; |
|
205 |
WindowClass cls; |
|
206 |
WindowClass parent_cls; |
|
207 |
uint32 flags; |
|
208 |
const Widget *widgets; |
|
209 |
WindowProc *proc; |
|
210 |
}; |
|
211 |
||
212 |
enum WindowDefaultFlag { |
|
213 |
WDF_STD_TOOLTIPS = 1 << 0, ///< use standard routine when displaying tooltips |
|
214 |
WDF_DEF_WIDGET = 1 << 1, ///< default widget control for some widgets in the on click event |
|
215 |
WDF_STD_BTN = 1 << 2, ///< default handling for close and drag widgets (widget no 0 and 1) |
|
216 |
||
217 |
WDF_UNCLICK_BUTTONS = 1 << 4, ///< Unclick buttons when the window event times out */ |
|
218 |
WDF_STICKY_BUTTON = 1 << 5, ///< Set window to sticky mode; they are not closed unless closed with 'X' (widget 2) |
|
219 |
WDF_RESIZABLE = 1 << 6, ///< A window can be resized |
|
220 |
WDF_MODAL = 1 << 7, ///< The window is a modal child of some other window, meaning the parent is 'inactive' |
|
221 |
}; |
|
222 |
||
223 |
/* can be used as x or y coordinates to cause a specific placement */ |
|
224 |
enum WindowDefaultPosition { |
|
225 |
WDP_AUTO = -1, ///< Find a place automatically |
|
226 |
WDP_CENTER = -2, ///< Center the window (left/right or top/bottom) |
|
227 |
WDP_ALIGN_TBR = -3, ///< Align the right side of the window with the right side of the main toolbar |
|
228 |
WDP_ALIGN_TBL = -4, ///< Align the left side of the window with the left side of the main toolbar |
|
229 |
}; |
|
230 |
||
231 |
#define WP(ptr, str) (*(str*)(ptr)->custom) |
|
232 |
||
233 |
struct Scrollbar { |
|
234 |
uint16 count, cap, pos; |
|
235 |
}; |
|
236 |
||
237 |
struct ResizeInfo { |
|
238 |
uint width; ///< Minimum width and height |
|
239 |
uint height; |
|
240 |
uint step_width; ///< In how big steps the width and height go |
|
241 |
uint step_height; |
|
242 |
}; |
|
243 |
||
244 |
struct WindowMessage { |
|
245 |
int msg; |
|
246 |
int wparam; |
|
247 |
int lparam; |
|
248 |
}; |
|
249 |
||
250 |
struct Window { |
|
251 |
uint16 flags4; |
|
252 |
WindowClass window_class; |
|
253 |
WindowNumber window_number; |
|
254 |
||
255 |
int left, top; |
|
256 |
int width, height; |
|
257 |
||
258 |
Scrollbar hscroll, vscroll, vscroll2; |
|
259 |
ResizeInfo resize; |
|
260 |
||
261 |
byte caption_color; |
|
262 |
||
263 |
WindowProc *wndproc; |
|
264 |
ViewPort *viewport; |
|
265 |
const Widget *original_widget; |
|
266 |
Widget *widget; |
|
267 |
uint widget_count; |
|
268 |
uint32 desc_flags; |
|
269 |
||
270 |
WindowMessage message; |
|
271 |
Window *parent; |
|
272 |
byte custom[WINDOW_CUSTOM_SIZE]; |
|
273 |
||
274 |
void HandleButtonClick(byte widget); |
|
275 |
||
276 |
void SetWidgetDisabledState(byte widget_index, bool disab_stat); |
|
277 |
void DisableWidget(byte widget_index); |
|
278 |
void EnableWidget(byte widget_index); |
|
279 |
bool IsWidgetDisabled(byte widget_index) const; |
|
280 |
void SetWidgetHiddenState(byte widget_index, bool hidden_stat); |
|
281 |
void HideWidget(byte widget_index); |
|
282 |
void ShowWidget(byte widget_index); |
|
283 |
bool IsWidgetHidden(byte widget_index) const; |
|
284 |
void SetWidgetLoweredState(byte widget_index, bool lowered_stat); |
|
285 |
void ToggleWidgetLoweredState(byte widget_index); |
|
286 |
void LowerWidget(byte widget_index); |
|
287 |
void RaiseWidget(byte widget_index); |
|
288 |
bool IsWidgetLowered(byte widget_index) const; |
|
289 |
||
290 |
void RaiseButtons(); |
|
291 |
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets, ...); |
|
292 |
void CDECL SetWidgetsHiddenState(bool hidden_stat, int widgets, ...); |
|
293 |
void CDECL SetWidgetsLoweredState(bool lowered_stat, int widgets, ...); |
|
294 |
void InvalidateWidget(byte widget_index) const; |
|
295 |
}; |
|
296 |
||
297 |
struct menu_d { |
|
298 |
byte item_count; ///< follow_vehicle |
|
299 |
byte sel_index; ///< scrollpos_x |
|
300 |
byte main_button; ///< scrollpos_y |
|
301 |
byte action_id; |
|
302 |
StringID string_id; ///< unk30 |
|
303 |
uint16 checked_items; ///< unk32 |
|
304 |
byte disabled_items; |
|
305 |
}; |
|
306 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(menu_d)); |
|
307 |
||
308 |
struct def_d { |
|
309 |
int16 data_1, data_2, data_3; |
|
310 |
int16 data_4, data_5; |
|
311 |
bool close; |
|
312 |
byte byte_1; |
|
313 |
}; |
|
314 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(def_d)); |
|
315 |
||
316 |
struct void_d { |
|
317 |
void *data; |
|
318 |
}; |
|
319 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(void_d)); |
|
320 |
||
321 |
struct tree_d { |
|
322 |
uint16 base; |
|
323 |
uint16 count; |
|
324 |
}; |
|
325 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(tree_d)); |
|
326 |
||
327 |
struct tooltips_d { |
|
328 |
StringID string_id; |
|
329 |
byte paramcount; |
|
330 |
uint64 params[5]; |
|
331 |
}; |
|
332 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(tooltips_d)); |
|
333 |
||
334 |
struct replaceveh_d { |
|
335 |
byte sel_index[2]; |
|
336 |
EngineID sel_engine[2]; |
|
337 |
uint16 count[2]; |
|
338 |
bool wagon_btnstate; ///< true means engine is selected |
|
339 |
EngineList list[2]; |
|
340 |
bool update_left; |
|
341 |
bool update_right; |
|
342 |
bool init_lists; |
|
343 |
GroupID sel_group; |
|
344 |
}; |
|
345 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(replaceveh_d)); |
|
346 |
||
347 |
struct depot_d { |
|
348 |
VehicleID sel; |
|
349 |
VehicleType type; |
|
350 |
bool generate_list; |
|
351 |
uint16 engine_list_length; |
|
352 |
uint16 wagon_list_length; |
|
353 |
uint16 engine_count; |
|
354 |
uint16 wagon_count; |
|
355 |
Vehicle **vehicle_list; |
|
356 |
Vehicle **wagon_list; |
|
357 |
}; |
|
358 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(depot_d)); |
|
359 |
||
360 |
struct order_d { |
|
361 |
int sel; |
|
362 |
}; |
|
363 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(order_d)); |
|
364 |
||
365 |
struct vehicledetails_d { |
|
366 |
byte tab; |
|
367 |
}; |
|
368 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vehicledetails_d)); |
|
369 |
||
370 |
struct smallmap_d { |
|
371 |
int32 scroll_x; |
|
372 |
int32 scroll_y; |
|
373 |
int32 subscroll; |
|
374 |
}; |
|
375 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(smallmap_d)); |
|
376 |
||
377 |
struct refit_d { |
|
378 |
int sel; |
|
379 |
struct RefitOption *cargo; |
|
380 |
struct RefitList *list; |
|
381 |
uint length; |
|
382 |
VehicleOrderID order; |
|
383 |
}; |
|
384 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(refit_d)); |
|
385 |
||
386 |
struct vp_d { |
|
387 |
VehicleID follow_vehicle; |
|
388 |
int32 scrollpos_x; |
|
389 |
int32 scrollpos_y; |
|
390 |
int32 dest_scrollpos_x; |
|
391 |
int32 dest_scrollpos_y; |
|
392 |
}; |
|
393 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vp_d)); |
|
394 |
||
395 |
struct highscore_d { |
|
396 |
uint32 background_img; |
|
397 |
int8 rank; |
|
398 |
}; |
|
399 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(highscore_d)); |
|
400 |
||
401 |
struct scroller_d { |
|
402 |
int height; |
|
403 |
uint16 counter; |
|
404 |
}; |
|
405 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(scroller_d)); |
|
406 |
||
407 |
enum SortListFlags { |
|
408 |
VL_NONE = 0, ///< no sort |
|
409 |
VL_DESC = 1 << 0, ///< sort descending or ascending |
|
410 |
VL_RESORT = 1 << 1, ///< instruct the code to resort the list in the next loop |
|
411 |
VL_REBUILD = 1 << 2, ///< create sort-listing to use for qsort and friends |
|
412 |
VL_END = 1 << 3, |
|
413 |
}; |
|
414 |
||
415 |
DECLARE_ENUM_AS_BIT_SET(SortListFlags); |
|
416 |
||
417 |
struct Listing { |
|
418 |
bool order; ///< Ascending/descending |
|
419 |
byte criteria; ///< Sorting criteria |
|
420 |
}; |
|
421 |
||
422 |
struct list_d { |
|
423 |
uint16 list_length; ///< length of the list being sorted |
|
424 |
byte sort_type; ///< what criteria to sort on |
|
425 |
SortListFlags flags; ///< used to control sorting/resorting/etc. |
|
426 |
uint16 resort_timer; ///< resort list after a given amount of ticks if set |
|
427 |
}; |
|
428 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(list_d)); |
|
429 |
||
430 |
struct message_d { |
|
431 |
int msg; |
|
432 |
int wparam; |
|
433 |
int lparam; |
|
434 |
}; |
|
435 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(message_d)); |
|
436 |
||
437 |
struct vehiclelist_d { |
|
438 |
const Vehicle** sort_list; // List of vehicles (sorted) |
|
439 |
Listing *_sorting; // pointer to the appropiate subcategory of _sorting |
|
440 |
uint16 length_of_sort_list; // Keeps track of how many vehicle pointers sort list got space for |
|
441 |
VehicleType vehicle_type; // The vehicle type that is sorted |
|
442 |
list_d l; // General list struct |
|
443 |
}; |
|
444 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vehiclelist_d)); |
|
445 |
||
446 |
struct grouplist_d { |
|
447 |
const Group **sort_list; |
|
448 |
list_d l; // General list struct |
|
449 |
}; |
|
450 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(grouplist_d)); |
|
451 |
||
452 |
struct groupveh_d : vehiclelist_d { |
|
453 |
GroupID group_sel; |
|
454 |
VehicleID vehicle_sel; |
|
455 |
||
456 |
grouplist_d gl; |
|
457 |
}; |
|
458 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(groupveh_d)); |
|
459 |
||
460 |
/****************** THESE ARE NOT WIDGET TYPES!!!!! *******************/ |
|
461 |
enum WindowWidgetBehaviours { |
|
462 |
WWB_PUSHBUTTON = 1 << 5, |
|
463 |
||
464 |
WWB_MASK = 0xE0, |
|
465 |
}; |
|
466 |
||
467 |
||
468 |
enum WindowWidgetTypes { |
|
469 |
WWT_EMPTY, |
|
470 |
||
471 |
WWT_PANEL, ///< simple depressed panel |
|
472 |
WWT_INSET, ///< pressed (inset) panel, most commonly used as combo box _text_ area |
|
473 |
WWT_IMGBTN, ///< button with image |
|
474 |
WWT_IMGBTN_2, ///< button with diff image when clicked |
|
475 |
||
476 |
WWT_TEXTBTN, ///< button with text |
|
477 |
WWT_TEXTBTN_2, ///< button with diff text when clicked |
|
478 |
WWT_LABEL, ///< centered label |
|
479 |
WWT_TEXT, ///< pure simple text |
|
480 |
WWT_MATRIX, |
|
481 |
WWT_SCROLLBAR, |
|
482 |
WWT_FRAME, ///< frame |
|
483 |
WWT_CAPTION, |
|
484 |
||
485 |
WWT_HSCROLLBAR, |
|
486 |
WWT_STICKYBOX, |
|
487 |
WWT_SCROLL2BAR, ///< 2nd vertical scrollbar |
|
488 |
WWT_RESIZEBOX, |
|
489 |
WWT_CLOSEBOX, |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
490 |
WWT_DROPDOWN, ///< Raised drop down list (regular) |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
491 |
WWT_DROPDOWNIN, ///< Inset drop down list (used on game options only) |
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
492 |
WWT_EDITBOX, ///< a textbox for typing (don't forget to call ShowOnScreenKeyboard() when clicked) |
9723 | 493 |
WWT_LAST, ///< Last Item. use WIDGETS_END to fill up padding!! |
494 |
||
495 |
WWT_MASK = 0x1F, |
|
496 |
||
497 |
WWT_PUSHBTN = WWT_PANEL | WWB_PUSHBUTTON, |
|
498 |
WWT_PUSHTXTBTN = WWT_TEXTBTN | WWB_PUSHBUTTON, |
|
499 |
WWT_PUSHIMGBTN = WWT_IMGBTN | WWB_PUSHBUTTON, |
|
500 |
}; |
|
501 |
||
502 |
#define WIDGETS_END WWT_LAST, RESIZE_NONE, 0, 0, 0, 0, 0, 0, STR_NULL |
|
503 |
||
504 |
enum WindowFlags { |
|
505 |
WF_TIMEOUT_SHL = 0, |
|
506 |
WF_TIMEOUT_MASK = 7, |
|
507 |
WF_DRAGGING = 1 << 3, |
|
508 |
WF_SCROLL_UP = 1 << 4, |
|
509 |
WF_SCROLL_DOWN = 1 << 5, |
|
510 |
WF_SCROLL_MIDDLE = 1 << 6, |
|
511 |
WF_HSCROLL = 1 << 7, |
|
512 |
WF_SIZING = 1 << 8, |
|
513 |
WF_STICKY = 1 << 9, |
|
514 |
||
515 |
WF_DISABLE_VP_SCROLL = 1 << 10, |
|
516 |
||
517 |
WF_WHITE_BORDER_ONE = 1 << 11, |
|
518 |
WF_WHITE_BORDER_MASK = 1 << 12 | WF_WHITE_BORDER_ONE, |
|
519 |
WF_SCROLL2 = 1 << 13, |
|
520 |
}; |
|
521 |
||
522 |
/* window.cpp */ |
|
523 |
void CallWindowEventNP(Window *w, int event); |
|
524 |
void CallWindowTickEvent(); |
|
525 |
||
526 |
/** |
|
527 |
* Marks the window as dirty for repaint. |
|
528 |
* |
|
529 |
* @ingroup dirty |
|
530 |
*/ |
|
531 |
void SetWindowDirty(const Window *w); |
|
532 |
void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, int msg, int wparam, int lparam); |
|
533 |
void SendWindowMessageClass(WindowClass wnd_class, int msg, int wparam, int lparam); |
|
534 |
||
535 |
Window *FindWindowById(WindowClass cls, WindowNumber number); |
|
536 |
void DeleteWindow(Window *w); |
|
537 |
void DeletePlayerWindows(PlayerID pi); |
|
538 |
void ChangeWindowOwner(PlayerID old_player, PlayerID new_player); |
|
539 |
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number); |
|
540 |
Window *FindWindowFromPt(int x, int y); |
|
541 |
||
542 |
bool IsWindowOfPrototype(const Window *w, const Widget *widget); |
|
543 |
void AssignWidgetToWindow(Window *w, const Widget *widget); |
|
544 |
Window *AllocateWindow( |
|
545 |
int x, |
|
546 |
int y, |
|
547 |
int width, |
|
548 |
int height, |
|
549 |
WindowProc *proc, |
|
550 |
WindowClass cls, |
|
551 |
const Widget *widget, |
|
552 |
void *data = NULL); |
|
553 |
||
554 |
Window *AllocateWindowDesc(const WindowDesc *desc, void *data = NULL); |
|
555 |
Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number, void *data = NULL); |
|
556 |
||
557 |
void DrawWindowViewport(const Window *w); |
|
558 |
void ResizeWindow(Window *w, int x, int y); |
|
559 |
||
560 |
void InitWindowSystem(); |
|
561 |
void UnInitWindowSystem(); |
|
562 |
void ResetWindowSystem(); |
|
563 |
int GetMenuItemIndex(const Window *w, int x, int y); |
|
564 |
void InputLoop(); |
|
565 |
void InvalidateThisWindowData(Window *w); |
|
566 |
void InvalidateWindowData(WindowClass cls, WindowNumber number); |
|
567 |
void RelocateAllWindows(int neww, int newh); |
|
568 |
||
569 |
/* misc_gui.cpp */ |
|
570 |
void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint64 params[]); |
|
571 |
static inline void GuiShowTooltips(StringID str) |
|
572 |
{ |
|
573 |
GuiShowTooltipsWithArgs(str, 0, NULL); |
|
574 |
} |
|
575 |
||
576 |
/* widget.cpp */ |
|
577 |
int GetWidgetFromPos(const Window *w, int x, int y); |
|
578 |
void DrawWindowWidgets(const Window *w); |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
579 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
580 |
enum SortButtonState { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
581 |
SBS_OFF, |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
582 |
SBS_DOWN, |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
583 |
SBS_UP, |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
584 |
}; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
585 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
586 |
void DrawSortButtonState(const Window *w, int widget, SortButtonState state); |
9723 | 587 |
|
588 |
||
589 |
Window *GetCallbackWnd(); |
|
590 |
void DeleteNonVitalWindows(); |
|
591 |
void DeleteAllNonVitalWindows(); |
|
592 |
void HideVitalWindows(); |
|
593 |
void ShowVitalWindows(); |
|
594 |
Window **FindWindowZPosition(const Window *w); |
|
595 |
||
596 |
/* window.cpp */ |
|
597 |
extern Window *_z_windows[]; |
|
598 |
extern Window **_last_z_window; |
|
599 |
#define FOR_ALL_WINDOWS(wz) for (wz = _z_windows; wz != _last_z_window; wz++) |
|
600 |
||
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
601 |
extern Point _cursorpos_drag_start; |
9723 | 602 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
603 |
extern int _scrollbar_start_pos; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
604 |
extern int _scrollbar_size; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
605 |
extern byte _scroller_click_timeout; |
9723 | 606 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
607 |
extern bool _scrolling_scrollbar; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
608 |
extern bool _scrolling_viewport; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
609 |
extern bool _popup_menu_active; |
9723 | 610 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
611 |
extern byte _special_mouse_mode; |
9723 | 612 |
enum SpecialMouseMode { |
613 |
WSM_NONE = 0, |
|
614 |
WSM_DRAGDROP = 1, |
|
615 |
WSM_SIZING = 2, |
|
616 |
WSM_PRESIZE = 3, |
|
617 |
}; |
|
618 |
||
619 |
void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y); |
|
620 |
||
621 |
/** Evenly distribute some widgets when resizing horizontally (often a button row) |
|
622 |
* The widgets are presumed to be in a line and numberef from left to right (without gaps) |
|
623 |
* @param w widow to modify |
|
624 |
* @param left The leftmost widget to resize |
|
625 |
* @param right The rightmost widget to resize. Since right side of it is used, remember to set it to RESIZE_RIGHT |
|
626 |
*/ |
|
627 |
void ResizeButtons(Window *w, byte left, byte right); |
|
628 |
||
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
629 |
/** Resize a widget an shuffle other widgets around to fit. |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
630 |
*/ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
631 |
void ResizeWindowForWidget(Window *w, int widget, int delta_x, int delta_y); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
632 |
|
9723 | 633 |
|
634 |
/** |
|
635 |
* Sets the enabled/disabled status of a widget. |
|
636 |
* By default, widgets are enabled. |
|
637 |
* On certain conditions, they have to be disabled. |
|
638 |
* @param widget_index : index of this widget in the window |
|
639 |
* @param disab_stat : status to use ie: disabled = true, enabled = false |
|
640 |
*/ |
|
641 |
inline void Window::SetWidgetDisabledState(byte widget_index, bool disab_stat) |
|
642 |
{ |
|
643 |
assert(widget_index < this->widget_count); |
|
644 |
SB(this->widget[widget_index].display_flags, WIDG_DISABLED, 1, !!disab_stat); |
|
645 |
} |
|
646 |
||
647 |
/** |
|
648 |
* Sets a widget to disabled. |
|
649 |
* @param widget_index : index of this widget in the window |
|
650 |
*/ |
|
651 |
inline void Window::DisableWidget(byte widget_index) |
|
652 |
{ |
|
653 |
SetWidgetDisabledState(widget_index, true); |
|
654 |
} |
|
655 |
||
656 |
/** |
|
657 |
* Sets a widget to Enabled. |
|
658 |
* @param widget_index : index of this widget in the window |
|
659 |
*/ |
|
660 |
inline void Window::EnableWidget(byte widget_index) |
|
661 |
{ |
|
662 |
SetWidgetDisabledState(widget_index, false); |
|
663 |
} |
|
664 |
||
665 |
/** |
|
666 |
* Gets the enabled/disabled status of a widget. |
|
667 |
* @param widget_index : index of this widget in the window |
|
668 |
* @return status of the widget ie: disabled = true, enabled = false |
|
669 |
*/ |
|
670 |
inline bool Window::IsWidgetDisabled(byte widget_index) const |
|
671 |
{ |
|
672 |
assert(widget_index < this->widget_count); |
|
673 |
return HasBit(this->widget[widget_index].display_flags, WIDG_DISABLED); |
|
674 |
} |
|
675 |
||
676 |
/** |
|
677 |
* Sets the hidden/shown status of a widget. |
|
678 |
* By default, widgets are visible. |
|
679 |
* On certain conditions, they have to be hidden. |
|
680 |
* @param widget_index index of this widget in the window |
|
681 |
* @param hidden_stat status to use ie. hidden = true, visible = false |
|
682 |
*/ |
|
683 |
inline void Window::SetWidgetHiddenState(byte widget_index, bool hidden_stat) |
|
684 |
{ |
|
685 |
assert(widget_index < this->widget_count); |
|
686 |
SB(this->widget[widget_index].display_flags, WIDG_HIDDEN, 1, !!hidden_stat); |
|
687 |
} |
|
688 |
||
689 |
/** |
|
690 |
* Sets a widget hidden. |
|
691 |
* @param widget_index : index of this widget in the window |
|
692 |
*/ |
|
693 |
inline void Window::HideWidget(byte widget_index) |
|
694 |
{ |
|
695 |
SetWidgetHiddenState(widget_index, true); |
|
696 |
} |
|
697 |
||
698 |
/** |
|
699 |
* Sets a widget visible. |
|
700 |
* @param widget_index : index of this widget in the window |
|
701 |
*/ |
|
702 |
inline void Window::ShowWidget(byte widget_index) |
|
703 |
{ |
|
704 |
SetWidgetHiddenState(widget_index, false); |
|
705 |
} |
|
706 |
||
707 |
/** |
|
708 |
* Gets the visibility of a widget. |
|
709 |
* @param widget_index : index of this widget in the window |
|
710 |
* @return status of the widget ie: hidden = true, visible = false |
|
711 |
*/ |
|
712 |
inline bool Window::IsWidgetHidden(byte widget_index) const |
|
713 |
{ |
|
714 |
assert(widget_index < this->widget_count); |
|
715 |
return HasBit(this->widget[widget_index].display_flags, WIDG_HIDDEN); |
|
716 |
} |
|
717 |
||
718 |
/** |
|
719 |
* Sets the lowered/raised status of a widget. |
|
720 |
* @param widget_index : index of this widget in the window |
|
721 |
* @param lowered_stat : status to use ie: lowered = true, raised = false |
|
722 |
*/ |
|
723 |
inline void Window::SetWidgetLoweredState(byte widget_index, bool lowered_stat) |
|
724 |
{ |
|
725 |
assert(widget_index < this->widget_count); |
|
726 |
SB(this->widget[widget_index].display_flags, WIDG_LOWERED, 1, !!lowered_stat); |
|
727 |
} |
|
728 |
||
729 |
/** |
|
730 |
* Invert the lowered/raised status of a widget. |
|
731 |
* @param widget_index : index of this widget in the window |
|
732 |
*/ |
|
733 |
inline void Window::ToggleWidgetLoweredState(byte widget_index) |
|
734 |
{ |
|
735 |
assert(widget_index < this->widget_count); |
|
736 |
ToggleBit(this->widget[widget_index].display_flags, WIDG_LOWERED); |
|
737 |
} |
|
738 |
||
739 |
/** |
|
740 |
* Marks a widget as lowered. |
|
741 |
* @param widget_index : index of this widget in the window |
|
742 |
*/ |
|
743 |
inline void Window::LowerWidget(byte widget_index) |
|
744 |
{ |
|
745 |
SetWidgetLoweredState(widget_index, true); |
|
746 |
} |
|
747 |
||
748 |
/** |
|
749 |
* Marks a widget as raised. |
|
750 |
* @param widget_index : index of this widget in the window |
|
751 |
*/ |
|
752 |
inline void Window::RaiseWidget(byte widget_index) |
|
753 |
{ |
|
754 |
SetWidgetLoweredState(widget_index, false); |
|
755 |
} |
|
756 |
||
757 |
/** |
|
758 |
* Gets the lowered state of a widget. |
|
759 |
* @param widget_index : index of this widget in the window |
|
760 |
* @return status of the widget ie: lowered = true, raised= false |
|
761 |
*/ |
|
762 |
inline bool Window::IsWidgetLowered(byte widget_index) const |
|
763 |
{ |
|
764 |
assert(widget_index < this->widget_count); |
|
765 |
return HasBit(this->widget[widget_index].display_flags, WIDG_LOWERED); |
|
766 |
} |
|
767 |
||
768 |
#endif /* WINDOW_GUI_H */ |