OpenTTD Source: src/window_gui.h Source File

OpenTTD Source 14.1

window_gui.h
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #ifndef WINDOW_GUI_H
11 #define WINDOW_GUI_H
12
13 #include "vehiclelist.h"
14 #include "vehicle_type.h"
15 #include "viewport_type.h"
16 #include "company_type.h"
17 #include "tile_type.h"
18 #include "widget_type.h"
19 #include "string_type.h"
20
24 enum FrameFlags {
25 FR_NONE = 0,
26 FR_TRANSPARENT = 1 << 0,
27 FR_BORDERONLY = 1 << 4,
28 FR_LOWERED = 1 << 5,
29 FR_DARKENED = 1 << 6,
30 };
31
32 DECLARE_ENUM_AS_BIT_SET(FrameFlags)
33
34 class WidgetDimensions {
35 public:
36 RectPadding imgbtn;
37 RectPadding inset;
38 RectPadding vscrollbar;
39 RectPadding hscrollbar;
40 RectPadding bevel;
41 RectPadding fullbevel;
42 RectPadding framerect;
43 RectPadding frametext;
44 RectPadding matrix;
45 RectPadding shadebox;
46 RectPadding stickybox;
47 RectPadding debugbox;
48 RectPadding defsizebox;
49 RectPadding resizebox;
50 RectPadding closebox;
51 RectPadding captiontext;
52 RectPadding dropdowntext;
53 RectPadding dropdownlist;
54 RectPadding modalpopup;
55 RectPadding picker;
56 RectPadding sparse;
57 RectPadding sparse_resize;
58
59 int vsep_picker;
60 int vsep_normal;
61 int vsep_sparse;
62 int vsep_wide;
63 int hsep_normal;
64 int hsep_wide;
65 int hsep_indent;
66
67 static const WidgetDimensions unscaled;
68 static WidgetDimensions scaled;
69
70 private:
75 enum WidgetDrawDistances {
76 WD_SHADEBOX_WIDTH = 12,
77 WD_STICKYBOX_WIDTH = 12,
78 WD_DEBUGBOX_WIDTH = 12,
79 WD_DEFSIZEBOX_WIDTH = 12,
80 WD_RESIZEBOX_WIDTH = 12,
81 WD_CLOSEBOX_WIDTH = 11,
82
83 WD_CAPTION_HEIGHT = 14,
84 WD_DROPDOWN_HEIGHT = 12,
85 };
86
87 friend NWidgetLeaf;
88 };
89
90 inline constexpr WidgetDimensions WidgetDimensions::unscaled = {
91 .imgbtn = { .left = 1, .top = 1, .right = 1, .bottom = 1},
92 .inset = { .left = 2, .top = 1, .right = 2, .bottom = 1},
93 .vscrollbar = { .left = 2, .top = 3, .right = 2, .bottom = 3},
94 .hscrollbar = { .left = 3, .top = 2, .right = 3, .bottom = 2},
95 .bevel = { .left = 1, .top = 1, .right = 1, .bottom = 1},
96 .fullbevel = { .left = 1, .top = 1, .right = 1, .bottom = 1},
97 .framerect = { .left = 2, .top = 1, .right = 2, .bottom = 1},
98 .frametext = { .left = 6, .top = 6, .right = 6, .bottom = 6},
99 .matrix = { .left = 2, .top = 3, .right = 2, .bottom = 1},
100 .shadebox = { .left = 2, .top = 3, .right = 2, .bottom = 3},
101 .stickybox = { .left = 2, .top = 3, .right = 2, .bottom = 3},
102 .debugbox = { .left = 2, .top = 3, .right = 2, .bottom = 3},
103 .defsizebox = { .left = 2, .top = 3, .right = 2, .bottom = 3},
104 .resizebox = { .left = 2, .top = 2, .right = 2, .bottom = 2},
105 .closebox = { .left = 2, .top = 2, .right = 1, .bottom = 2},
106 .captiontext = { .left = 2, .top = 2, .right = 2, .bottom = 2},
107 .dropdowntext = { .left = 2, .top = 1, .right = 2, .bottom = 1},
108 .dropdownlist = { .left = 1, .top = 2, .right = 1, .bottom = 2},
109 .modalpopup = { .left = 20, .top = 10, .right = 20, .bottom = 10},
110 .picker = { .left = 3, .top = 3, .right = 3, .bottom = 3},
111 .sparse = { .left = 10, .top = 8, .right = 10, .bottom = 8},
112 .sparse_resize = { .left = 10, .top = 8, .right = 10, .bottom = 0},
113 .vsep_picker = 1,
114 .vsep_normal = 2,
115 .vsep_sparse = 4,
116 .vsep_wide = 8,
117 .hsep_normal = 2,
118 .hsep_wide = 6,
119 .hsep_indent = 10,
120 };
121
122 /* widget.cpp */
123 void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags);
124
125 inline void DrawFrameRect(const Rect &r, Colours colour, FrameFlags flags)
126 {
127 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, flags);
128 }
129
130 void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align, FontSize fs);
131
132 /* window.cpp */
133 using WindowList = std::list<Window *>;
134 extern WindowList _z_windows;
135 extern Window *_focused_window;
136
137
139 enum WindowPosition {
140 WDP_MANUAL,
141 WDP_AUTO,
142 WDP_CENTER,
143 WDP_ALIGN_TOOLBAR,
144 };
145
146 Point GetToolbarAlignedWindowPosition(int window_width);
147
148 struct HotkeyList;
149
153 struct WindowDesc : ZeroedMemoryAllocator {
154
155 WindowDesc(const char * const file, const int line, WindowPosition default_pos, const char *ini_key, int16_t def_width_trad, int16_t def_height_trad,
156 WindowClass window_class, WindowClass parent_class, uint32_t flags,
157 const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, HotkeyList *hotkeys = nullptr);
158
159 ~WindowDesc();
160
161 const char * const file;
162 const int line;
163 WindowPosition default_pos;
164 WindowClass cls;
165 WindowClass parent_cls;
166 const char *ini_key;
167 uint32_t flags;
168 const NWidgetPart *nwid_begin;
169 const NWidgetPart *nwid_end;
170 HotkeyList *hotkeys;
171
172 bool pref_sticky;
173 int16_t pref_width;
174 int16_t pref_height;
175
176 int16_t GetDefaultWidth() const;
177 int16_t GetDefaultHeight() const;
178
179 static void LoadFromConfig();
180 static void SaveToConfig();
181
182 private:
183 int16_t default_width_trad;
184 int16_t default_height_trad;
185
190 WindowDesc(const WindowDesc &other);
191 };
192
196 enum WindowDefaultFlag {
197 WDF_CONSTRUCTION = 1 << 0,
198 WDF_MODAL = 1 << 1,
199 WDF_NO_FOCUS = 1 << 2,
200 WDF_NO_CLOSE = 1 << 3,
201 };
202
206 struct ResizeInfo {
207 uint step_width;
208 uint step_height;
209 };
210
212 enum SortButtonState {
213 SBS_OFF,
214 SBS_DOWN,
215 SBS_UP,
216 };
217
221 enum WindowFlags {
222 WF_TIMEOUT = 1 << 0,
223
224 WF_DRAGGING = 1 << 3,
225 WF_SIZING_RIGHT = 1 << 4,
226 WF_SIZING_LEFT = 1 << 5,
227 WF_SIZING = WF_SIZING_RIGHT | WF_SIZING_LEFT,
228 WF_STICKY = 1 << 6,
229 WF_DISABLE_VP_SCROLL = 1 << 7,
230 WF_WHITE_BORDER = 1 << 8,
231 WF_HIGHLIGHTED = 1 << 9,
232 WF_CENTERED = 1 << 10,
233 };
234 DECLARE_ENUM_AS_BIT_SET(WindowFlags)
235
236 static const int TIMEOUT_DURATION = 7;
237 static const int WHITE_BORDER_DURATION = 3;
238
246 struct ViewportData : Viewport {
247 VehicleID follow_vehicle;
248 int32_t scrollpos_x;
249 int32_t scrollpos_y;
250 int32_t dest_scrollpos_x;
251 int32_t dest_scrollpos_y;
252 };
253
254 struct QueryString;
255
256 /* misc_gui.cpp */
257 enum TooltipCloseCondition {
258 TCC_RIGHT_CLICK,
259 TCC_HOVER,
260 TCC_NONE,
261 TCC_EXIT_VIEWPORT,
262 };
263
267 struct Window : ZeroedMemoryAllocator {
268 private:
269 static std::vector<Window *> closed_windows;
270
271 protected:
272 void InitializeData(WindowNumber window_number);
273 void InitializePositionSize(int x, int y, int min_width, int min_height);
274 virtual void FindWindowPlacementAndResize(int def_width, int def_height);
275
276 std::vector<int> scheduled_invalidation_data;
277 bool scheduled_resize;
278
279 /* Protected to prevent deletion anywhere outside Window::DeleteClosedWindows(). */
280 virtual ~Window();
281
282 public:
283 Window(WindowDesc *desc);
284
291 inline void *operator new[](size_t size) = delete;
292
293 WindowDesc *window_desc;
294 WindowFlags flags;
295 WindowClass window_class;
296 WindowNumber window_number;
297
298 int scale;
299
300 uint8_t timeout_timer;
301 uint8_t white_border_timer;
302
303 int left;
304 int top;
305 int width;
306 int height;
307
308 ResizeInfo resize;
309
310 Owner owner;
311
312 ViewportData *viewport;
313 const NWidgetCore *nested_focus;
314 std::map<WidgetID, QueryString*> querystrings;
315 std::unique_ptr<NWidgetBase> nested_root;
316 WidgetLookup widget_lookup;
317 NWidgetStacked *shade_select;
318 Dimension unshaded_size;
319
320 WidgetID mouse_capture_widget;
321
322 Window *parent;
323 WindowList::iterator z_position;
324
325 template <class NWID>
326 inline const NWID *GetWidget(WidgetID widnum) const;
327 template <class NWID>
328 inline NWID *GetWidget(WidgetID widnum);
329
330 const Scrollbar *GetScrollbar(WidgetID widnum) const;
331 Scrollbar *GetScrollbar(WidgetID widnum);
332
333 const QueryString *GetQueryString(WidgetID widnum) const;
334 QueryString *GetQueryString(WidgetID widnum);
335 void UpdateQueryStringSize();
336
337 virtual const struct Textbuf *GetFocusedTextbuf() const;
338 virtual Point GetCaretPosition() const;
339 virtual Rect GetTextBoundingRect(const char *from, const char *to) const;
340 virtual ptrdiff_t GetTextCharacterAtPosition(const Point &pt) const;
341
342 void InitNested(WindowNumber number = 0);
343 void CreateNestedTree();
344 void FinishInitNested(WindowNumber window_number = 0);
345
346 template<typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
347 void FinishInitNested(T number)
348 {
349 this->FinishInitNested(number.base());
350 }
351
355 inline void SetTimeout()
356 {
357 this->flags |= WF_TIMEOUT;
358 this->timeout_timer = TIMEOUT_DURATION;
359 }
360
364 inline void SetWhiteBorder()
365 {
366 this->flags |= WF_WHITE_BORDER;
367 this->white_border_timer = WHITE_BORDER_DURATION;
368 }
369
370 void DisableAllWidgetHighlight();
371 void SetWidgetHighlight(WidgetID widget_index, TextColour highlighted_colour);
372 bool IsWidgetHighlighted(WidgetID widget_index) const;
373
381 inline void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
382 {
383 NWidgetCore *nwid = this->GetWidget<NWidgetCore>(widget_index);
384 if (nwid != nullptr) nwid->SetDisabled(disab_stat);
385 }
386
391 inline void DisableWidget(WidgetID widget_index)
392 {
393 SetWidgetDisabledState(widget_index, true);
394 }
395
400 inline void EnableWidget(WidgetID widget_index)
401 {
402 SetWidgetDisabledState(widget_index, false);
403 }
404
410 inline bool IsWidgetDisabled(WidgetID widget_index) const
411 {
412 return this->GetWidget<NWidgetCore>(widget_index)->IsDisabled();
413 }
414
420 inline bool IsWidgetFocused(WidgetID widget_index) const
421 {
422 return this->nested_focus != nullptr && this->nested_focus->index == widget_index;
423 }
424
431 inline bool IsWidgetGloballyFocused(WidgetID widget_index) const
432 {
433 return _focused_window == this && IsWidgetFocused(widget_index);
434 }
435
441 inline void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
442 {
443 this->GetWidget<NWidgetCore>(widget_index)->SetLowered(lowered_stat);
444 }
445
450 inline void ToggleWidgetLoweredState(WidgetID widget_index)
451 {
452 bool lowered_state = this->GetWidget<NWidgetCore>(widget_index)->IsLowered();
453 this->GetWidget<NWidgetCore>(widget_index)->SetLowered(!lowered_state);
454 }
455
460 inline void LowerWidget(WidgetID widget_index)
461 {
462 SetWidgetLoweredState(widget_index, true);
463 }
464
469 inline void RaiseWidget(WidgetID widget_index)
470 {
471 SetWidgetLoweredState(widget_index, false);
472 }
473
478 inline void RaiseWidgetWhenLowered(byte widget_index)
479 {
480 if (this->IsWidgetLowered(widget_index)) {
481 this->RaiseWidget(widget_index);
482 this->SetWidgetDirty(widget_index);
483 }
484 }
485
491 inline bool IsWidgetLowered(WidgetID widget_index) const
492 {
493 return this->GetWidget<NWidgetCore>(widget_index)->IsLowered();
494 }
495
496 void UnfocusFocusedWidget();
497 bool SetFocusedWidget(WidgetID widget_index);
498
499 EventState HandleEditBoxKey(WidgetID wid, char32_t key, uint16_t keycode);
500 virtual void InsertTextString(WidgetID wid, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end);
501
502 void HandleButtonClick(WidgetID widget);
503 int GetRowFromWidget(int clickpos, WidgetID widget, int padding, int line_height = -1) const;
504
505 void RaiseButtons(bool autoraise = false);
506
514 template<typename... Args>
515 void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
516 {
517 (SetWidgetDisabledState(widgets, disab_stat), ...);
518 }
519
525 template<typename... Args>
526 void SetWidgetsLoweredState(bool lowered_stat, Args... widgets)
527 {
528 (SetWidgetLoweredState(widgets, lowered_stat), ...);
529 }
530
535 template<typename... Args>
536 void RaiseWidgetsWhenLowered(Args... widgets)
537 {
538 (this->RaiseWidgetWhenLowered(widgets), ...);
539 }
540
541 void SetWidgetDirty(WidgetID widget_index) const;
542
543 void DrawWidgets() const;
544 void DrawViewport() const;
545 void DrawSortButtonState(WidgetID widget, SortButtonState state) const;
546 static int SortButtonWidth();
547
548 Window *FindChildWindow(WindowClass wc = WC_INVALID) const;
549 void CloseChildWindows(WindowClass wc = WC_INVALID) const;
550 virtual void Close(int data = 0);
551 static void DeleteClosedWindows();
552
553 void SetDirty() const;
554 void ReInit(int rx = 0, int ry = 0, bool reposition = false);
555
557 inline bool IsShaded() const
558 {
559 return this->shade_select != nullptr && this->shade_select->shown_plane == SZSP_HORIZONTAL;
560 }
561
562 void SetShaded(bool make_shaded);
563
564 void ScheduleResize();
565 void ProcessScheduledResize();
566 void InvalidateData(int data = 0, bool gui_scope = true);
567 void ProcessScheduledInvalidations();
568 void ProcessHighlightedInvalidations();
569
570 /*** Event handling ***/
571
576 virtual void OnInit() { }
577
578 virtual void ApplyDefaults();
579
587 virtual Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number);
588
593 virtual void OnPaint()
594 {
595 this->DrawWidgets();
596 }
597
604 virtual void DrawWidget([[maybe_unused]] const Rect &r, [[maybe_unused]] WidgetID widget) const {}
605
618 virtual void UpdateWidgetSize([[maybe_unused]] WidgetID widget, [[maybe_unused]] Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) {}
619
626 virtual void SetStringParameters([[maybe_unused]] WidgetID widget) const {}
627
631 virtual void OnFocus();
632
637 virtual void OnFocusLost(bool closing);
638
646 virtual EventState OnKeyPress([[maybe_unused]] char32_t key, [[maybe_unused]] uint16_t keycode) { return ES_NOT_HANDLED; }
647
648 virtual EventState OnHotkey(int hotkey);
649
655 virtual EventState OnCTRLStateChange() { return ES_NOT_HANDLED; }
656
657
664 virtual void OnClick([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget, [[maybe_unused]] int click_count) {}
665
673 virtual bool OnRightClick([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget) { return false; }
674
680 virtual void OnHover([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget) {}
681
688 virtual bool OnTooltip([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget, [[maybe_unused]] TooltipCloseCondition close_cond) { return false; }
689
695 virtual void OnMouseDrag([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget) {}
696
702 virtual void OnDragDrop([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget) {}
703
708 virtual void OnScroll([[maybe_unused]] Point delta) {}
709
716 virtual void OnMouseOver([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget) {}
717
722 virtual void OnMouseWheel([[maybe_unused]] int wheel) {}
723
724
728 virtual void OnMouseLoop() {}
729
733 virtual void OnGameTick() {}
734
738 virtual void OnRealtimeTick([[maybe_unused]] uint delta_ms) {}
739
743 virtual void OnTimeout() {}
744
745
750 virtual void OnResize() {}
751
757 virtual void OnDropdownSelect([[maybe_unused]] WidgetID widget, [[maybe_unused]] int index) {}
758
759 virtual void OnDropdownClose(Point pt, WidgetID widget, int index, bool instant_close);
760
765 virtual void OnEditboxChanged([[maybe_unused]] WidgetID widget) {}
766
773 virtual void OnQueryTextFinished([[maybe_unused]] char *str) {}
774
780 virtual void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) {}
781
788 virtual void OnPlaceObject([[maybe_unused]] Point pt, [[maybe_unused]] TileIndex tile) {}
789
796 virtual bool OnVehicleSelect([[maybe_unused]] const struct Vehicle *v) { return false; }
797
804 virtual bool OnVehicleSelect([[maybe_unused]] VehicleList::const_iterator begin, [[maybe_unused]] VehicleList::const_iterator end) { return false; }
805
809 virtual void OnPlaceObjectAbort() {}
810
811
819 virtual void OnPlaceDrag([[maybe_unused]] ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt) {}
820
830 virtual void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, [[maybe_unused]] TileIndex start_tile, [[maybe_unused]] TileIndex end_tile) {}
831
839 virtual void OnPlacePresize([[maybe_unused]] Point pt, [[maybe_unused]] TileIndex tile) {}
840
841 /*** End of the event handling ***/
842
847 virtual bool IsNewGRFInspectable() const { return false; }
848
855 virtual void ShowNewGRFInspectWindow() const { NOT_REACHED(); }
856
861 template <bool TtoBack>
862 struct WindowIterator {
863 typedef Window *value_type;
864 typedef value_type *pointer;
865 typedef value_type &reference;
866 typedef size_t difference_type;
867 typedef std::forward_iterator_tag iterator_category;
868
869 explicit WindowIterator(WindowList::iterator start) : it(start)
870 {
871 this->Validate();
872 }
873 explicit WindowIterator(const Window *w) : it(w->z_position) {}
874
875 bool operator==(const WindowIterator &other) const { return this->it == other.it; }
876 bool operator!=(const WindowIterator &other) const { return !(*this == other); }
877 Window * operator*() const { return *this->it; }
878 WindowIterator & operator++() { this->Next(); this->Validate(); return *this; }
879
880 bool IsEnd() const { return this->it == _z_windows.end(); }
881
882 private:
883 WindowList::iterator it;
884 void Validate()
885 {
886 while (!this->IsEnd() && *this->it == nullptr) this->Next();
887 }
888 void Next()
889 {
890 if constexpr (!TtoBack) {
891 ++this->it;
892 } else if (this->it == _z_windows.begin()) {
893 this->it = _z_windows.end();
894 } else {
895 --this->it;
896 }
897 }
898 };
899 using IteratorToFront = WindowIterator<false>;
900 using IteratorToBack = WindowIterator<true>;
901
906 template <bool Tfront>
907 struct AllWindows {
908 AllWindows() {}
909 WindowIterator<Tfront> begin()
910 {
911 if constexpr (Tfront) {
912 auto back = _z_windows.end();
913 if (back != _z_windows.begin()) --back;
914 return WindowIterator<Tfront>(back);
915 } else {
916 return WindowIterator<Tfront>(_z_windows.begin());
917 }
918 }
919 WindowIterator<Tfront> end() { return WindowIterator<Tfront>(_z_windows.end()); }
920 };
921 using Iterate = AllWindows<false>;
922 using IterateFromBack = AllWindows<false>;
923 using IterateFromFront = AllWindows<true>;
924 };
925
933 template <class It, class Pred>
934 inline bool AllEqual(It begin, It end, Pred pred)
935 {
936 return std::adjacent_find(begin, end, std::not_fn(pred)) == end;
937 }
938
945 template <class NWID>
946 inline NWID *Window::GetWidget(WidgetID widnum)
947 {
948 auto it = this->widget_lookup.find(widnum);
949 if (it == std::end(this->widget_lookup)) return nullptr;
950 NWID *nwid = dynamic_cast<NWID *>(it->second);
951 assert(nwid != nullptr);
952 return nwid;
953 }
954
956 template <>
957 inline const NWidgetBase *Window::GetWidget<NWidgetBase>(WidgetID widnum) const
958 {
959 auto it = this->widget_lookup.find(widnum);
960 if (it == std::end(this->widget_lookup)) return nullptr;
961 return it->second;
962 }
963
970 template <class NWID>
971 inline const NWID *Window::GetWidget(WidgetID widnum) const
972 {
973 return const_cast<Window *>(this)->GetWidget<NWID>(widnum);
974 }
975
976
980 class PickerWindowBase : public Window {
981
982 public:
983 PickerWindowBase(WindowDesc *desc, Window *parent) : Window(desc)
984 {
985 this->parent = parent;
986 }
987
988 void Close([[maybe_unused]] int data = 0) override;
989 };
990
991 Window *BringWindowToFrontById(WindowClass cls, WindowNumber number);
992 Window *FindWindowFromPt(int x, int y);
993
994 template<typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
995 Window *BringWindowToFrontById(WindowClass cls, T number)
996 {
997 return BringWindowToFrontById(cls, number.base());
998 }
999
1008 template <typename Wcls>
1009 Wcls *AllocateWindowDescFront(WindowDesc *desc, int window_number, bool return_existing = false)
1010 {
1011 Wcls *w = static_cast<Wcls *>(BringWindowToFrontById(desc->cls, window_number));
1012 if (w != nullptr) return return_existing ? w : nullptr;
1013 return new Wcls(desc, window_number);
1014 }
1015
1016 void RelocateAllWindows(int neww, int newh);
1017
1018 void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, uint paramcount = 0);
1019
1020 /* widget.cpp */
1021 WidgetID GetWidgetFromPos(const Window *w, int x, int y);
1022
1023 extern Point _cursorpos_drag_start;
1024
1025 extern int _scrollbar_start_pos;
1026 extern int _scrollbar_size;
1027 extern byte _scroller_click_timeout;
1028
1029 extern bool _scrolling_viewport;
1030 extern bool _mouse_hovering;
1031
1033 enum SpecialMouseMode {
1034 WSM_NONE,
1035 WSM_DRAGDROP,
1036 WSM_SIZING,
1037 WSM_PRESIZE,
1038 WSM_DRAGGING,
1039 };
1040 extern SpecialMouseMode _special_mouse_mode;
1041
1042 void SetFocusedWindow(Window *w);
1043
1044 void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y);
1045
1046 #endif /* WINDOW_GUI_H */
Window::timeout_timer
uint8_t timeout_timer
Timer value of the WF_TIMEOUT for flags.
Definition: window_gui.h:300
Window::WindowIterator
Iterator to iterate all valid Windows.
Definition: window_gui.h:862
ViewportData
Data structure for a window viewport.
Definition: window_gui.h:246
Window::SetTimeout
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:355
Window::OnPlaceObject
virtual void OnPlaceObject([[maybe_unused]] Point pt, [[maybe_unused]] TileIndex tile)
The user clicked some place on the map when a tile highlight mode has been set.
Definition: window_gui.h:788
WindowDesc::pref_width
int16_t pref_width
User-preferred width of the window. Zero if unset.
Definition: window_gui.h:173
Window::OnVehicleSelect
virtual bool OnVehicleSelect([[maybe_unused]] const struct Vehicle *v)
The user clicked on a vehicle while HT_VEHICLE has been set.
Definition: window_gui.h:796
Window::OnScroll
virtual void OnScroll([[maybe_unused]] Point delta)
Handle the request for (viewport) scrolling.
Definition: window_gui.h:708
WC_INVALID
@ WC_INVALID
Invalid window.
Definition: window_type.h:719
WindowDesc::default_height_trad
int16_t default_height_trad
Preferred initial height of the window (pixels at 1x zoom).
Definition: window_gui.h:184
WidgetDimensions::imgbtn
RectPadding imgbtn
Padding around image button image.
Definition: window_gui.h:36
WF_SIZING
@ WF_SIZING
Window is being resized.
Definition: window_gui.h:227
WidgetDimensions::dropdownlist
RectPadding dropdownlist
Padding of complete drop down list.
Definition: window_gui.h:53
Window::OnInitialPosition
virtual Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number)
Compute the initial position of the window.
Definition: window.cpp:1712
Window::SetWhiteBorder
void SetWhiteBorder()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:364
SortButtonState
SortButtonState
State of a sort direction button.
Definition: window_gui.h:212
HotkeyList
List of hotkeys for a window.
Definition: hotkeys.h:37
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
Window::~Window
virtual ~Window()
Remove window and all its child windows from the window stack.
Definition: window.cpp:1085
AllocateWindowDescFront
Wcls * AllocateWindowDescFront(WindowDesc *desc, int window_number, bool return_existing=false)
Open a new window.
Definition: window_gui.h:1009
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
Window::GetFocusedTextbuf
virtual const struct Textbuf * GetFocusedTextbuf() const
Get the current input text buffer.
Definition: window.cpp:366
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:197
_scrolling_viewport
bool _scrolling_viewport
A viewport is being scrolled with the mouse.
Definition: window.cpp:90
Window::shade_select
NWidgetStacked * shade_select
Selection widget (NWID_SELECTION) to use for shading the window. If nullptr, window cannot shade.
Definition: window_gui.h:317
WF_SIZING_RIGHT
@ WF_SIZING_RIGHT
Window is being resized towards the right.
Definition: window_gui.h:225
WidgetDimensions::WidgetDrawDistances
WidgetDrawDistances
Distances used in drawing widgets.
Definition: window_gui.h:75
Window::ApplyDefaults
virtual void ApplyDefaults()
Read default values from WindowDesc configuration an apply them to the window.
Definition: window.cpp:195
WindowDesc::WindowDesc
WindowDesc(const char *const file, const int line, WindowPosition default_pos, const char *ini_key, int16_t def_width_trad, int16_t def_height_trad, WindowClass window_class, WindowClass parent_class, uint32_t flags, const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, HotkeyList *hotkeys=nullptr)
Window description constructor.
Definition: window.cpp:105
Window::OnDropdownClose
virtual void OnDropdownClose(Point pt, WidgetID widget, int index, bool instant_close)
A dropdown window associated to this window has been closed.
Definition: window.cpp:288
ViewportDragDropSelectionProcess
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
Definition: viewport_type.h:107
ScrollbarClickHandler
void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
Special handling for the scrollbar widget type.
Definition: widget.cpp:242
Window::InitializePositionSize
void InitializePositionSize(int x, int y, int min_width, int min_height)
Set the position and smallest size of the window.
Definition: window.cpp:1403
widget_type.h
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:552
Window::GetTextCharacterAtPosition
virtual ptrdiff_t GetTextCharacterAtPosition(const Point &pt) const
Get the character that is rendered at a position by the focused edit box.
Definition: window.cpp:410
_z_windows
WindowList _z_windows
List of windows opened at the screen sorted from the front to back.
Definition: window.cpp:57
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
WF_DISABLE_VP_SCROLL
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
Definition: window_gui.h:229
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:312
vehiclelist.h
FrameFlags
FrameFlags
Flags to describe the look of the frame.
Definition: window_gui.h:24
WDP_ALIGN_TOOLBAR
@ WDP_ALIGN_TOOLBAR
Align toward the toolbar.
Definition: window_gui.h:143
WindowDesc::line
const int line
Source line of this definition.
Definition: window_gui.h:162
Window::OnGameTick
virtual void OnGameTick()
Called once per (game) tick.
Definition: window_gui.h:733
Window::IsNewGRFInspectable
virtual bool IsNewGRFInspectable() const
Is the data related to this window NewGRF inspectable?
Definition: window_gui.h:847
WF_STICKY
@ WF_STICKY
Window is made sticky by user.
Definition: window_gui.h:228
Window::OnFocusLost
virtual void OnFocusLost(bool closing)
The window has lost focus.
Definition: window.cpp:517
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1048
WindowDesc::nwid_end
const NWidgetPart * nwid_end
Ending of nested widget parts describing the window.
Definition: window_gui.h:169
Window::EnableWidget
void EnableWidget(WidgetID widget_index)
Sets a widget to Enabled.
Definition: window_gui.h:400
WDF_NO_FOCUS
@ WDF_NO_FOCUS
This window won't get focus/make any other window lose focus when click.
Definition: window_gui.h:199
Window::IsWidgetFocused
bool IsWidgetFocused(WidgetID widget_index) const
Check if given widget is focused within this window.
Definition: window_gui.h:420
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
WidgetDimensions::closebox
RectPadding closebox
Padding around image in closebox widget.
Definition: window_gui.h:50
Window::IsWidgetHighlighted
bool IsWidgetHighlighted(WidgetID widget_index) const
Gets the highlighted status of a widget.
Definition: window.cpp:273
Window::RaiseButtons
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition: window.cpp:526
NWidgetLeaf
Leaf widget.
Definition: widget_type.h:886
StringAlignment
StringAlignment
How to align the to-be drawn text.
Definition: gfx_type.h:337
WindowDesc::cls
WindowClass cls
Class of the window,.
Definition: window_gui.h:164
ViewportData::dest_scrollpos_y
int32_t dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition: window_gui.h:251
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:468
Window::OnTimeout
virtual void OnTimeout()
Called when this window's timeout has been reached.
Definition: window_gui.h:743
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:310
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
FR_LOWERED
@ FR_LOWERED
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
Definition: window_gui.h:28
WidgetDimensions::vsep_picker
int vsep_picker
Vertical spacing of picker-window widgets.
Definition: window_gui.h:59
Window::UpdateWidgetSize
virtual void UpdateWidgetSize([[maybe_unused]] WidgetID widget, [[maybe_unused]] Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize)
Update size and resize step of a widget in the window.
Definition: window_gui.h:618
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
ViewportPlaceMethod
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
Definition: viewport_type.h:88
Window::OnPlacePresize
virtual void OnPlacePresize([[maybe_unused]] Point pt, [[maybe_unused]] TileIndex tile)
The user moves over the map when a tile highlight mode has been set when the special mouse mode has b...
Definition: window_gui.h:839
Window::GetCaretPosition
virtual Point GetCaretPosition() const
Get the current caret position if an edit box has the focus.
Definition: window.cpp:379
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:680
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
FR_TRANSPARENT
@ FR_TRANSPARENT
Makes the background transparent if set.
Definition: window_gui.h:26
Window::OnHotkey
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: window.cpp:566
Window::Window
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1757
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1040
Window::nested_focus
const NWidgetCore * nested_focus
Currently focused nested widget, or nullptr if no nested widget has focus.
Definition: window_gui.h:313
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
Window::scheduled_invalidation_data
std::vector< int > scheduled_invalidation_data
Data of scheduled OnInvalidateData() calls.
Definition: window_gui.h:276
Window::OnEditboxChanged
virtual void OnEditboxChanged([[maybe_unused]] WidgetID widget)
The text in an editbox has been edited.
Definition: window_gui.h:765
Window::OnCTRLStateChange
virtual EventState OnCTRLStateChange()
The state of the control key has changed.
Definition: window_gui.h:655
Window::ProcessScheduledInvalidations
void ProcessScheduledInvalidations()
Process all scheduled invalidations.
Definition: window.cpp:3157
Window::OnMouseDrag
virtual void OnMouseDrag([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget)
An 'object' is being dragged at the provided position, highlight the target if possible.
Definition: window_gui.h:695
WindowDesc::default_pos
WindowPosition default_pos
Preferred position of the window.
Definition: window_gui.h:163
WidgetDimensions::shadebox
RectPadding shadebox
Padding around image in shadebox widget.
Definition: window_gui.h:45
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
SetFocusedWindow
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Definition: window.cpp:423
WidgetDimensions::sparse_resize
RectPadding sparse_resize
Padding used for a resizeable 'sparse' widget window, usually containing multiple frames.
Definition: window_gui.h:57
WF_SIZING_LEFT
@ WF_SIZING_LEFT
Window is being resized towards the left.
Definition: window_gui.h:226
Window::SetShaded
void SetShaded(bool make_shaded)
Set the shaded state of the window to make_shaded.
Definition: window.cpp:996
RectPadding
Padding dimensions to apply to each side of a Rect.
Definition: geometry_type.hpp:51
Viewport
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:22
_mouse_hovering
bool _mouse_hovering
The mouse is hovering over the same point.
Definition: window.cpp:91
Window::UnfocusFocusedWidget
void UnfocusFocusedWidget()
Makes no widget on this window have focus.
Definition: window.cpp:471
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
Window::IsWidgetGloballyFocused
bool IsWidgetGloballyFocused(WidgetID widget_index) const
Check if given widget has user input focus.
Definition: window_gui.h:431
WindowDesc::ini_key
const char * ini_key
Key to store window defaults in openttd.cfg. nullptr if nothing shall be stored.
Definition: window_gui.h:166
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
WindowDesc::flags
uint32_t flags
Flags.
Definition: window_gui.h:167
WSM_PRESIZE
@ WSM_PRESIZE
Presizing mode (docks, tunnels).
Definition: window_gui.h:1037
WidgetDimensions::matrix
RectPadding matrix
Padding of WWT_MATRIX items.
Definition: window_gui.h:44
WindowNumber
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:732
WidgetDimensions::picker
RectPadding picker
Padding for a picker (dock, station, etc) window.
Definition: window_gui.h:55
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1747
Window::ProcessHighlightedInvalidations
void ProcessHighlightedInvalidations()
Process all invalidation of highlighted widgets.
Definition: window.cpp:3169
Window::OnMouseWheel
virtual void OnMouseWheel([[maybe_unused]] int wheel)
The mouse wheel has been turned.
Definition: window_gui.h:722
Window::nested_root
std::unique_ptr< NWidgetBase > nested_root
Root of the nested tree.
Definition: window_gui.h:315
Window::ScheduleResize
void ScheduleResize()
Mark this window as resized and in need of OnResize() event.
Definition: window.cpp:3122
Window::HandleButtonClick
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
Definition: window.cpp:591
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:306
WF_CENTERED
@ WF_CENTERED
Window is centered and shall stay centered after ReInit.
Definition: window_gui.h:232
WF_WHITE_BORDER
@ WF_WHITE_BORDER
Window white border counter bit mask.
Definition: window_gui.h:230
ViewportData::dest_scrollpos_x
int32_t dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition: window_gui.h:250
WindowDesc::pref_height
int16_t pref_height
User-preferred height of the window. Zero if unset.
Definition: window_gui.h:174
SpecialMouseMode
SpecialMouseMode
Mouse modes.
Definition: window_gui.h:1033
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
WidgetDimensions::hscrollbar
RectPadding hscrollbar
Padding inside horizontal scrollbar buttons.
Definition: window_gui.h:39
GetToolbarAlignedWindowPosition
Point GetToolbarAlignedWindowPosition(int window_width)
Computer the position of the top-left corner of a window to be opened right under the toolbar.
Definition: window.cpp:1628
Window::OnDragDrop
virtual void OnDragDrop([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget)
A dragged 'object' has been released.
Definition: window_gui.h:702
Window::OnFocus
virtual void OnFocus()
The window has gained focus.
Definition: window.cpp:509
Window::OnPlaceMouseUp
virtual void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, [[maybe_unused]] TileIndex start_tile, [[maybe_unused]] TileIndex end_tile)
The user has dragged over the map when the tile highlight mode has been set.
Definition: window_gui.h:830
ZeroedMemoryAllocator
Base class that provides memory initialization on dynamically created objects.
Definition: alloc_type.hpp:85
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:740
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:135
PickerWindowBase::Close
void Close([[maybe_unused]] int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:3504
Window::DisableAllWidgetHighlight
void DisableAllWidgetHighlight()
Disable the highlighted status of all widgets.
Definition: window.cpp:225
ViewportData::scrollpos_y
int32_t scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition: window_gui.h:249
WindowDesc::GetDefaultHeight
int16_t GetDefaultHeight() const
Determine default height of window.
Definition: window.cpp:148
Window::OnPlaceDrag
virtual void OnPlaceDrag([[maybe_unused]] ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt)
The user is dragging over the map when the tile highlight mode has been set.
Definition: window_gui.h:819
Window::OnTooltip
virtual bool OnTooltip([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget, [[maybe_unused]] TooltipCloseCondition close_cond)
Event to display a custom tooltip.
Definition: window_gui.h:688
Window::ReInit
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:953
Window::DeleteClosedWindows
static void DeleteClosedWindows()
Delete all closed windows.
Definition: window.cpp:65
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:322
Window::LowerWidget
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition: window_gui.h:460
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:303
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:294
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:281
WF_TIMEOUT
@ WF_TIMEOUT
Window timeout counter.
Definition: window_gui.h:222
Textbuf::caret
bool caret
is the caret ("_") visible or not
Definition: textbuf_type.h:38
GuiShowTooltips
void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, uint paramcount=0)
Shows a tooltip.
Definition: misc_gui.cpp:758
WindowClass
WindowClass
Window classes.
Definition: window_type.h:44
Window::ShowNewGRFInspectWindow
virtual void ShowNewGRFInspectWindow() const
Show the NewGRF inspection window.
Definition: window_gui.h:855
Window::GetQueryString
const QueryString * GetQueryString(WidgetID widnum) const
Return the querystring associated to a editbox.
Definition: window.cpp:335
VehicleID
uint32_t VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
WDF_MODAL
@ WDF_MODAL
The window is a modal child of some other window, meaning the parent is 'inactive'.
Definition: window_gui.h:198
TIMEOUT_DURATION
static const int TIMEOUT_DURATION
The initial timeout value for WF_TIMEOUT.
Definition: window_gui.h:236
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
WF_HIGHLIGHTED
@ WF_HIGHLIGHTED
Window has a widget that has a highlight.
Definition: window_gui.h:231
WindowDefaultFlag
WindowDefaultFlag
Window default widget/window handling flags.
Definition: window_gui.h:196
Window::IsWidgetDisabled
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition: window_gui.h:410
WDF_NO_CLOSE
@ WDF_NO_CLOSE
This window can't be interactively closed.
Definition: window_gui.h:200
WSM_DRAGDROP
@ WSM_DRAGDROP
Drag&drop an object.
Definition: window_gui.h:1035
WidgetDimensions::debugbox
RectPadding debugbox
Padding around image in debugbox widget.
Definition: window_gui.h:47
Window::OnInit
virtual void OnInit()
Notification that the nested widget tree gets initialized.
Definition: window_gui.h:576
WSM_SIZING
@ WSM_SIZING
Sizing mode.
Definition: window_gui.h:1036
Window::unshaded_size
Dimension unshaded_size
Last known unshaded size (only valid while shaded).
Definition: window_gui.h:318
WindowDesc::SaveToConfig
static void SaveToConfig()
Save all WindowDesc settings to _windows_file.
Definition: window.cpp:178
string_type.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
Window::SetFocusedWidget
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:487
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:208
WidgetDimensions::inset
RectPadding inset
Padding inside inset container.
Definition: window_gui.h:37
WindowFlags
WindowFlags
Window flags.
Definition: window_gui.h:221
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition: window.cpp:3144
Window::InsertTextString
virtual void InsertTextString(WidgetID wid, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end)
Insert a text string at the cursor position into the edit box widget.
Definition: window.cpp:2636
NWidgetStacked
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:484
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:441
Window::AllWindows
Iterable ensemble of all valid Windows.
Definition: window_gui.h:907
Window::scheduled_resize
bool scheduled_resize
Set if window has been resized.
Definition: window_gui.h:277
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:381
Window::DrawWidget
virtual void DrawWidget([[maybe_unused]] const Rect &r, [[maybe_unused]] WidgetID widget) const
Draw the contents of a nested widget.
Definition: window_gui.h:604
Window::IsWidgetLowered
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:491
Window::querystrings
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:314
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:214
Window::DrawSortButtonState
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:763
vehicle_type.h
Window::SetStringParameters
virtual void SetStringParameters([[maybe_unused]] WidgetID widget) const
Initialize string parameters for a widget.
Definition: window_gui.h:626
Window::OnMouseLoop
virtual void OnMouseLoop()
Called for every mouse loop run, which is at least once per (game) tick.
Definition: window_gui.h:728
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
WidgetDimensions::dropdowntext
RectPadding dropdowntext
Padding of drop down list item.
Definition: window_gui.h:52
WidgetDimensions::vsep_wide
int vsep_wide
Wide vertical spacing.
Definition: window_gui.h:62
ResizeInfo::step_width
uint step_width
Step-size of width resize changes.
Definition: window_gui.h:207
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:557
Window::OnRealtimeTick
virtual void OnRealtimeTick([[maybe_unused]] uint delta_ms)
Called periodically.
Definition: window_gui.h:738
Window::OnPlaceObjectAbort
virtual void OnPlaceObjectAbort()
The user cancelled a tile highlight mode that has been set.
Definition: window_gui.h:809
WidgetLookup
std::map< WidgetID, class NWidgetBase * > WidgetLookup
Lookup between widget IDs and NWidget objects.
Definition: widget_type.h:127
WindowDesc::default_width_trad
int16_t default_width_trad
Preferred initial width of the window (pixels at 1x zoom).
Definition: window_gui.h:183
ResizeInfo
Data structure for resizing a window.
Definition: window_gui.h:206
Window::DisableWidget
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition: window_gui.h:391
Window::closed_windows
static std::vector< Window * > closed_windows
List of closed windows to delete.
Definition: window_gui.h:269
Window::CloseChildWindows
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition: window.cpp:1036
WidgetDimensions::hsep_indent
int hsep_indent
Width of identation for tree layouts.
Definition: window_gui.h:65
tile_type.h
Window::GetTextBoundingRect
virtual Rect GetTextBoundingRect(const char *from, const char *to) const
Get the bounding rectangle for a text range if an edit box has the focus.
Definition: window.cpp:395
Window::OnInvalidateData
virtual void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true)
Some data on this window has become invalid.
Definition: window_gui.h:780
Window::OnQueryTextFinished
virtual void OnQueryTextFinished([[maybe_unused]] char *str)
The query window opened from this window has closed.
Definition: window_gui.h:773
WidgetDimensions::vsep_sparse
int vsep_sparse
Normal vertical spacing for 'sparse' widget window.
Definition: window_gui.h:61
Window::OnPaint
virtual void OnPaint()
The window must be repainted.
Definition: window_gui.h:593
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition: window_gui.h:60
ViewportData::scrollpos_x
int32_t scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition: window_gui.h:248
EventState
EventState
State of handling an event.
Definition: window_type.h:738
WindowDesc::pref_sticky
bool pref_sticky
Preferred stickyness.
Definition: window_gui.h:172
Window::mouse_capture_widget
WidgetID mouse_capture_widget
ID of current mouse capture widget (e.g. dragged scrollbar). -1 if no widget has mouse capture.
Definition: window_gui.h:320
WF_DRAGGING
@ WF_DRAGGING
Window is being dragged.
Definition: window_gui.h:224
WidgetDimensions::vscrollbar
RectPadding vscrollbar
Padding inside vertical scrollbar buttons.
Definition: window_gui.h:38
WidgetDimensions::modalpopup
RectPadding modalpopup
Spacing for popup warning/information windows.
Definition: window_gui.h:54
WSM_DRAGGING
@ WSM_DRAGGING
Dragging mode (trees).
Definition: window_gui.h:1038
WidgetDimensions::stickybox
RectPadding stickybox
Padding around image in stickybox widget.
Definition: window_gui.h:46
Window::window_class
WindowClass window_class
Window class.
Definition: window_gui.h:295
Window::OnRightClick
virtual bool OnRightClick([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget)
A click with the right mouse button has been made on the window.
Definition: window_gui.h:673
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
Window::widget_lookup
WidgetLookup widget_lookup
Indexed access to the nested widget tree. Do not access directly, use Window::GetWidget() instead.
Definition: window_gui.h:316
Window::OnDropdownSelect
virtual void OnDropdownSelect([[maybe_unused]] WidgetID widget, [[maybe_unused]] int index)
A dropdown option associated to this window has been selected.
Definition: window_gui.h:757
PickerWindowBase
Base class for windows opened from a toolbar.
Definition: window_gui.h:980
_special_mouse_mode
SpecialMouseMode _special_mouse_mode
Mode of the mouse.
Definition: window.cpp:93
WidgetDimensions::fullbevel
RectPadding fullbevel
Always-scaled bevel thickness.
Definition: window_gui.h:41
Window::UpdateQueryStringSize
void UpdateQueryStringSize()
Update size of all QueryStrings of this window.
Definition: window.cpp:355
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:304
Window::DrawViewport
void DrawViewport() const
Draw the viewport of this window.
Definition: viewport.cpp:1826
DECLARE_ENUM_AS_BIT_SET
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Definition: company_manager_face.h:29
Window::SetWidgetsLoweredState
void SetWidgetsLoweredState(bool lowered_stat, Args... widgets)
Sets the lowered/raised status of a list of widgets.
Definition: window_gui.h:526
Window::RaiseWidget
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition: window_gui.h:469
NWidgetCore::index
const WidgetID index
Index of the nested widget (-1 means 'not used').
Definition: widget_type.h:378
WHITE_BORDER_DURATION
static const int WHITE_BORDER_DURATION
The initial timeout value for WF_WHITE_BORDER.
Definition: window_gui.h:237
Window::OnHover
virtual void OnHover([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget)
The mouse is hovering over a widget in the window, perform an action for it.
Definition: window_gui.h:680
ViewportData::follow_vehicle
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
Definition: window_gui.h:247
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:305
WindowDesc::LoadFromConfig
static void LoadFromConfig()
Load all WindowDesc settings from _windows_file.
Definition: window.cpp:156
RelocateAllWindows
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
Definition: window.cpp:3435
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:140
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:780
WidgetDimensions::resizebox
RectPadding resizebox
Padding around image in resizebox widget.
Definition: window_gui.h:49
FR_DARKENED
@ FR_DARKENED
If set the background is darker, allows for lowered frames with normal background colour when used wi...
Definition: window_gui.h:29
Window::GetRowFromWidget
int GetRowFromWidget(int clickpos, WidgetID widget, int padding, int line_height=-1) const
Compute the row of a widget that a user clicked in.
Definition: window.cpp:214
Window::scale
int scale
Scale of this window – used to determine how to resize.
Definition: window_gui.h:298
Window::window_desc
WindowDesc * window_desc
Window description.
Definition: window_gui.h:293
WidgetDimensions::bevel
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition: window_gui.h:40
Window::RaiseWidgetsWhenLowered
void RaiseWidgetsWhenLowered(Args... widgets)
Raises the widgets and sets widgets dirty that are lowered.
Definition: window_gui.h:536
WidgetDimensions::frametext
RectPadding frametext
Padding inside frame with text.
Definition: window_gui.h:43
FontSize
FontSize
Available font sizes.
Definition: gfx_type.h:202
WindowDesc::parent_cls
WindowClass parent_cls
Class of the parent window.
Definition: window_gui.h:165
Window
Data structure for an opened window.
Definition: window_gui.h:267
viewport_type.h
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
FindWindowFromPt
Window * FindWindowFromPt(int x, int y)
Do a search for a window at specific coordinates.
Definition: window.cpp:1769
AllEqual
bool AllEqual(It begin, It end, Pred pred)
Generic helper function that checks if all elements of the range are equal with respect to the given ...
Definition: window_gui.h:934
Window::OnMouseOver
virtual void OnMouseOver([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget)
The mouse is currently moving over the window or has just moved outside of the window.
Definition: window_gui.h:716
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:215
SBS_OFF
@ SBS_OFF
Do not sort (with this button).
Definition: window_gui.h:213
Window::SetWidgetHighlight
void SetWidgetHighlight(WidgetID widget_index, TextColour highlighted_colour)
Sets the highlighted status of a widget.
Definition: window.cpp:243
Window::RaiseWidgetWhenLowered
void RaiseWidgetWhenLowered(byte widget_index)
Marks a widget as raised and dirty (redraw), when it is marked as lowered.
Definition: window_gui.h:478
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:356
WindowDesc::GetDefaultWidth
int16_t GetDefaultWidth() const
Determine default width of window.
Definition: window.cpp:138
WindowDesc::file
const char *const file
Source file of this definition.
Definition: window_gui.h:161
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
Window::ToggleWidgetLoweredState
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
Definition: window_gui.h:450
WidgetDimensions::defsizebox
RectPadding defsizebox
Padding around image in defsizebox widget.
Definition: window_gui.h:48
Window::HandleEditBoxKey
EventState HandleEditBoxKey(WidgetID wid, char32_t key, uint16_t keycode)
Process keypress for editbox widget.
Definition: window.cpp:2478
WindowDesc::nwid_begin
const NWidgetPart * nwid_begin
Beginning of nested widget parts describing the window.
Definition: window_gui.h:168
Window::SetWidgetsDisabledState
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition: window_gui.h:515
Window::OnResize
virtual void OnResize()
Called after the window got resized.
Definition: window_gui.h:750
Window::OnVehicleSelect
virtual bool OnVehicleSelect([[maybe_unused]] VehicleList::const_iterator begin, [[maybe_unused]] VehicleList::const_iterator end)
The user clicked on a vehicle while HT_VEHICLE has been set.
Definition: window_gui.h:804
WindowDesc::hotkeys
HotkeyList * hotkeys
Hotkeys for the window.
Definition: window_gui.h:170
NWidgetStacked::shown_plane
int shown_plane
Plane being displayed (for NWID_SELECTION only).
Definition: widget_type.h:498
GetWidgetFromPos
WidgetID GetWidgetFromPos(const Window *w, int x, int y)
Returns the index for the widget located at the given position relative to the window.
Definition: widget.cpp:266
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition: window_gui.h:42
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
WindowPosition
WindowPosition
How do we the window to be placed?
Definition: window_gui.h:139
Window::OnClick
virtual void OnClick([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget, [[maybe_unused]] int click_count)
A click with the left mouse button has been made on the window.
Definition: window_gui.h:664
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:142
company_type.h
WidgetDimensions
Definition: window_gui.h:34
WidgetDimensions::sparse
RectPadding sparse
Padding used for 'sparse' widget window, usually containing multiple frames.
Definition: window_gui.h:56
NWidgetCore::SetDisabled
void SetDisabled(bool disabled)
Disable (grey-out) or enable the widget.
Definition: widget_type.h:429
Window::white_border_timer
uint8_t white_border_timer
Timer value of the WF_WHITE_BORDER for flags.
Definition: window_gui.h:301
Window::OnKeyPress
virtual EventState OnKeyPress([[maybe_unused]] char32_t key, [[maybe_unused]] uint16_t keycode)
A key has been pressed.
Definition: window_gui.h:646
WSM_NONE
@ WSM_NONE
No special mouse mode.
Definition: window_gui.h:1034
Window::InitializeData
void InitializeData(WindowNumber window_number)
Initializes the data (except the position and initial size) of a new Window.
Definition: window.cpp:1365
FR_BORDERONLY
@ FR_BORDERONLY
Draw border only, no background.
Definition: window_gui.h:27
Window::FindChildWindow
Window * FindChildWindow(WindowClass wc=WC_INVALID) const
Find the Window whose parent pointer points to this window.
Definition: window.cpp:1023
Window::FindWindowPlacementAndResize
virtual void FindWindowPlacementAndResize(int def_width, int def_height)
Resize window towards the default size.
Definition: window.cpp:1421
WidgetDimensions::captiontext
RectPadding captiontext
Padding for text within caption widget.
Definition: window_gui.h:51
Textbuf
Helper/buffer for input fields.
Definition: textbuf_type.h:30
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1224
DrawCaption
void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align, FontSize fs)
Draw a caption bar.
Definition: widget.cpp:679
Window::GetWidget
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition: window_gui.h:971
Window::ProcessScheduledResize
void ProcessScheduledResize()
Process scheduled OnResize() event.
Definition: window.cpp:3130