71 |
71 |
72 enum { |
72 enum { |
73 WIDGET_LIST_END = -1, ///< indicate the end of widgets' list for vararg functions |
73 WIDGET_LIST_END = -1, ///< indicate the end of widgets' list for vararg functions |
74 }; |
74 }; |
75 |
75 |
|
76 /** |
|
77 * Window widget data structure |
|
78 */ |
76 struct Widget { |
79 struct Widget { |
77 byte type; ///< Widget type, see WindowWidgetTypes |
80 byte type; ///< Widget type, see WindowWidgetTypes |
78 byte display_flags; ///< Resize direction, alignment, etc. during resizing, see ResizeFlags |
81 byte display_flags; ///< Resize direction, alignment, etc. during resizing, see ResizeFlags |
79 byte color; ///< Widget colour, see docs/ottd-colourtext-palette.png |
82 byte color; ///< Widget colour, see docs/ottd-colourtext-palette.png |
80 int16 left, right, top, bottom; ///< The position offsets inside the window |
83 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 |
84 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 |
85 StringID tooltips; ///< Tooltips that are shown when rightclicking on a widget |
83 }; |
86 }; |
84 |
87 |
|
88 /** |
|
89 * Flags to describe the look of the frame |
|
90 */ |
85 enum FrameFlags { |
91 enum FrameFlags { |
86 FR_NONE = 0, |
92 FR_NONE = 0, |
87 FR_TRANSPARENT = 1 << 0, ///< Makes the background transparent if set |
93 FR_TRANSPARENT = 1 << 0, ///< Makes the background transparent if set |
88 FR_BORDERONLY = 1 << 4, ///< Draw border only, no background |
94 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) |
95 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) |
96 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 }; |
97 }; |
92 |
98 |
93 DECLARE_ENUM_AS_BIT_SET(FrameFlags); |
99 DECLARE_ENUM_AS_BIT_SET(FrameFlags); |
94 |
100 |
|
101 /* wiget.cpp */ |
95 void DrawFrameRect(int left, int top, int right, int bottom, int color, FrameFlags flags); |
102 void DrawFrameRect(int left, int top, int right, int bottom, int color, FrameFlags flags); |
96 |
103 |
|
104 /** |
|
105 * Available window events |
|
106 */ |
97 enum WindowEventCodes { |
107 enum WindowEventCodes { |
98 WE_CREATE, |
108 WE_CREATE, ///< Initialize the Window |
99 WE_DESTROY, |
109 WE_DESTROY, ///< Prepare for deletion of the window |
100 WE_PAINT, |
110 WE_PAINT, ///< Repaint the window contents |
101 WE_KEYPRESS, |
111 WE_KEYPRESS, ///< Key pressed |
102 WE_CLICK, |
112 WE_CLICK, ///< Left mouse button click |
103 WE_DOUBLE_CLICK, |
113 WE_DOUBLE_CLICK, ///< Left mouse button double click |
104 WE_RCLICK, |
114 WE_RCLICK, ///< Right mouse button click |
105 WE_MOUSEOVER, |
115 WE_MOUSEOVER, |
106 WE_MOUSELOOP, |
116 WE_MOUSELOOP, |
107 WE_MOUSEWHEEL, |
117 WE_MOUSEWHEEL, |
108 WE_TICK, |
118 WE_TICK, ///< Regularly occurring event (about once every 20 seconds orso, 10 days) for slowly changing content (typically list sorting) |
109 WE_4, |
119 WE_4, ///< Regularly occurring event for updating continuously changing window content (other than view ports), or timer expiring |
110 WE_TIMEOUT, |
120 WE_TIMEOUT, |
111 WE_PLACE_OBJ, |
121 WE_PLACE_OBJ, |
112 WE_ABORT_PLACE_OBJ, |
122 WE_ABORT_PLACE_OBJ, |
113 WE_ON_EDIT_TEXT, |
123 WE_ON_EDIT_TEXT, |
114 WE_ON_EDIT_TEXT_CANCEL, |
124 WE_ON_EDIT_TEXT_CANCEL, |
198 bool cont; ///< continue the search? (default true) |
212 bool cont; ///< continue the search? (default true) |
199 } ctrl; |
213 } ctrl; |
200 } we; |
214 } we; |
201 }; |
215 }; |
202 |
216 |
|
217 /** |
|
218 * High level window description |
|
219 */ |
203 struct WindowDesc { |
220 struct WindowDesc { |
204 int16 left, top, minimum_width, minimum_height, default_width, default_height; |
221 int16 left; ///< Prefered x position of left edge of the window, @see WindowDefaultPosition() |
205 WindowClass cls; |
222 int16 top; ///< Prefered y position of the top of the window, @see WindowDefaultPosition() |
206 WindowClass parent_cls; |
223 int16 minimum_width; ///< Minimal width of the window |
207 uint32 flags; |
224 int16 minimum_height; ///< Minimal height of the window |
208 const Widget *widgets; |
225 int16 default_width; ///< Prefered initial width of the window |
209 WindowProc *proc; |
226 int16 default_height; ///< Prefered initial height of the window |
210 }; |
227 WindowClass cls; ///< Class of the window, @see WindowClass |
211 |
228 WindowClass parent_cls; ///< Class of the parent window, @see WindowClass |
|
229 uint32 flags; ///< Flags, @see WindowDefaultFlags |
|
230 const Widget *widgets; ///< List of widgets with their position and size for the window |
|
231 WindowProc *proc; ///< Window event handler function for the window |
|
232 }; |
|
233 |
|
234 /** |
|
235 * Window default widget/window handling flags |
|
236 */ |
212 enum WindowDefaultFlag { |
237 enum WindowDefaultFlag { |
213 WDF_STD_TOOLTIPS = 1 << 0, ///< use standard routine when displaying tooltips |
238 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 |
239 WDF_DEF_WIDGET = 1 << 1, ///< Default widget control for some widgets in the on click event, @see DispatchLeftClickEvent() |
215 WDF_STD_BTN = 1 << 2, ///< default handling for close and drag widgets (widget no 0 and 1) |
240 WDF_STD_BTN = 1 << 2, ///< Default handling for close and titlebar widgets (widget no 0 and 1) |
216 |
241 |
217 WDF_UNCLICK_BUTTONS = 1 << 4, ///< Unclick buttons when the window event times out */ |
242 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) |
243 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 |
244 WDF_RESIZABLE = 1 << 6, ///< Window can be resized |
220 WDF_MODAL = 1 << 7, ///< The window is a modal child of some other window, meaning the parent is 'inactive' |
245 WDF_MODAL = 1 << 7, ///< The window is a modal child of some other window, meaning the parent is 'inactive' |
221 }; |
246 }; |
222 |
247 |
223 /* can be used as x or y coordinates to cause a specific placement */ |
248 /** |
|
249 * Special values for 'left' and 'top' to cause a specific placement |
|
250 */ |
224 enum WindowDefaultPosition { |
251 enum WindowDefaultPosition { |
225 WDP_AUTO = -1, ///< Find a place automatically |
252 WDP_AUTO = -1, ///< Find a place automatically |
226 WDP_CENTER = -2, ///< Center the window (left/right or top/bottom) |
253 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 |
254 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 |
255 WDP_ALIGN_TBL = -4, ///< Align the left side of the window with the left side of the main toolbar |
229 }; |
256 }; |
230 |
257 |
231 #define WP(ptr, str) (*(str*)(ptr)->custom) |
258 #define WP(ptr, str) (*(str*)(ptr)->custom) |
232 |
259 |
|
260 /** |
|
261 * Scrollbar data structure |
|
262 */ |
233 struct Scrollbar { |
263 struct Scrollbar { |
234 uint16 count, cap, pos; |
264 uint16 count; ///< Number of elements in the list |
235 }; |
265 uint16 cap; ///< Number of visible elements of the scroll bar |
236 |
266 uint16 pos; |
|
267 }; |
|
268 |
|
269 /** |
|
270 * Data structure for resizing a window |
|
271 */ |
237 struct ResizeInfo { |
272 struct ResizeInfo { |
238 uint width; ///< Minimum width and height |
273 uint width; ///< Minimum allowed width of the window |
239 uint height; |
274 uint height; ///< Minimum allowed height of the window |
240 uint step_width; ///< In how big steps the width and height go |
275 uint step_width; ///< Step-size of width resize changes |
241 uint step_height; |
276 uint step_height; ///< Step-size of height resize changes |
242 }; |
277 }; |
243 |
278 |
|
279 /** |
|
280 * Message data structure for messages sent between winodows |
|
281 * @see SendWindowMessageW() |
|
282 */ |
244 struct WindowMessage { |
283 struct WindowMessage { |
245 int msg; |
284 int msg; |
246 int wparam; |
285 int wparam; |
247 int lparam; |
286 int lparam; |
248 }; |
287 }; |
249 |
288 |
|
289 /** |
|
290 * Data structure for an opened window |
|
291 */ |
250 struct Window { |
292 struct Window { |
251 uint16 flags4; |
293 uint16 flags4; ///< Window flags, @see WindowFlags |
252 WindowClass window_class; |
294 WindowClass window_class; ///< Window class |
253 WindowNumber window_number; |
295 WindowNumber window_number; ///< Window number within the window class |
254 |
296 |
255 int left, top; |
297 int left; ///< x position of left edge of the window |
256 int width, height; |
298 int top; ///< y position of top edge of the window |
257 |
299 int width; ///< width of the window (number of pixels to the right in x direction) |
258 Scrollbar hscroll, vscroll, vscroll2; |
300 int height; ///< Height of the window (number of pixels down in y direction) |
259 ResizeInfo resize; |
301 |
260 |
302 Scrollbar hscroll; ///< Horizontal scroll bar |
261 byte caption_color; |
303 Scrollbar vscroll; ///< First vertical scroll bar |
262 |
304 Scrollbar vscroll2; ///< Second vertical scroll bar |
263 WindowProc *wndproc; |
305 ResizeInfo resize; ///< Resize information |
264 ViewPort *viewport; |
306 |
265 const Widget *original_widget; |
307 byte caption_color; ///< Background color of the window caption, contains PlayerID |
266 Widget *widget; |
308 |
267 uint widget_count; |
309 WindowProc *wndproc; ///< Event handler function for the window |
268 uint32 desc_flags; |
310 ViewPort *viewport; ///< Pointer to viewport, if present (structure is part of derived class) |
269 |
311 const Widget *original_widget; ///< Original widget layout, copied from WindowDesc |
270 WindowMessage message; |
312 Widget *widget; ///< Widgets of the window |
271 Window *parent; |
313 uint widget_count; ///< Number of widgets of the window |
272 byte custom[WINDOW_CUSTOM_SIZE]; |
314 uint32 desc_flags; ///< Window/widgets default flags setting, @see WindowDefaultFlag |
|
315 |
|
316 WindowMessage message; ///< Buffer for storing received messages (for communication between different window events) |
|
317 Window *parent; ///< Parent window |
|
318 byte custom[WINDOW_CUSTOM_SIZE]; ///< Additional data depending on window type |
273 |
319 |
274 void HandleButtonClick(byte widget); |
320 void HandleButtonClick(byte widget); |
275 |
321 |
276 void SetWidgetDisabledState(byte widget_index, bool disab_stat); |
322 void SetWidgetDisabledState(byte widget_index, bool disab_stat); |
277 void DisableWidget(byte widget_index); |
323 void DisableWidget(byte widget_index); |
451 VehicleType vehicle_type; // The vehicle type that is sorted |
465 VehicleType vehicle_type; // The vehicle type that is sorted |
452 list_d l; // General list struct |
466 list_d l; // General list struct |
453 }; |
467 }; |
454 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vehiclelist_d)); |
468 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vehiclelist_d)); |
455 |
469 |
456 struct grouplist_d { |
|
457 const Group **sort_list; |
|
458 list_d l; // General list struct |
|
459 }; |
|
460 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(grouplist_d)); |
|
461 |
|
462 struct groupveh_d : vehiclelist_d { |
|
463 GroupID group_sel; |
|
464 VehicleID vehicle_sel; |
|
465 |
|
466 grouplist_d gl; |
|
467 }; |
|
468 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(groupveh_d)); |
|
469 |
|
470 /****************** THESE ARE NOT WIDGET TYPES!!!!! *******************/ |
470 /****************** THESE ARE NOT WIDGET TYPES!!!!! *******************/ |
471 enum WindowWidgetBehaviours { |
471 enum WindowWidgetBehaviours { |
472 WWB_PUSHBUTTON = 1 << 5, |
472 WWB_PUSHBUTTON = 1 << 5, |
473 |
473 |
474 WWB_MASK = 0xE0, |
474 WWB_MASK = 0xE0, |
475 }; |
475 }; |
476 |
476 |
477 |
477 |
|
478 /** |
|
479 * Window widget types |
|
480 */ |
478 enum WindowWidgetTypes { |
481 enum WindowWidgetTypes { |
479 WWT_EMPTY, |
482 WWT_EMPTY, ///< Empty widget, place holder to reserve space in widget array |
480 |
483 |
481 WWT_PANEL, ///< simple depressed panel |
484 WWT_PANEL, ///< Simple depressed panel |
482 WWT_INSET, ///< pressed (inset) panel, most commonly used as combo box _text_ area |
485 WWT_INSET, ///< Pressed (inset) panel, most commonly used as combo box _text_ area |
483 WWT_IMGBTN, ///< button with image |
486 WWT_IMGBTN, ///< Button with image |
484 WWT_IMGBTN_2, ///< button with diff image when clicked |
487 WWT_IMGBTN_2, ///< Button with diff image when clicked |
485 |
488 |
486 WWT_TEXTBTN, ///< button with text |
489 WWT_TEXTBTN, ///< Button with text |
487 WWT_TEXTBTN_2, ///< button with diff text when clicked |
490 WWT_TEXTBTN_2, ///< Button with diff text when clicked |
488 WWT_LABEL, ///< centered label |
491 WWT_LABEL, ///< Centered label |
489 WWT_TEXT, ///< pure simple text |
492 WWT_TEXT, ///< Pure simple text |
490 WWT_MATRIX, |
493 WWT_MATRIX, ///< List of items underneath each other |
491 WWT_SCROLLBAR, |
494 WWT_SCROLLBAR, ///< Vertical scrollbar |
492 WWT_FRAME, ///< frame |
495 WWT_FRAME, ///< Frame |
493 WWT_CAPTION, |
496 WWT_CAPTION, ///< Window caption (window title between closebox and stickybox) |
494 |
497 |
495 WWT_HSCROLLBAR, |
498 WWT_HSCROLLBAR, ///< Horizontal scrollbar |
496 WWT_STICKYBOX, |
499 WWT_STICKYBOX, ///< Sticky box (normally at top-right of a window) |
497 WWT_SCROLL2BAR, ///< 2nd vertical scrollbar |
500 WWT_SCROLL2BAR, ///< 2nd vertical scrollbar |
498 WWT_RESIZEBOX, |
501 WWT_RESIZEBOX, ///< Resize box (normally at bottom-right of a window) |
499 WWT_CLOSEBOX, |
502 WWT_CLOSEBOX, ///< Close box (at top-left of a window) |
500 WWT_DROPDOWN, ///< Raised drop down list (regular) |
503 WWT_DROPDOWN, ///< Raised drop down list (regular) |
501 WWT_DROPDOWNIN, ///< Inset drop down list (used on game options only) |
504 WWT_DROPDOWNIN, ///< Inset drop down list (used on game options only) |
|
505 WWT_EDITBOX, ///< a textbox for typing (don't forget to call ShowOnScreenKeyboard() when clicked) |
502 WWT_LAST, ///< Last Item. use WIDGETS_END to fill up padding!! |
506 WWT_LAST, ///< Last Item. use WIDGETS_END to fill up padding!! |
503 |
507 |
504 WWT_MASK = 0x1F, |
508 WWT_MASK = 0x1F, |
505 |
509 |
506 WWT_PUSHBTN = WWT_PANEL | WWB_PUSHBUTTON, |
510 WWT_PUSHBTN = WWT_PANEL | WWB_PUSHBUTTON, |
508 WWT_PUSHIMGBTN = WWT_IMGBTN | WWB_PUSHBUTTON, |
512 WWT_PUSHIMGBTN = WWT_IMGBTN | WWB_PUSHBUTTON, |
509 }; |
513 }; |
510 |
514 |
511 #define WIDGETS_END WWT_LAST, RESIZE_NONE, 0, 0, 0, 0, 0, 0, STR_NULL |
515 #define WIDGETS_END WWT_LAST, RESIZE_NONE, 0, 0, 0, 0, 0, 0, STR_NULL |
512 |
516 |
|
517 /** |
|
518 * Window flags |
|
519 */ |
513 enum WindowFlags { |
520 enum WindowFlags { |
514 WF_TIMEOUT_SHL = 0, |
521 WF_TIMEOUT_SHL = 0, ///< Window timeout counter shift |
515 WF_TIMEOUT_MASK = 7, |
522 WF_TIMEOUT_MASK = 7, ///< Window timeout counter bit mask (3 bits), @see WF_TIMEOUT_SHL |
516 WF_DRAGGING = 1 << 3, |
523 WF_DRAGGING = 1 << 3, ///< Window is being dragged |
517 WF_SCROLL_UP = 1 << 4, |
524 WF_SCROLL_UP = 1 << 4, ///< Upper scroll button has been pressed, @see ScrollbarClickHandler() |
518 WF_SCROLL_DOWN = 1 << 5, |
525 WF_SCROLL_DOWN = 1 << 5, ///< Lower scroll button has been pressed, @see ScrollbarClickHandler() |
519 WF_SCROLL_MIDDLE = 1 << 6, |
526 WF_SCROLL_MIDDLE = 1 << 6, ///< Scrollbar scrolling, @see ScrollbarClickHandler() |
520 WF_HSCROLL = 1 << 7, |
527 WF_HSCROLL = 1 << 7, |
521 WF_SIZING = 1 << 8, |
528 WF_SIZING = 1 << 8, |
522 WF_STICKY = 1 << 9, |
529 WF_STICKY = 1 << 9, ///< Window is made sticky by user |
523 |
530 |
524 WF_DISABLE_VP_SCROLL = 1 << 10, |
531 WF_DISABLE_VP_SCROLL = 1 << 10, ///< Window does not do autoscroll, @see HandleAutoscroll() |
525 |
532 |
526 WF_WHITE_BORDER_ONE = 1 << 11, |
533 WF_WHITE_BORDER_ONE = 1 << 11, |
527 WF_WHITE_BORDER_MASK = 1 << 12 | WF_WHITE_BORDER_ONE, |
534 WF_WHITE_BORDER_MASK = 1 << 12 | WF_WHITE_BORDER_ONE, |
528 WF_SCROLL2 = 1 << 13, |
535 WF_SCROLL2 = 1 << 13, |
529 }; |
536 }; |
530 |
537 |
531 /* window.cpp */ |
538 /* window.cpp */ |
532 void CallWindowEventNP(Window *w, int event); |
539 void CallWindowEventNP(Window *w, int event); |
533 void CallWindowTickEvent(); |
540 void CallWindowTickEvent(); |
534 |
541 |
535 /** |
|
536 * Marks the window as dirty for repaint. |
|
537 * |
|
538 * @ingroup dirty |
|
539 */ |
|
540 void SetWindowDirty(const Window *w); |
542 void SetWindowDirty(const Window *w); |
541 void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, int msg, int wparam, int lparam); |
543 void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, int msg, int wparam, int lparam); |
542 void SendWindowMessageClass(WindowClass wnd_class, int msg, int wparam, int lparam); |
544 void SendWindowMessageClass(WindowClass wnd_class, int msg, int wparam, int lparam); |
543 |
545 |
544 Window *FindWindowById(WindowClass cls, WindowNumber number); |
546 Window *FindWindowById(WindowClass cls, WindowNumber number); |