OpenTTD Source 20261112-master-gbcbec5e63f
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
9
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
29
32
34public:
57
65
66 static const WidgetDimensions unscaled;
68
69 static constexpr float ASPECT_LOCATION = 12.f / 14.f;
70 static constexpr float ASPECT_RENAME = 12.f / 14.f;
71 static constexpr float ASPECT_TOGGLE_SIZE = 12.f / 14.f;
72 static constexpr float ASPECT_LEFT_RIGHT_BUTTON = 8.f / 12.f;
73 static constexpr float ASPECT_UP_DOWN_BUTTON = 11.f / 12.f;
74 static constexpr float ASPECT_VEHICLE_ICON = 15.f / 12.f;
75 static constexpr float ASPECT_VEHICLE_FLAG = 11.f / 12.f;
76
77private:
82 static constexpr uint WD_SHADEBOX_WIDTH = 12;
83 static constexpr uint WD_STICKYBOX_WIDTH = 12;
84 static constexpr uint WD_DEBUGBOX_WIDTH = 12;
85 static constexpr uint WD_DEFSIZEBOX_WIDTH = 12;
86 static constexpr uint WD_RESIZEBOX_WIDTH = 12;
87 static constexpr uint WD_CLOSEBOX_WIDTH = 11;
88 static constexpr uint WD_CAPTION_HEIGHT = 14;
89 static constexpr uint WD_DROPDOWN_HEIGHT = 12;
90
91 friend NWidgetLeaf;
92};
93
95 .imgbtn = { .left = 1, .top = 1, .right = 1, .bottom = 1},
96 .inset = { .left = 2, .top = 1, .right = 2, .bottom = 1},
97 .vscrollbar = { .left = 2, .top = 3, .right = 2, .bottom = 3},
98 .hscrollbar = { .left = 3, .top = 2, .right = 3, .bottom = 2},
99 .bevel = { .left = 1, .top = 1, .right = 1, .bottom = 1},
100 .fullbevel = { .left = 1, .top = 1, .right = 1, .bottom = 1},
101 .framerect = { .left = 2, .top = 1, .right = 2, .bottom = 1},
102 .frametext = { .left = 6, .top = 6, .right = 6, .bottom = 6},
103 .matrix = { .left = 2, .top = 3, .right = 2, .bottom = 1},
104 .shadebox = { .left = 2, .top = 3, .right = 2, .bottom = 3},
105 .stickybox = { .left = 2, .top = 3, .right = 2, .bottom = 3},
106 .debugbox = { .left = 2, .top = 3, .right = 2, .bottom = 3},
107 .defsizebox = { .left = 2, .top = 3, .right = 2, .bottom = 3},
108 .resizebox = { .left = 2, .top = 2, .right = 2, .bottom = 2},
109 .closebox = { .left = 2, .top = 2, .right = 1, .bottom = 2},
110 .captiontext = { .left = 2, .top = 2, .right = 2, .bottom = 2},
111 .dropdowntext = { .left = 2, .top = 1, .right = 2, .bottom = 1},
112 .dropdownlist = { .left = 1, .top = 2, .right = 1, .bottom = 2},
113 .modalpopup = { .left = 20, .top = 10, .right = 20, .bottom = 10},
114 .picker = { .left = 3, .top = 3, .right = 3, .bottom = 3},
115 .sparse = { .left = 10, .top = 8, .right = 10, .bottom = 8},
116 .sparse_resize = { .left = 10, .top = 8, .right = 10, .bottom = 0},
117 .vsep_picker = 1,
118 .vsep_normal = 2,
119 .vsep_sparse = 4,
120 .vsep_wide = 8,
121 .hsep_normal = 2,
122 .hsep_wide = 6,
123 .hsep_indent = 10,
124};
125
126/* widget.cpp */
127void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags);
128
129inline void DrawFrameRect(const Rect &r, Colours colour, FrameFlags flags)
130{
131 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, flags);
132}
133
134void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, std::string_view str, Alignment align, FontSize fs);
135
136/* window.cpp */
137using WindowList = std::list<Window *>;
138extern WindowList _z_windows;
139extern Window *_focused_window;
140
141
149
159
162
163Point GetToolbarAlignedWindowPosition(int window_width);
164Point AlignInitialConstructionToolbar(int window_width);
165
166struct HotkeyList;
167
172
173 WindowDesc(WindowPosition default_pos, std::string_view ini_key, int16_t def_width_trad, int16_t def_height_trad,
174 WindowClass window_class, WindowClass parent_class, WindowDefaultFlags flags,
175 const std::span<const NWidgetPart> nwid_parts, HotkeyList *hotkeys = nullptr,
176 const std::source_location location = std::source_location::current());
177
178 ~WindowDesc();
179
180 const std::source_location source_location;
182 const WindowClass cls;
183 const WindowClass parent_cls;
184 const std::string_view ini_key;
186 const std::span<const NWidgetPart> nwid_parts;
188
189 bool pref_sticky = false;
190 int16_t pref_width = 0;
191 int16_t pref_height = 0;
192
193 int16_t GetDefaultWidth() const;
194 int16_t GetDefaultHeight() const;
195
196 static void LoadFromConfig();
197 static void SaveToConfig();
198
199private:
200 const int16_t default_width_trad;
201 const int16_t default_height_trad;
202
207 WindowDesc(const WindowDesc &) = delete;
208 WindowDesc& operator=(const WindowDesc &) = delete;
209};
210
217};
218
235
238
239static const int TIMEOUT_DURATION = 7;
240static const int WHITE_BORDER_DURATION = 3;
241
251 int32_t scrollpos_x;
252 int32_t scrollpos_y;
255
256 void CancelFollow(const Window &viewport_window);
257};
258
259struct QueryString;
260
261/* Automatic closing conditions for tooltips. */
268
272struct Window {
273private:
274 static std::vector<Window *> closed_windows;
275
276protected:
278 void InitializePositionSize(int x, int y, int min_width, int min_height);
279 virtual void FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize);
280
281 std::vector<int> scheduled_invalidation_data{};
282 bool scheduled_resize = false;
283
284 /* Protected to prevent deletion anywhere outside Window::DeleteClosedWindows(). */
285 virtual ~Window();
286
287public:
288 Window(WindowDesc &desc);
289
296 inline void *operator new[](size_t size) = delete;
297
300 WindowClass window_class{};
302
303 int scale = 0;
304
305 uint8_t timeout_timer = 0;
306 uint8_t white_border_timer = 0;
307
308 int left = 0;
309 int top = 0;
310 int width = 0;
311 int height = 0;
312
314
316
317 std::unique_ptr<ViewportData> viewport;
318 const NWidgetCore *nested_focus = nullptr;
319 std::map<WidgetID, QueryString*> querystrings{};
320 std::unique_ptr<NWidgetBase> nested_root{};
324
326
327 Window *parent = nullptr;
328 WindowList::iterator z_position{};
329
330 template <class NWID>
331 inline const NWID *GetWidget(WidgetID widnum) const;
332 template <class NWID>
333 inline NWID *GetWidget(WidgetID widnum);
334
335 const Scrollbar *GetScrollbar(WidgetID widnum) const;
337
338 const QueryString *GetQueryString(WidgetID widnum) const;
341
342 virtual const struct Textbuf *GetFocusedTextbuf() const;
343 virtual Point GetCaretPosition() const;
344 virtual Rect GetTextBoundingRect(size_t from, size_t to) const;
345 virtual ptrdiff_t GetTextCharacterAtPosition(const Point &pt) const;
346
347 void InitNested(WindowNumber number = 0);
348 void CreateNestedTree();
350
354 inline void SetTimeout()
355 {
356 this->flags.Set(WindowFlag::Timeout);
357 this->timeout_timer = TIMEOUT_DURATION;
358 }
359
363 inline void SetWhiteBorder()
364 {
365 this->flags.Set(WindowFlag::WhiteBorder);
366 this->white_border_timer = WHITE_BORDER_DURATION;
367 }
368
370 void SetWidgetHighlight(WidgetID widget_index, TextColour highlighted_colour);
371 bool IsWidgetHighlighted(WidgetID widget_index) const;
372
380 inline void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
381 {
382 NWidgetCore *nwid = this->GetWidget<NWidgetCore>(widget_index);
383 if (nwid != nullptr) nwid->SetDisabled(disab_stat);
384 }
385
390 inline void DisableWidget(WidgetID widget_index)
391 {
392 SetWidgetDisabledState(widget_index, true);
393 }
394
399 inline void EnableWidget(WidgetID widget_index)
400 {
401 SetWidgetDisabledState(widget_index, false);
402 }
403
409 inline bool IsWidgetDisabled(WidgetID widget_index) const
410 {
411 return this->GetWidget<NWidgetCore>(widget_index)->IsDisabled();
412 }
413
419 inline bool IsWidgetFocused(WidgetID widget_index) const
420 {
421 return this->nested_focus != nullptr && this->nested_focus->GetIndex() == widget_index;
422 }
423
430 inline bool IsWidgetGloballyFocused(WidgetID widget_index) const
431 {
432 return _focused_window == this && IsWidgetFocused(widget_index);
433 }
434
440 inline void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
441 {
442 this->GetWidget<NWidgetCore>(widget_index)->SetLowered(lowered_stat);
443 }
444
449 inline void ToggleWidgetLoweredState(WidgetID widget_index)
450 {
451 bool lowered_state = this->GetWidget<NWidgetCore>(widget_index)->IsLowered();
452 this->GetWidget<NWidgetCore>(widget_index)->SetLowered(!lowered_state);
453 }
454
459 inline void LowerWidget(WidgetID widget_index)
460 {
461 SetWidgetLoweredState(widget_index, true);
462 }
463
468 inline void RaiseWidget(WidgetID widget_index)
469 {
470 SetWidgetLoweredState(widget_index, false);
471 }
472
477 inline void RaiseWidgetWhenLowered(WidgetID widget_index)
478 {
479 if (this->IsWidgetLowered(widget_index)) {
480 this->RaiseWidget(widget_index);
481 this->SetWidgetDirty(widget_index);
482 }
483 }
484
490 inline bool IsWidgetLowered(WidgetID widget_index) const
491 {
492 return this->GetWidget<NWidgetCore>(widget_index)->IsLowered();
493 }
494
496 bool SetFocusedWidget(WidgetID widget_index);
497
498 EventState HandleEditBoxKey(WidgetID wid, char32_t key, uint16_t keycode);
499 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);
500
501 void HandleButtonClick(WidgetID widget);
502 int GetRowFromWidget(int clickpos, WidgetID widget, int padding, int line_height = -1) const;
503
504 void RaiseButtons(bool autoraise = false);
505
513 template <typename... Args>
514 void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
515 {
516 (SetWidgetDisabledState(widgets, disab_stat), ...);
517 }
518
524 template <typename... Args>
525 void SetWidgetsLoweredState(bool lowered_stat, Args... widgets)
526 {
527 (SetWidgetLoweredState(widgets, lowered_stat), ...);
528 }
529
534 template <typename... Args>
535 void RaiseWidgetsWhenLowered(Args... widgets)
536 {
537 (this->RaiseWidgetWhenLowered(widgets), ...);
538 }
539
540 void SetWidgetDirty(WidgetID widget_index) const;
541
542 void DrawWidgets() const;
543 void DrawViewport() const;
544 void DrawSortButton(WidgetID widget, bool descending) const;
545 static int SortButtonWidth();
546
547 Window *FindChildWindow(WindowClass wc = WindowClass::Invalid) const;
548 Window *FindChildWindowById(WindowClass wc, WindowNumber number) const;
549 void CloseChildWindows(WindowClass wc = WindowClass::Invalid) const;
550 void CloseChildWindowById(WindowClass wc, WindowNumber number) const;
551 virtual void Close(int data = 0);
552 static void DeleteClosedWindows();
553
554 void SetDirty() const;
555 void ReInit(int rx = 0, int ry = 0, bool reposition = false);
556
561 inline bool IsShaded() const
562 {
563 return this->shade_select != nullptr && this->shade_select->shown_plane == SZSP_HORIZONTAL;
564 }
565
566 void SetShaded(bool make_shaded);
567
568 void ScheduleResize();
570 void InvalidateData(int data = 0, bool gui_scope = true);
573
574 /*** Event handling ***/
575
580 virtual void OnInit() { }
581
582 virtual void ApplyDefaults();
583
591 virtual Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number);
592
597 virtual void OnPaint()
598 {
599 this->DrawWidgets();
600 }
601
608 virtual void DrawWidget([[maybe_unused]] const Rect &r, [[maybe_unused]] WidgetID widget) const {}
609
622 virtual void UpdateWidgetSize([[maybe_unused]] WidgetID widget, [[maybe_unused]] Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) {}
623
632 virtual std::string GetWidgetString([[maybe_unused]] WidgetID widget, StringID stringid) const;
633
637 virtual void OnFocus();
638
643 virtual void OnFocusLost(bool closing);
644
652 virtual EventState OnKeyPress([[maybe_unused]] char32_t key, [[maybe_unused]] uint16_t keycode) { return EventState::NotHandled; }
653
654 virtual EventState OnHotkey(int hotkey);
655
662
663
670 virtual void OnClick([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget, [[maybe_unused]] int click_count) {}
671
679 virtual bool OnRightClick([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget) { return false; }
680
686 virtual void OnMiddleClick([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget) {}
687
693 virtual void OnX1Click([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget) {}
694
700 virtual void OnX2Click([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget) {}
701
707 virtual void OnHover([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget) {}
708
716 virtual bool OnTooltip([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget, [[maybe_unused]] TooltipCloseCondition close_cond) { return false; }
717
723 virtual void OnMouseDrag([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget) {}
724
730 virtual void OnDragDrop([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget) {}
731
736 virtual void OnScroll([[maybe_unused]] Point delta) {}
737
743 virtual void OnScrollbarScroll([[maybe_unused]] WidgetID widget) {}
744
751 virtual void OnMouseOver([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget) {}
752
758 virtual void OnMouseWheel([[maybe_unused]] int wheel, [[maybe_unused]] WidgetID widget) {}
759
760
764 virtual void OnMouseLoop() {}
765
769 virtual void OnGameTick() {}
770
775 virtual void OnRealtimeTick([[maybe_unused]] uint delta_ms) {}
776
780 virtual void OnTimeout() {}
781
782
787 virtual void OnResize() {}
788
795 virtual void OnDropdownSelect([[maybe_unused]] WidgetID widget, [[maybe_unused]] int index, [[maybe_unused]] int click_result) {}
796
797 virtual void OnDropdownClose(Point pt, WidgetID widget, int index, int click_result, bool instant_close);
798
803 virtual void OnEditboxChanged([[maybe_unused]] WidgetID widget) {}
804
811 virtual void OnQueryTextFinished([[maybe_unused]] std::optional<std::string> str) {}
812
818 virtual void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) {}
819
826 virtual void OnPlaceObject([[maybe_unused]] Point pt, [[maybe_unused]] TileIndex tile) {}
827
834 virtual bool OnVehicleSelect([[maybe_unused]] const struct Vehicle *v) { return false; }
835
843 virtual bool OnVehicleSelect([[maybe_unused]] VehicleList::const_iterator begin, [[maybe_unused]] VehicleList::const_iterator end) { return false; }
844
848 virtual void OnPlaceObjectAbort() {}
849
850
858 virtual void OnPlaceDrag([[maybe_unused]] ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt) {}
859
869 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) {}
870
878 virtual void OnPlacePresize([[maybe_unused]] Point pt, [[maybe_unused]] TileIndex tile) {}
879
880 /*** End of the event handling ***/
881
886 virtual bool IsNewGRFInspectable() const { return false; }
887
894 virtual void ShowNewGRFInspectWindow() const { NOT_REACHED(); }
895
900 template <bool TtoBack>
901 struct WindowIterator {
902 typedef Window *value_type;
903 typedef value_type *pointer;
904 typedef value_type &reference;
905 typedef size_t difference_type;
906 typedef std::forward_iterator_tag iterator_category;
907
908 explicit WindowIterator(WindowList::iterator start) : it(start)
909 {
910 this->Validate();
911 }
912 explicit WindowIterator(const Window *w) : it(w->z_position) {}
913
914 bool operator==(const WindowIterator &other) const { return this->it == other.it; }
915 Window * operator*() const { return *this->it; }
916 WindowIterator & operator++() { this->Next(); this->Validate(); return *this; }
917
918 bool IsEnd() const { return this->it == _z_windows.end(); }
919
920 private:
921 WindowList::iterator it;
922 void Validate()
923 {
924 while (!this->IsEnd() && *this->it == nullptr) this->Next();
925 }
926 void Next()
927 {
928 if constexpr (!TtoBack) {
929 ++this->it;
930 } else if (this->it == _z_windows.begin()) {
931 this->it = _z_windows.end();
932 } else {
933 --this->it;
934 }
935 }
936 };
939
944 template <bool Tfront>
945 struct AllWindows {
946 AllWindows() {}
948 {
949 if constexpr (Tfront) {
950 auto back = _z_windows.end();
951 if (back != _z_windows.begin()) --back;
952 return WindowIterator<Tfront>(back);
953 } else {
954 return WindowIterator<Tfront>(_z_windows.begin());
955 }
956 }
958 };
962};
963
971template <class It, class Pred>
972inline bool AllEqual(It begin, It end, Pred pred)
973{
974 return std::adjacent_find(begin, end, std::not_fn(pred)) == end;
975}
976
983template <class NWID>
984inline NWID *Window::GetWidget(WidgetID widnum)
985{
986 auto it = this->widget_lookup.find(widnum);
987 if (it == std::end(this->widget_lookup)) return nullptr;
988 NWID *nwid = dynamic_cast<NWID *>(it->second);
989 assert(nwid != nullptr);
990 return nwid;
991}
992
994template <>
996{
997 auto it = this->widget_lookup.find(widnum);
998 if (it == std::end(this->widget_lookup)) return nullptr;
999 return it->second;
1000}
1001
1008template <class NWID>
1009inline const NWID *Window::GetWidget(WidgetID widnum) const
1010{
1011 return const_cast<Window *>(this)->GetWidget<NWID>(widnum);
1012}
1013
1014
1018class PickerWindowBase : public Window {
1019
1020public:
1021 PickerWindowBase(WindowDesc &desc, Window *parent) : Window(desc)
1022 {
1023 this->parent = parent;
1024 }
1025
1026 void Close(int data = 0) override;
1027};
1028
1029Window *BringWindowToFrontById(WindowClass cls, WindowNumber number);
1030Window *FindWindowFromPt(int x, int y);
1031
1041template <typename Twindow, bool Treturn_existing = false, typename... Targs>
1042Twindow *AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
1043{
1044 Twindow *w = static_cast<Twindow *>(BringWindowToFrontById(desc.cls, window_number));
1045 if (w != nullptr) return Treturn_existing ? w : nullptr;
1046 return new Twindow(desc, window_number, std::forward<Targs>(extra_arguments)...);
1047}
1048
1049void RelocateAllWindows(int neww, int newh);
1050
1051void GuiShowTooltips(Window *parent, EncodedString &&text, TooltipCloseCondition close_tooltip);
1052
1053/* widget.cpp */
1054WidgetID GetWidgetFromPos(const Window *w, int x, int y);
1055
1056extern Point _cursorpos_drag_start;
1057
1058extern int _scrollbar_start_pos;
1059extern int _scrollbar_size;
1060extern uint8_t _scroller_click_timeout;
1061
1062extern bool _scrolling_viewport;
1063extern bool _mouse_hovering;
1064
1074
1075void SetFocusedWindow(Window *w);
1076
1077void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y);
1078Rect ScrollRect(Rect r, const Scrollbar &sb, int resize_step = 1);
1079
1080#endif /* WINDOW_GUI_H */
constexpr Timpl & Set()
Set all bits.
Container for an encoded string, created by GetEncodedString.
Enum-as-bit-set wrapper.
Baseclass for nested widgets.
Base class for a 'real' widget.
void SetDisabled(bool disabled)
Disable (grey-out) or enable the widget.
Stacked widgets, widgets all occupying the same space in the window.
int shown_plane
Plane being displayed (for NWID_SELECTION only).
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:3684
Scrollbar data structure.
static constexpr uint WD_CAPTION_HEIGHT
Minimum height of a title bar.
Definition window_gui.h:88
RectPadding defsizebox
Padding around image in defsizebox widget.
Definition window_gui.h:47
RectPadding closebox
Padding around image in closebox widget.
Definition window_gui.h:49
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:41
static constexpr uint WD_DROPDOWN_HEIGHT
Minimum height of a drop down widget.
Definition window_gui.h:89
RectPadding captiontext
Padding for text within caption widget.
Definition window_gui.h:50
RectPadding sparse_resize
Padding used for a resizeable 'sparse' widget window, usually containing multiple frames.
Definition window_gui.h:56
RectPadding debugbox
Padding around image in debugbox widget.
Definition window_gui.h:46
int vsep_sparse
Normal vertical spacing for 'sparse' widget window.
Definition window_gui.h:60
RectPadding sparse
Padding used for 'sparse' widget window, usually containing multiple frames.
Definition window_gui.h:55
RectPadding frametext
Padding inside frame with text.
Definition window_gui.h:42
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
RectPadding modalpopup
Spacing for popup warning/information windows.
Definition window_gui.h:53
RectPadding hscrollbar
Padding inside horizontal scrollbar buttons.
Definition window_gui.h:38
RectPadding shadebox
Padding around image in shadebox widget.
Definition window_gui.h:44
RectPadding resizebox
Padding around image in resizebox widget.
Definition window_gui.h:48
RectPadding vscrollbar
Padding inside vertical scrollbar buttons.
Definition window_gui.h:37
RectPadding imgbtn
Padding around image button image.
Definition window_gui.h:35
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:59
int vsep_picker
Vertical spacing of picker-window widgets.
Definition window_gui.h:58
int vsep_wide
Wide vertical spacing.
Definition window_gui.h:61
int hsep_wide
Wide horizontal spacing.
Definition window_gui.h:63
static constexpr uint WD_CLOSEBOX_WIDTH
Minimum width of a close box widget.
Definition window_gui.h:87
RectPadding fullbevel
Always-scaled bevel thickness.
Definition window_gui.h:40
RectPadding inset
Padding inside inset container.
Definition window_gui.h:36
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
static constexpr uint WD_RESIZEBOX_WIDTH
Minimum width of a resize box widget.
Definition window_gui.h:86
RectPadding picker
Padding for a picker (dock, station, etc) window.
Definition window_gui.h:54
static constexpr uint WD_STICKYBOX_WIDTH
Minimum width of a standard sticky box widget.
Definition window_gui.h:83
RectPadding matrix
Padding of WWT_MATRIX items.
Definition window_gui.h:43
int hsep_normal
Normal horizontal spacing.
Definition window_gui.h:62
RectPadding dropdownlist
Padding of complete drop down list.
Definition window_gui.h:52
static constexpr uint WD_DEBUGBOX_WIDTH
Minimum width of a standard debug box widget.
Definition window_gui.h:84
RectPadding stickybox
Padding around image in stickybox widget.
Definition window_gui.h:45
static constexpr uint WD_DEFSIZEBOX_WIDTH
Minimum width of a standard defsize box widget.
Definition window_gui.h:85
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition window_gui.h:39
RectPadding dropdowntext
Padding of drop down list item.
Definition window_gui.h:51
static constexpr uint WD_SHADEBOX_WIDTH
Distances used in drawing widgets.
Definition window_gui.h:82
int hsep_indent
Width of indentation for tree layouts.
Definition window_gui.h:64
Types related to companies.
static constexpr Owner INVALID_OWNER
An invalid owner.
FontSize
Available font sizes.
Definition gfx_type.h:248
Colours
One of 16 base colours used for companies and windows/widgets.
Definition gfx_type.h:283
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:315
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:1013
#define Rect
Macro that prevents name conflicts between included headers.
#define Point
Macro that prevents name conflicts between included headers.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
Horizontal and vertical alignment.
Dimensions (a width and height) of a rectangle in 2D.
List of hotkeys for a window.
Definition hotkeys.h:44
Data stored about a string that can be modified in the GUI.
Padding dimensions to apply to each side of a Rect.
Data structure for resizing a window.
Definition window_gui.h:214
uint step_height
Step-size of height resize changes.
Definition window_gui.h:216
uint step_width
Step-size of width resize changes.
Definition window_gui.h:215
Helper/buffer for input fields.
Vehicle data structure.
Data structure for a window viewport.
Definition window_gui.h:249
void CancelFollow(const Window &viewport_window)
Cancel viewport vehicle following, and raise follow location widget if needed.
int32_t dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition window_gui.h:254
int32_t scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition window_gui.h:252
int32_t dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition window_gui.h:253
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, VehicleID::Invalid() otherwise.
Definition window_gui.h:250
int32_t scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition window_gui.h:251
Data structure for viewport, display of a part of the world.
High level window description.
Definition window_gui.h:171
int16_t GetDefaultWidth() const
Determine default width of window.
Definition window.cpp:145
~WindowDesc()
Remove ourselves from the global list of window descs.
Definition window.cpp:135
static void SaveToConfig()
Save all WindowDesc settings to _windows_file.
Definition window.cpp:182
int16_t pref_width
User-preferred width of the window. Zero if unset.
Definition window_gui.h:190
const WindowPosition default_pos
Preferred position of the window.
Definition window_gui.h:181
bool pref_sticky
Preferred stickyness.
Definition window_gui.h:189
WindowDesc(const WindowDesc &)=delete
Delete copy constructor to prevent compilers from copying the structure, which fails due to _window_d...
int16_t pref_height
User-preferred height of the window. Zero if unset.
Definition window_gui.h:191
int16_t GetDefaultHeight() const
Determine default height of window.
Definition window.cpp:155
const int16_t default_height_trad
Preferred initial height of the window (pixels at 1x zoom).
Definition window_gui.h:201
const int16_t default_width_trad
Preferred initial width of the window (pixels at 1x zoom).
Definition window_gui.h:200
const WindowClass cls
Class of the window,.
Definition window_gui.h:182
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:184
const std::source_location source_location
Source location of this definition.
Definition window_gui.h:180
const WindowDefaultFlags flags
Flags.
Definition window_gui.h:185
static void LoadFromConfig()
Load all WindowDesc settings from _windows_file.
Definition window.cpp:163
const WindowClass parent_cls
Class of the parent window.
Definition window_gui.h:183
const HotkeyList * hotkeys
Hotkeys for the window.
Definition window_gui.h:187
WindowDesc(WindowPosition default_pos, std::string_view ini_key, int16_t def_width_trad, int16_t def_height_trad, WindowClass window_class, WindowClass parent_class, WindowDefaultFlags flags, const std::span< const NWidgetPart > nwid_parts, HotkeyList *hotkeys=nullptr, const std::source_location location=std::source_location::current())
Window description constructor.
Definition window.cpp:115
const std::span< const NWidgetPart > nwid_parts
Span of nested widget parts describing the window.
Definition window_gui.h:186
Number to differentiate different windows of the same class.
Iterable ensemble of all valid Windows.
Definition window_gui.h:945
Iterator to iterate all valid Windows.
Definition window_gui.h:901
Data structure for an opened window.
Definition window_gui.h:272
virtual const struct Textbuf * GetFocusedTextbuf() const
Get the current input text buffer.
Definition window.cpp:373
void SetWidgetHighlight(WidgetID widget_index, TextColour highlighted_colour)
Sets the highlighted status of a widget.
Definition window.cpp:247
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:1025
void CloseChildWindows(WindowClass wc=WindowClass::Invalid) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1122
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1150
bool IsWidgetGloballyFocused(WidgetID widget_index) const
Check if given widget has user input focus.
Definition window_gui.h:430
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:622
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition window_gui.h:818
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition widget.cpp:839
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1855
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition window_gui.h:319
virtual void ApplyDefaults()
Read default values from WindowDesc configuration an apply them to the window.
Definition window.cpp:199
uint8_t white_border_timer
Timer value of the WindowFlag::WhiteBorder for flags.
Definition window_gui.h:306
NWidgetStacked * shade_select
Selection widget (NWID_SELECTION) to use for shading the window. If nullptr, window cannot shade.
Definition window_gui.h:322
void InitializePositionSize(int x, int y, int min_width, int min_height)
Set the position and smallest size of the window.
Definition window.cpp:1504
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:792
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:843
Dimension unshaded_size
Last known unshaded size (only valid while shaded).
Definition window_gui.h:323
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
Definition window.cpp:3317
virtual EventState OnKeyPress(char32_t key, uint16_t keycode)
A key has been pressed.
Definition window_gui.h:652
Window * parent
Parent window.
Definition window_gui.h:327
AllWindows< false > IterateFromBack
Iterate all windows in Z order from back to front.
Definition window_gui.h:960
virtual ~Window()
Remove window and all its child windows from the window stack.
Definition window.cpp:1187
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition window_gui.h:468
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:565
uint8_t timeout_timer
Timer value of the WindowFlag::Timeout for flags.
Definition window_gui.h:305
std::unique_ptr< ViewportData > viewport
Pointer to viewport data, if present.
Definition window_gui.h:317
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:513
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:325
virtual void OnGameTick()
Called once per (game) tick.
Definition window_gui.h:769
virtual void ShowNewGRFInspectWindow() const
Show the NewGRF inspection window.
Definition window_gui.h:894
virtual bool OnRightClick(Point pt, WidgetID widget)
A click with the right mouse button has been made on the window.
Definition window_gui.h:679
virtual void OnScrollbarScroll(WidgetID widget)
Notify window that a scrollbar position has been updated.
Definition window_gui.h:743
void RaiseWidgetWhenLowered(WidgetID widget_index)
Marks a widget as raised and dirty (redraw), when it is marked as lowered.
Definition window_gui.h:477
virtual void OnDropdownSelect(WidgetID widget, int index, int click_result)
A dropdown option associated to this window has been selected.
Definition window_gui.h:795
virtual void OnX2Click(Point pt, WidgetID widget)
A click with the X2 mouse button has been made on the window.
Definition window_gui.h:700
void ProcessScheduledInvalidations()
Process all scheduled invalidations.
Definition window.cpp:3330
ResizeInfo resize
Resize information.
Definition window_gui.h:313
void UnfocusFocusedWidget()
Makes no widget on this window have focus.
Definition window.cpp:478
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition window_gui.h:390
virtual void OnMouseLoop()
Called for every mouse loop run, which is at least once per (game) tick.
Definition window_gui.h:764
void SetShaded(bool make_shaded)
Set the shaded state of the window to make_shaded.
Definition window.cpp:1068
virtual void OnPlaceObjectAbort()
The user cancelled a tile highlight mode that has been set.
Definition window_gui.h:848
int scale
Scale of this window – used to determine how to resize.
Definition window_gui.h:303
void ScheduleResize()
Mark this window as resized and in need of OnResize() event.
Definition window.cpp:3295
virtual bool OnVehicleSelect(const struct Vehicle *v)
The user clicked on a vehicle while HT_VEHICLE has been set.
Definition window_gui.h:834
bool IsWidgetFocused(WidgetID widget_index) const
Check if given widget is focused within this window.
Definition window_gui.h:419
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:514
virtual void OnPaint()
The window must be repainted.
Definition window_gui.h:597
void DrawSortButton(WidgetID widget, bool descending) const
Draw a sort button's up or down arrow symbol.
Definition widget.cpp:824
virtual void OnDragDrop(Point pt, WidgetID widget)
A dragged 'object' has been released.
Definition window_gui.h:730
virtual bool IsNewGRFInspectable() const
Is the data related to this window NewGRF inspectable?
Definition window_gui.h:886
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1845
WindowDesc & window_desc
Window description.
Definition window_gui.h:298
WindowClass window_class
Window class.
Definition window_gui.h:300
virtual void OnRealtimeTick(uint delta_ms)
Called periodically.
Definition window_gui.h:775
virtual void OnMouseWheel(int wheel, WidgetID widget)
The mouse wheel has been turned.
Definition window_gui.h:758
AllWindows< true > IterateFromFront
Iterate all windows in Z order from front to back.
Definition window_gui.h:961
void CloseChildWindowById(WindowClass wc, WindowNumber number) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1137
virtual void OnQueryTextFinished(std::optional< std::string > str)
The query window opened from this window has closed.
Definition window_gui.h:811
void SetWhiteBorder()
Set the timeout flag of the window and initiate the timer.
Definition window_gui.h:363
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition window.cpp:494
virtual void OnFocusLost(bool closing)
The window has lost focus.
Definition window.cpp:530
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:490
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition window_gui.h:409
void DrawViewport() const
Draw the viewport of this window.
static std::vector< Window * > closed_windows
List of closed windows to delete.
Definition window_gui.h:274
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition window.cpp:539
virtual void DrawWidget(const Rect &r, WidgetID widget) const
Draw the contents of a nested widget.
Definition window_gui.h:608
void SetWidgetsLoweredState(bool lowered_stat, Args... widgets)
Sets the lowered/raised status of a list of widgets.
Definition window_gui.h:525
virtual Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number)
Compute the initial position of the window.
Definition window.cpp:1834
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition window_gui.h:315
WindowIterator< true > IteratorToBack
Iterate in Z order towards back.
Definition window_gui.h:938
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:440
void EnableWidget(WidgetID widget_index)
Sets a widget to Enabled.
Definition window_gui.h:399
virtual void OnMiddleClick(Point pt, WidgetID widget)
A click with the middle mouse button has been made on the window.
Definition window_gui.h:686
virtual Point GetCaretPosition() const
Get the current caret position if an edit box has the focus.
Definition window.cpp:386
virtual void FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize)
Resize window towards the default size.
Definition window.cpp:1523
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:293
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:2788
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:826
WindowIterator< false > IteratorToFront
Iterate in Z order towards front.
Definition window_gui.h:937
int left
x position of left edge of the window
Definition window_gui.h:308
bool IsShaded() const
Is window shaded currently?
Definition window_gui.h:561
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition window_gui.h:354
const NWidgetCore * nested_focus
Currently focused nested widget, or nullptr if no nested widget has focus.
Definition window_gui.h:318
virtual void OnEditboxChanged(WidgetID widget)
The text in an editbox has been edited.
Definition window_gui.h:803
void UpdateQueryStringSize()
Update size of all QueryStrings of this window.
Definition window.cpp:362
virtual void OnScroll(Point delta)
Handle the request for (viewport) scrolling.
Definition window_gui.h:736
void RaiseWidgetsWhenLowered(Args... widgets)
Raises the widgets and sets widgets dirty that are lowered.
Definition window_gui.h:535
int top
y position of top edge of the window
Definition window_gui.h:309
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:670
const QueryString * GetQueryString(WidgetID widnum) const
Return the querystring associated to a editbox.
Definition window.cpp:342
WidgetLookup widget_lookup
Indexed access to the nested widget tree. Do not access directly, use Window::GetWidget() instead.
Definition window_gui.h:321
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:417
Window * FindChildWindow(WindowClass wc=WindowClass::Invalid) const
Find the Window whose parent pointer points to this window.
Definition window.cpp:1094
std::vector< int > scheduled_invalidation_data
Data of scheduled OnInvalidateData() calls.
Definition window_gui.h:281
void InitializeData(WindowNumber window_number)
Initializes the data (except the position and initial size) of a new Window.
Definition window.cpp:1466
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:869
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:751
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1879
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:218
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
virtual void OnX1Click(Point pt, WidgetID widget)
A click with the X1 mouse button has been made on the window.
Definition window_gui.h:693
virtual bool OnTooltip(Point pt, WidgetID widget, TooltipCloseCondition close_cond)
Event to display a custom tooltip.
Definition window_gui.h:716
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:459
virtual EventState OnCTRLStateChange()
The state of the control key has changed.
Definition window_gui.h:661
void ProcessScheduledResize()
Process scheduled OnResize() event.
Definition window.cpp:3303
EventState HandleEditBoxKey(WidgetID wid, char32_t key, uint16_t keycode)
Process keypress for editbox widget.
Definition window.cpp:2611
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:723
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:604
virtual void OnResize()
Called after the window got resized.
Definition window_gui.h:787
Window * FindChildWindowById(WindowClass wc, WindowNumber number) const
Find the Window whose parent pointer points to this window.
Definition window.cpp:1109
virtual void OnFocus()
The window has gained focus.
Definition window.cpp:522
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1869
virtual void OnTimeout()
Called when this window's timeout has been reached.
Definition window_gui.h:780
WindowFlags flags
Window flags.
Definition window_gui.h:299
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:322
void ProcessHighlightedInvalidations()
Process all invalidation of highlighted widgets.
Definition window.cpp:3342
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:858
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:579
static void DeleteClosedWindows()
Delete all closed windows.
Definition window.cpp:63
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:380
std::unique_ptr< NWidgetBase > nested_root
Root of the nested tree.
Definition window_gui.h:320
bool scheduled_resize
Set if window has been resized.
Definition window_gui.h:282
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:402
bool IsWidgetHighlighted(WidgetID widget_index) const
Gets the highlighted status of a widget.
Definition window.cpp:277
void DisableAllWidgetHighlight()
Disable the highlighted status of all widgets.
Definition window.cpp:229
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:878
AllWindows< false > Iterate
Iterate all windows in whatever order is easiest.
Definition window_gui.h:959
int height
Height of the window (number of pixels down in y direction).
Definition window_gui.h:311
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:707
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:310
virtual void OnInit()
Notification that the nested widget tree gets initialized.
Definition window_gui.h:580
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
Definition window_gui.h:449
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:301
Types related to tiles.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
Types related to vehicles.
PoolID< uint32_t, struct VehicleIDTag, 0xFF000, 0xFFFFF > VehicleID
The type all our vehicle IDs have.
Functions and type for generating vehicle lists.
Types related to viewports.
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects).
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
Definitions about widgets.
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
std::map< WidgetID, class NWidgetBase * > WidgetLookup
Lookup between widget IDs and NWidget objects.
bool _scrolling_viewport
A viewport is being scrolled with the mouse.
Definition window.cpp:88
Window * _focused_window
Window that currently has focus.
Definition window.cpp:80
bool _mouse_hovering
The mouse is hovering over the same point.
Definition window.cpp:89
WindowList _z_windows
List of windows opened at the screen sorted from the front to back.
Definition window.cpp:55
SpecialMouseMode _special_mouse_mode
Mode of the mouse.
Definition window.cpp:91
WindowDefaultFlag
Window default widget/window handling flags.
Definition window_gui.h:153
@ Construction
This window is used for construction; close it whenever changing company.
Definition window_gui.h:154
@ NoClose
This window can't be interactively closed.
Definition window_gui.h:157
@ NoFocus
This window won't get focus/make any other window lose focus when click.
Definition window_gui.h:156
@ Modal
The window is a modal child of some other window, meaning the parent is 'inactive'.
Definition window_gui.h:155
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition widget.cpp:308
TooltipCloseCondition
Definition window_gui.h:262
@ RightClick
Close the tooltip when releasing the right mouse button.
Definition window_gui.h:263
@ ExitViewport
Close the tooltip when leaving the viewport.
Definition window_gui.h:266
@ None
Do not automatically close the tooltip.
Definition window_gui.h:265
@ Hover
Close the tooltip when stopping to hovering, i.e. moving the mouse.
Definition window_gui.h:264
EnumBitSet< FrameFlag, uint8_t > FrameFlags
Bitset of FrameFlag elements.
Definition window_gui.h:31
void GuiShowTooltips(Window *parent, EncodedString &&text, TooltipCloseCondition close_tooltip)
Shows a tooltip.
Definition misc_gui.cpp:690
Window * _focused_window
Window that currently has focus.
Definition window.cpp:80
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:972
FrameFlag
Flags to describe the look of the frame.
Definition window_gui.h:23
@ Transparent
Makes the background transparent if set.
Definition window_gui.h:24
@ BorderOnly
Draw border only, no background.
Definition window_gui.h:25
@ Darkened
If set the background is darker, allows for lowered frames with normal background colour when used wi...
Definition window_gui.h:27
@ Lowered
If set the frame is lowered and the background colour brighter (ie. buttons when pressed).
Definition window_gui.h:26
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Definition window.cpp:430
EnumBitSet< WindowFlag, uint16_t > WindowFlags
Bitset of WindowFlag elements.
Definition window_gui.h:237
WindowFlag
Window flags.
Definition window_gui.h:222
@ SizingLeft
Window is being resized towards the left.
Definition window_gui.h:227
@ DisableVpScroll
Window does not do autoscroll,.
Definition window_gui.h:230
@ Highlighted
Window has a widget that has a highlight.
Definition window_gui.h:232
@ Centred
Window is centered and shall stay centered after ReInit.
Definition window_gui.h:233
@ Dragging
Window is being dragged.
Definition window_gui.h:225
@ SizingRight
Window is being resized towards the right.
Definition window_gui.h:226
@ WhiteBorder
Window white border counter bit mask.
Definition window_gui.h:231
@ Timeout
Window timeout counter.
Definition window_gui.h:223
@ Sticky
Window is made sticky by user.
Definition window_gui.h:229
Window * FindWindowFromPt(int x, int y)
Do a search for a window at specific coordinates.
Definition window.cpp:1891
static const int TIMEOUT_DURATION
The initial timeout value for WindowFlag::Timeout.
Definition window_gui.h:239
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:293
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:1732
SpecialMouseMode
Mouse modes.
@ DragDrop
Drag&drop an object.
@ Sizing
Sizing mode.
@ Presize
Presizing mode (docks, tunnels).
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition window.cpp:1326
Point AlignInitialConstructionToolbar(int window_width)
Compute the position of the construction toolbars.
Definition window.cpp:1748
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
Definition window.cpp:3610
void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
Special handling for the scrollbar widget type.
Definition widget.cpp:269
EnumBitSet< WindowDefaultFlag, uint8_t > WindowDefaultFlags
Bitset of WindowDefaultFlag elements.
Definition window_gui.h:161
WindowPosition
How do we the window to be placed?
Definition window_gui.h:143
@ AlignToolbar
Align toward the toolbar.
Definition window_gui.h:147
@ Automatic
Find a place automatically.
Definition window_gui.h:145
@ Center
Center the window.
Definition window_gui.h:146
@ Manual
Manually align the window (so no automatic location finding).
Definition window_gui.h:144
WindowList _z_windows
List of windows opened at the screen sorted from the front to back.
Definition window.cpp:55
static const int WHITE_BORDER_DURATION
The initial timeout value for WindowFlag::WhiteBorder.
Definition window_gui.h:240
Rect ScrollRect(Rect r, const Scrollbar &sb, int resize_step=1)
Apply 'scroll' to a rect to be drawn in.
Definition widget.cpp:2565
void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, std::string_view str, Alignment align, FontSize fs)
Draw a caption bar.
Definition widget.cpp:744
int WidgetID
Widget ID.
Definition window_type.h:21
EventState
State of handling an event.
@ NotHandled
The passed event is not handled.
static constexpr WidgetID INVALID_WIDGET
An invalid widget index.
Definition window_type.h:24