57 |
59 |
58 /* The following flags are used by the system to specify what is disabled, hidden, or clicked |
60 /* The following flags are used by the system to specify what is disabled, hidden, or clicked |
59 * They are used in the same place as the above RESIZE_x flags, Widget visual_flags. |
61 * They are used in the same place as the above RESIZE_x flags, Widget visual_flags. |
60 * These states are used in exceptions. If nothing is specified, they will indicate |
62 * These states are used in exceptions. If nothing is specified, they will indicate |
61 * Enabled, visible or unclicked widgets*/ |
63 * Enabled, visible or unclicked widgets*/ |
62 WIDG_DISABLED = 4, // widget is greyed out, not available |
64 WIDG_DISABLED = 4, ///< widget is greyed out, not available |
63 WIDG_HIDDEN = 5, // widget is made invisible |
65 WIDG_HIDDEN = 5, ///< widget is made invisible |
64 WIDG_LOWERED = 6, // widget is paint lowered, a pressed button in fact |
66 WIDG_LOWERED = 6, ///< widget is paint lowered, a pressed button in fact |
65 } ResizeFlag; |
67 } ResizeFlag; |
66 |
68 |
67 /* used to indicate the end of widgets' list for vararg functions */ |
69 /* used to indicate the end of widgets' list for vararg functions */ |
68 enum { |
70 enum { |
69 WIDGET_LIST_END = -1, |
71 WIDGET_LIST_END = -1, |
70 }; |
72 }; |
71 |
73 |
72 typedef struct Widget { |
74 typedef struct Widget { |
73 byte type; ///< Widget type, see @WindowWidgetTypes |
75 byte type; ///< Widget type, see WindowWidgetTypes |
74 byte display_flags; ///< Resize direction, alignment, etc. during resizing, see @ResizeFlags |
76 byte display_flags; ///< Resize direction, alignment, etc. during resizing, see ResizeFlags |
75 byte color; ///< Widget colour, see docs/ottd-colourtext-palette.png |
77 byte color; ///< Widget colour, see docs/ottd-colourtext-palette.png |
76 int16 left, right, top, bottom; ///< The position offsets inside the window |
78 int16 left, right, top, bottom; ///< The position offsets inside the window |
77 uint16 data; ///< The String/Image or special code (list-matrixes) of a widget |
79 uint16 data; ///< The String/Image or special code (list-matrixes) of a widget |
78 StringID tooltips; ///< Tooltips that are shown when rightclicking on a widget |
80 StringID tooltips; ///< Tooltips that are shown when rightclicking on a widget |
79 } Widget; |
81 } Widget; |
162 Point pt; |
164 Point pt; |
163 int widget; |
165 int widget; |
164 } mouseover; |
166 } mouseover; |
165 |
167 |
166 struct { |
168 struct { |
167 bool cont; // continue the search? (default true) |
169 bool cont; ///< continue the search? (default true) |
168 uint16 key; // 16-bit Unicode value of the key |
170 uint16 key; ///< 16-bit Unicode value of the key |
169 uint16 keycode;// untranslated key (including shift-state) |
171 uint16 keycode; ///< untranslated key (including shift-state) |
170 } keypress; |
172 } keypress; |
171 |
173 |
172 struct { |
174 struct { |
173 int msg; // message to be sent |
175 int msg; ///< message to be sent |
174 int wparam; // additional message-specific information |
176 int wparam; ///< additional message-specific information |
175 int lparam; // additional message-specific information |
177 int lparam; ///< additional message-specific information |
176 } message; |
178 } message; |
177 |
179 |
178 struct { |
180 struct { |
179 Point delta; // delta position against position of last call |
181 Point delta; ///< delta position against position of last call |
180 } scroll; |
182 } scroll; |
181 |
183 |
182 struct { |
184 struct { |
183 int wheel; // how much was 'wheel'd' |
185 int wheel; ///< how much was 'wheel'd' |
184 } wheel; |
186 } wheel; |
185 } we; |
187 } we; |
186 }; |
188 }; |
187 |
189 |
188 typedef struct WindowDesc { |
190 typedef struct WindowDesc { |
193 const Widget *widgets; |
195 const Widget *widgets; |
194 WindowProc *proc; |
196 WindowProc *proc; |
195 } WindowDesc; |
197 } WindowDesc; |
196 |
198 |
197 enum WindowDefaultFlag { |
199 enum WindowDefaultFlag { |
198 WDF_STD_TOOLTIPS = 1, /* use standard routine when displaying tooltips */ |
200 WDF_STD_TOOLTIPS = 1, ///< use standard routine when displaying tooltips |
199 WDF_DEF_WIDGET = 2, /* default widget control for some widgets in the on click event */ |
201 WDF_DEF_WIDGET = 2, ///< default widget control for some widgets in the on click event |
200 WDF_STD_BTN = 4, /* default handling for close and drag widgets (widget no 0 and 1) */ |
202 WDF_STD_BTN = 4, ///< default handling for close and drag widgets (widget no 0 and 1) |
201 |
203 |
202 WDF_UNCLICK_BUTTONS = 16, /* Unclick buttons when the window event times out */ |
204 WDF_UNCLICK_BUTTONS = 16, ///< Unclick buttons when the window event times out */ |
203 WDF_STICKY_BUTTON = 32, /* Set window to sticky mode; they are not closed unless closed with 'X' (widget 2) */ |
205 WDF_STICKY_BUTTON = 32, ///< Set window to sticky mode; they are not closed unless closed with 'X' (widget 2) |
204 WDF_RESIZABLE = 64, /* A window can be resized */ |
206 WDF_RESIZABLE = 64, ///< A window can be resized |
205 WDF_MODAL = 128, /* The window is a modal child of some other window, meaning the parent is 'inactive' */ |
207 WDF_MODAL = 128, ///< The window is a modal child of some other window, meaning the parent is 'inactive' |
206 }; |
208 }; |
207 |
209 |
208 /* can be used as x or y coordinates to cause a specific placement */ |
210 /* can be used as x or y coordinates to cause a specific placement */ |
209 enum WindowDefaultPosition { |
211 enum WindowDefaultPosition { |
210 WDP_AUTO = -1, ///< Find a place automatically |
212 WDP_AUTO = -1, ///< Find a place automatically |
212 WDP_ALIGN_TBR = -3, ///< Align the right side of the window with the right side of the main toolbar |
214 WDP_ALIGN_TBR = -3, ///< Align the right side of the window with the right side of the main toolbar |
213 WDP_ALIGN_TBL = -4, ///< Align the left side of the window with the left side of the main toolbar |
215 WDP_ALIGN_TBL = -4, ///< Align the left side of the window with the left side of the main toolbar |
214 }; |
216 }; |
215 |
217 |
216 typedef struct Textbuf { |
218 typedef struct Textbuf { |
217 char *buf; /* buffer in which text is saved */ |
219 char *buf; ///< buffer in which text is saved |
218 uint16 maxlength, maxwidth; /* the maximum size of the buffer. Maxwidth specifies screensize in pixels, maxlength is in bytes */ |
220 uint16 maxlength, maxwidth; ///< the maximum size of the buffer. Maxwidth specifies screensize in pixels, maxlength is in bytes |
219 uint16 length, width; /* the current size of the string. Width specifies screensize in pixels, length is in bytes */ |
221 uint16 length, width; ///< the current size of the string. Width specifies screensize in pixels, length is in bytes |
220 bool caret; /* is the caret ("_") visible or not */ |
222 bool caret; ///< is the caret ("_") visible or not |
221 uint16 caretpos; /* the current position of the caret in the buffer, in bytes */ |
223 uint16 caretpos; ///< the current position of the caret in the buffer, in bytes |
222 uint16 caretxoffs; /* the current position of the caret in pixels */ |
224 uint16 caretxoffs; ///< the current position of the caret in pixels |
223 } Textbuf; |
225 } Textbuf; |
224 |
226 |
225 #define WP(ptr,str) (*(str*)(ptr)->custom) |
227 #define WP(ptr,str) (*(str*)(ptr)->custom) |
226 /* You cannot 100% reliably calculate the biggest custom struct as |
228 /* You cannot 100% reliably calculate the biggest custom struct as |
227 * the number of pointers in it and alignment will have a huge impact. |
229 * the number of pointers in it and alignment will have a huge impact. |
231 typedef struct Scrollbar { |
233 typedef struct Scrollbar { |
232 uint16 count, cap, pos; |
234 uint16 count, cap, pos; |
233 } Scrollbar; |
235 } Scrollbar; |
234 |
236 |
235 typedef struct ResizeInfo { |
237 typedef struct ResizeInfo { |
236 uint width; /* Minimum width and height */ |
238 uint width; ///< Minimum width and height |
237 uint height; |
239 uint height; |
238 |
240 |
239 uint step_width; /* In how big steps the width and height go */ |
241 uint step_width; ///< In how big steps the width and height go |
240 uint step_height; |
242 uint step_height; |
241 } ResizeInfo; |
243 } ResizeInfo; |
242 |
244 |
243 typedef struct WindowMessage { |
245 typedef struct WindowMessage { |
244 int msg; |
246 int msg; |
279 bool handled; |
281 bool handled; |
280 } querystr_d; |
282 } querystr_d; |
281 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(querystr_d)); |
283 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(querystr_d)); |
282 |
284 |
283 typedef struct { |
285 typedef struct { |
284 byte item_count; /* follow_vehicle */ |
286 byte item_count; ///< follow_vehicle |
285 byte sel_index; /* scrollpos_x */ |
287 byte sel_index; ///< scrollpos_x |
286 byte main_button; /* scrollpos_y */ |
288 byte main_button; ///< scrollpos_y |
287 byte action_id; |
289 byte action_id; |
288 StringID string_id; /* unk30 */ |
290 StringID string_id; ///< unk30 |
289 uint16 checked_items; /* unk32 */ |
291 uint16 checked_items; ///< unk32 |
290 byte disabled_items; |
292 byte disabled_items; |
291 } menu_d; |
293 } menu_d; |
292 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(menu_d)); |
294 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(menu_d)); |
293 |
295 |
294 typedef struct { |
296 typedef struct { |
321 byte vehicle_type; |
323 byte vehicle_type; |
322 union { |
324 union { |
323 RailTypeByte railtype; |
325 RailTypeByte railtype; |
324 AirportFTAClass::Flags flags; |
326 AirportFTAClass::Flags flags; |
325 } filter; |
327 } filter; |
326 byte sel_index; // deprecated value, used for 'unified' ship and road |
328 byte sel_index; ///< deprecated value, used for 'unified' ship and road |
327 bool descending_sort_order; |
329 bool descending_sort_order; |
328 byte sort_criteria; |
330 byte sort_criteria; |
329 bool regenerate_list; |
331 bool regenerate_list; |
330 EngineID sel_engine; |
332 EngineID sel_engine; |
331 EngineID rename_engine; |
333 EngineID rename_engine; |
428 } scroller_d; |
430 } scroller_d; |
429 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(scroller_d)); |
431 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(scroller_d)); |
430 |
432 |
431 typedef enum SortListFlags { |
433 typedef enum SortListFlags { |
432 VL_NONE = 0x00, |
434 VL_NONE = 0x00, |
433 VL_DESC = 0x01, // sort descending or ascending |
435 VL_DESC = 0x01, ///< sort descending or ascending |
434 VL_RESORT = 0x02, // instruct the code to resort the list in the next loop |
436 VL_RESORT = 0x02, ///< instruct the code to resort the list in the next loop |
435 VL_REBUILD = 0x04, // create sort-listing to use for qsort and friends |
437 VL_REBUILD = 0x04, ///< create sort-listing to use for qsort and friends |
436 VL_END = 0x08 |
438 VL_END = 0x08 |
437 } SortListFlags; |
439 } SortListFlags; |
438 |
440 |
439 DECLARE_ENUM_AS_BIT_SET(SortListFlags); |
441 DECLARE_ENUM_AS_BIT_SET(SortListFlags); |
440 |
442 |
441 typedef struct Listing { |
443 typedef struct Listing { |
442 bool order; // Ascending/descending |
444 bool order; ///< Ascending/descending |
443 byte criteria; // Sorting criteria |
445 byte criteria; ///< Sorting criteria |
444 } Listing; |
446 } Listing; |
445 |
447 |
446 typedef struct list_d { |
448 typedef struct list_d { |
447 uint16 list_length; // length of the list being sorted |
449 uint16 list_length; ///< length of the list being sorted |
448 byte sort_type; // what criteria to sort on |
450 byte sort_type; ///< what criteria to sort on |
449 SortListFlags flags; // used to control sorting/resorting/etc. |
451 SortListFlags flags; ///< used to control sorting/resorting/etc. |
450 uint16 resort_timer; // resort list after a given amount of ticks if set |
452 uint16 resort_timer; ///< resort list after a given amount of ticks if set |
451 } list_d; |
453 } list_d; |
452 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(list_d)); |
454 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(list_d)); |
453 |
455 |
454 typedef struct message_d { |
456 typedef struct message_d { |
455 int msg; |
457 int msg; |
482 |
484 |
483 |
485 |
484 enum WindowWidgetTypes { |
486 enum WindowWidgetTypes { |
485 WWT_EMPTY, |
487 WWT_EMPTY, |
486 |
488 |
487 WWT_PANEL, /* simple depressed panel */ |
489 WWT_PANEL, ///< simple depressed panel |
488 WWT_INSET, /* pressed (inset) panel, most commonly used as combo box _text_ area */ |
490 WWT_INSET, ///< pressed (inset) panel, most commonly used as combo box _text_ area |
489 WWT_IMGBTN, /* button with image */ |
491 WWT_IMGBTN, ///< button with image |
490 WWT_IMGBTN_2, /* button with diff image when clicked */ |
492 WWT_IMGBTN_2, ///< button with diff image when clicked |
491 |
493 |
492 WWT_TEXTBTN, /* button with text */ |
494 WWT_TEXTBTN, ///< button with text |
493 WWT_TEXTBTN_2, /* button with diff text when clicked */ |
495 WWT_TEXTBTN_2, ///< button with diff text when clicked |
494 WWT_LABEL, /* centered label */ |
496 WWT_LABEL, ///< centered label |
495 WWT_MATRIX, |
497 WWT_MATRIX, |
496 WWT_SCROLLBAR, |
498 WWT_SCROLLBAR, |
497 WWT_FRAME, /* frame */ |
499 WWT_FRAME, ///< frame |
498 WWT_CAPTION, |
500 WWT_CAPTION, |
499 |
501 |
500 WWT_HSCROLLBAR, |
502 WWT_HSCROLLBAR, |
501 WWT_STICKYBOX, |
503 WWT_STICKYBOX, |
502 WWT_SCROLL2BAR, /* 2nd vertical scrollbar*/ |
504 WWT_SCROLL2BAR, ///< 2nd vertical scrollbar |
503 WWT_RESIZEBOX, |
505 WWT_RESIZEBOX, |
504 WWT_CLOSEBOX, |
506 WWT_CLOSEBOX, |
505 WWT_LAST, /* Last Item. use WIDGETS_END to fill up padding!! */ |
507 WWT_LAST, ///< Last Item. use WIDGETS_END to fill up padding!! |
506 |
508 |
507 WWT_MASK = 0x1F, |
509 WWT_MASK = 0x1F, |
508 |
510 |
509 WWT_PUSHBTN = WWT_PANEL | WWB_PUSHBUTTON, |
511 WWT_PUSHBTN = WWT_PANEL | WWB_PUSHBUTTON, |
510 WWT_PUSHTXTBTN = WWT_TEXTBTN | WWB_PUSHBUTTON, |
512 WWT_PUSHTXTBTN = WWT_TEXTBTN | WWB_PUSHBUTTON, |
529 WF_WHITE_BORDER_ONE = 1 << 11, |
531 WF_WHITE_BORDER_ONE = 1 << 11, |
530 WF_WHITE_BORDER_MASK = 1 << 12 | WF_WHITE_BORDER_ONE, |
532 WF_WHITE_BORDER_MASK = 1 << 12 | WF_WHITE_BORDER_ONE, |
531 WF_SCROLL2 = 1 << 13, |
533 WF_SCROLL2 = 1 << 13, |
532 }; |
534 }; |
533 |
535 |
534 /* window.c */ |
536 /* window.cpp */ |
535 void CallWindowEventNP(Window *w, int event); |
537 void CallWindowEventNP(Window *w, int event); |
536 void CallWindowTickEvent(void); |
538 void CallWindowTickEvent(void); |
537 void SetWindowDirty(const Window *w); |
539 void SetWindowDirty(const Window *w); |
538 void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, int msg, int wparam, int lparam); |
540 void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, int msg, int wparam, int lparam); |
539 void SendWindowMessageClass(WindowClass wnd_class, int msg, int wparam, int lparam); |
541 void SendWindowMessageClass(WindowClass wnd_class, int msg, int wparam, int lparam); |
722 int PositionMainToolbar(Window *w); |
724 int PositionMainToolbar(Window *w); |
723 void CDECL SetWindowWidgetsDisabledState(Window *w, bool disab_stat, int widgets, ...); |
725 void CDECL SetWindowWidgetsDisabledState(Window *w, bool disab_stat, int widgets, ...); |
724 void CDECL SetWindowWidgetsHiddenState(Window *w, bool hidden_stat, int widgets, ...); |
726 void CDECL SetWindowWidgetsHiddenState(Window *w, bool hidden_stat, int widgets, ...); |
725 void CDECL SetWindowWidgetsLoweredState(Window *w, bool lowered_stat, int widgets, ...); |
727 void CDECL SetWindowWidgetsLoweredState(Window *w, bool lowered_stat, int widgets, ...); |
726 |
728 |
727 /* misc_gui.c*/ |
729 /* misc_gui.cpp */ |
728 void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint params[]); |
730 void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint params[]); |
729 static inline void GuiShowTooltips(StringID str) |
731 static inline void GuiShowTooltips(StringID str) |
730 { |
732 { |
731 GuiShowTooltipsWithArgs(str, 0, NULL); |
733 GuiShowTooltipsWithArgs(str, 0, NULL); |
732 } |
734 } |
733 |
735 |
734 /* widget.c */ |
736 /* widget.cpp */ |
735 int GetWidgetFromPos(const Window *w, int x, int y); |
737 int GetWidgetFromPos(const Window *w, int x, int y); |
736 void DrawWindowWidgets(const Window *w); |
738 void DrawWindowWidgets(const Window *w); |
737 void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask); |
739 void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask); |
738 |
740 |
739 void HandleButtonClick(Window *w, byte widget); |
741 void HandleButtonClick(Window *w, byte widget); |
743 void DeleteAllNonVitalWindows(void); |
745 void DeleteAllNonVitalWindows(void); |
744 void HideVitalWindows(void); |
746 void HideVitalWindows(void); |
745 void ShowVitalWindows(void); |
747 void ShowVitalWindows(void); |
746 Window **FindWindowZPosition(const Window *w); |
748 Window **FindWindowZPosition(const Window *w); |
747 |
749 |
748 /* window.c */ |
750 /* window.cpp */ |
749 extern Window *_z_windows[]; |
751 extern Window *_z_windows[]; |
750 extern Window **_last_z_window; |
752 extern Window **_last_z_window; |
751 #define FOR_ALL_WINDOWS(wz) for (wz = _z_windows; wz != _last_z_window; wz++) |
753 #define FOR_ALL_WINDOWS(wz) for (wz = _z_windows; wz != _last_z_window; wz++) |
752 |
754 |
753 VARDEF Point _cursorpos_drag_start; |
755 VARDEF Point _cursorpos_drag_start; |