OpenTTD Source: src/window_gui.h Source File

OpenTTD Source 15.3

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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 class FrameFlag : uint8_t {
25 Transparent,
26 BorderOnly,
27 Lowered,
28 Darkened,
29};
30 using FrameFlags = EnumBitSet<FrameFlag, uint8_t>;
31
32 class WidgetDimensions {
33public:
34 RectPadding imgbtn;
35 RectPadding inset;
36 RectPadding vscrollbar;
37 RectPadding hscrollbar;
38 RectPadding bevel;
39 RectPadding fullbevel;
40 RectPadding framerect;
41 RectPadding frametext;
42 RectPadding matrix;
43 RectPadding shadebox;
44 RectPadding stickybox;
45 RectPadding debugbox;
46 RectPadding defsizebox;
47 RectPadding resizebox;
48 RectPadding closebox;
49 RectPadding captiontext;
50 RectPadding dropdowntext;
51 RectPadding dropdownlist;
52 RectPadding modalpopup;
53 RectPadding picker;
54 RectPadding sparse;
55 RectPadding sparse_resize;
56
57 int vsep_picker;
58 int vsep_normal;
59 int vsep_sparse;
60 int vsep_wide;
61 int hsep_normal;
62 int hsep_wide;
63 int hsep_indent;
64
65 static const WidgetDimensions unscaled;
66 static WidgetDimensions scaled;
67
68 static constexpr float ASPECT_LOCATION = 12.f / 14.f;
69 static constexpr float ASPECT_RENAME = 12.f / 14.f;
70 static constexpr float ASPECT_TOGGLE_SIZE = 12.f / 14.f;
71 static constexpr float ASPECT_LEFT_RIGHT_BUTTON = 8.f / 12.f;
72 static constexpr float ASPECT_UP_DOWN_BUTTON = 11.f / 12.f;
73 static constexpr float ASPECT_VEHICLE_ICON = 15.f / 12.f;
74 static constexpr float ASPECT_VEHICLE_FLAG = 11.f / 12.f;
75
76private:
81 static constexpr uint WD_SHADEBOX_WIDTH = 12;
82 static constexpr uint WD_STICKYBOX_WIDTH = 12;
83 static constexpr uint WD_DEBUGBOX_WIDTH = 12;
84 static constexpr uint WD_DEFSIZEBOX_WIDTH = 12;
85 static constexpr uint WD_RESIZEBOX_WIDTH = 12;
86 static constexpr uint WD_CLOSEBOX_WIDTH = 11;
87 static constexpr uint WD_CAPTION_HEIGHT = 14;
88 static constexpr uint WD_DROPDOWN_HEIGHT = 12;
89
90 friend NWidgetLeaf;
91};
92
93 inline constexpr WidgetDimensions WidgetDimensions::unscaled = {
94 .imgbtn = { .left = 1, .top = 1, .right = 1, .bottom = 1},
95 .inset = { .left = 2, .top = 1, .right = 2, .bottom = 1},
96 .vscrollbar = { .left = 2, .top = 3, .right = 2, .bottom = 3},
97 .hscrollbar = { .left = 3, .top = 2, .right = 3, .bottom = 2},
98 .bevel = { .left = 1, .top = 1, .right = 1, .bottom = 1},
99 .fullbevel = { .left = 1, .top = 1, .right = 1, .bottom = 1},
100 .framerect = { .left = 2, .top = 1, .right = 2, .bottom = 1},
101 .frametext = { .left = 6, .top = 6, .right = 6, .bottom = 6},
102 .matrix = { .left = 2, .top = 3, .right = 2, .bottom = 1},
103 .shadebox = { .left = 2, .top = 3, .right = 2, .bottom = 3},
104 .stickybox = { .left = 2, .top = 3, .right = 2, .bottom = 3},
105 .debugbox = { .left = 2, .top = 3, .right = 2, .bottom = 3},
106 .defsizebox = { .left = 2, .top = 3, .right = 2, .bottom = 3},
107 .resizebox = { .left = 2, .top = 2, .right = 2, .bottom = 2},
108 .closebox = { .left = 2, .top = 2, .right = 1, .bottom = 2},
109 .captiontext = { .left = 2, .top = 2, .right = 2, .bottom = 2},
110 .dropdowntext = { .left = 2, .top = 1, .right = 2, .bottom = 1},
111 .dropdownlist = { .left = 1, .top = 2, .right = 1, .bottom = 2},
112 .modalpopup = { .left = 20, .top = 10, .right = 20, .bottom = 10},
113 .picker = { .left = 3, .top = 3, .right = 3, .bottom = 3},
114 .sparse = { .left = 10, .top = 8, .right = 10, .bottom = 8},
115 .sparse_resize = { .left = 10, .top = 8, .right = 10, .bottom = 0},
116 .vsep_picker = 1,
117 .vsep_normal = 2,
118 .vsep_sparse = 4,
119 .vsep_wide = 8,
120 .hsep_normal = 2,
121 .hsep_wide = 6,
122 .hsep_indent = 10,
123};
124
125/* widget.cpp */
126void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags);
127
128inline void DrawFrameRect(const Rect &r, Colours colour, FrameFlags flags)
129{
130 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, flags);
131}
132
133void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, std::string_view str, StringAlignment align, FontSize fs);
134
135/* window.cpp */
136using WindowList = std::list<Window *>;
137extern WindowList _z_windows;
138extern Window *_focused_window;
139
140
142 enum WindowPosition : uint8_t {
143 WDP_MANUAL,
144 WDP_AUTO,
145 WDP_CENTER,
146 WDP_ALIGN_TOOLBAR,
147};
148
152 enum class WindowDefaultFlag : uint8_t {
153 Construction,
154 Modal,
155 NoFocus,
156 NoClose,
157};
158using WindowDefaultFlags = EnumBitSet<WindowDefaultFlag, uint8_t>;
159
160 Point GetToolbarAlignedWindowPosition(int window_width);
161 Point AlignInitialConstructionToolbar(int window_width);
162
163struct HotkeyList;
164
168 struct WindowDesc {
169
170 WindowDesc(WindowPosition default_pos, std::string_view ini_key, int16_t def_width_trad, int16_t def_height_trad,
171 WindowClass window_class, WindowClass parent_class, WindowDefaultFlags flags,
172 const std::span<const NWidgetPart> nwid_parts, HotkeyList *hotkeys = nullptr,
173 const std::source_location location = std::source_location::current());
174
175 ~WindowDesc();
176
177 const std::source_location source_location;
178 const WindowPosition default_pos;
179 const WindowClass cls;
180 const WindowClass parent_cls;
181 const std::string_view ini_key;
182 const WindowDefaultFlags flags;
183 const std::span<const NWidgetPart> nwid_parts;
184 const HotkeyList *hotkeys;
185
186 bool pref_sticky = false;
187 int16_t pref_width = 0;
188 int16_t pref_height = 0;
189
190 int16_t GetDefaultWidth() const;
191 int16_t GetDefaultHeight() const;
192
193 static void LoadFromConfig();
194 static void SaveToConfig();
195
196private:
197 const int16_t default_width_trad;
198 const int16_t default_height_trad;
199
204 WindowDesc(const WindowDesc &) = delete;
205 WindowDesc& operator=(const WindowDesc &) = delete;
206};
207
211 struct ResizeInfo {
212 uint step_width;
213 uint step_height;
214};
215
217 enum SortButtonState : uint8_t {
218 SBS_OFF,
219 SBS_DOWN,
220 SBS_UP,
221};
222
226 enum class WindowFlag : uint8_t {
227 Timeout,
228
229 Dragging,
230 SizingRight,
231 SizingLeft,
232
233 Sticky,
234 DisableVpScroll,
235 WhiteBorder,
236 Highlighted,
237 Centred,
238};
239using WindowFlags = EnumBitSet<WindowFlag, uint16_t>;
240
241 static const int TIMEOUT_DURATION = 7;
242 static const int WHITE_BORDER_DURATION = 3;
243
251 struct ViewportData : Viewport {
252 VehicleID follow_vehicle;
253 int32_t scrollpos_x;
254 int32_t scrollpos_y;
255 int32_t dest_scrollpos_x;
256 int32_t dest_scrollpos_y;
257
258 void CancelFollow(const Window &viewport_window);
259};
260
261struct QueryString;
262
263/* misc_gui.cpp */
264enum TooltipCloseCondition : uint8_t {
265 TCC_RIGHT_CLICK,
266 TCC_HOVER,
267 TCC_NONE,
268 TCC_EXIT_VIEWPORT,
269};
270
274 struct Window {
275private:
276 static std::vector<Window *> closed_windows;
277
278protected:
279 void InitializeData(WindowNumber window_number);
280 void InitializePositionSize(int x, int y, int min_width, int min_height);
281 virtual void FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize);
282
283 std::vector<int> scheduled_invalidation_data{};
284 bool scheduled_resize = false;
285
286 /* Protected to prevent deletion anywhere outside Window::DeleteClosedWindows(). */
287 virtual ~Window();
288
289public:
290 Window(WindowDesc &desc);
291
298 inline void *operator new[](size_t size) = delete;
299
300 WindowDesc &window_desc;
301 WindowFlags flags{};
302 WindowClass window_class{};
303 WindowNumber window_number = 0;
304
305 int scale = 0;
306
307 uint8_t timeout_timer = 0;
308 uint8_t white_border_timer = 0;
309
310 int left = 0;
311 int top = 0;
312 int width = 0;
313 int height = 0;
314
315 ResizeInfo resize{};
316
317 Owner owner = INVALID_OWNER;
318
319 std::unique_ptr<ViewportData> viewport;
320 const NWidgetCore *nested_focus = nullptr;
321 std::map<WidgetID, QueryString*> querystrings{};
322 std::unique_ptr<NWidgetBase> nested_root{};
323 WidgetLookup widget_lookup{};
324 NWidgetStacked *shade_select = nullptr;
325 Dimension unshaded_size{};
326
327 WidgetID mouse_capture_widget = INVALID_WIDGET;
328
329 Window *parent = nullptr;
330 WindowList::iterator z_position{};
331
332 template <class NWID>
333 inline const NWID *GetWidget(WidgetID widnum) const;
334 template <class NWID>
335 inline NWID *GetWidget(WidgetID widnum);
336
337 const Scrollbar *GetScrollbar(WidgetID widnum) const;
338 Scrollbar *GetScrollbar(WidgetID widnum);
339
340 const QueryString *GetQueryString(WidgetID widnum) const;
341 QueryString *GetQueryString(WidgetID widnum);
342 void UpdateQueryStringSize();
343
344 virtual const struct Textbuf *GetFocusedTextbuf() const;
345 virtual Point GetCaretPosition() const;
346 virtual Rect GetTextBoundingRect(size_t from, size_t to) const;
347 virtual ptrdiff_t GetTextCharacterAtPosition(const Point &pt) const;
348
349 void InitNested(WindowNumber number = 0);
350 void CreateNestedTree();
351 void FinishInitNested(WindowNumber window_number = 0);
352
356 inline void SetTimeout()
357 {
358 this->flags.Set(WindowFlag::Timeout);
359 this->timeout_timer = TIMEOUT_DURATION;
360 }
361
365 inline void SetWhiteBorder()
366 {
367 this->flags.Set(WindowFlag::WhiteBorder);
368 this->white_border_timer = WHITE_BORDER_DURATION;
369 }
370
371 void DisableAllWidgetHighlight();
372 void SetWidgetHighlight(WidgetID widget_index, TextColour highlighted_colour);
373 bool IsWidgetHighlighted(WidgetID widget_index) const;
374
382 inline void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
383 {
384 NWidgetCore *nwid = this->GetWidget<NWidgetCore>(widget_index);
385 if (nwid != nullptr) nwid->SetDisabled(disab_stat);
386 }
387
392 inline void DisableWidget(WidgetID widget_index)
393 {
394 SetWidgetDisabledState(widget_index, true);
395 }
396
401 inline void EnableWidget(WidgetID widget_index)
402 {
403 SetWidgetDisabledState(widget_index, false);
404 }
405
411 inline bool IsWidgetDisabled(WidgetID widget_index) const
412 {
413 return this->GetWidget<NWidgetCore>(widget_index)->IsDisabled();
414 }
415
421 inline bool IsWidgetFocused(WidgetID widget_index) const
422 {
423 return this->nested_focus != nullptr && this->nested_focus->GetIndex() == widget_index;
424 }
425
432 inline bool IsWidgetGloballyFocused(WidgetID widget_index) const
433 {
434 return _focused_window == this && IsWidgetFocused(widget_index);
435 }
436
442 inline void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
443 {
444 this->GetWidget<NWidgetCore>(widget_index)->SetLowered(lowered_stat);
445 }
446
451 inline void ToggleWidgetLoweredState(WidgetID widget_index)
452 {
453 bool lowered_state = this->GetWidget<NWidgetCore>(widget_index)->IsLowered();
454 this->GetWidget<NWidgetCore>(widget_index)->SetLowered(!lowered_state);
455 }
456
461 inline void LowerWidget(WidgetID widget_index)
462 {
463 SetWidgetLoweredState(widget_index, true);
464 }
465
470 inline void RaiseWidget(WidgetID widget_index)
471 {
472 SetWidgetLoweredState(widget_index, false);
473 }
474
479 inline void RaiseWidgetWhenLowered(WidgetID widget_index)
480 {
481 if (this->IsWidgetLowered(widget_index)) {
482 this->RaiseWidget(widget_index);
483 this->SetWidgetDirty(widget_index);
484 }
485 }
486
492 inline bool IsWidgetLowered(WidgetID widget_index) const
493 {
494 return this->GetWidget<NWidgetCore>(widget_index)->IsLowered();
495 }
496
497 void UnfocusFocusedWidget();
498 bool SetFocusedWidget(WidgetID widget_index);
499
500 EventState HandleEditBoxKey(WidgetID wid, char32_t key, uint16_t keycode);
501 virtual void InsertTextString(WidgetID wid, std::string_view str, bool marked, std::optional<size_t> caret, std::optional<size_t> insert_location, std::optional<size_t> replacement_end);
502
503 void HandleButtonClick(WidgetID widget);
504 int GetRowFromWidget(int clickpos, WidgetID widget, int padding, int line_height = -1) const;
505
506 void RaiseButtons(bool autoraise = false);
507
515 template <typename... Args>
516 void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
517 {
518 (SetWidgetDisabledState(widgets, disab_stat), ...);
519 }
520
526 template <typename... Args>
527 void SetWidgetsLoweredState(bool lowered_stat, Args... widgets)
528 {
529 (SetWidgetLoweredState(widgets, lowered_stat), ...);
530 }
531
536 template <typename... Args>
537 void RaiseWidgetsWhenLowered(Args... widgets)
538 {
539 (this->RaiseWidgetWhenLowered(widgets), ...);
540 }
541
542 void SetWidgetDirty(WidgetID widget_index) const;
543
544 void DrawWidgets() const;
545 void DrawViewport() const;
546 void DrawSortButtonState(WidgetID widget, SortButtonState state) const;
547 static int SortButtonWidth();
548
549 Window *FindChildWindow(WindowClass wc = WC_INVALID) const;
550 Window *FindChildWindowById(WindowClass wc, WindowNumber number) const;
551 void CloseChildWindows(WindowClass wc = WC_INVALID) const;
552 void CloseChildWindowById(WindowClass wc, WindowNumber number) const;
553 virtual void Close(int data = 0);
554 static void DeleteClosedWindows();
555
556 void SetDirty() const;
557 void ReInit(int rx = 0, int ry = 0, bool reposition = false);
558
560 inline bool IsShaded() const
561 {
562 return this->shade_select != nullptr && this->shade_select->shown_plane == SZSP_HORIZONTAL;
563 }
564
565 void SetShaded(bool make_shaded);
566
567 void ScheduleResize();
568 void ProcessScheduledResize();
569 void InvalidateData(int data = 0, bool gui_scope = true);
570 void ProcessScheduledInvalidations();
571 void ProcessHighlightedInvalidations();
572
573 /*** Event handling ***/
574
579 virtual void OnInit() { }
580
581 virtual void ApplyDefaults();
582
590 virtual Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number);
591
596 virtual void OnPaint()
597 {
598 this->DrawWidgets();
599 }
600
607 virtual void DrawWidget([[maybe_unused]] const Rect &r, [[maybe_unused]] WidgetID widget) const {}
608
621 virtual void UpdateWidgetSize([[maybe_unused]] WidgetID widget, [[maybe_unused]] Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) {}
622
631 virtual std::string GetWidgetString([[maybe_unused]] WidgetID widget, StringID stringid) const;
632
636 virtual void OnFocus();
637
642 virtual void OnFocusLost(bool closing);
643
651 virtual EventState OnKeyPress([[maybe_unused]] char32_t key, [[maybe_unused]] uint16_t keycode) { return ES_NOT_HANDLED; }
652
653 virtual EventState OnHotkey(int hotkey);
654
660 virtual EventState OnCTRLStateChange() { return ES_NOT_HANDLED; }
661
662
669 virtual void OnClick([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget, [[maybe_unused]] int click_count) {}
670
678 virtual bool OnRightClick([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget) { return false; }
679
685 virtual void OnHover([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget) {}
686
693 virtual bool OnTooltip([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget, [[maybe_unused]] TooltipCloseCondition close_cond) { return false; }
694
700 virtual void OnMouseDrag([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget) {}
701
707 virtual void OnDragDrop([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget) {}
708
713 virtual void OnScroll([[maybe_unused]] Point delta) {}
714
720 virtual void OnScrollbarScroll([[maybe_unused]] WidgetID widget) {}
721
728 virtual void OnMouseOver([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget) {}
729
735 virtual void OnMouseWheel([[maybe_unused]] int wheel, [[maybe_unused]] WidgetID widget) {}
736
737
741 virtual void OnMouseLoop() {}
742
746 virtual void OnGameTick() {}
747
751 virtual void OnRealtimeTick([[maybe_unused]] uint delta_ms) {}
752
756 virtual void OnTimeout() {}
757
758
763 virtual void OnResize() {}
764
770 virtual void OnDropdownSelect([[maybe_unused]] WidgetID widget, [[maybe_unused]] int index, [[maybe_unused]] int click_result) {}
771
772 virtual void OnDropdownClose(Point pt, WidgetID widget, int index, int click_result, bool instant_close);
773
778 virtual void OnEditboxChanged([[maybe_unused]] WidgetID widget) {}
779
786 virtual void OnQueryTextFinished([[maybe_unused]] std::optional<std::string> str) {}
787
793 virtual void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) {}
794
801 virtual void OnPlaceObject([[maybe_unused]] Point pt, [[maybe_unused]] TileIndex tile) {}
802
809 virtual bool OnVehicleSelect([[maybe_unused]] const struct Vehicle *v) { return false; }
810
817 virtual bool OnVehicleSelect([[maybe_unused]] VehicleList::const_iterator begin, [[maybe_unused]] VehicleList::const_iterator end) { return false; }
818
822 virtual void OnPlaceObjectAbort() {}
823
824
832 virtual void OnPlaceDrag([[maybe_unused]] ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt) {}
833
843 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) {}
844
852 virtual void OnPlacePresize([[maybe_unused]] Point pt, [[maybe_unused]] TileIndex tile) {}
853
854 /*** End of the event handling ***/
855
860 virtual bool IsNewGRFInspectable() const { return false; }
861
868 virtual void ShowNewGRFInspectWindow() const { NOT_REACHED(); }
869
874 template <bool TtoBack>
875 struct WindowIterator {
876 typedef Window *value_type;
877 typedef value_type *pointer;
878 typedef value_type &reference;
879 typedef size_t difference_type;
880 typedef std::forward_iterator_tag iterator_category;
881
882 explicit WindowIterator(WindowList::iterator start) : it(start)
883 {
884 this->Validate();
885 }
886 explicit WindowIterator(const Window *w) : it(w->z_position) {}
887
888 bool operator==(const WindowIterator &other) const { return this->it == other.it; }
889 Window * operator*() const { return *this->it; }
890 WindowIterator & operator++() { this->Next(); this->Validate(); return *this; }
891
892 bool IsEnd() const { return this->it == _z_windows.end(); }
893
894 private:
895 WindowList::iterator it;
896 void Validate()
897 {
898 while (!this->IsEnd() && *this->it == nullptr) this->Next();
899 }
900 void Next()
901 {
902 if constexpr (!TtoBack) {
903 ++this->it;
904 } else if (this->it == _z_windows.begin()) {
905 this->it = _z_windows.end();
906 } else {
907 --this->it;
908 }
909 }
910 };
911 using IteratorToFront = WindowIterator<false>;
912 using IteratorToBack = WindowIterator<true>;
913
918 template <bool Tfront>
919 struct AllWindows {
920 AllWindows() {}
921 WindowIterator<Tfront> begin()
922 {
923 if constexpr (Tfront) {
924 auto back = _z_windows.end();
925 if (back != _z_windows.begin()) --back;
926 return WindowIterator<Tfront>(back);
927 } else {
928 return WindowIterator<Tfront>(_z_windows.begin());
929 }
930 }
931 WindowIterator<Tfront> end() { return WindowIterator<Tfront>(_z_windows.end()); }
932 };
933 using Iterate = AllWindows<false>;
934 using IterateFromBack = AllWindows<false>;
935 using IterateFromFront = AllWindows<true>;
936};
937
945template <class It, class Pred>
946 inline bool AllEqual(It begin, It end, Pred pred)
947{
948 return std::adjacent_find(begin, end, std::not_fn(pred)) == end;
949}
950
957template <class NWID>
958 inline NWID *Window::GetWidget(WidgetID widnum)
959{
960 auto it = this->widget_lookup.find(widnum);
961 if (it == std::end(this->widget_lookup)) return nullptr;
962 NWID *nwid = dynamic_cast<NWID *>(it->second);
963 assert(nwid != nullptr);
964 return nwid;
965}
966
968template <>
969 inline const NWidgetBase *Window::GetWidget<NWidgetBase>(WidgetID widnum) const
970{
971 auto it = this->widget_lookup.find(widnum);
972 if (it == std::end(this->widget_lookup)) return nullptr;
973 return it->second;
974}
975
982template <class NWID>
983 inline const NWID *Window::GetWidget(WidgetID widnum) const
984{
985 return const_cast<Window *>(this)->GetWidget<NWID>(widnum);
986}
987
988
992 class PickerWindowBase : public Window {
993
994public:
995 PickerWindowBase(WindowDesc &desc, Window *parent) : Window(desc)
996 {
997 this->parent = parent;
998 }
999
1000 void Close([[maybe_unused]] int data = 0) override;
1001};
1002
1003 Window *BringWindowToFrontById(WindowClass cls, WindowNumber number);
1004 Window *FindWindowFromPt(int x, int y);
1005
1015template <typename Twindow, bool Treturn_existing = false, typename... Targs>
1016Twindow *AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
1017{
1018 Twindow *w = static_cast<Twindow *>(BringWindowToFrontById(desc.cls, window_number));
1019 if (w != nullptr) return Treturn_existing ? w : nullptr;
1020 return new Twindow(desc, window_number, std::forward<Targs>(extra_arguments)...);
1021}
1022
1023void RelocateAllWindows(int neww, int newh);
1024
1025void GuiShowTooltips(Window *parent, EncodedString &&text, TooltipCloseCondition close_tooltip);
1026
1027/* widget.cpp */
1028 WidgetID GetWidgetFromPos(const Window *w, int x, int y);
1029
1030extern Point _cursorpos_drag_start;
1031
1032extern int _scrollbar_start_pos;
1033extern int _scrollbar_size;
1034extern uint8_t _scroller_click_timeout;
1035
1036extern bool _scrolling_viewport;
1037extern bool _mouse_hovering;
1038
1040 enum SpecialMouseMode : uint8_t {
1041 WSM_NONE,
1042 WSM_DRAGDROP,
1043 WSM_SIZING,
1044 WSM_PRESIZE,
1045 WSM_DRAGGING,
1046};
1047extern SpecialMouseMode _special_mouse_mode;
1048
1049void SetFocusedWindow(Window *w);
1050
1051void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y);
1052 Rect ScrollRect(Rect r, const Scrollbar &sb, int resize_step = 1);
1053
1054#endif /* WINDOW_GUI_H */
BaseBitSet::Set
constexpr Timpl & Set()
Set all bits.
Definition base_bitset_type.hpp:40
EncodedString
Container for an encoded string, created by GetEncodedString.
Definition strings_type.h:98
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
NWidgetBase
Baseclass for nested widgets.
Definition widget_type.h:137
NWidgetCore
Base class for a 'real' widget.
Definition widget_type.h:371
NWidgetCore::SetDisabled
void SetDisabled(bool disabled)
Disable (grey-out) or enable the widget.
Definition widget_type.h:458
NWidgetLeaf
Leaf widget.
Definition widget_type.h:931
NWidgetStacked
Stacked widgets, widgets all occupying the same space in the window.
Definition widget_type.h:524
NWidgetStacked::shown_plane
int shown_plane
Plane being displayed (for NWID_SELECTION only).
Definition widget_type.h:537
PickerWindowBase
Base class for windows opened from a toolbar.
Definition window_gui.h:992
PickerWindowBase::Close
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:3602
Scrollbar
Scrollbar data structure.
Definition widget_type.h:711
WidgetDimensions
Definition window_gui.h:32
WidgetDimensions::WD_CAPTION_HEIGHT
static constexpr uint WD_CAPTION_HEIGHT
Minimum height of a title bar.
Definition window_gui.h:87
WidgetDimensions::defsizebox
RectPadding defsizebox
Padding around image in defsizebox widget.
Definition window_gui.h:46
WidgetDimensions::closebox
RectPadding closebox
Padding around image in closebox widget.
Definition window_gui.h:48
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:40
WidgetDimensions::WD_DROPDOWN_HEIGHT
static constexpr uint WD_DROPDOWN_HEIGHT
Minimum height of a drop down widget.
Definition window_gui.h:88
WidgetDimensions::captiontext
RectPadding captiontext
Padding for text within caption widget.
Definition window_gui.h:49
WidgetDimensions::sparse_resize
RectPadding sparse_resize
Padding used for a resizeable 'sparse' widget window, usually containing multiple frames.
Definition window_gui.h:55
WidgetDimensions::debugbox
RectPadding debugbox
Padding around image in debugbox widget.
Definition window_gui.h:45
WidgetDimensions::vsep_sparse
int vsep_sparse
Normal vertical spacing for 'sparse' widget window.
Definition window_gui.h:59
WidgetDimensions::sparse
RectPadding sparse
Padding used for 'sparse' widget window, usually containing multiple frames.
Definition window_gui.h:54
WidgetDimensions::frametext
RectPadding frametext
Padding inside frame with text.
Definition window_gui.h:41
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
WidgetDimensions::modalpopup
RectPadding modalpopup
Spacing for popup warning/information windows.
Definition window_gui.h:52
WidgetDimensions::hscrollbar
RectPadding hscrollbar
Padding inside horizontal scrollbar buttons.
Definition window_gui.h:37
WidgetDimensions::shadebox
RectPadding shadebox
Padding around image in shadebox widget.
Definition window_gui.h:43
WidgetDimensions::resizebox
RectPadding resizebox
Padding around image in resizebox widget.
Definition window_gui.h:47
WidgetDimensions::vscrollbar
RectPadding vscrollbar
Padding inside vertical scrollbar buttons.
Definition window_gui.h:36
WidgetDimensions::imgbtn
RectPadding imgbtn
Padding around image button image.
Definition window_gui.h:34
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:58
WidgetDimensions::vsep_picker
int vsep_picker
Vertical spacing of picker-window widgets.
Definition window_gui.h:57
WidgetDimensions::vsep_wide
int vsep_wide
Wide vertical spacing.
Definition window_gui.h:60
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition window_gui.h:62
WidgetDimensions::WD_CLOSEBOX_WIDTH
static constexpr uint WD_CLOSEBOX_WIDTH
Minimum width of a close box widget.
Definition window_gui.h:86
WidgetDimensions::fullbevel
RectPadding fullbevel
Always-scaled bevel thickness.
Definition window_gui.h:39
WidgetDimensions::inset
RectPadding inset
Padding inside inset container.
Definition window_gui.h:35
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
WidgetDimensions::WD_RESIZEBOX_WIDTH
static constexpr uint WD_RESIZEBOX_WIDTH
Minimum width of a resize box widget.
Definition window_gui.h:85
WidgetDimensions::picker
RectPadding picker
Padding for a picker (dock, station, etc) window.
Definition window_gui.h:53
WidgetDimensions::WD_STICKYBOX_WIDTH
static constexpr uint WD_STICKYBOX_WIDTH
Minimum width of a standard sticky box widget.
Definition window_gui.h:82
WidgetDimensions::matrix
RectPadding matrix
Padding of WWT_MATRIX items.
Definition window_gui.h:42
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition window_gui.h:61
WidgetDimensions::dropdownlist
RectPadding dropdownlist
Padding of complete drop down list.
Definition window_gui.h:51
WidgetDimensions::WD_DEBUGBOX_WIDTH
static constexpr uint WD_DEBUGBOX_WIDTH
Minimum width of a standard debug box widget.
Definition window_gui.h:83
WidgetDimensions::stickybox
RectPadding stickybox
Padding around image in stickybox widget.
Definition window_gui.h:44
WidgetDimensions::WD_DEFSIZEBOX_WIDTH
static constexpr uint WD_DEFSIZEBOX_WIDTH
Minimum width of a standard defsize box widget.
Definition window_gui.h:84
WidgetDimensions::bevel
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition window_gui.h:38
WidgetDimensions::dropdowntext
RectPadding dropdowntext
Padding of drop down list item.
Definition window_gui.h:50
WidgetDimensions::WD_SHADEBOX_WIDTH
static constexpr uint WD_SHADEBOX_WIDTH
Distances used in drawing widgets.
Definition window_gui.h:81
WidgetDimensions::hsep_indent
int hsep_indent
Width of indentation for tree layouts.
Definition window_gui.h:63
company_type.h
Types related to companies.
INVALID_OWNER
static constexpr Owner INVALID_OWNER
An invalid owner.
Definition company_type.h:30
FontSize
FontSize
Available font sizes.
Definition gfx_type.h:248
StringAlignment
StringAlignment
How to align the to-be drawn text.
Definition gfx_type.h:387
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:307
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:968
string_type.h
Types for strings.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
Coord2D< int >
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:56
HotkeyList
List of hotkeys for a window.
Definition hotkeys.h:37
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
QueryString
Data stored about a string that can be modified in the GUI.
Definition querystring_gui.h:20
RectPadding
Padding dimensions to apply to each side of a Rect.
Definition geometry_type.hpp:77
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
ResizeInfo
Data structure for resizing a window.
Definition window_gui.h:211
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition window_gui.h:213
ResizeInfo::step_width
uint step_width
Step-size of width resize changes.
Definition window_gui.h:212
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
Textbuf
Helper/buffer for input fields.
Definition textbuf_type.h:30
Vehicle
Vehicle data structure.
Definition vehicle_base.h:205
ViewportData
Data structure for a window viewport.
Definition window_gui.h:251
ViewportData::CancelFollow
void CancelFollow(const Window &viewport_window)
Cancel viewport vehicle following, and raise follow location widget if needed.
Definition viewport.cpp:3826
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:256
ViewportData::scrollpos_y
int32_t scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition window_gui.h:254
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:255
ViewportData::follow_vehicle
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, VehicleID::Invalid() otherwise.
Definition window_gui.h:252
ViewportData::scrollpos_x
int32_t scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition window_gui.h:253
Viewport
Data structure for viewport, display of a part of the world.
Definition viewport_type.h:31
WindowDesc
High level window description.
Definition window_gui.h:168
WindowDesc::GetDefaultWidth
int16_t GetDefaultWidth() const
Determine default width of window.
Definition window.cpp:137
WindowDesc::SaveToConfig
static void SaveToConfig()
Save all WindowDesc settings to _windows_file.
Definition window.cpp:176
WindowDesc::pref_width
int16_t pref_width
User-preferred width of the window. Zero if unset.
Definition window_gui.h:187
WindowDesc::default_pos
const WindowPosition default_pos
Preferred position of the window.
Definition window_gui.h:178
WindowDesc::pref_sticky
bool pref_sticky
Preferred stickyness.
Definition window_gui.h:186
WindowDesc::WindowDesc
WindowDesc(const WindowDesc &)=delete
Delete copy constructor to prevent compilers from copying the structure, which fails due to _window_d...
WindowDesc::pref_height
int16_t pref_height
User-preferred height of the window. Zero if unset.
Definition window_gui.h:188
WindowDesc::GetDefaultHeight
int16_t GetDefaultHeight() const
Determine default height of window.
Definition window.cpp:147
WindowDesc::default_height_trad
const int16_t default_height_trad
Preferred initial height of the window (pixels at 1x zoom).
Definition window_gui.h:198
WindowDesc::default_width_trad
const int16_t default_width_trad
Preferred initial width of the window (pixels at 1x zoom).
Definition window_gui.h:197
WindowDesc::cls
const WindowClass cls
Class of the window,.
Definition window_gui.h:179
WindowDesc::ini_key
const std::string_view ini_key
Key to store window defaults in openttd.cfg. An empty string if nothing shall be stored.
Definition window_gui.h:181
WindowDesc::source_location
const std::source_location source_location
Source location of this definition.
Definition window_gui.h:177
WindowDesc::flags
const WindowDefaultFlags flags
Flags.
Definition window_gui.h:182
WindowDesc::LoadFromConfig
static void LoadFromConfig()
Load all WindowDesc settings from _windows_file.
Definition window.cpp:155
WindowDesc::parent_cls
const WindowClass parent_cls
Class of the parent window.
Definition window_gui.h:180
WindowDesc::hotkeys
const HotkeyList * hotkeys
Hotkeys for the window.
Definition window_gui.h:184
WindowDesc::nwid_parts
const std::span< const NWidgetPart > nwid_parts
Span of nested widget parts describing the window.
Definition window_gui.h:183
WindowNumber
Number to differentiate different windows of the same class.
Definition window_type.h:760
Window::AllWindows
Iterable ensemble of all valid Windows.
Definition window_gui.h:919
Window::WindowIterator
Iterator to iterate all valid Windows.
Definition window_gui.h:875
Window
Data structure for an opened window.
Definition window_gui.h:274
Window::GetFocusedTextbuf
virtual const struct Textbuf * GetFocusedTextbuf() const
Get the current input text buffer.
Definition window.cpp:366
Window::SetWidgetHighlight
void SetWidgetHighlight(WidgetID widget_index, TextColour highlighted_colour)
Sets the highlighted status of a widget.
Definition window.cpp:241
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:980
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:1104
Window::IsWidgetGloballyFocused
bool IsWidgetGloballyFocused(WidgetID widget_index) const
Check if given widget has user input focus.
Definition window_gui.h:432
Window::UpdateWidgetSize
virtual void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize)
Update size and resize step of a widget in the window.
Definition window_gui.h:621
Window::OnInvalidateData
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition window_gui.h:793
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition widget.cpp:833
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1809
Window::querystrings
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition window_gui.h:321
Window::ApplyDefaults
virtual void ApplyDefaults()
Read default values from WindowDesc configuration an apply them to the window.
Definition window.cpp:193
Window::white_border_timer
uint8_t white_border_timer
Timer value of the WindowFlag::WhiteBorder for flags.
Definition window_gui.h:308
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:324
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:1457
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:784
Window::OnVehicleSelect
virtual bool OnVehicleSelect(VehicleList::const_iterator begin, VehicleList::const_iterator end)
The user clicked on a vehicle while HT_VEHICLE has been set.
Definition window_gui.h:817
Window::unshaded_size
Dimension unshaded_size
Last known unshaded size (only valid while shaded).
Definition window_gui.h:325
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:3237
Window::OnKeyPress
virtual EventState OnKeyPress(char32_t key, uint16_t keycode)
A key has been pressed.
Definition window_gui.h:651
Window::parent
Window * parent
Parent window.
Definition window_gui.h:329
Window::~Window
virtual ~Window()
Remove window and all its child windows from the window stack.
Definition window.cpp:1141
Window::RaiseWidget
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition window_gui.h:470
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:558
Window::timeout_timer
uint8_t timeout_timer
Timer value of the WindowFlag::Timeout for flags.
Definition window_gui.h:307
Window::viewport
std::unique_ptr< ViewportData > viewport
Pointer to viewport data, if present.
Definition window_gui.h:319
Window::GetWidgetString
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:506
Window::mouse_capture_widget
WidgetID mouse_capture_widget
ID of current mouse capture widget (e.g. dragged scrollbar). INVALID_WIDGET if no widget has mouse ca...
Definition window_gui.h:327
Window::OnGameTick
virtual void OnGameTick()
Called once per (game) tick.
Definition window_gui.h:746
Window::ShowNewGRFInspectWindow
virtual void ShowNewGRFInspectWindow() const
Show the NewGRF inspection window.
Definition window_gui.h:868
Window::OnRightClick
virtual bool OnRightClick(Point pt, WidgetID widget)
A click with the right mouse button has been made on the window.
Definition window_gui.h:678
Window::OnScrollbarScroll
virtual void OnScrollbarScroll(WidgetID widget)
Notify window that a scrollbar position has been updated.
Definition window_gui.h:720
Window::RaiseWidgetWhenLowered
void RaiseWidgetWhenLowered(WidgetID widget_index)
Marks a widget as raised and dirty (redraw), when it is marked as lowered.
Definition window_gui.h:479
Window::OnDropdownSelect
virtual void OnDropdownSelect(WidgetID widget, int index, int click_result)
A dropdown option associated to this window has been selected.
Definition window_gui.h:770
Window::DrawSortButtonState
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition widget.cpp:816
Window::ProcessScheduledInvalidations
void ProcessScheduledInvalidations()
Process all scheduled invalidations.
Definition window.cpp:3250
Window::CloseChildWindows
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1077
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:315
Window::UnfocusFocusedWidget
void UnfocusFocusedWidget()
Makes no widget on this window have focus.
Definition window.cpp:471
Window::DisableWidget
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition window_gui.h:392
Window::OnMouseLoop
virtual void OnMouseLoop()
Called for every mouse loop run, which is at least once per (game) tick.
Definition window_gui.h:741
Window::SetShaded
void SetShaded(bool make_shaded)
Set the shaded state of the window to make_shaded.
Definition window.cpp:1023
Window::OnPlaceObjectAbort
virtual void OnPlaceObjectAbort()
The user cancelled a tile highlight mode that has been set.
Definition window_gui.h:822
Window::scale
int scale
Scale of this window – used to determine how to resize.
Definition window_gui.h:305
Window::ScheduleResize
void ScheduleResize()
Mark this window as resized and in need of OnResize() event.
Definition window.cpp:3215
Window::OnVehicleSelect
virtual bool OnVehicleSelect(const struct Vehicle *v)
The user clicked on a vehicle while HT_VEHICLE has been set.
Definition window_gui.h:809
Window::IsWidgetFocused
bool IsWidgetFocused(WidgetID widget_index) const
Check if given widget is focused within this window.
Definition window_gui.h:421
Window::SetWidgetsDisabledState
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:516
Window::OnPaint
virtual void OnPaint()
The window must be repainted.
Definition window_gui.h:596
Window::OnDragDrop
virtual void OnDragDrop(Point pt, WidgetID widget)
A dragged 'object' has been released.
Definition window_gui.h:707
Window::IsNewGRFInspectable
virtual bool IsNewGRFInspectable() const
Is the data related to this window NewGRF inspectable?
Definition window_gui.h:860
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1799
Window::window_desc
WindowDesc & window_desc
Window description.
Definition window_gui.h:300
Window::window_class
WindowClass window_class
Window class.
Definition window_gui.h:302
Window::OnRealtimeTick
virtual void OnRealtimeTick(uint delta_ms)
Called periodically.
Definition window_gui.h:751
Window::OnMouseWheel
virtual void OnMouseWheel(int wheel, WidgetID widget)
The mouse wheel has been turned.
Definition window_gui.h:735
Window::CloseChildWindowById
void CloseChildWindowById(WindowClass wc, WindowNumber number) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1092
Window::OnQueryTextFinished
virtual void OnQueryTextFinished(std::optional< std::string > str)
The query window opened from this window has closed.
Definition window_gui.h:786
Window::SetWhiteBorder
void SetWhiteBorder()
Set the timeout flag of the window and initiate the timer.
Definition window_gui.h:365
Window::SetFocusedWidget
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition window.cpp:487
Window::OnFocusLost
virtual void OnFocusLost(bool closing)
The window has lost focus.
Definition window.cpp:523
Window::IsWidgetLowered
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:492
Window::IsWidgetDisabled
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition window_gui.h:411
Window::DrawViewport
void DrawViewport() const
Draw the viewport of this window.
Definition viewport.cpp:1903
Window::closed_windows
static std::vector< Window * > closed_windows
List of closed windows to delete.
Definition window_gui.h:276
Window::RaiseButtons
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition window.cpp:532
Window::DrawWidget
virtual void DrawWidget(const Rect &r, WidgetID widget) const
Draw the contents of a nested widget.
Definition window_gui.h:607
Window::SetWidgetsLoweredState
void SetWidgetsLoweredState(bool lowered_stat, Args... widgets)
Sets the lowered/raised status of a list of widgets.
Definition window_gui.h:527
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:1787
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition window_gui.h:317
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:442
Window::EnableWidget
void EnableWidget(WidgetID widget_index)
Sets a widget to Enabled.
Definition window_gui.h:401
Window::GetCaretPosition
virtual Point GetCaretPosition() const
Get the current caret position if an edit box has the focus.
Definition window.cpp:379
Window::FindWindowPlacementAndResize
virtual void FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize)
Resize window towards the default size.
Definition window.cpp:1476
Window::OnDropdownClose
virtual void OnDropdownClose(Point pt, WidgetID widget, int index, int click_result, bool instant_close)
A dropdown window associated to this window has been closed.
Definition window.cpp:286
Window::InsertTextString
virtual void InsertTextString(WidgetID wid, std::string_view str, bool marked, std::optional< size_t > caret, std::optional< size_t > insert_location, std::optional< size_t > replacement_end)
Insert a text string at the cursor position into the edit box widget.
Definition window.cpp:2722
Window::OnPlaceObject
virtual void OnPlaceObject(Point pt, TileIndex tile)
The user clicked some place on the map when a tile highlight mode has been set.
Definition window_gui.h:801
Window::left
int left
x position of left edge of the window
Definition window_gui.h:310
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition window_gui.h:560
Window::FindChildWindow
Window * FindChildWindow(WindowClass wc=WC_INVALID) const
Find the Window whose parent pointer points to this window.
Definition window.cpp:1049
Window::SetTimeout
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition window_gui.h:356
Window::nested_focus
const NWidgetCore * nested_focus
Currently focused nested widget, or nullptr if no nested widget has focus.
Definition window_gui.h:320
Window::OnEditboxChanged
virtual void OnEditboxChanged(WidgetID widget)
The text in an editbox has been edited.
Definition window_gui.h:778
Window::UpdateQueryStringSize
void UpdateQueryStringSize()
Update size of all QueryStrings of this window.
Definition window.cpp:355
Window::OnScroll
virtual void OnScroll(Point delta)
Handle the request for (viewport) scrolling.
Definition window_gui.h:713
Window::RaiseWidgetsWhenLowered
void RaiseWidgetsWhenLowered(Args... widgets)
Raises the widgets and sets widgets dirty that are lowered.
Definition window_gui.h:537
Window::top
int top
y position of top edge of the window
Definition window_gui.h:311
Window::OnClick
virtual void OnClick(Point pt, WidgetID widget, int click_count)
A click with the left mouse button has been made on the window.
Definition window_gui.h:669
Window::GetQueryString
const QueryString * GetQueryString(WidgetID widnum) const
Return the querystring associated to a editbox.
Definition window.cpp:335
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:323
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
Window::scheduled_invalidation_data
std::vector< int > scheduled_invalidation_data
Data of scheduled OnInvalidateData() calls.
Definition window_gui.h:283
Window::InitializeData
void InitializeData(WindowNumber window_number)
Initializes the data (except the position and initial size) of a new Window.
Definition window.cpp:1419
Window::OnPlaceMouseUp
virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
The user has dragged over the map when the tile highlight mode has been set.
Definition window_gui.h:843
Window::OnMouseOver
virtual void OnMouseOver(Point pt, WidgetID widget)
The mouse is currently moving over the window or has just moved outside of the window.
Definition window_gui.h:728
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:212
Window::GetWidget
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:983
Window::OnTooltip
virtual bool OnTooltip(Point pt, WidgetID widget, TooltipCloseCondition close_cond)
Event to display a custom tooltip.
Definition window_gui.h:693
Window::LowerWidget
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:461
Window::OnCTRLStateChange
virtual EventState OnCTRLStateChange()
The state of the control key has changed.
Definition window_gui.h:660
Window::ProcessScheduledResize
void ProcessScheduledResize()
Process scheduled OnResize() event.
Definition window.cpp:3223
Window::HandleEditBoxKey
EventState HandleEditBoxKey(WidgetID wid, char32_t key, uint16_t keycode)
Process keypress for editbox widget.
Definition window.cpp:2564
Window::OnMouseDrag
virtual void OnMouseDrag(Point pt, WidgetID widget)
An 'object' is being dragged at the provided position, highlight the target if possible.
Definition window_gui.h:700
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:597
Window::OnResize
virtual void OnResize()
Called after the window got resized.
Definition window_gui.h:763
Window::FindChildWindowById
Window * FindChildWindowById(WindowClass wc, WindowNumber number) const
Find the Window whose parent pointer points to this window.
Definition window.cpp:1064
Window::OnFocus
virtual void OnFocus()
The window has gained focus.
Definition window.cpp:515
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1823
Window::OnTimeout
virtual void OnTimeout()
Called when this window's timeout has been reached.
Definition window_gui.h:756
Window::flags
WindowFlags flags
Window flags.
Definition window_gui.h:301
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:315
Window::ProcessHighlightedInvalidations
void ProcessHighlightedInvalidations()
Process all invalidation of highlighted widgets.
Definition window.cpp:3262
Window::OnPlaceDrag
virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
The user is dragging over the map when the tile highlight mode has been set.
Definition window_gui.h:832
Window::OnHotkey
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:572
Window::DeleteClosedWindows
static void DeleteClosedWindows()
Delete all closed windows.
Definition window.cpp:68
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
Window::nested_root
std::unique_ptr< NWidgetBase > nested_root
Root of the nested tree.
Definition window_gui.h:322
Window::scheduled_resize
bool scheduled_resize
Set if window has been resized.
Definition window_gui.h:284
Window::GetTextBoundingRect
virtual Rect GetTextBoundingRect(size_t from, size_t to) const
Get the bounding rectangle for a text range if an edit box has the focus.
Definition window.cpp:395
Window::IsWidgetHighlighted
bool IsWidgetHighlighted(WidgetID widget_index) const
Gets the highlighted status of a widget.
Definition window.cpp:271
Window::DisableAllWidgetHighlight
void DisableAllWidgetHighlight()
Disable the highlighted status of all widgets.
Definition window.cpp:223
Window::OnPlacePresize
virtual void OnPlacePresize(Point pt, 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:852
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition window_gui.h:313
Window::OnHover
virtual void OnHover(Point pt, WidgetID widget)
The mouse is hovering over a widget in the window, perform an action for it.
Definition window_gui.h:685
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:312
Window::OnInit
virtual void OnInit()
Notification that the nested widget tree gets initialized.
Definition window_gui.h:579
Window::ToggleWidgetLoweredState
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
Definition window_gui.h:451
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:303
tile_type.h
Types related to tiles.
vehicle_type.h
Types related to vehicles.
vehiclelist.h
Functions and type for generating vehicle lists.
viewport_type.h
Types related to viewports.
ViewportPlaceMethod
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
Definition viewport_type.h:96
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:115
widget_type.h
Definitions about widgets.
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition widget_type.h:508
WidgetLookup
std::map< WidgetID, class NWidgetBase * > WidgetLookup
Lookup between widget IDs and NWidget objects.
Definition widget_type.h:129
WindowDefaultFlag
WindowDefaultFlag
Window default widget/window handling flags.
Definition window_gui.h:152
WindowDefaultFlag::Construction
@ Construction
This window is used for construction; close it whenever changing company.
WindowDefaultFlag::NoClose
@ NoClose
This window can't be interactively closed.
WindowDefaultFlag::NoFocus
@ NoFocus
This window won't get focus/make any other window lose focus when click.
WindowDefaultFlag::Modal
@ Modal
The window is a modal child of some other window, meaning the parent is 'inactive'.
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition widget.cpp:307
_scrolling_viewport
bool _scrolling_viewport
A viewport is being scrolled with the mouse.
Definition window.cpp:93
GuiShowTooltips
void GuiShowTooltips(Window *parent, EncodedString &&text, TooltipCloseCondition close_tooltip)
Shows a tooltip.
Definition misc_gui.cpp:693
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:946
FrameFlag
FrameFlag
Flags to describe the look of the frame.
Definition window_gui.h:24
FrameFlag::Transparent
@ Transparent
Makes the background transparent if set.
FrameFlag::BorderOnly
@ BorderOnly
Draw border only, no background.
FrameFlag::Darkened
@ Darkened
If set the background is darker, allows for lowered frames with normal background colour when used wi...
FrameFlag::Lowered
@ Lowered
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
AllocateWindowDescFront
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
Definition window_gui.h:1016
SetFocusedWindow
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Definition window.cpp:423
WindowFlag
WindowFlag
Window flags.
Definition window_gui.h:226
WindowFlag::SizingLeft
@ SizingLeft
Window is being resized towards the left.
WindowFlag::DisableVpScroll
@ DisableVpScroll
Window does not do autoscroll,.
WindowFlag::Highlighted
@ Highlighted
Window has a widget that has a highlight.
WindowFlag::Centred
@ Centred
Window is centered and shall stay centered after ReInit.
WindowFlag::Dragging
@ Dragging
Window is being dragged.
WindowFlag::SizingRight
@ SizingRight
Window is being resized towards the right.
WindowFlag::WhiteBorder
@ WhiteBorder
Window white border counter bit mask.
WindowFlag::Timeout
@ Timeout
Window timeout counter.
WindowFlag::Sticky
@ Sticky
Window is made sticky by user.
FindWindowFromPt
Window * FindWindowFromPt(int x, int y)
Do a search for a window at specific coordinates.
Definition window.cpp:1845
DrawCaption
void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, std::string_view str, StringAlignment align, FontSize fs)
Draw a caption bar.
Definition widget.cpp:736
TIMEOUT_DURATION
static const int TIMEOUT_DURATION
The initial timeout value for WindowFlag::Timeout.
Definition window_gui.h:241
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:292
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:1685
SortButtonState
SortButtonState
State of a sort direction button.
Definition window_gui.h:217
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition window_gui.h:219
SBS_UP
@ SBS_UP
Sort descending.
Definition window_gui.h:220
SBS_OFF
@ SBS_OFF
Do not sort (with this button).
Definition window_gui.h:218
SpecialMouseMode
SpecialMouseMode
Mouse modes.
Definition window_gui.h:1040
WSM_DRAGDROP
@ WSM_DRAGDROP
Drag&drop an object.
Definition window_gui.h:1042
WSM_DRAGGING
@ WSM_DRAGGING
Dragging mode (trees).
Definition window_gui.h:1045
WSM_PRESIZE
@ WSM_PRESIZE
Presizing mode (docks, tunnels).
Definition window_gui.h:1044
WSM_NONE
@ WSM_NONE
No special mouse mode.
Definition window_gui.h:1041
WSM_SIZING
@ WSM_SIZING
Sizing mode.
Definition window_gui.h:1043
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition window.cpp:1278
AlignInitialConstructionToolbar
Point AlignInitialConstructionToolbar(int window_width)
Compute the position of the construction toolbars.
Definition window.cpp:1701
RelocateAllWindows
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
Definition window.cpp:3529
ScrollbarClickHandler
void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
Special handling for the scrollbar widget type.
Definition widget.cpp:268
_mouse_hovering
bool _mouse_hovering
The mouse is hovering over the same point.
Definition window.cpp:94
WindowPosition
WindowPosition
How do we the window to be placed?
Definition window_gui.h:142
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition window_gui.h:145
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:144
WDP_ALIGN_TOOLBAR
@ WDP_ALIGN_TOOLBAR
Align toward the toolbar.
Definition window_gui.h:146
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition window_gui.h:143
_z_windows
WindowList _z_windows
List of windows opened at the screen sorted from the front to back.
Definition window.cpp:60
_special_mouse_mode
SpecialMouseMode _special_mouse_mode
Mode of the mouse.
Definition window.cpp:96
WHITE_BORDER_DURATION
static const int WHITE_BORDER_DURATION
The initial timeout value for WindowFlag::WhiteBorder.
Definition window_gui.h:242
ScrollRect
Rect ScrollRect(Rect r, const Scrollbar &sb, int resize_step=1)
Apply 'scroll' to a rect to be drawn in.
Definition widget.cpp:2544
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20
EventState
EventState
State of handling an event.
Definition window_type.h:780
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition window_type.h:782
INVALID_WIDGET
static constexpr WidgetID INVALID_WIDGET
An invalid widget index.
Definition window_type.h:23
WindowClass
WindowClass
Window classes.
Definition window_type.h:49
WC_INVALID
@ WC_INVALID
Invalid window.
Definition window_type.h:735