OpenTTD Source: src/window.cpp Source File

OpenTTD Source 14.1

window.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "company_func.h"
12 #include "gfx_func.h"
13 #include "console_func.h"
14 #include "console_gui.h"
15 #include "viewport_func.h"
16 #include "progress.h"
17 #include "blitter/factory.hpp"
18 #include "zoom_func.h"
19 #include "vehicle_base.h"
20 #include "depot_func.h"
21 #include "window_func.h"
22 #include "tilehighlight_func.h"
23 #include "network/network.h"
24 #include "querystring_gui.h"
25 #include "strings_func.h"
26 #include "settings_type.h"
27 #include "settings_func.h"
28 #include "ini_type.h"
29 #include "newgrf_debug.h"
30 #include "hotkeys.h"
31 #include "toolbar_gui.h"
32 #include "statusbar_gui.h"
33 #include "error.h"
34 #include "game/game.hpp"
35 #include "video/video_driver.hpp"
36 #include "framerate_type.h"
37 #include "network/network_func.h"
38 #include "news_func.h"
39 #include "timer/timer.h"
40 #include "timer/timer_window.h"
41
42 #include "safeguards.h"
43
45 enum ViewportAutoscrolling {
46 VA_DISABLED,
47 VA_MAIN_VIEWPORT_FULLSCREEN,
48 VA_MAIN_VIEWPORT,
49 VA_EVERY_VIEWPORT,
50 };
51
52 static Point _drag_delta;
53 static Window *_mouseover_last_w = nullptr;
54 static Window *_last_scroll_window = nullptr;
55
57 WindowList _z_windows;
58
60 /* static */ std::vector<Window *> Window::closed_windows;
61
65 /* static */ void Window::DeleteClosedWindows()
66 {
67 for (Window *w : Window::closed_windows) delete w;
68 Window::closed_windows.clear();
69
70 /* Remove dead entries from the window list */
71 _z_windows.remove(nullptr);
72 }
73
75 bool _window_highlight_colour = false;
76
77 /*
78 * Window that currently has focus. - The main purpose is to generate
79 * #FocusLost events, not to give next window in z-order focus when a
80 * window is closed.
81 */
82 Window *_focused_window;
83
84 Point _cursorpos_drag_start;
85
86 int _scrollbar_start_pos;
87 int _scrollbar_size;
88 byte _scroller_click_timeout = 0;
89
90 bool _scrolling_viewport;
91 bool _mouse_hovering;
92
93 SpecialMouseMode _special_mouse_mode;
94
99 std::vector<WindowDesc*> *_window_descs = nullptr;
100
102 std::string _windows_file;
103
105 WindowDesc::WindowDesc(const char * const file, const int line, WindowPosition def_pos, const char *ini_key, int16_t def_width_trad, int16_t def_height_trad,
106 WindowClass window_class, WindowClass parent_class, uint32_t flags,
107 const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, HotkeyList *hotkeys) :
108 file(file),
109 line(line),
110 default_pos(def_pos),
111 cls(window_class),
112 parent_cls(parent_class),
113 ini_key(ini_key),
114 flags(flags),
115 nwid_begin(nwid_begin),
116 nwid_end(nwid_end),
117 hotkeys(hotkeys),
118 pref_sticky(false),
119 pref_width(0),
120 pref_height(0),
121 default_width_trad(def_width_trad),
122 default_height_trad(def_height_trad)
123 {
124 if (_window_descs == nullptr) _window_descs = new std::vector<WindowDesc*>();
125 _window_descs->push_back(this);
126 }
127
128 WindowDesc::~WindowDesc()
129 {
130 _window_descs->erase(std::find(_window_descs->begin(), _window_descs->end(), this));
131 }
132
138 int16_t WindowDesc::GetDefaultWidth() const
139 {
140 return this->pref_width != 0 ? this->pref_width : ScaleGUITrad(this->default_width_trad);
141 }
142
148 int16_t WindowDesc::GetDefaultHeight() const
149 {
150 return this->pref_height != 0 ? this->pref_height : ScaleGUITrad(this->default_height_trad);
151 }
152
156 void WindowDesc::LoadFromConfig()
157 {
158 IniFile ini;
159 ini.LoadFromDisk(_windows_file, NO_DIRECTORY);
160 for (WindowDesc *wd : *_window_descs) {
161 if (wd->ini_key == nullptr) continue;
162 IniLoadWindowSettings(ini, wd->ini_key, wd);
163 }
164 }
165
169 static bool DescSorter(WindowDesc * const &a, WindowDesc * const &b)
170 {
171 if (a->ini_key != nullptr && b->ini_key != nullptr) return strcmp(a->ini_key, b->ini_key) < 0;
172 return a->ini_key != nullptr;
173 }
174
178 void WindowDesc::SaveToConfig()
179 {
180 /* Sort the stuff to get a nice ini file on first write */
181 std::sort(_window_descs->begin(), _window_descs->end(), DescSorter);
182
183 IniFile ini;
184 ini.LoadFromDisk(_windows_file, NO_DIRECTORY);
185 for (WindowDesc *wd : *_window_descs) {
186 if (wd->ini_key == nullptr) continue;
187 IniSaveWindowSettings(ini, wd->ini_key, wd);
188 }
189 ini.SaveToDisk(_windows_file);
190 }
191
195 void Window::ApplyDefaults()
196 {
197 if (this->nested_root != nullptr && this->nested_root->GetWidgetOfType(WWT_STICKYBOX) != nullptr) {
198 if (this->window_desc->pref_sticky) this->flags |= WF_STICKY;
199 } else {
200 /* There is no stickybox; clear the preference in case someone tried to be funny */
201 this->window_desc->pref_sticky = false;
202 }
203 }
204
214 int Window::GetRowFromWidget(int clickpos, WidgetID widget, int padding, int line_height) const
215 {
216 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(widget);
217 if (line_height < 0) line_height = wid->resize_y;
218 if (clickpos < wid->pos_y + padding) return INT_MAX;
219 return (clickpos - wid->pos_y - padding) / line_height;
220 }
221
225 void Window::DisableAllWidgetHighlight()
226 {
227 for (auto &pair : this->widget_lookup) {
228 NWidgetBase *nwid = pair.second;
229 if (nwid->IsHighlighted()) {
230 nwid->SetHighlighted(TC_INVALID);
231 nwid->SetDirty(this);
232 }
233 }
234
235 CLRBITS(this->flags, WF_HIGHLIGHTED);
236 }
237
243 void Window::SetWidgetHighlight(WidgetID widget_index, TextColour highlighted_colour)
244 {
245 NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget_index);
246 if (nwid == nullptr) return;
247
248 nwid->SetHighlighted(highlighted_colour);
249 nwid->SetDirty(this);
250
251 if (highlighted_colour != TC_INVALID) {
252 /* If we set a highlight, the window has a highlight */
253 this->flags |= WF_HIGHLIGHTED;
254 } else {
255 /* If we disable a highlight, check all widgets if anyone still has a highlight */
256 bool valid = false;
257 for (const auto &pair : this->widget_lookup) {
258 nwid = pair.second;
259 if (!nwid->IsHighlighted()) continue;
260
261 valid = true;
262 }
263 /* If nobody has a highlight, disable the flag on the window */
264 if (!valid) CLRBITS(this->flags, WF_HIGHLIGHTED);
265 }
266 }
267
273 bool Window::IsWidgetHighlighted(WidgetID widget_index) const
274 {
275 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget_index);
276 if (nwid == nullptr) return false;
277
278 return nwid->IsHighlighted();
279 }
280
288 void Window::OnDropdownClose(Point pt, WidgetID widget, int index, bool instant_close)
289 {
290 if (widget < 0) return;
291
292 if (instant_close) {
293 /* Send event for selected option if we're still
294 * on the parent button of the dropdown (behaviour of the dropdowns in the main toolbar). */
295 if (GetWidgetFromPos(this, pt.x, pt.y) == widget) {
296 this->OnDropdownSelect(widget, index);
297 }
298 }
299
300 /* Raise the dropdown button */
301 NWidgetCore *nwi2 = this->GetWidget<NWidgetCore>(widget);
302 if ((nwi2->type & WWT_MASK) == NWID_BUTTON_DROPDOWN) {
303 nwi2->disp_flags &= ~ND_DROPDOWN_ACTIVE;
304 } else {
305 this->RaiseWidget(widget);
306 }
307 this->SetWidgetDirty(widget);
308 }
309
315 const Scrollbar *Window::GetScrollbar(WidgetID widnum) const
316 {
317 return this->GetWidget<NWidgetScrollbar>(widnum);
318 }
319
325 Scrollbar *Window::GetScrollbar(WidgetID widnum)
326 {
327 return this->GetWidget<NWidgetScrollbar>(widnum);
328 }
329
335 const QueryString *Window::GetQueryString(WidgetID widnum) const
336 {
337 auto query = this->querystrings.find(widnum);
338 return query != this->querystrings.end() ? query->second : nullptr;
339 }
340
346 QueryString *Window::GetQueryString(WidgetID widnum)
347 {
348 auto query = this->querystrings.find(widnum);
349 return query != this->querystrings.end() ? query->second : nullptr;
350 }
351
355 void Window::UpdateQueryStringSize()
356 {
357 for (auto &qs : this->querystrings) {
358 qs.second->text.UpdateSize();
359 }
360 }
361
366 /* virtual */ const Textbuf *Window::GetFocusedTextbuf() const
367 {
368 if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) {
369 return &this->GetQueryString(this->nested_focus->index)->text;
370 }
371
372 return nullptr;
373 }
374
379 /* virtual */ Point Window::GetCaretPosition() const
380 {
381 if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX && !this->querystrings.empty()) {
382 return this->GetQueryString(this->nested_focus->index)->GetCaretPosition(this, this->nested_focus->index);
383 }
384
385 Point pt = {0, 0};
386 return pt;
387 }
388
395 /* virtual */ Rect Window::GetTextBoundingRect(const char *from, const char *to) const
396 {
397 if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) {
398 return this->GetQueryString(this->nested_focus->index)->GetBoundingRect(this, this->nested_focus->index, from, to);
399 }
400
401 Rect r = {0, 0, 0, 0};
402 return r;
403 }
404
410 /* virtual */ ptrdiff_t Window::GetTextCharacterAtPosition(const Point &pt) const
411 {
412 if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) {
413 return this->GetQueryString(this->nested_focus->index)->GetCharAtPosition(this, this->nested_focus->index, pt);
414 }
415
416 return -1;
417 }
418
423 void SetFocusedWindow(Window *w)
424 {
425 if (_focused_window == w) return;
426
427 /* Don't focus a tooltip */
428 if (w != nullptr && w->window_class == WC_TOOLTIPS) return;
429
430 /* Invalidate focused widget */
431 if (_focused_window != nullptr) {
432 if (_focused_window->nested_focus != nullptr) _focused_window->nested_focus->SetDirty(_focused_window);
433 }
434
435 /* Remember which window was previously focused */
436 Window *old_focused = _focused_window;
437 _focused_window = w;
438
439 /* So we can inform it that it lost focus */
440 if (old_focused != nullptr) old_focused->OnFocusLost(false);
441 if (_focused_window != nullptr) _focused_window->OnFocus();
442 }
443
449 bool EditBoxInGlobalFocus()
450 {
451 if (_focused_window == nullptr) return false;
452
453 /* The console does not have an edit box so a special case is needed. */
454 if (_focused_window->window_class == WC_CONSOLE) return true;
455
456 return _focused_window->nested_focus != nullptr && _focused_window->nested_focus->type == WWT_EDITBOX;
457 }
458
463 bool FocusedWindowIsConsole()
464 {
465 return _focused_window && _focused_window->window_class == WC_CONSOLE;
466 }
467
471 void Window::UnfocusFocusedWidget()
472 {
473 if (this->nested_focus != nullptr) {
474 if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus();
475
476 /* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */
477 this->nested_focus->SetDirty(this);
478 this->nested_focus = nullptr;
479 }
480 }
481
487 bool Window::SetFocusedWidget(WidgetID widget_index)
488 {
489 NWidgetCore *widget = this->GetWidget<NWidgetCore>(widget_index);
490 assert(widget != nullptr); /* Setting focus to a non-existing widget is a bad idea. */
491
492 if (this->nested_focus != nullptr) {
493 /* Do nothing if widget_index is already focused. */
494 if (widget == this->nested_focus) return false;
495
496 /* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */
497 this->nested_focus->SetDirty(this);
498 if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus();
499 }
500
501 this->nested_focus = widget;
502 if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxGainedFocus();
503 return true;
504 }
505
509 void Window::OnFocus()
510 {
511 if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxGainedFocus();
512 }
513
517 void Window::OnFocusLost(bool)
518 {
519 if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus();
520 }
521
526 void Window::RaiseButtons(bool autoraise)
527 {
528 for (auto &pair : this->widget_lookup) {
529 WidgetType type = pair.second->type;
530 NWidgetCore *wid = dynamic_cast<NWidgetCore *>(pair.second);
531 if (((type & ~WWB_PUSHBUTTON) < WWT_LAST || type == NWID_PUSHBUTTON_DROPDOWN) &&
532 (!autoraise || (type & WWB_PUSHBUTTON) || type == WWT_EDITBOX) && wid->IsLowered()) {
533 wid->SetLowered(false);
534 wid->SetDirty(this);
535 }
536 }
537
538 /* Special widgets without widget index */
539 {
540 NWidgetCore *wid = this->nested_root != nullptr ? dynamic_cast<NWidgetCore *>(this->nested_root->GetWidgetOfType(WWT_DEFSIZEBOX)) : nullptr;
541 if (wid != nullptr) {
542 wid->SetLowered(false);
543 wid->SetDirty(this);
544 }
545 }
546 }
547
552 void Window::SetWidgetDirty(WidgetID widget_index) const
553 {
554 /* Sometimes this function is called before the window is even fully initialized */
555 auto it = this->widget_lookup.find(widget_index);
556 if (it == std::end(this->widget_lookup)) return;
557
558 it->second->SetDirty(this);
559 }
560
566 EventState Window::OnHotkey(int hotkey)
567 {
568 if (hotkey < 0) return ES_NOT_HANDLED;
569
570 NWidgetCore *nw = this->GetWidget<NWidgetCore>(hotkey);
571 if (nw == nullptr || nw->IsDisabled()) return ES_NOT_HANDLED;
572
573 if (nw->type == WWT_EDITBOX) {
574 if (this->IsShaded()) return ES_NOT_HANDLED;
575
576 /* Focus editbox */
577 this->SetFocusedWidget(hotkey);
578 SetFocusedWindow(this);
579 } else {
580 /* Click button */
581 this->OnClick(Point(), hotkey, 1);
582 }
583 return ES_HANDLED;
584 }
585
591 void Window::HandleButtonClick(WidgetID widget)
592 {
593 this->LowerWidget(widget);
594 this->SetTimeout();
595 this->SetWidgetDirty(widget);
596 }
597
598 static void StartWindowDrag(Window *w);
599 static void StartWindowSizing(Window *w, bool to_left);
600
608 static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
609 {
610 NWidgetCore *nw = w->nested_root->GetWidgetFromPos(x, y);
611 WidgetType widget_type = (nw != nullptr) ? nw->type : WWT_EMPTY;
612
613 /* Allow dropdown close flag detection to work. */
614 if (nw != nullptr) ClrBit(nw->disp_flags, NDB_DROPDOWN_CLOSED);
615
616 bool focused_widget_changed = false;
617 /* If clicked on a window that previously did not have focus */
618 if (_focused_window != w && // We already have focus, right?
619 (w->window_desc->flags & WDF_NO_FOCUS) == 0 && // Don't lose focus to toolbars
620 widget_type != WWT_CLOSEBOX) { // Don't change focused window if 'X' (close button) was clicked
621 focused_widget_changed = true;
622 SetFocusedWindow(w);
623 }
624
625 if (nw == nullptr) return; // exit if clicked outside of widgets
626
627 /* don't allow any interaction if the button has been disabled */
628 if (nw->IsDisabled()) return;
629
630 WidgetID widget_index = nw->index;
631
632 /* Clicked on a widget that is not disabled.
633 * So unless the clicked widget is the caption bar, change focus to this widget.
634 * Exception: In the OSK we always want the editbox to stay focused. */
635 if (widget_index >= 0 && widget_type != WWT_CAPTION && w->window_class != WC_OSK) {
636 /* focused_widget_changed is 'now' only true if the window this widget
637 * is in gained focus. In that case it must remain true, also if the
638 * local widget focus did not change. As such it's the logical-or of
639 * both changed states.
640 *
641 * If this is not preserved, then the OSK window would be opened when
642 * a user has the edit box focused and then click on another window and
643 * then back again on the edit box (to type some text).
644 */
645 focused_widget_changed |= w->SetFocusedWidget(widget_index);
646 }
647
648 /* Dropdown window of this widget was closed so don't process click this time. */
649 if (HasBit(nw->disp_flags, NDB_DROPDOWN_CLOSED)) return;
650
651 if ((widget_type & ~WWB_PUSHBUTTON) < WWT_LAST && (widget_type & WWB_PUSHBUTTON)) w->HandleButtonClick(widget_index);
652
653 Point pt = { x, y };
654
655 switch (widget_type) {
656 case NWID_VSCROLLBAR:
657 case NWID_HSCROLLBAR:
658 ScrollbarClickHandler(w, nw, x, y);
659 break;
660
661 case WWT_EDITBOX: {
662 QueryString *query = w->GetQueryString(widget_index);
663 if (query != nullptr) query->ClickEditBox(w, pt, widget_index, click_count, focused_widget_changed);
664 break;
665 }
666
667 case WWT_CLOSEBOX: // 'X'
668 w->Close();
669 return;
670
671 case WWT_CAPTION: // 'Title bar'
672 StartWindowDrag(w);
673 return;
674
675 case WWT_RESIZEBOX:
676 /* When the resize widget is on the left size of the window
677 * we assume that that button is used to resize to the left. */
678 StartWindowSizing(w, nw->pos_x < (w->width / 2));
679 nw->SetDirty(w);
680 return;
681
682 case WWT_DEFSIZEBOX: {
683 if (_ctrl_pressed) {
684 w->window_desc->pref_width = w->width;
685 w->window_desc->pref_height = w->height;
686 } else {
687 int16_t def_width = std::max<int16_t>(std::min<int16_t>(w->window_desc->GetDefaultWidth(), _screen.width), w->nested_root->smallest_x);
688 int16_t def_height = std::max<int16_t>(std::min<int16_t>(w->window_desc->GetDefaultHeight(), _screen.height - 50), w->nested_root->smallest_y);
689
690 int dx = (w->resize.step_width == 0) ? 0 : def_width - w->width;
691 int dy = (w->resize.step_height == 0) ? 0 : def_height - w->height;
692 /* dx and dy has to go by step.. calculate it.
693 * The cast to int is necessary else dx/dy are implicitly casted to unsigned int, which won't work. */
694 if (w->resize.step_width > 1) dx -= dx % (int)w->resize.step_width;
695 if (w->resize.step_height > 1) dy -= dy % (int)w->resize.step_height;
696 ResizeWindow(w, dx, dy, false);
697 }
698
699 nw->SetLowered(true);
700 nw->SetDirty(w);
701 w->SetTimeout();
702 break;
703 }
704
705 case WWT_DEBUGBOX:
706 w->ShowNewGRFInspectWindow();
707 break;
708
709 case WWT_SHADEBOX:
710 nw->SetDirty(w);
711 w->SetShaded(!w->IsShaded());
712 return;
713
714 case WWT_STICKYBOX:
715 w->flags ^= WF_STICKY;
716 nw->SetDirty(w);
717 if (_ctrl_pressed) w->window_desc->pref_sticky = (w->flags & WF_STICKY) != 0;
718 return;
719
720 default:
721 break;
722 }
723
724 /* Widget has no index, so the window is not interested in it. */
725 if (widget_index < 0) return;
726
727 /* Check if the widget is highlighted; if so, disable highlight and dispatch an event to the GameScript */
728 if (w->IsWidgetHighlighted(widget_index)) {
729 w->SetWidgetHighlight(widget_index, TC_INVALID);
730 Game::NewEvent(new ScriptEventWindowWidgetClick((ScriptWindow::WindowClass)w->window_class, w->window_number, widget_index));
731 }
732
733 w->OnClick(pt, widget_index, click_count);
734 }
735
742 static void DispatchRightClickEvent(Window *w, int x, int y)
743 {
744 NWidgetCore *wid = w->nested_root->GetWidgetFromPos(x, y);
745 if (wid == nullptr) return;
746
747 Point pt = { x, y };
748
749 /* No widget to handle, or the window is not interested in it. */
750 if (wid->index >= 0) {
751 if (w->OnRightClick(pt, wid->index)) return;
752 }
753
754 /* Right-click close is enabled and there is a closebox. */
755 if (_settings_client.gui.right_click_wnd_close == RCC_YES && (w->window_desc->flags & WDF_NO_CLOSE) == 0) {
756 w->Close();
757 } else if (_settings_client.gui.right_click_wnd_close == RCC_YES_EXCEPT_STICKY && (w->flags & WF_STICKY) == 0 && (w->window_desc->flags & WDF_NO_CLOSE) == 0) {
758 /* Right-click close is enabled, but excluding sticky windows. */
759 w->Close();
760 } else if (_settings_client.gui.hover_delay_ms == 0 && !w->OnTooltip(pt, wid->index, TCC_RIGHT_CLICK) && wid->tool_tip != 0) {
761 GuiShowTooltips(w, wid->tool_tip, TCC_RIGHT_CLICK);
762 }
763 }
764
771 static void DispatchHoverEvent(Window *w, int x, int y)
772 {
773 NWidgetCore *wid = w->nested_root->GetWidgetFromPos(x, y);
774
775 /* No widget to handle */
776 if (wid == nullptr) return;
777
778 Point pt = { x, y };
779
780 /* Show the tooltip if there is any */
781 if (!w->OnTooltip(pt, wid->index, TCC_HOVER) && wid->tool_tip != 0) {
782 GuiShowTooltips(w, wid->tool_tip, TCC_HOVER);
783 return;
784 }
785
786 /* Widget has no index, so the window is not interested in it. */
787 if (wid->index < 0) return;
788
789 w->OnHover(pt, wid->index);
790 }
791
799 static void DispatchMouseWheelEvent(Window *w, NWidgetCore *nwid, int wheel)
800 {
801 if (nwid == nullptr) return;
802
803 /* Using wheel on caption/shade-box shades or unshades the window. */
804 if (nwid->type == WWT_CAPTION || nwid->type == WWT_SHADEBOX) {
805 w->SetShaded(wheel < 0);
806 return;
807 }
808
809 /* Wheeling a vertical scrollbar. */
810 if (nwid->type == NWID_VSCROLLBAR) {
811 NWidgetScrollbar *sb = static_cast<NWidgetScrollbar *>(nwid);
812 if (sb->GetCount() > sb->GetCapacity()) {
813 if (sb->UpdatePosition(wheel)) w->SetDirty();
814 }
815 return;
816 }
817
818 /* Scroll the widget attached to the scrollbar. */
819 Scrollbar *sb = (nwid->scrollbar_index >= 0 ? w->GetScrollbar(nwid->scrollbar_index) : nullptr);
820 if (sb != nullptr && sb->GetCount() > sb->GetCapacity()) {
821 if (sb->UpdatePosition(wheel)) w->SetDirty();
822 }
823 }
824
830 static bool MayBeShown(const Window *w)
831 {
832 /* If we're not modal, everything is okay. */
833 if (!HasModalProgress()) return true;
834
835 switch (w->window_class) {
836 case WC_MAIN_WINDOW:
837 case WC_MODAL_PROGRESS:
838 case WC_CONFIRM_POPUP_QUERY:
839 return true;
840
841 default:
842 return false;
843 }
844 }
845
858 static void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom)
859 {
860 Window::IteratorToFront it(w);
861 ++it;
862 for (; !it.IsEnd(); ++it) {
863 const Window *v = *it;
864 if (MayBeShown(v) &&
865 right > v->left &&
866 bottom > v->top &&
867 left < v->left + v->width &&
868 top < v->top + v->height) {
869 /* v and rectangle intersect with each other */
870 int x;
871
872 if (left < (x = v->left)) {
873 DrawOverlappedWindow(w, left, top, x, bottom);
874 DrawOverlappedWindow(w, x, top, right, bottom);
875 return;
876 }
877
878 if (right > (x = v->left + v->width)) {
879 DrawOverlappedWindow(w, left, top, x, bottom);
880 DrawOverlappedWindow(w, x, top, right, bottom);
881 return;
882 }
883
884 if (top < (x = v->top)) {
885 DrawOverlappedWindow(w, left, top, right, x);
886 DrawOverlappedWindow(w, left, x, right, bottom);
887 return;
888 }
889
890 if (bottom > (x = v->top + v->height)) {
891 DrawOverlappedWindow(w, left, top, right, x);
892 DrawOverlappedWindow(w, left, x, right, bottom);
893 return;
894 }
895
896 return;
897 }
898 }
899
900 /* Setup blitter, and dispatch a repaint event to window *wz */
901 DrawPixelInfo *dp = _cur_dpi;
902 dp->width = right - left;
903 dp->height = bottom - top;
904 dp->left = left - w->left;
905 dp->top = top - w->top;
906 dp->pitch = _screen.pitch;
907 dp->dst_ptr = BlitterFactory::GetCurrentBlitter()->MoveTo(_screen.dst_ptr, left, top);
908 dp->zoom = ZOOM_LVL_NORMAL;
909 w->OnPaint();
910 }
911
920 void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
921 {
922 DrawPixelInfo bk;
923 AutoRestoreBackup dpi_backup(_cur_dpi, &bk);
924
925 for (Window *w : Window::IterateFromBack()) {
926 if (MayBeShown(w) &&
927 right > w->left &&
928 bottom > w->top &&
929 left < w->left + w->width &&
930 top < w->top + w->height) {
931 /* Window w intersects with the rectangle => needs repaint */
932 DrawOverlappedWindow(w, std::max(left, w->left), std::max(top, w->top), std::min(right, w->left + w->width), std::min(bottom, w->top + w->height));
933 }
934 }
935 }
936
941 void Window::SetDirty() const
942 {
943 AddDirtyBlock(this->left, this->top, this->left + this->width, this->top + this->height);
944 }
945
953 void Window::ReInit(int rx, int ry, bool reposition)
954 {
955 this->SetDirty(); // Mark whole current window as dirty.
956
957 /* Save current size. */
958 int window_width = this->width * _gui_scale / this->scale;
959 int window_height = this->height * _gui_scale / this->scale;
960 this->scale = _gui_scale;
961
962 this->OnInit();
963 /* Re-initialize window smallest size. */
964 this->nested_root->SetupSmallestSize(this);
965 this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, _current_text_dir == TD_RTL);
966 this->width = this->nested_root->smallest_x;
967 this->height = this->nested_root->smallest_y;
968 this->resize.step_width = this->nested_root->resize_x;
969 this->resize.step_height = this->nested_root->resize_y;
970
971 /* Resize as close to the original size + requested resize as possible. */
972 window_width = std::max(window_width + rx, this->width);
973 window_height = std::max(window_height + ry, this->height);
974 int dx = (this->resize.step_width == 0) ? 0 : window_width - this->width;
975 int dy = (this->resize.step_height == 0) ? 0 : window_height - this->height;
976 /* dx and dy has to go by step.. calculate it.
977 * The cast to int is necessary else dx/dy are implicitly casted to unsigned int, which won't work. */
978 if (this->resize.step_width > 1) dx -= dx % (int)this->resize.step_width;
979 if (this->resize.step_height > 1) dy -= dy % (int)this->resize.step_height;
980
981 if (reposition) {
982 Point pt = this->OnInitialPosition(this->nested_root->smallest_x, this->nested_root->smallest_y, window_number);
983 this->InitializePositionSize(pt.x, pt.y, this->nested_root->smallest_x, this->nested_root->smallest_y);
984 this->FindWindowPlacementAndResize(this->window_desc->GetDefaultWidth(), this->window_desc->GetDefaultHeight());
985 }
986
987 ResizeWindow(this, dx, dy, true, false);
988 /* ResizeWindow() does this->SetDirty() already, no need to do it again here. */
989 }
990
996 void Window::SetShaded(bool make_shaded)
997 {
998 if (this->shade_select == nullptr) return;
999
1000 int desired = make_shaded ? SZSP_HORIZONTAL : 0;
1001 if (this->shade_select->shown_plane != desired) {
1002 if (make_shaded) {
1003 if (this->nested_focus != nullptr) this->UnfocusFocusedWidget();
1004 this->unshaded_size.width = this->width;
1005 this->unshaded_size.height = this->height;
1006 this->shade_select->SetDisplayedPlane(desired);
1007 this->ReInit(0, -this->height);
1008 } else {
1009 this->shade_select->SetDisplayedPlane(desired);
1010 int dx = ((int)this->unshaded_size.width > this->width) ? (int)this->unshaded_size.width - this->width : 0;
1011 int dy = ((int)this->unshaded_size.height > this->height) ? (int)this->unshaded_size.height - this->height : 0;
1012 this->ReInit(dx, dy);
1013 }
1014 }
1015 }
1016
1023 Window *Window::FindChildWindow(WindowClass wc) const
1024 {
1025 for (Window *v : Window::Iterate()) {
1026 if ((wc == WC_INVALID || wc == v->window_class) && v->parent == this) return v;
1027 }
1028
1029 return nullptr;
1030 }
1031
1036 void Window::CloseChildWindows(WindowClass wc) const
1037 {
1038 Window *child = this->FindChildWindow(wc);
1039 while (child != nullptr) {
1040 child->Close();
1041 child = this->FindChildWindow(wc);
1042 }
1043 }
1044
1048 void Window::Close([[maybe_unused]] int data)
1049 {
1050 /* Don't close twice. */
1051 if (*this->z_position == nullptr) return;
1052
1053 *this->z_position = nullptr;
1054
1055 if (_thd.window_class == this->window_class &&
1056 _thd.window_number == this->window_number) {
1057 ResetObjectToPlace();
1058 }
1059
1060 /* Prevent Mouseover() from resetting mouse-over coordinates on a non-existing window */
1061 if (_mouseover_last_w == this) _mouseover_last_w = nullptr;
1062
1063 /* We can't scroll the window when it's closed. */
1064 if (_last_scroll_window == this) _last_scroll_window = nullptr;
1065
1066 /* Make sure we don't try to access non-existing query strings. */
1067 this->querystrings.clear();
1068
1069 /* Make sure we don't try to access this window as the focused window when it doesn't exist anymore. */
1070 if (_focused_window == this) {
1071 this->OnFocusLost(true);
1072 _focused_window = nullptr;
1073 }
1074
1075 this->CloseChildWindows();
1076
1077 this->SetDirty();
1078
1079 Window::closed_windows.push_back(this);
1080 }
1081
1085 Window::~Window()
1086 {
1087 /* Make sure the window is closed, deletion is allowed only in Window::DeleteClosedWindows(). */
1088 assert(*this->z_position == nullptr);
1089
1090 if (this->viewport != nullptr) DeleteWindowViewport(this);
1091 }
1092
1099 Window *FindWindowById(WindowClass cls, WindowNumber number)
1100 {
1101 for (Window *w : Window::Iterate()) {
1102 if (w->window_class == cls && w->window_number == number) return w;
1103 }
1104
1105 return nullptr;
1106 }
1107
1114 Window *FindWindowByClass(WindowClass cls)
1115 {
1116 for (Window *w : Window::Iterate()) {
1117 if (w->window_class == cls) return w;
1118 }
1119
1120 return nullptr;
1121 }
1122
1128 Window *GetMainWindow()
1129 {
1130 Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
1131 assert(w != nullptr);
1132 return w;
1133 }
1134
1141 void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
1142 {
1143 Window *w = FindWindowById(cls, number);
1144 if (w != nullptr && (force || (w->flags & WF_STICKY) == 0)) {
1145 w->Close(data);
1146 }
1147 }
1148
1153 void CloseWindowByClass(WindowClass cls, int data)
1154 {
1155 /* Note: the container remains stable, even when deleting windows. */
1156 for (Window *w : Window::Iterate()) {
1157 if (w->window_class == cls) {
1158 w->Close(data);
1159 }
1160 }
1161 }
1162
1169 void CloseCompanyWindows(CompanyID id)
1170 {
1171 /* Note: the container remains stable, even when deleting windows. */
1172 for (Window *w : Window::Iterate()) {
1173 if (w->owner == id) {
1174 w->Close();
1175 }
1176 }
1177
1178 /* Also delete the company specific windows that don't have a company-colour. */
1179 CloseWindowById(WC_BUY_COMPANY, id);
1180 }
1181
1189 void ChangeWindowOwner(Owner old_owner, Owner new_owner)
1190 {
1191 for (Window *w : Window::Iterate()) {
1192 if (w->owner != old_owner) continue;
1193
1194 switch (w->window_class) {
1195 case WC_COMPANY_COLOUR:
1196 case WC_FINANCES:
1197 case WC_STATION_LIST:
1198 case WC_TRAINS_LIST:
1199 case WC_ROADVEH_LIST:
1200 case WC_SHIPS_LIST:
1201 case WC_AIRCRAFT_LIST:
1202 case WC_BUY_COMPANY:
1203 case WC_COMPANY:
1204 case WC_COMPANY_INFRASTRUCTURE:
1205 case WC_VEHICLE_ORDERS: // Changing owner would also require changing WindowDesc, which is not possible; however keeping the old one crashes because of missing widgets etc.. See ShowOrdersWindow().
1206 continue;
1207
1208 default:
1209 w->owner = new_owner;
1210 break;
1211 }
1212 }
1213 }
1214
1215 static void BringWindowToFront(Window *w, bool dirty = true);
1216
1224 Window *BringWindowToFrontById(WindowClass cls, WindowNumber number)
1225 {
1226 Window *w = FindWindowById(cls, number);
1227
1228 if (w != nullptr) {
1229 if (w->IsShaded()) w->SetShaded(false); // Restore original window size if it was shaded.
1230
1231 w->SetWhiteBorder();
1232 BringWindowToFront(w);
1233 w->SetDirty();
1234 }
1235
1236 return w;
1237 }
1238
1239 static inline bool IsVitalWindow(const Window *w)
1240 {
1241 switch (w->window_class) {
1242 case WC_MAIN_TOOLBAR:
1243 case WC_STATUS_BAR:
1244 case WC_NEWS_WINDOW:
1245 case WC_SEND_NETWORK_MSG:
1246 return true;
1247
1248 default:
1249 return false;
1250 }
1251 }
1252
1261 static uint GetWindowZPriority(WindowClass wc)
1262 {
1263 assert(wc != WC_INVALID);
1264
1265 uint z_priority = 0;
1266
1267 switch (wc) {
1268 case WC_TOOLTIPS:
1269 ++z_priority;
1270 [[fallthrough]];
1271
1272 case WC_ERRMSG:
1273 case WC_CONFIRM_POPUP_QUERY:
1274 ++z_priority;
1275 [[fallthrough]];
1276
1277 case WC_ENDSCREEN:
1278 ++z_priority;
1279 [[fallthrough]];
1280
1281 case WC_HIGHSCORE:
1282 ++z_priority;
1283 [[fallthrough]];
1284
1285 case WC_DROPDOWN_MENU:
1286 ++z_priority;
1287 [[fallthrough]];
1288
1289 case WC_MAIN_TOOLBAR:
1290 case WC_STATUS_BAR:
1291 ++z_priority;
1292 [[fallthrough]];
1293
1294 case WC_OSK:
1295 ++z_priority;
1296 [[fallthrough]];
1297
1298 case WC_QUERY_STRING:
1299 case WC_SEND_NETWORK_MSG:
1300 ++z_priority;
1301 [[fallthrough]];
1302
1303 case WC_NETWORK_ASK_RELAY:
1304 case WC_MODAL_PROGRESS:
1305 case WC_NETWORK_STATUS_WINDOW:
1306 case WC_SAVE_PRESET:
1307 ++z_priority;
1308 [[fallthrough]];
1309
1310 case WC_GENERATE_LANDSCAPE:
1311 case WC_SAVELOAD:
1312 case WC_GAME_OPTIONS:
1313 case WC_CUSTOM_CURRENCY:
1314 case WC_NETWORK_WINDOW:
1315 case WC_GRF_PARAMETERS:
1316 case WC_SCRIPT_LIST:
1317 case WC_SCRIPT_SETTINGS:
1318 case WC_TEXTFILE:
1319 ++z_priority;
1320 [[fallthrough]];
1321
1322 case WC_CONSOLE:
1323 ++z_priority;
1324 [[fallthrough]];
1325
1326 case WC_NEWS_WINDOW:
1327 ++z_priority;
1328 [[fallthrough]];
1329
1330 default:
1331 ++z_priority;
1332 [[fallthrough]];
1333
1334 case WC_MAIN_WINDOW:
1335 return z_priority;
1336 }
1337 }
1338
1345 static void BringWindowToFront(Window *w, bool dirty)
1346 {
1347 auto priority = GetWindowZPriority(w->window_class);
1348 WindowList::iterator dest = _z_windows.begin();
1349 while (dest != _z_windows.end() && (*dest == nullptr || GetWindowZPriority((*dest)->window_class) <= priority)) ++dest;
1350
1351 if (dest != w->z_position) {
1352 _z_windows.splice(dest, _z_windows, w->z_position);
1353 }
1354
1355 if (dirty) w->SetDirty();
1356 }
1357
1365 void Window::InitializeData(WindowNumber window_number)
1366 {
1367 /* Set up window properties; some of them are needed to set up smallest size below */
1368 this->window_class = this->window_desc->cls;
1369 this->SetWhiteBorder();
1370 if (this->window_desc->default_pos == WDP_CENTER) this->flags |= WF_CENTERED;
1371 this->owner = INVALID_OWNER;
1372 this->nested_focus = nullptr;
1373 this->window_number = window_number;
1374
1375 this->OnInit();
1376 /* Initialize smallest size. */
1377 this->nested_root->SetupSmallestSize(this);
1378 /* Initialize to smallest size. */
1379 this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, _current_text_dir == TD_RTL);
1380
1381 /* Further set up window properties,
1382 * this->left, this->top, this->width, this->height, this->resize.width, and this->resize.height are initialized later. */
1383 this->resize.step_width = this->nested_root->resize_x;
1384 this->resize.step_height = this->nested_root->resize_y;
1385
1386 /* Give focus to the opened window unless a dropdown menu has focus or a text box of the focused window has focus
1387 * (so we don't interrupt typing) unless the new window has a text box. */
1388 bool dropdown_active = _focused_window != nullptr && _focused_window->window_class == WC_DROPDOWN_MENU;
1389 bool editbox_active = EditBoxInGlobalFocus() && this->nested_root->GetWidgetOfType(WWT_EDITBOX) == nullptr;
1390 if (!dropdown_active && !editbox_active) SetFocusedWindow(this);
1391
1392 /* Insert the window into the correct location in the z-ordering. */
1393 BringWindowToFront(this, false);
1394 }
1395
1403 void Window::InitializePositionSize(int x, int y, int sm_width, int sm_height)
1404 {
1405 this->left = x;
1406 this->top = y;
1407 this->width = sm_width;
1408 this->height = sm_height;
1409 }
1410
1421 void Window::FindWindowPlacementAndResize(int def_width, int def_height)
1422 {
1423 def_width = std::max(def_width, this->width); // Don't allow default size to be smaller than smallest size
1424 def_height = std::max(def_height, this->height);
1425 /* Try to make windows smaller when our window is too small.
1426 * w->(width|height) is normally the same as min_(width|height),
1427 * but this way the GUIs can be made a little more dynamic;
1428 * one can use the same spec for multiple windows and those
1429 * can then determine the real minimum size of the window. */
1430 if (this->width != def_width || this->height != def_height) {
1431 /* Think about the overlapping toolbars when determining the minimum window size */
1432 int free_height = _screen.height;
1433 const Window *wt = FindWindowById(WC_STATUS_BAR, 0);
1434 if (wt != nullptr) free_height -= wt->height;
1435 wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
1436 if (wt != nullptr) free_height -= wt->height;
1437
1438 int enlarge_x = std::max(std::min(def_width - this->width, _screen.width - this->width), 0);
1439 int enlarge_y = std::max(std::min(def_height - this->height, free_height - this->height), 0);
1440
1441 /* X and Y has to go by step.. calculate it.
1442 * The cast to int is necessary else x/y are implicitly casted to
1443 * unsigned int, which won't work. */
1444 if (this->resize.step_width > 1) enlarge_x -= enlarge_x % (int)this->resize.step_width;
1445 if (this->resize.step_height > 1) enlarge_y -= enlarge_y % (int)this->resize.step_height;
1446
1447 ResizeWindow(this, enlarge_x, enlarge_y, true, false);
1448 /* ResizeWindow() calls this->OnResize(). */
1449 } else {
1450 /* Always call OnResize; that way the scrollbars and matrices get initialized. */
1451 this->OnResize();
1452 }
1453
1454 int nx = this->left;
1455 int ny = this->top;
1456
1457 if (nx + this->width > _screen.width) nx -= (nx + this->width - _screen.width);
1458
1459 const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
1460 ny = std::max(ny, (wt == nullptr || this == wt || this->top == 0) ? 0 : wt->height);
1461 nx = std::max(nx, 0);
1462
1463 if (this->viewport != nullptr) {
1464 this->viewport->left += nx - this->left;
1465 this->viewport->top += ny - this->top;
1466 }
1467 this->left = nx;
1468 this->top = ny;
1469
1470 this->SetDirty();
1471 }
1472
1485 static bool IsGoodAutoPlace1(int left, int top, int width, int height, int toolbar_y, Point &pos)
1486 {
1487 int right = width + left;
1488 int bottom = height + top;
1489
1490 if (left < 0 || top < toolbar_y || right > _screen.width || bottom > _screen.height) return false;
1491
1492 /* Make sure it is not obscured by any window. */
1493 for (const Window *w : Window::Iterate()) {
1494 if (w->window_class == WC_MAIN_WINDOW) continue;
1495
1496 if (right > w->left &&
1497 w->left + w->width > left &&
1498 bottom > w->top &&
1499 w->top + w->height > top) {
1500 return false;
1501 }
1502 }
1503
1504 pos.x = left;
1505 pos.y = top;
1506 return true;
1507 }
1508
1521 static bool IsGoodAutoPlace2(int left, int top, int width, int height, int toolbar_y, Point &pos)
1522 {
1523 bool rtl = _current_text_dir == TD_RTL;
1524
1525 /* Left part of the rectangle may be at most 1/4 off-screen,
1526 * right part of the rectangle may be at most 1/2 off-screen
1527 */
1528 if (rtl) {
1529 if (left < -(width >> 1) || left > _screen.width - (width >> 2)) return false;
1530 } else {
1531 if (left < -(width >> 2) || left > _screen.width - (width >> 1)) return false;
1532 }
1533
1534 /* Bottom part of the rectangle may be at most 1/4 off-screen */
1535 if (top < toolbar_y || top > _screen.height - (height >> 2)) return false;
1536
1537 /* Make sure it is not obscured by any window. */
1538 for (const Window *w : Window::Iterate()) {
1539 if (w->window_class == WC_MAIN_WINDOW) continue;
1540
1541 if (left + width > w->left &&
1542 w->left + w->width > left &&
1543 top + height > w->top &&
1544 w->top + w->height > top) {
1545 return false;
1546 }
1547 }
1548
1549 pos.x = left;
1550 pos.y = top;
1551 return true;
1552 }
1553
1560 static Point GetAutoPlacePosition(int width, int height)
1561 {
1562 Point pt;
1563
1564 bool rtl = _current_text_dir == TD_RTL;
1565
1566 /* First attempt, try top-left of the screen */
1567 const Window *main_toolbar = FindWindowByClass(WC_MAIN_TOOLBAR);
1568 const int toolbar_y = main_toolbar != nullptr ? main_toolbar->height : 0;
1569 if (IsGoodAutoPlace1(rtl ? _screen.width - width : 0, toolbar_y, width, height, toolbar_y, pt)) return pt;
1570
1571 /* Second attempt, try around all existing windows.
1572 * The new window must be entirely on-screen, and not overlap with an existing window.
1573 * Eight starting points are tried, two at each corner.
1574 */
1575 for (const Window *w : Window::Iterate()) {
1576 if (w->window_class == WC_MAIN_WINDOW) continue;
1577
1578 if (IsGoodAutoPlace1(w->left + w->width, w->top, width, height, toolbar_y, pt)) return pt;
1579 if (IsGoodAutoPlace1(w->left - width, w->top, width, height, toolbar_y, pt)) return pt;
1580 if (IsGoodAutoPlace1(w->left, w->top + w->height, width, height, toolbar_y, pt)) return pt;
1581 if (IsGoodAutoPlace1(w->left, w->top - height, width, height, toolbar_y, pt)) return pt;
1582 if (IsGoodAutoPlace1(w->left + w->width, w->top + w->height - height, width, height, toolbar_y, pt)) return pt;
1583 if (IsGoodAutoPlace1(w->left - width, w->top + w->height - height, width, height, toolbar_y, pt)) return pt;
1584 if (IsGoodAutoPlace1(w->left + w->width - width, w->top + w->height, width, height, toolbar_y, pt)) return pt;
1585 if (IsGoodAutoPlace1(w->left + w->width - width, w->top - height, width, height, toolbar_y, pt)) return pt;
1586 }
1587
1588 /* Third attempt, try around all existing windows.
1589 * The new window may be partly off-screen, and must not overlap with an existing window.
1590 * Only four starting points are tried.
1591 */
1592 for (const Window *w : Window::Iterate()) {
1593 if (w->window_class == WC_MAIN_WINDOW) continue;
1594
1595 if (IsGoodAutoPlace2(w->left + w->width, w->top, width, height, toolbar_y, pt)) return pt;
1596 if (IsGoodAutoPlace2(w->left - width, w->top, width, height, toolbar_y, pt)) return pt;
1597 if (IsGoodAutoPlace2(w->left, w->top + w->height, width, height, toolbar_y, pt)) return pt;
1598 if (IsGoodAutoPlace2(w->left, w->top - height, width, height, toolbar_y, pt)) return pt;
1599 }
1600
1601 /* Fourth and final attempt, put window at diagonal starting from (0, toolbar_y), try multiples
1602 * of the closebox
1603 */
1604 int left = rtl ? _screen.width - width : 0, top = toolbar_y;
1605 int offset_x = rtl ? -(int)NWidgetLeaf::closebox_dimension.width : (int)NWidgetLeaf::closebox_dimension.width;
1606 int offset_y = std::max<int>(NWidgetLeaf::closebox_dimension.height, GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.captiontext.Vertical());
1607
1608 restart:
1609 for (const Window *w : Window::Iterate()) {
1610 if (w->left == left && w->top == top) {
1611 left += offset_x;
1612 top += offset_y;
1613 goto restart;
1614 }
1615 }
1616
1617 pt.x = left;
1618 pt.y = top;
1619 return pt;
1620 }
1621
1628 Point GetToolbarAlignedWindowPosition(int window_width)
1629 {
1630 const Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
1631 assert(w != nullptr);
1632 Point pt = { _current_text_dir == TD_RTL ? w->left : (w->left + w->width) - window_width, w->top + w->height };
1633 return pt;
1634 }
1635
1653 static Point LocalGetWindowPlacement(const WindowDesc *desc, int16_t sm_width, int16_t sm_height, int window_number)
1654 {
1655 Point pt;
1656 const Window *w;
1657
1658 int16_t default_width = std::max(desc->GetDefaultWidth(), sm_width);
1659 int16_t default_height = std::max(desc->GetDefaultHeight(), sm_height);
1660
1661 if (desc->parent_cls != WC_NONE && (w = FindWindowById(desc->parent_cls, window_number)) != nullptr) {
1662 bool rtl = _current_text_dir == TD_RTL;
1663 if (desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) {
1664 pt.x = w->left + (rtl ? w->width - default_width : 0);
1665 pt.y = w->top + w->height;
1666 return pt;
1667 } else {
1668 /* Position child window with offset of closebox, but make sure that either closebox or resizebox is visible
1669 * - Y position: closebox of parent + closebox of child + statusbar
1670 * - X position: closebox on left/right, resizebox on right/left (depending on ltr/rtl)
1671 */
1672 int indent_y = std::max<int>(NWidgetLeaf::closebox_dimension.height, GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.captiontext.Vertical());
1673 if (w->top + 3 * indent_y < _screen.height) {
1674 pt.y = w->top + indent_y;
1675 int indent_close = NWidgetLeaf::closebox_dimension.width;
1676 int indent_resize = NWidgetLeaf::resizebox_dimension.width;
1677 if (_current_text_dir == TD_RTL) {
1678 pt.x = std::max(w->left + w->width - default_width - indent_close, 0);
1679 if (pt.x + default_width >= indent_close && pt.x + indent_resize <= _screen.width) return pt;
1680 } else {
1681 pt.x = std::min(w->left + indent_close, _screen.width - default_width);
1682 if (pt.x + default_width >= indent_resize && pt.x + indent_close <= _screen.width) return pt;
1683 }
1684 }
1685 }
1686 }
1687
1688 switch (desc->default_pos) {
1689 case WDP_ALIGN_TOOLBAR: // Align to the toolbar
1690 return GetToolbarAlignedWindowPosition(default_width);
1691
1692 case WDP_AUTO: // Find a good automatic position for the window
1693 return GetAutoPlacePosition(default_width, default_height);
1694
1695 case WDP_CENTER: // Centre the window horizontally
1696 pt.x = (_screen.width - default_width) / 2;
1697 pt.y = (_screen.height - default_height) / 2;
1698 break;
1699
1700 case WDP_MANUAL:
1701 pt.x = 0;
1702 pt.y = 0;
1703 break;
1704
1705 default:
1706 NOT_REACHED();
1707 }
1708
1709 return pt;
1710 }
1711
1712 /* virtual */ Point Window::OnInitialPosition([[maybe_unused]]int16_t sm_width, [[maybe_unused]]int16_t sm_height, [[maybe_unused]]int window_number)
1713 {
1714 return LocalGetWindowPlacement(this->window_desc, sm_width, sm_height, window_number);
1715 }
1716
1724 void Window::CreateNestedTree()
1725 {
1726 this->nested_root = MakeWindowNWidgetTree(this->window_desc->nwid_begin, this->window_desc->nwid_end, &this->shade_select);
1727 this->nested_root->FillWidgetLookup(this->widget_lookup);
1728 }
1729
1734 void Window::FinishInitNested(WindowNumber window_number)
1735 {
1736 this->InitializeData(window_number);
1737 this->ApplyDefaults();
1738 Point pt = this->OnInitialPosition(this->nested_root->smallest_x, this->nested_root->smallest_y, window_number);
1739 this->InitializePositionSize(pt.x, pt.y, this->nested_root->smallest_x, this->nested_root->smallest_y);
1740 this->FindWindowPlacementAndResize(this->window_desc->GetDefaultWidth(), this->window_desc->GetDefaultHeight());
1741 }
1742
1747 void Window::InitNested(WindowNumber window_number)
1748 {
1749 this->CreateNestedTree();
1750 this->FinishInitNested(window_number);
1751 }
1752
1757 Window::Window(WindowDesc *desc) : window_desc(desc), scale(_gui_scale), mouse_capture_widget(-1)
1758 {
1759 this->z_position = _z_windows.insert(_z_windows.end(), this);
1760 }
1761
1769 Window *FindWindowFromPt(int x, int y)
1770 {
1771 for (Window *w : Window::IterateFromFront()) {
1772 if (MayBeShown(w) && IsInsideBS(x, w->left, w->width) && IsInsideBS(y, w->top, w->height)) {
1773 return w;
1774 }
1775 }
1776
1777 return nullptr;
1778 }
1779
1783 void InitWindowSystem()
1784 {
1785 IConsoleClose();
1786
1787 _focused_window = nullptr;
1788 _mouseover_last_w = nullptr;
1789 _last_scroll_window = nullptr;
1790 _scrolling_viewport = false;
1791 _mouse_hovering = false;
1792
1793 SetupWidgetDimensions();
1794 NWidgetLeaf::InvalidateDimensionCache(); // Reset cached sizes of several widgets.
1795 NWidgetScrollbar::InvalidateDimensionCache();
1796
1797 InitDepotWindowBlockSizes();
1798
1799 ShowFirstError();
1800 }
1801
1805 void UnInitWindowSystem()
1806 {
1807 UnshowCriticalError();
1808
1809 for (Window *w : Window::Iterate()) w->Close();
1810
1811 Window::DeleteClosedWindows();
1812
1813 assert(_z_windows.empty());
1814 }
1815
1819 void ResetWindowSystem()
1820 {
1821 UnInitWindowSystem();
1822 InitWindowSystem();
1823 _thd.Reset();
1824 }
1825
1826 static void DecreaseWindowCounters()
1827 {
1828 if (_scroller_click_timeout != 0) _scroller_click_timeout--;
1829
1830 for (Window *w : Window::Iterate()) {
1831 if (_scroller_click_timeout == 0) {
1832 /* Unclick scrollbar buttons if they are pressed. */
1833 for (auto &pair : w->widget_lookup) {
1834 NWidgetBase *nwid = pair.second;
1835 if (nwid->type == NWID_HSCROLLBAR || nwid->type == NWID_VSCROLLBAR) {
1836 NWidgetScrollbar *sb = static_cast<NWidgetScrollbar*>(nwid);
1837 if (sb->disp_flags & (ND_SCROLLBAR_UP | ND_SCROLLBAR_DOWN)) {
1838 sb->disp_flags &= ~(ND_SCROLLBAR_UP | ND_SCROLLBAR_DOWN);
1839 w->mouse_capture_widget = -1;
1840 sb->SetDirty(w);
1841 }
1842 }
1843 }
1844 }
1845
1846 /* Handle editboxes */
1847 for (auto &pair : w->querystrings) {
1848 pair.second->HandleEditBox(w, pair.first);
1849 }
1850
1851 w->OnMouseLoop();
1852 }
1853
1854 for (Window *w : Window::Iterate()) {
1855 if ((w->flags & WF_TIMEOUT) && --w->timeout_timer == 0) {
1856 CLRBITS(w->flags, WF_TIMEOUT);
1857
1858 w->OnTimeout();
1859 w->RaiseButtons(true);
1860 }
1861 }
1862 }
1863
1864 static void HandlePlacePresize()
1865 {
1866 if (_special_mouse_mode != WSM_PRESIZE) return;
1867
1868 Window *w = _thd.GetCallbackWnd();
1869 if (w == nullptr) return;
1870
1871 Point pt = GetTileBelowCursor();
1872 if (pt.x == -1) {
1873 _thd.selend.x = -1;
1874 return;
1875 }
1876
1877 w->OnPlacePresize(pt, TileVirtXY(pt.x, pt.y));
1878 }
1879
1884 static EventState HandleMouseDragDrop()
1885 {
1886 if (_special_mouse_mode != WSM_DRAGDROP) return ES_NOT_HANDLED;
1887
1888 if (_left_button_down && _cursor.delta.x == 0 && _cursor.delta.y == 0) return ES_HANDLED; // Dragging, but the mouse did not move.
1889
1890 Window *w = _thd.GetCallbackWnd();
1891 if (w != nullptr) {
1892 /* Send an event in client coordinates. */
1893 Point pt;
1894 pt.x = _cursor.pos.x - w->left;
1895 pt.y = _cursor.pos.y - w->top;
1896 if (_left_button_down) {
1897 w->OnMouseDrag(pt, GetWidgetFromPos(w, pt.x, pt.y));
1898 } else {
1899 w->OnDragDrop(pt, GetWidgetFromPos(w, pt.x, pt.y));
1900 }
1901 }
1902
1903 if (!_left_button_down) ResetObjectToPlace(); // Button released, finished dragging.
1904 return ES_HANDLED;
1905 }
1906
1908 static void HandleMouseOver()
1909 {
1910 Window *w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
1911
1912 /* We changed window, put an OnMouseOver event to the last window */
1913 if (_mouseover_last_w != nullptr && _mouseover_last_w != w) {
1914 /* Reset mouse-over coordinates of previous window */
1915 Point pt = { -1, -1 };
1916 _mouseover_last_w->OnMouseOver(pt, 0);
1917 }
1918
1919 /* _mouseover_last_w will get reset when the window is deleted, see DeleteWindow() */
1920 _mouseover_last_w = w;
1921
1922 if (w != nullptr) {
1923 /* send an event in client coordinates. */
1924 Point pt = { _cursor.pos.x - w->left, _cursor.pos.y - w->top };
1925 const NWidgetCore *widget = w->nested_root->GetWidgetFromPos(pt.x, pt.y);
1926 if (widget != nullptr) w->OnMouseOver(pt, widget->index);
1927 }
1928 }
1929
1931 static const int MIN_VISIBLE_TITLE_BAR = 13;
1932
1934 enum PreventHideDirection {
1935 PHD_UP,
1936 PHD_DOWN,
1937 };
1938
1949 static void PreventHiding(int *nx, int *ny, const Rect &rect, const Window *v, int px, PreventHideDirection dir)
1950 {
1951 if (v == nullptr) return;
1952
1953 const int min_visible = ScaleGUITrad(MIN_VISIBLE_TITLE_BAR);
1954
1955 int v_bottom = v->top + v->height;
1956 int v_right = v->left + v->width;
1957 int safe_y = (dir == PHD_UP) ? (v->top - min_visible - rect.top) : (v_bottom + min_visible - rect.bottom); // Compute safe vertical position.
1958
1959 if (*ny + rect.top <= v->top - min_visible) return; // Above v is enough space
1960 if (*ny + rect.bottom >= v_bottom + min_visible) return; // Below v is enough space
1961
1962 /* Vertically, the rectangle is hidden behind v. */
1963 if (*nx + rect.left + min_visible < v->left) { // At left of v.
1964 if (v->left < min_visible) *ny = safe_y; // But enough room, force it to a safe position.
1965 return;
1966 }
1967 if (*nx + rect.right - min_visible > v_right) { // At right of v.
1968 if (v_right > _screen.width - min_visible) *ny = safe_y; // Not enough room, force it to a safe position.
1969 return;
1970 }
1971
1972 /* Horizontally also hidden, force movement to a safe area. */
1973 if (px + rect.left < v->left && v->left >= min_visible) { // Coming from the left, and enough room there.
1974 *nx = v->left - min_visible - rect.left;
1975 } else if (px + rect.right > v_right && v_right <= _screen.width - min_visible) { // Coming from the right, and enough room there.
1976 *nx = v_right + min_visible - rect.right;
1977 } else {
1978 *ny = safe_y;
1979 }
1980 }
1981
1989 static void EnsureVisibleCaption(Window *w, int nx, int ny)
1990 {
1991 /* Search for the title bar rectangle. */
1992 Rect caption_rect;
1993 const NWidgetBase *caption = w->nested_root->GetWidgetOfType(WWT_CAPTION);
1994 if (caption != nullptr) {
1995 caption_rect = caption->GetCurrentRect();
1996
1997 const int min_visible = ScaleGUITrad(MIN_VISIBLE_TITLE_BAR);
1998
1999 /* Make sure the window doesn't leave the screen */
2000 nx = Clamp(nx, min_visible - caption_rect.right, _screen.width - min_visible - caption_rect.left);
2001 ny = Clamp(ny, 0, _screen.height - min_visible);
2002
2003 /* Make sure the title bar isn't hidden behind the main tool bar or the status bar. */
2004 PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_MAIN_TOOLBAR, 0), w->left, PHD_DOWN);
2005 PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_STATUS_BAR, 0), w->left, PHD_UP);
2006 }
2007
2008 if (w->viewport != nullptr) {
2009 w->viewport->left += nx - w->left;
2010 w->viewport->top += ny - w->top;
2011 }
2012
2013 w->left = nx;
2014 w->top = ny;
2015 }
2016
2027 void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
2028 {
2029 if (delta_x != 0 || delta_y != 0) {
2030 if (clamp_to_screen) {
2031 /* Determine the new right/bottom position. If that is outside of the bounds of
2032 * the resolution clamp it in such a manner that it stays within the bounds. */
2033 int new_right = w->left + w->width + delta_x;
2034 int new_bottom = w->top + w->height + delta_y;
2035 if (new_right >= (int)_screen.width) delta_x -= Ceil(new_right - _screen.width, std::max(1U, w->nested_root->resize_x));
2036 if (new_bottom >= (int)_screen.height) delta_y -= Ceil(new_bottom - _screen.height, std::max(1U, w->nested_root->resize_y));
2037 }
2038
2039 w->SetDirty();
2040
2041 uint new_xinc = std::max(0, (w->nested_root->resize_x == 0) ? 0 : (int)(w->nested_root->current_x - w->nested_root->smallest_x) + delta_x);
2042 uint new_yinc = std::max(0, (w->nested_root->resize_y == 0) ? 0 : (int)(w->nested_root->current_y - w->nested_root->smallest_y) + delta_y);
2043 assert(w->nested_root->resize_x == 0 || new_xinc % w->nested_root->resize_x == 0);
2044 assert(w->nested_root->resize_y == 0 || new_yinc % w->nested_root->resize_y == 0);
2045
2046 w->nested_root->AssignSizePosition(ST_RESIZE, 0, 0, w->nested_root->smallest_x + new_xinc, w->nested_root->smallest_y + new_yinc, _current_text_dir == TD_RTL);
2047 w->width = w->nested_root->current_x;
2048 w->height = w->nested_root->current_y;
2049 }
2050
2051 EnsureVisibleCaption(w, w->left, w->top);
2052
2053 /* Schedule OnResize to make sure everything is initialised correctly if it needs to be. */
2054 if (schedule_resize) {
2055 w->ScheduleResize();
2056 } else {
2057 w->OnResize();
2058 }
2059 w->SetDirty();
2060 }
2061
2067 int GetMainViewTop()
2068 {
2069 Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
2070 return (w == nullptr) ? 0 : w->top + w->height;
2071 }
2072
2078 int GetMainViewBottom()
2079 {
2080 Window *w = FindWindowById(WC_STATUS_BAR, 0);
2081 return (w == nullptr) ? _screen.height : w->top;
2082 }
2083
2084 static bool _dragging_window;
2085
2090 static EventState HandleWindowDragging()
2091 {
2092 /* Get out immediately if no window is being dragged at all. */
2093 if (!_dragging_window) return ES_NOT_HANDLED;
2094
2095 /* If button still down, but cursor hasn't moved, there is nothing to do. */
2096 if (_left_button_down && _cursor.delta.x == 0 && _cursor.delta.y == 0) return ES_HANDLED;
2097
2098 /* Otherwise find the window... */
2099 for (Window *w : Window::Iterate()) {
2100 if (w->flags & WF_DRAGGING) {
2101 /* Stop the dragging if the left mouse button was released */
2102 if (!_left_button_down) {
2103 w->flags &= ~WF_DRAGGING;
2104 break;
2105 }
2106
2107 w->SetDirty();
2108
2109 int x = _cursor.pos.x + _drag_delta.x;
2110 int y = _cursor.pos.y + _drag_delta.y;
2111 int nx = x;
2112 int ny = y;
2113
2114 if (_settings_client.gui.window_snap_radius != 0) {
2115 int hsnap = _settings_client.gui.window_snap_radius;
2116 int vsnap = _settings_client.gui.window_snap_radius;
2117 int delta;
2118
2119 for (const Window *v : Window::Iterate()) {
2120 if (v == w) continue; // Don't snap at yourself
2121
2122 if (y + w->height > v->top && y < v->top + v->height) {
2123 /* Your left border <-> other right border */
2124 delta = abs(v->left + v->width - x);
2125 if (delta <= hsnap) {
2126 nx = v->left + v->width;
2127 hsnap = delta;
2128 }
2129
2130 /* Your right border <-> other left border */
2131 delta = abs(v->left - x - w->width);
2132 if (delta <= hsnap) {
2133 nx = v->left - w->width;
2134 hsnap = delta;
2135 }
2136 }
2137
2138 if (w->top + w->height >= v->top && w->top <= v->top + v->height) {
2139 /* Your left border <-> other left border */
2140 delta = abs(v->left - x);
2141 if (delta <= hsnap) {
2142 nx = v->left;
2143 hsnap = delta;
2144 }
2145
2146 /* Your right border <-> other right border */
2147 delta = abs(v->left + v->width - x - w->width);
2148 if (delta <= hsnap) {
2149 nx = v->left + v->width - w->width;
2150 hsnap = delta;
2151 }
2152 }
2153
2154 if (x + w->width > v->left && x < v->left + v->width) {
2155 /* Your top border <-> other bottom border */
2156 delta = abs(v->top + v->height - y);
2157 if (delta <= vsnap) {
2158 ny = v->top + v->height;
2159 vsnap = delta;
2160 }
2161
2162 /* Your bottom border <-> other top border */
2163 delta = abs(v->top - y - w->height);
2164 if (delta <= vsnap) {
2165 ny = v->top - w->height;
2166 vsnap = delta;
2167 }
2168 }
2169
2170 if (w->left + w->width >= v->left && w->left <= v->left + v->width) {
2171 /* Your top border <-> other top border */
2172 delta = abs(v->top - y);
2173 if (delta <= vsnap) {
2174 ny = v->top;
2175 vsnap = delta;
2176 }
2177
2178 /* Your bottom border <-> other bottom border */
2179 delta = abs(v->top + v->height - y - w->height);
2180 if (delta <= vsnap) {
2181 ny = v->top + v->height - w->height;
2182 vsnap = delta;
2183 }
2184 }
2185 }
2186 }
2187
2188 EnsureVisibleCaption(w, nx, ny);
2189
2190 w->SetDirty();
2191 return ES_HANDLED;
2192 } else if (w->flags & WF_SIZING) {
2193 /* Stop the sizing if the left mouse button was released */
2194 if (!_left_button_down) {
2195 w->flags &= ~WF_SIZING;
2196 w->SetDirty();
2197 break;
2198 }
2199
2200 /* Compute difference in pixels between cursor position and reference point in the window.
2201 * If resizing the left edge of the window, moving to the left makes the window bigger not smaller.
2202 */
2203 int x, y = _cursor.pos.y - _drag_delta.y;
2204 if (w->flags & WF_SIZING_LEFT) {
2205 x = _drag_delta.x - _cursor.pos.x;
2206 } else {
2207 x = _cursor.pos.x - _drag_delta.x;
2208 }
2209
2210 /* resize.step_width and/or resize.step_height may be 0, which means no resize is possible. */
2211 if (w->resize.step_width == 0) x = 0;
2212 if (w->resize.step_height == 0) y = 0;
2213
2214 /* Check the resize button won't go past the bottom of the screen */
2215 if (w->top + w->height + y > _screen.height) {
2216 y = _screen.height - w->height - w->top;
2217 }
2218
2219 /* X and Y has to go by step.. calculate it.
2220 * The cast to int is necessary else x/y are implicitly casted to
2221 * unsigned int, which won't work. */
2222 if (w->resize.step_width > 1) x -= x % (int)w->resize.step_width;
2223 if (w->resize.step_height > 1) y -= y % (int)w->resize.step_height;
2224
2225 /* Check that we don't go below the minimum set size */
2226 if ((int)w->width + x < (int)w->nested_root->smallest_x) {
2227 x = w->nested_root->smallest_x - w->width;
2228 }
2229 if ((int)w->height + y < (int)w->nested_root->smallest_y) {
2230 y = w->nested_root->smallest_y - w->height;
2231 }
2232
2233 /* Window already on size */
2234 if (x == 0 && y == 0) return ES_HANDLED;
2235
2236 /* Now find the new cursor pos.. this is NOT _cursor, because we move in steps. */
2237 _drag_delta.y += y;
2238 if ((w->flags & WF_SIZING_LEFT) && x != 0) {
2239 _drag_delta.x -= x; // x > 0 -> window gets longer -> left-edge moves to left -> subtract x to get new position.
2240 w->SetDirty();
2241 w->left -= x; // If dragging left edge, move left window edge in opposite direction by the same amount.
2242 /* ResizeWindow() below ensures marking new position as dirty. */
2243 } else {
2244 _drag_delta.x += x;
2245 }
2246
2247 /* ResizeWindow sets both pre- and after-size to dirty for redrawal */
2248 ResizeWindow(w, x, y);
2249 return ES_HANDLED;
2250 }
2251 }
2252
2253 _dragging_window = false;
2254 return ES_HANDLED;
2255 }
2256
2261 static void StartWindowDrag(Window *w)
2262 {
2263 w->flags |= WF_DRAGGING;
2264 w->flags &= ~WF_CENTERED;
2265 _dragging_window = true;
2266
2267 _drag_delta.x = w->left - _cursor.pos.x;
2268 _drag_delta.y = w->top - _cursor.pos.y;
2269
2270 BringWindowToFront(w);
2271 }
2272
2278 static void StartWindowSizing(Window *w, bool to_left)
2279 {
2280 w->flags |= to_left ? WF_SIZING_LEFT : WF_SIZING_RIGHT;
2281 w->flags &= ~WF_CENTERED;
2282 _dragging_window = true;
2283
2284 _drag_delta.x = _cursor.pos.x;
2285 _drag_delta.y = _cursor.pos.y;
2286
2287 BringWindowToFront(w);
2288 }
2289
2294 static void HandleScrollbarScrolling(Window *w)
2295 {
2296 int i;
2297 NWidgetScrollbar *sb = w->GetWidget<NWidgetScrollbar>(w->mouse_capture_widget);
2298 bool rtl = false;
2299
2300 if (sb->type == NWID_HSCROLLBAR) {
2301 i = _cursor.pos.x - _cursorpos_drag_start.x;
2302 rtl = _current_text_dir == TD_RTL;
2303 } else {
2304 i = _cursor.pos.y - _cursorpos_drag_start.y;
2305 }
2306
2307 if (sb->disp_flags & ND_SCROLLBAR_BTN) {
2308 if (_scroller_click_timeout == 1) {
2309 _scroller_click_timeout = 3;
2310 if (sb->UpdatePosition(rtl == HasBit(sb->disp_flags, NDB_SCROLLBAR_UP) ? 1 : -1)) w->SetDirty();
2311 }
2312 return;
2313 }
2314
2315 /* Find the item we want to move to. SetPosition will make sure it's inside bounds. */
2316 int pos = RoundDivSU((i + _scrollbar_start_pos) * sb->GetCount(), _scrollbar_size);
2317 if (rtl) pos = sb->GetCount() - sb->GetCapacity() - pos;
2318 if (sb->SetPosition(pos)) w->SetDirty();
2319 }
2320
2325 static EventState HandleActiveWidget()
2326 {
2327 for (Window *w : Window::Iterate()) {
2328 if (w->mouse_capture_widget >= 0) {
2329 /* Abort if no button is clicked any more. */
2330 if (!_left_button_down) {
2331 w->SetWidgetDirty(w->mouse_capture_widget);
2332 w->mouse_capture_widget = -1;
2333 return ES_HANDLED;
2334 }
2335
2336 /* Handle scrollbar internally, or dispatch click event */
2337 WidgetType type = w->GetWidget<NWidgetBase>(w->mouse_capture_widget)->type;
2338 if (type == NWID_VSCROLLBAR || type == NWID_HSCROLLBAR) {
2339 HandleScrollbarScrolling(w);
2340 } else {
2341 /* If cursor hasn't moved, there is nothing to do. */
2342 if (_cursor.delta.x == 0 && _cursor.delta.y == 0) return ES_HANDLED;
2343
2344 Point pt = { _cursor.pos.x - w->left, _cursor.pos.y - w->top };
2345 w->OnClick(pt, w->mouse_capture_widget, 0);
2346 }
2347 return ES_HANDLED;
2348 }
2349 }
2350
2351 return ES_NOT_HANDLED;
2352 }
2353
2358 static EventState HandleViewportScroll()
2359 {
2360 bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
2361
2362 if (!_scrolling_viewport) return ES_NOT_HANDLED;
2363
2364 /* When we don't have a last scroll window we are starting to scroll.
2365 * When the last scroll window and this are not the same we went
2366 * outside of the window and should not left-mouse scroll anymore. */
2367 if (_last_scroll_window == nullptr) _last_scroll_window = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
2368
2369 if (_last_scroll_window == nullptr || !((_settings_client.gui.scroll_mode != VSM_MAP_LMB && _right_button_down) || scrollwheel_scrolling || (_settings_client.gui.scroll_mode == VSM_MAP_LMB && _left_button_down))) {
2370 _cursor.fix_at = false;
2371 _scrolling_viewport = false;
2372 _last_scroll_window = nullptr;
2373 return ES_NOT_HANDLED;
2374 }
2375
2376 if (_last_scroll_window == GetMainWindow() && _last_scroll_window->viewport->follow_vehicle != INVALID_VEHICLE) {
2377 /* If the main window is following a vehicle, then first let go of it! */
2378 const Vehicle *veh = Vehicle::Get(_last_scroll_window->viewport->follow_vehicle);
2379 ScrollMainWindowTo(veh->x_pos, veh->y_pos, veh->z_pos, true); // This also resets follow_vehicle
2380 return ES_NOT_HANDLED;
2381 }
2382
2383 Point delta;
2384 if (scrollwheel_scrolling) {
2385 /* We are using scrollwheels for scrolling */
2386 delta.x = _cursor.h_wheel;
2387 delta.y = _cursor.v_wheel;
2388 _cursor.v_wheel = 0;
2389 _cursor.h_wheel = 0;
2390 } else {
2391 if (_settings_client.gui.scroll_mode != VSM_VIEWPORT_RMB_FIXED) {
2392 delta.x = -_cursor.delta.x;
2393 delta.y = -_cursor.delta.y;
2394 } else {
2395 delta.x = _cursor.delta.x;
2396 delta.y = _cursor.delta.y;
2397 }
2398 }
2399
2400 /* Create a scroll-event and send it to the window */
2401 if (delta.x != 0 || delta.y != 0) _last_scroll_window->OnScroll(delta);
2402
2403 _cursor.delta.x = 0;
2404 _cursor.delta.y = 0;
2405 return ES_HANDLED;
2406 }
2407
2418 static bool MaybeBringWindowToFront(Window *w)
2419 {
2420 bool bring_to_front = false;
2421
2422 if (w->window_class == WC_MAIN_WINDOW ||
2423 IsVitalWindow(w) ||
2424 w->window_class == WC_TOOLTIPS ||
2425 w->window_class == WC_DROPDOWN_MENU) {
2426 return true;
2427 }
2428
2429 /* Use unshaded window size rather than current size for shaded windows. */
2430 int w_width = w->width;
2431 int w_height = w->height;
2432 if (w->IsShaded()) {
2433 w_width = w->unshaded_size.width;
2434 w_height = w->unshaded_size.height;
2435 }
2436
2437 Window::IteratorToFront it(w);
2438 ++it;
2439 for (; !it.IsEnd(); ++it) {
2440 Window *u = *it;
2441 /* A modal child will prevent the activation of the parent window */
2442 if (u->parent == w && (u->window_desc->flags & WDF_MODAL)) {
2443 u->SetWhiteBorder();
2444 u->SetDirty();
2445 return false;
2446 }
2447
2448 if (u->window_class == WC_MAIN_WINDOW ||
2449 IsVitalWindow(u) ||
2450 u->window_class == WC_TOOLTIPS ||
2451 u->window_class == WC_DROPDOWN_MENU) {
2452 continue;
2453 }
2454
2455 /* Window sizes don't interfere, leave z-order alone */
2456 if (w->left + w_width <= u->left ||
2457 u->left + u->width <= w->left ||
2458 w->top + w_height <= u->top ||
2459 u->top + u->height <= w->top) {
2460 continue;
2461 }
2462
2463 bring_to_front = true;
2464 }
2465
2466 if (bring_to_front) BringWindowToFront(w);
2467 return true;
2468 }
2469
2478 EventState Window::HandleEditBoxKey(WidgetID wid, char32_t key, uint16_t keycode)
2479 {
2480 QueryString *query = this->GetQueryString(wid);
2481 if (query == nullptr) return ES_NOT_HANDLED;
2482
2483 int action = QueryString::ACTION_NOTHING;
2484
2485 switch (query->text.HandleKeyPress(key, keycode)) {
2486 case HKPR_EDITING:
2487 this->SetWidgetDirty(wid);
2488 this->OnEditboxChanged(wid);
2489 break;
2490
2491 case HKPR_CURSOR:
2492 this->SetWidgetDirty(wid);
2493 /* For the OSK also invalidate the parent window */
2494 if (this->window_class == WC_OSK) this->InvalidateData();
2495 break;
2496
2497 case HKPR_CONFIRM:
2498 if (this->window_class == WC_OSK) {
2499 this->OnClick(Point(), WID_OSK_OK, 1);
2500 } else if (query->ok_button >= 0) {
2501 this->OnClick(Point(), query->ok_button, 1);
2502 } else {
2503 action = query->ok_button;
2504 }
2505 break;
2506
2507 case HKPR_CANCEL:
2508 if (this->window_class == WC_OSK) {
2509 this->OnClick(Point(), WID_OSK_CANCEL, 1);
2510 } else if (query->cancel_button >= 0) {
2511 this->OnClick(Point(), query->cancel_button, 1);
2512 } else {
2513 action = query->cancel_button;
2514 }
2515 break;
2516
2517 case HKPR_NOT_HANDLED:
2518 return ES_NOT_HANDLED;
2519
2520 default: break;
2521 }
2522
2523 switch (action) {
2524 case QueryString::ACTION_DESELECT:
2525 this->UnfocusFocusedWidget();
2526 break;
2527
2528 case QueryString::ACTION_CLEAR:
2529 if (query->text.bytes <= 1) {
2530 /* If already empty, unfocus instead */
2531 this->UnfocusFocusedWidget();
2532 } else {
2533 query->text.DeleteAll();
2534 this->SetWidgetDirty(wid);
2535 this->OnEditboxChanged(wid);
2536 }
2537 break;
2538
2539 default:
2540 break;
2541 }
2542
2543 return ES_HANDLED;
2544 }
2545
2550 void HandleToolbarHotkey(int hotkey)
2551 {
2552 assert(HasModalProgress() || IsLocalCompany());
2553
2554 Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
2555 if (w != nullptr) {
2556 if (w->window_desc->hotkeys != nullptr) {
2557 if (hotkey >= 0 && w->OnHotkey(hotkey) == ES_HANDLED) return;
2558 }
2559 }
2560 }
2561
2567 void HandleKeypress(uint keycode, char32_t key)
2568 {
2569 /* World generation is multithreaded and messes with companies.
2570 * But there is no company related window open anyway, so _current_company is not used. */
2571 assert(HasModalProgress() || IsLocalCompany());
2572
2573 /*
2574 * The Unicode standard defines an area called the private use area. Code points in this
2575 * area are reserved for private use and thus not portable between systems. For instance,
2576 * Apple defines code points for the arrow keys in this area, but these are only printable
2577 * on a system running OS X. We don't want these keys to show up in text fields and such,
2578 * and thus we have to clear the unicode character when we encounter such a key.
2579 */
2580 if (key >= 0xE000 && key <= 0xF8FF) key = 0;
2581
2582 /*
2583 * If both key and keycode is zero, we don't bother to process the event.
2584 */
2585 if (key == 0 && keycode == 0) return;
2586
2587 /* Check if the focused window has a focused editbox */
2588 if (EditBoxInGlobalFocus()) {
2589 /* All input will in this case go to the focused editbox */
2590 if (_focused_window->window_class == WC_CONSOLE) {
2591 if (_focused_window->OnKeyPress(key, keycode) == ES_HANDLED) return;
2592 } else {
2593 if (_focused_window->HandleEditBoxKey(_focused_window->nested_focus->index, key, keycode) == ES_HANDLED) return;
2594 }
2595 }
2596
2597 /* Call the event, start with the uppermost window, but ignore the toolbar. */
2598 for (Window *w : Window::IterateFromFront()) {
2599 if (w->window_class == WC_MAIN_TOOLBAR) continue;
2600 if (w->window_desc->hotkeys != nullptr) {
2601 int hotkey = w->window_desc->hotkeys->CheckMatch(keycode);
2602 if (hotkey >= 0 && w->OnHotkey(hotkey) == ES_HANDLED) return;
2603 }
2604 if (w->OnKeyPress(key, keycode) == ES_HANDLED) return;
2605 }
2606
2607 Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
2608 /* When there is no toolbar w is null, check for that */
2609 if (w != nullptr) {
2610 if (w->window_desc->hotkeys != nullptr) {
2611 int hotkey = w->window_desc->hotkeys->CheckMatch(keycode);
2612 if (hotkey >= 0 && w->OnHotkey(hotkey) == ES_HANDLED) return;
2613 }
2614 if (w->OnKeyPress(key, keycode) == ES_HANDLED) return;
2615 }
2616
2617 HandleGlobalHotkeys(key, keycode);
2618 }
2619
2623 void HandleCtrlChanged()
2624 {
2625 /* Call the event, start with the uppermost window. */
2626 for (Window *w : Window::IterateFromFront()) {
2627 if (w->OnCTRLStateChange() == ES_HANDLED) return;
2628 }
2629 }
2630
2636 /* virtual */ void Window::InsertTextString(WidgetID wid, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end)
2637 {
2638 QueryString *query = this->GetQueryString(wid);
2639 if (query == nullptr) return;
2640
2641 if (query->text.InsertString(str, marked, caret, insert_location, replacement_end) || marked) {
2642 this->SetWidgetDirty(wid);
2643 this->OnEditboxChanged(wid);
2644 }
2645 }
2646
2653 void HandleTextInput(const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end)
2654 {
2655 if (!EditBoxInGlobalFocus()) return;
2656
2657 _focused_window->InsertTextString(_focused_window->window_class == WC_CONSOLE ? 0 : _focused_window->nested_focus->index, str, marked, caret, insert_location, replacement_end);
2658 }
2659
2666 static int _input_events_this_tick = 0;
2667
2672 static void HandleAutoscroll()
2673 {
2674 if (_game_mode == GM_MENU || HasModalProgress()) return;
2675 if (_settings_client.gui.auto_scrolling == VA_DISABLED) return;
2676 if (_settings_client.gui.auto_scrolling == VA_MAIN_VIEWPORT_FULLSCREEN && !_fullscreen) return;
2677
2678 int x = _cursor.pos.x;
2679 int y = _cursor.pos.y;
2680 Window *w = FindWindowFromPt(x, y);
2681 if (w == nullptr || w->flags & WF_DISABLE_VP_SCROLL) return;
2682 if (_settings_client.gui.auto_scrolling != VA_EVERY_VIEWPORT && w->window_class != WC_MAIN_WINDOW) return;
2683
2684 Viewport *vp = IsPtInWindowViewport(w, x, y);
2685 if (vp == nullptr) return;
2686
2687 x -= vp->left;
2688 y -= vp->top;
2689
2690 /* here allows scrolling in both x and y axis */
2691 static const int SCROLLSPEED = 3;
2692 if (x - 15 < 0) {
2693 w->viewport->dest_scrollpos_x += ScaleByZoom((x - 15) * SCROLLSPEED, vp->zoom);
2694 } else if (15 - (vp->width - x) > 0) {
2695 w->viewport->dest_scrollpos_x += ScaleByZoom((15 - (vp->width - x)) * SCROLLSPEED, vp->zoom);
2696 }
2697 if (y - 15 < 0) {
2698 w->viewport->dest_scrollpos_y += ScaleByZoom((y - 15) * SCROLLSPEED, vp->zoom);
2699 } else if (15 - (vp->height - y) > 0) {
2700 w->viewport->dest_scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * SCROLLSPEED, vp->zoom);
2701 }
2702 }
2703
2704 enum MouseClick {
2705 MC_NONE = 0,
2706 MC_LEFT,
2707 MC_RIGHT,
2708 MC_DOUBLE_LEFT,
2709 MC_HOVER,
2710
2711 MAX_OFFSET_DOUBLE_CLICK = 5,
2712 MAX_OFFSET_HOVER = 5,
2713 };
2714 extern EventState VpHandlePlaceSizingDrag();
2715
2716 const std::chrono::milliseconds TIME_BETWEEN_DOUBLE_CLICK(500);
2717
2718 static void ScrollMainViewport(int x, int y)
2719 {
2720 if (_game_mode != GM_MENU) {
2721 Window *w = GetMainWindow();
2722 w->viewport->dest_scrollpos_x += ScaleByZoom(x, w->viewport->zoom);
2723 w->viewport->dest_scrollpos_y += ScaleByZoom(y, w->viewport->zoom);
2724 }
2725 }
2726
2736 static const int8_t scrollamt[16][2] = {
2737 { 0, 0},
2738 {-2, 0},
2739 { 0, -2},
2740 {-2, -1},
2741 { 2, 0},
2742 { 0, 0},
2743 { 2, -1},
2744 { 0, -2},
2745 { 0, 2},
2746 {-2, 1},
2747 { 0, 0},
2748 {-2, 0},
2749 { 2, 1},
2750 { 0, 2},
2751 { 2, 0},
2752 { 0, 0},
2753 };
2754
2755 static void HandleKeyScrolling()
2756 {
2757 /*
2758 * Check that any of the dirkeys is pressed and that the focused window
2759 * doesn't have an edit-box as focused widget.
2760 */
2761 if (_dirkeys && !EditBoxInGlobalFocus()) {
2762 int factor = _shift_pressed ? 50 : 10;
2763 ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor);
2764 }
2765 }
2766
2767 static void MouseLoop(MouseClick click, int mousewheel)
2768 {
2769 /* World generation is multithreaded and messes with companies.
2770 * But there is no company related window open anyway, so _current_company is not used. */
2771 assert(HasModalProgress() || IsLocalCompany());
2772
2773 HandlePlacePresize();
2774 UpdateTileSelection();
2775
2776 if (VpHandlePlaceSizingDrag() == ES_HANDLED) return;
2777 if (HandleMouseDragDrop() == ES_HANDLED) return;
2778 if (HandleWindowDragging() == ES_HANDLED) return;
2779 if (HandleActiveWidget() == ES_HANDLED) return;
2780 if (HandleViewportScroll() == ES_HANDLED) return;
2781
2782 HandleMouseOver();
2783
2784 bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
2785 if (click == MC_NONE && mousewheel == 0 && !scrollwheel_scrolling) return;
2786
2787 int x = _cursor.pos.x;
2788 int y = _cursor.pos.y;
2789 Window *w = FindWindowFromPt(x, y);
2790 if (w == nullptr) return;
2791
2792 if (click != MC_HOVER && !MaybeBringWindowToFront(w)) return;
2793 Viewport *vp = IsPtInWindowViewport(w, x, y);
2794
2795 /* Don't allow any action in a viewport if either in menu or when having a modal progress window */
2796 if (vp != nullptr && (_game_mode == GM_MENU || HasModalProgress())) return;
2797
2798 if (mousewheel != 0) {
2799 /* Send mousewheel event to window, unless we're scrolling a viewport or the map */
2800 if (!scrollwheel_scrolling || (vp == nullptr && w->window_class != WC_SMALLMAP)) w->OnMouseWheel(mousewheel);
2801
2802 /* Dispatch a MouseWheelEvent for widgets if it is not a viewport */
2803 if (vp == nullptr) DispatchMouseWheelEvent(w, w->nested_root->GetWidgetFromPos(x - w->left, y - w->top), mousewheel);
2804 }
2805
2806 if (vp != nullptr) {
2807 if (scrollwheel_scrolling && !(w->flags & WF_DISABLE_VP_SCROLL)) {
2808 _scrolling_viewport = true;
2809 _cursor.fix_at = true;
2810 return;
2811 }
2812
2813 switch (click) {
2814 case MC_DOUBLE_LEFT:
2815 case MC_LEFT:
2816 if (HandleViewportClicked(vp, x, y)) return;
2817 if (!(w->flags & WF_DISABLE_VP_SCROLL) &&
2818 _settings_client.gui.scroll_mode == VSM_MAP_LMB) {
2819 _scrolling_viewport = true;
2820 _cursor.fix_at = false;
2821 return;
2822 }
2823 break;
2824
2825 case MC_RIGHT:
2826 if (!(w->flags & WF_DISABLE_VP_SCROLL) &&
2827 _settings_client.gui.scroll_mode != VSM_MAP_LMB) {
2828 _scrolling_viewport = true;
2829 _cursor.fix_at = (_settings_client.gui.scroll_mode == VSM_VIEWPORT_RMB_FIXED ||
2830 _settings_client.gui.scroll_mode == VSM_MAP_RMB_FIXED);
2831 DispatchRightClickEvent(w, x - w->left, y - w->top);
2832 return;
2833 }
2834 break;
2835
2836 default:
2837 break;
2838 }
2839 }
2840
2841 switch (click) {
2842 case MC_LEFT:
2843 case MC_DOUBLE_LEFT:
2844 DispatchLeftClickEvent(w, x - w->left, y - w->top, click == MC_DOUBLE_LEFT ? 2 : 1);
2845 return;
2846
2847 default:
2848 if (!scrollwheel_scrolling || w == nullptr || w->window_class != WC_SMALLMAP) break;
2849 /* We try to use the scrollwheel to scroll since we didn't touch any of the buttons.
2850 * Simulate a right button click so we can get started. */
2851 [[fallthrough]];
2852
2853 case MC_RIGHT:
2854 DispatchRightClickEvent(w, x - w->left, y - w->top);
2855 return;
2856
2857 case MC_HOVER:
2858 DispatchHoverEvent(w, x - w->left, y - w->top);
2859 break;
2860 }
2861
2862 /* We're not doing anything with 2D scrolling, so reset the value. */
2863 _cursor.h_wheel = 0;
2864 _cursor.v_wheel = 0;
2865 }
2866
2870 void HandleMouseEvents()
2871 {
2872 /* World generation is multithreaded and messes with companies.
2873 * But there is no company related window open anyway, so _current_company is not used. */
2874 assert(HasModalProgress() || IsLocalCompany());
2875
2876 /* Handle sprite picker before any GUI interaction */
2877 if (_newgrf_debug_sprite_picker.mode == SPM_REDRAW && _input_events_this_tick == 0) {
2878 /* We are done with the last draw-frame, so we know what sprites we
2879 * clicked on. Reset the picker mode and invalidate the window. */
2880 _newgrf_debug_sprite_picker.mode = SPM_NONE;
2881 InvalidateWindowData(WC_SPRITE_ALIGNER, 0, 1);
2882 }
2883
2884 static std::chrono::steady_clock::time_point double_click_time = {};
2885 static Point double_click_pos = {0, 0};
2886
2887 /* Mouse event? */
2888 MouseClick click = MC_NONE;
2889 if (_left_button_down && !_left_button_clicked) {
2890 click = MC_LEFT;
2891 if (std::chrono::steady_clock::now() <= double_click_time + TIME_BETWEEN_DOUBLE_CLICK &&
2892 double_click_pos.x != 0 && abs(_cursor.pos.x - double_click_pos.x) < MAX_OFFSET_DOUBLE_CLICK &&
2893 double_click_pos.y != 0 && abs(_cursor.pos.y - double_click_pos.y) < MAX_OFFSET_DOUBLE_CLICK) {
2894 click = MC_DOUBLE_LEFT;
2895 }
2896 double_click_time = std::chrono::steady_clock::now();
2897 double_click_pos = _cursor.pos;
2898 _left_button_clicked = true;
2899 _input_events_this_tick++;
2900 } else if (_right_button_clicked) {
2901 _right_button_clicked = false;
2902 click = MC_RIGHT;
2903 _input_events_this_tick++;
2904 }
2905
2906 int mousewheel = 0;
2907 if (_cursor.wheel) {
2908 mousewheel = _cursor.wheel;
2909 _cursor.wheel = 0;
2910 _input_events_this_tick++;
2911 }
2912
2913 static std::chrono::steady_clock::time_point hover_time = {};
2914 static Point hover_pos = {0, 0};
2915
2916 if (_settings_client.gui.hover_delay_ms > 0) {
2917 if (!_cursor.in_window || click != MC_NONE || mousewheel != 0 || _left_button_down || _right_button_down ||
2918 hover_pos.x == 0 || abs(_cursor.pos.x - hover_pos.x) >= MAX_OFFSET_HOVER ||
2919 hover_pos.y == 0 || abs(_cursor.pos.y - hover_pos.y) >= MAX_OFFSET_HOVER) {
2920 hover_pos = _cursor.pos;
2921 hover_time = std::chrono::steady_clock::now();
2922 _mouse_hovering = false;
2923 } else if (!_mouse_hovering) {
2924 if (std::chrono::steady_clock::now() > hover_time + std::chrono::milliseconds(_settings_client.gui.hover_delay_ms)) {
2925 click = MC_HOVER;
2926 _input_events_this_tick++;
2927 _mouse_hovering = true;
2928 hover_time = std::chrono::steady_clock::now();
2929 }
2930 }
2931 }
2932
2933 if (click == MC_LEFT && _newgrf_debug_sprite_picker.mode == SPM_WAIT_CLICK) {
2934 /* Mark whole screen dirty, and wait for the next realtime tick, when drawing is finished. */
2935 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
2936 _newgrf_debug_sprite_picker.clicked_pixel = blitter->MoveTo(_screen.dst_ptr, _cursor.pos.x, _cursor.pos.y);
2937 _newgrf_debug_sprite_picker.sprites.clear();
2938 _newgrf_debug_sprite_picker.mode = SPM_REDRAW;
2939 MarkWholeScreenDirty();
2940 } else {
2941 MouseLoop(click, mousewheel);
2942 }
2943
2944 /* We have moved the mouse the required distance,
2945 * no need to move it at any later time. */
2946 _cursor.delta.x = 0;
2947 _cursor.delta.y = 0;
2948 }
2949
2953 static void CheckSoftLimit()
2954 {
2955 if (_settings_client.gui.window_soft_limit == 0) return;
2956
2957 for (;;) {
2958 uint deletable_count = 0;
2959 Window *last_deletable = nullptr;
2960 for (Window *w : Window::IterateFromFront()) {
2961 if (w->window_class == WC_MAIN_WINDOW || IsVitalWindow(w) || (w->flags & WF_STICKY)) continue;
2962
2963 last_deletable = w;
2964 deletable_count++;
2965 }
2966
2967 /* We've not reached the soft limit yet. */
2968 if (deletable_count <= _settings_client.gui.window_soft_limit) break;
2969
2970 assert(last_deletable != nullptr);
2971 last_deletable->Close();
2972 }
2973 }
2974
2978 void InputLoop()
2979 {
2980 /* World generation is multithreaded and messes with companies.
2981 * But there is no company related window open anyway, so _current_company is not used. */
2982 assert(HasModalProgress() || IsLocalCompany());
2983
2984 CheckSoftLimit();
2985
2986 /* Process scheduled window deletion. */
2987 Window::DeleteClosedWindows();
2988
2989 if (_input_events_this_tick != 0) {
2990 /* The input loop is called only once per GameLoop() - so we can clear the counter here */
2991 _input_events_this_tick = 0;
2992 /* there were some inputs this tick, don't scroll ??? */
2993 return;
2994 }
2995
2996 /* HandleMouseEvents was already called for this tick */
2997 HandleMouseEvents();
2998 }
2999
3003 void CallWindowRealtimeTickEvent(uint delta_ms)
3004 {
3005 for (Window *w : Window::Iterate()) {
3006 w->OnRealtimeTick(delta_ms);
3007 }
3008 }
3009
3011 static IntervalTimer<TimerWindow> window_interval(std::chrono::milliseconds(30), [](auto) {
3012 extern int _caret_timer;
3013 _caret_timer += 3;
3014 CursorTick();
3015
3016 HandleKeyScrolling();
3017 HandleAutoscroll();
3018 DecreaseWindowCounters();
3019 });
3020
3022 static IntervalTimer<TimerWindow> highlight_interval(std::chrono::milliseconds(450), [](auto) {
3023 _window_highlight_colour = !_window_highlight_colour;
3024 });
3025
3027 static IntervalTimer<TimerWindow> white_border_interval(std::chrono::milliseconds(30), [](auto) {
3028 if (_network_dedicated) return;
3029
3030 for (Window *w : Window::Iterate()) {
3031 if ((w->flags & WF_WHITE_BORDER) && --w->white_border_timer == 0) {
3032 CLRBITS(w->flags, WF_WHITE_BORDER);
3033 w->SetDirty();
3034 }
3035 }
3036 });
3037
3041 void UpdateWindows()
3042 {
3043 static auto last_time = std::chrono::steady_clock::now();
3044 auto now = std::chrono::steady_clock::now();
3045 auto delta_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_time);
3046
3047 if (delta_ms.count() == 0) return;
3048
3049 last_time = now;
3050
3051 PerformanceMeasurer framerate(PFE_DRAWING);
3052 PerformanceAccumulator::Reset(PFE_DRAWWORLD);
3053
3054 ProcessPendingPerformanceMeasurements();
3055
3056 TimerManager<TimerWindow>::Elapsed(delta_ms);
3057 CallWindowRealtimeTickEvent(delta_ms.count());
3058
3059 /* Process invalidations before anything else. */
3060 for (Window *w : Window::Iterate()) {
3061 w->ProcessScheduledResize();
3062 w->ProcessScheduledInvalidations();
3063 w->ProcessHighlightedInvalidations();
3064 }
3065
3066 /* Skip the actual drawing on dedicated servers without screen.
3067 * But still empty the invalidation queues above. */
3068 if (_network_dedicated) return;
3069
3070 DrawDirtyBlocks();
3071
3072 for (Window *w : Window::Iterate()) {
3073 /* Update viewport only if window is not shaded. */
3074 if (w->viewport != nullptr && !w->IsShaded()) UpdateViewportPosition(w, delta_ms.count());
3075 }
3076 NetworkDrawChatMessage();
3077 /* Redraw mouse cursor in case it was hidden */
3078 DrawMouseCursor();
3079 }
3080
3086 void SetWindowDirty(WindowClass cls, WindowNumber number)
3087 {
3088 for (const Window *w : Window::Iterate()) {
3089 if (w->window_class == cls && w->window_number == number) w->SetDirty();
3090 }
3091 }
3092
3099 void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, WidgetID widget_index)
3100 {
3101 for (const Window *w : Window::Iterate()) {
3102 if (w->window_class == cls && w->window_number == number) {
3103 w->SetWidgetDirty(widget_index);
3104 }
3105 }
3106 }
3107
3112 void SetWindowClassesDirty(WindowClass cls)
3113 {
3114 for (const Window *w : Window::Iterate()) {
3115 if (w->window_class == cls) w->SetDirty();
3116 }
3117 }
3118
3122 void Window::ScheduleResize()
3123 {
3124 this->scheduled_resize = true;
3125 }
3126
3130 void Window::ProcessScheduledResize()
3131 {
3132 /* Sometimes OnResize() resizes the window again, in which case we can reprocess immediately. */
3133 while (this->scheduled_resize) {
3134 this->scheduled_resize = false;
3135 this->OnResize();
3136 }
3137 }
3138
3144 void Window::InvalidateData(int data, bool gui_scope)
3145 {
3146 this->SetDirty();
3147 if (!gui_scope) {
3148 /* Schedule GUI-scope invalidation for next redraw. */
3149 this->scheduled_invalidation_data.push_back(data);
3150 }
3151 this->OnInvalidateData(data, gui_scope);
3152 }
3153
3157 void Window::ProcessScheduledInvalidations()
3158 {
3159 for (int data : this->scheduled_invalidation_data) {
3160 if (this->window_class == WC_INVALID) break;
3161 this->OnInvalidateData(data, true);
3162 }
3163 this->scheduled_invalidation_data.clear();
3164 }
3165
3169 void Window::ProcessHighlightedInvalidations()
3170 {
3171 if ((this->flags & WF_HIGHLIGHTED) == 0) return;
3172
3173 for (const auto &pair : this->widget_lookup) {
3174 if (pair.second->IsHighlighted()) pair.second->SetDirty(this);
3175 }
3176 }
3177
3204 void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
3205 {
3206 for (Window *w : Window::Iterate()) {
3207 if (w->window_class == cls && w->window_number == number) {
3208 w->InvalidateData(data, gui_scope);
3209 }
3210 }
3211 }
3212
3221 void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
3222 {
3223 for (Window *w : Window::Iterate()) {
3224 if (w->window_class == cls) {
3225 w->InvalidateData(data, gui_scope);
3226 }
3227 }
3228 }
3229
3233 void CallWindowGameTickEvent()
3234 {
3235 for (Window *w : Window::Iterate()) {
3236 w->OnGameTick();
3237 }
3238 }
3239
3246 void CloseNonVitalWindows()
3247 {
3248 /* Note: the container remains stable, even when deleting windows. */
3249 for (Window *w : Window::Iterate()) {
3250 if ((w->window_desc->flags & WDF_NO_CLOSE) == 0 &&
3251 (w->flags & WF_STICKY) == 0) { // do not delete windows which are 'pinned'
3252
3253 w->Close();
3254 }
3255 }
3256 }
3257
3265 void CloseAllNonVitalWindows()
3266 {
3267 /* Note: the container remains stable, even when closing windows. */
3268 for (Window *w : Window::Iterate()) {
3269 if ((w->window_desc->flags & WDF_NO_CLOSE) == 0) {
3270 w->Close();
3271 }
3272 }
3273 }
3274
3278 void DeleteAllMessages()
3279 {
3280 InitNewsItemStructs();
3281 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar
3282 InvalidateWindowData(WC_MESSAGE_HISTORY, 0); // invalidate the message history
3283 CloseWindowById(WC_NEWS_WINDOW, 0); // close newspaper or general message window if shown
3284 }
3285
3290 void CloseConstructionWindows()
3291 {
3292 /* Note: the container remains stable, even when deleting windows. */
3293 for (Window *w : Window::Iterate()) {
3294 if (w->window_desc->flags & WDF_CONSTRUCTION) {
3295 w->Close();
3296 }
3297 }
3298
3299 for (const Window *w : Window::Iterate()) w->SetDirty();
3300 }
3301
3303 void HideVitalWindows()
3304 {
3305 CloseWindowById(WC_MAIN_TOOLBAR, 0);
3306 CloseWindowById(WC_STATUS_BAR, 0);
3307 }
3308
3309 void ReInitWindow(Window *w, bool zoom_changed)
3310 {
3311 if (w == nullptr) return;
3312 if (zoom_changed) {
3313 w->nested_root->AdjustPaddingForZoom();
3314 w->UpdateQueryStringSize();
3315 }
3316 w->ReInit();
3317 }
3318
3320 void ReInitAllWindows(bool zoom_changed)
3321 {
3322 SetupWidgetDimensions();
3323 NWidgetLeaf::InvalidateDimensionCache(); // Reset cached sizes of several widgets.
3324 NWidgetScrollbar::InvalidateDimensionCache();
3325
3326 InitDepotWindowBlockSizes();
3327
3328 /* When _gui_zoom has changed, we need to resize toolbar and statusbar first,
3329 * so EnsureVisibleCaption uses the updated size information. */
3330 ReInitWindow(FindWindowById(WC_MAIN_TOOLBAR, 0), zoom_changed);
3331 ReInitWindow(FindWindowById(WC_STATUS_BAR, 0), zoom_changed);
3332 for (Window *w : Window::Iterate()) {
3333 if (w->window_class == WC_MAIN_TOOLBAR || w->window_class == WC_STATUS_BAR) continue;
3334 ReInitWindow(w, zoom_changed);
3335 }
3336
3337 NetworkReInitChatBoxSize();
3338
3339 /* Make sure essential parts of all windows are visible */
3340 RelocateAllWindows(_screen.width, _screen.height);
3341 MarkWholeScreenDirty();
3342 }
3343
3351 static int PositionWindow(Window *w, WindowClass clss, int setting)
3352 {
3353 if (w == nullptr || w->window_class != clss) {
3354 w = FindWindowById(clss, 0);
3355 }
3356 if (w == nullptr) return 0;
3357
3358 int old_left = w->left;
3359 switch (setting) {
3360 case 1: w->left = (_screen.width - w->width) / 2; break;
3361 case 2: w->left = _screen.width - w->width; break;
3362 default: w->left = 0; break;
3363 }
3364 if (w->viewport != nullptr) w->viewport->left += w->left - old_left;
3365 AddDirtyBlock(0, w->top, _screen.width, w->top + w->height); // invalidate the whole row
3366 return w->left;
3367 }
3368
3374 int PositionMainToolbar(Window *w)
3375 {
3376 Debug(misc, 5, "Repositioning Main Toolbar...");
3377 return PositionWindow(w, WC_MAIN_TOOLBAR, _settings_client.gui.toolbar_pos);
3378 }
3379
3385 int PositionStatusbar(Window *w)
3386 {
3387 Debug(misc, 5, "Repositioning statusbar...");
3388 return PositionWindow(w, WC_STATUS_BAR, _settings_client.gui.statusbar_pos);
3389 }
3390
3396 int PositionNewsMessage(Window *w)
3397 {
3398 Debug(misc, 5, "Repositioning news message...");
3399 return PositionWindow(w, WC_NEWS_WINDOW, _settings_client.gui.statusbar_pos);
3400 }
3401
3407 int PositionNetworkChatWindow(Window *w)
3408 {
3409 Debug(misc, 5, "Repositioning network chat window...");
3410 return PositionWindow(w, WC_SEND_NETWORK_MSG, _settings_client.gui.statusbar_pos);
3411 }
3412
3413
3419 void ChangeVehicleViewports(VehicleID from_index, VehicleID to_index)
3420 {
3421 for (const Window *w : Window::Iterate()) {
3422 if (w->viewport != nullptr && w->viewport->follow_vehicle == from_index) {
3423 w->viewport->follow_vehicle = to_index;
3424 w->SetDirty();
3425 }
3426 }
3427 }
3428
3429
3435 void RelocateAllWindows(int neww, int newh)
3436 {
3437 CloseWindowByClass(WC_DROPDOWN_MENU);
3438
3439 for (Window *w : Window::Iterate()) {
3440 int left, top;
3441 /* XXX - this probably needs something more sane. For example specifying
3442 * in a 'backup'-desc that the window should always be centered. */
3443 switch (w->window_class) {
3444 case WC_MAIN_WINDOW:
3445 case WC_BOOTSTRAP:
3446 ResizeWindow(w, neww, newh);
3447 continue;
3448
3449 case WC_MAIN_TOOLBAR:
3450 ResizeWindow(w, std::min<uint>(neww, _toolbar_width) - w->width, 0, false);
3451
3452 top = w->top;
3453 left = PositionMainToolbar(w); // changes toolbar orientation
3454 break;
3455
3456 case WC_NEWS_WINDOW:
3457 top = newh - w->height;
3458 left = PositionNewsMessage(w);
3459 break;
3460
3461 case WC_STATUS_BAR:
3462 ResizeWindow(w, std::min<uint>(neww, _toolbar_width) - w->width, 0, false);
3463
3464 top = newh - w->height;
3465 left = PositionStatusbar(w);
3466 break;
3467
3468 case WC_SEND_NETWORK_MSG:
3469 ResizeWindow(w, std::min<uint>(neww, _toolbar_width) - w->width, 0, false);
3470
3471 top = newh - w->height - FindWindowById(WC_STATUS_BAR, 0)->height;
3472 left = PositionNetworkChatWindow(w);
3473 break;
3474
3475 case WC_CONSOLE:
3476 IConsoleResize(w);
3477 continue;
3478
3479 default: {
3480 if (w->flags & WF_CENTERED) {
3481 top = (newh - w->height) >> 1;
3482 left = (neww - w->width) >> 1;
3483 break;
3484 }
3485
3486 left = w->left;
3487 if (left + (w->width >> 1) >= neww) left = neww - w->width;
3488 if (left < 0) left = 0;
3489
3490 top = w->top;
3491 if (top + (w->height >> 1) >= newh) top = newh - w->height;
3492 break;
3493 }
3494 }
3495
3496 EnsureVisibleCaption(w, left, top);
3497 }
3498 }
3499
3504 void PickerWindowBase::Close([[maybe_unused]] int data)
3505 {
3506 ResetObjectToPlace();
3507 this->Window::Close();
3508 }
_dirkeys
byte _dirkeys
1 = left, 2 = up, 4 = right, 8 = down
Definition: gfx.cpp:33
game.hpp
NewGrfDebugSpritePicker::clicked_pixel
void * clicked_pixel
Clicked pixel (pointer to blitter buffer)
Definition: newgrf_debug.h:27
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:739
ShowFirstError
void ShowFirstError()
Show the first error of the queue.
Definition: error_gui.cpp:335
Window::timeout_timer
uint8_t timeout_timer
Timer value of the WF_TIMEOUT for flags.
Definition: window_gui.h:300
Window::WindowIterator
Iterator to iterate all valid Windows.
Definition: window_gui.h:862
WC_CUSTOM_CURRENCY
@ WC_CUSTOM_CURRENCY
Custom currency; Window numbers:
Definition: window_type.h:625
WC_SAVELOAD
@ WC_SAVELOAD
Saveload window; Window numbers:
Definition: window_type.h:144
ScrollbarClickHandler
void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
Special handling for the scrollbar widget type.
Definition: widget.cpp:242
Window::SetTimeout
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:355
WC_ROADVEH_LIST
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
Definition: window_type.h:314
WindowDesc::pref_width
int16_t pref_width
User-preferred width of the window. Zero if unset.
Definition: window_gui.h:173
MAX_OFFSET_HOVER
@ MAX_OFFSET_HOVER
Maximum mouse movement before stopping a hover event.
Definition: window.cpp:2712
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition: window.cpp:3204
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition: window.cpp:1153
HideVitalWindows
void HideVitalWindows()
Close all always on-top windows to get an empty screen.
Definition: window.cpp:3303
factory.hpp
Window::OnScroll
virtual void OnScroll([[maybe_unused]] Point delta)
Handle the request for (viewport) scrolling.
Definition: window_gui.h:708
FindWindowFromPt
Window * FindWindowFromPt(int x, int y)
Do a search for a window at specific coordinates.
Definition: window.cpp:1769
WC_INVALID
@ WC_INVALID
Invalid window.
Definition: window_type.h:719
NWidgetCore::IsDisabled
bool IsDisabled() const
Return whether the widget is disabled.
Definition: widget_type.h:435
_mouseover_last_w
static Window * _mouseover_last_w
Window of the last OnMouseOver event.
Definition: window.cpp:53
WindowDesc::default_height_trad
int16_t default_height_trad
Preferred initial height of the window (pixels at 1x zoom).
Definition: window_gui.h:184
Pool::PoolItem<&_vehicle_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:339
WC_BUILD_TOOLBAR
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition: window_type.h:73
MouseClick
MouseClick
Definition: window.cpp:2704
QueryString::ok_button
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Definition: querystring_gui.h:27
HKPR_EDITING
@ HKPR_EDITING
Textbuf content changed.
Definition: textbuf_type.h:22
AddDirtyBlock
void AddDirtyBlock(int left, int top, int right, int bottom)
Extend the internal _invalid_rect rectangle to contain the rectangle defined by the given parameters.
Definition: gfx.cpp:1505
WF_SIZING
@ WF_SIZING
Window is being resized.
Definition: window_gui.h:227
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3086
CheckSoftLimit
static void CheckSoftLimit()
Check the soft limit of deletable (non vital, non sticky) windows.
Definition: window.cpp:2953
UpdateTileSelection
void UpdateTileSelection()
Updates tile highlighting for all cases.
Definition: viewport.cpp:2596
Window::OnInitialPosition
virtual Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number)
Compute the initial position of the window.
Definition: window.cpp:1712
querystring_gui.h
Window::SetWhiteBorder
void SetWhiteBorder()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:364
HotkeyList
List of hotkeys for a window.
Definition: hotkeys.h:37
SetFocusedWindow
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Definition: window.cpp:423
Window::~Window
virtual ~Window()
Remove window and all its child windows from the window stack.
Definition: window.cpp:1085
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
Window::GetFocusedTextbuf
virtual const struct Textbuf * GetFocusedTextbuf() const
Get the current input text buffer.
Definition: window.cpp:366
HKPR_CONFIRM
@ HKPR_CONFIRM
Return or enter key pressed.
Definition: textbuf_type.h:24
NWidgetLeaf::resizebox_dimension
static Dimension resizebox_dimension
Cached size of a resizebox widget.
Definition: widget_type.h:898
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:197
PositionMainToolbar
int PositionMainToolbar(Window *w)
(Re)position main toolbar window at the screen.
Definition: window.cpp:3374
Window::shade_select
NWidgetStacked * shade_select
Selection widget (NWID_SELECTION) to use for shading the window. If nullptr, window cannot shade.
Definition: window_gui.h:317
WF_SIZING_RIGHT
@ WF_SIZING_RIGHT
Window is being resized towards the right.
Definition: window_gui.h:225
Ceil
constexpr uint Ceil(uint a, uint b)
Computes ceil(a / b) * b for non-negative a and b.
Definition: math_func.hpp:331
_special_mouse_mode
SpecialMouseMode _special_mouse_mode
Mode of the mouse.
Definition: window.cpp:93
toolbar_gui.h
_left_button_down
bool _left_button_down
Is left mouse button pressed?
Definition: gfx.cpp:40
statusbar_gui.h
Window::ApplyDefaults
virtual void ApplyDefaults()
Read default values from WindowDesc configuration an apply them to the window.
Definition: window.cpp:195
WindowDesc::WindowDesc
WindowDesc(const char *const file, const int line, WindowPosition default_pos, const char *ini_key, int16_t def_width_trad, int16_t def_height_trad, WindowClass window_class, WindowClass parent_class, uint32_t flags, const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, HotkeyList *hotkeys=nullptr)
Window description constructor.
Definition: window.cpp:105
Window::OnDropdownClose
virtual void OnDropdownClose(Point pt, WidgetID widget, int index, bool instant_close)
A dropdown window associated to this window has been closed.
Definition: window.cpp:288
CloseCompanyWindows
void CloseCompanyWindows(CompanyID id)
Close all windows of a company.
Definition: window.cpp:1169
ND_SCROLLBAR_DOWN
@ ND_SCROLLBAR_DOWN
Bit value of the 'scrollbar down' flag.
Definition: widget_type.h:346
NWID_HSCROLLBAR
@ NWID_HSCROLLBAR
Horizontal scrollbar.
Definition: widget_type.h:85
WC_COMPANY_COLOUR
@ WC_COMPANY_COLOUR
Company colour selection; Window numbers:
Definition: window_type.h:230
Blitter
How all blitters should look like.
Definition: base.hpp:29
IniLoadWindowSettings
void IniLoadWindowSettings(IniFile &ini, const char *grpname, void *desc)
Load a WindowDesc from config.
Definition: settings.cpp:878
Window::InitializePositionSize
void InitializePositionSize(int x, int y, int min_width, int min_height)
Set the position and smallest size of the window.
Definition: window.cpp:1403
HandleScrollbarScrolling
static void HandleScrollbarScrolling(Window *w)
Handle scrollbar scrolling with the mouse.
Definition: window.cpp:2294
HandleTextInput
void HandleTextInput(const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end)
Handle text input.
Definition: window.cpp:2653
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
Viewport::width
int width
Screen width of the viewport.
Definition: viewport_type.h:25
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:552
Window::GetTextCharacterAtPosition
virtual ptrdiff_t GetTextCharacterAtPosition(const Point &pt) const
Get the character that is rendered at a position by the focused edit box.
Definition: window.cpp:410
PHD_DOWN
@ PHD_DOWN
Below v is a safe position.
Definition: window.cpp:1936
WF_DISABLE_VP_SCROLL
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
Definition: window_gui.h:229
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:312
NDB_DROPDOWN_CLOSED
@ NDB_DROPDOWN_CLOSED
Dropdown menu of the dropdown widget has closed.
Definition: widget_type.h:336
GUISettings::statusbar_pos
uint8_t statusbar_pos
position of statusbar, 0=left, 1=center, 2=right
Definition: settings_type.h:154
_newgrf_debug_sprite_picker
NewGrfDebugSpritePicker _newgrf_debug_sprite_picker
The sprite picker.
Definition: newgrf_debug_gui.cpp:49
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1141
Viewport::height
int height
Screen height of the viewport.
Definition: viewport_type.h:26
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
IntervalTimer< TimerWindow >
NewGrfDebugSpritePicker::sprites
std::vector< SpriteID > sprites
Sprites found.
Definition: newgrf_debug.h:28
WDP_ALIGN_TOOLBAR
@ WDP_ALIGN_TOOLBAR
Align toward the toolbar.
Definition: window_gui.h:143
InitWindowSystem
void InitWindowSystem()
(re)initialize the windowing system
Definition: window.cpp:1783
NewGrfDebugSpritePicker::mode
NewGrfDebugSpritePickerMode mode
Current state.
Definition: newgrf_debug.h:26
depot_func.h
Window::OnGameTick
virtual void OnGameTick()
Called once per (game) tick.
Definition: window_gui.h:733
valid
uint8_t valid
Bits indicating what variable is valid (for each bit, 0 is invalid, 1 is valid).
Definition: newgrf_station.cpp:246
Viewport::top
int top
Screen coordinate top edge of the viewport.
Definition: viewport_type.h:24
WF_STICKY
@ WF_STICKY
Window is made sticky by user.
Definition: window_gui.h:228
Window::OnFocusLost
virtual void OnFocusLost(bool closing)
The window has lost focus.
Definition: window.cpp:517
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1048
UpdateWindows
void UpdateWindows()
Update the continuously changing contents of the windows, such as the viewports.
Definition: window.cpp:3041
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1099
InitNewsItemStructs
void InitNewsItemStructs()
Initialize the news-items data structures.
Definition: news_gui.cpp:634
StartWindowSizing
static void StartWindowSizing(Window *w, bool to_left)
Start resizing a window.
Definition: window.cpp:2278
window_interval
static IntervalTimer< TimerWindow > window_interval(std::chrono::milliseconds(30), [](auto) { extern int _caret_timer;_caret_timer+=3;CursorTick();HandleKeyScrolling();HandleAutoscroll();DecreaseWindowCounters();})
Update various of window-related information on a regular interval.
PerformanceMeasurer
RAII class for measuring simple elements of performance.
Definition: framerate_type.h:92
BringWindowToFront
static void BringWindowToFront(Window *w, bool dirty=true)
On clicking on a window, make it the frontmost window of all windows with an equal or lower z-priorit...
Definition: window.cpp:1345
WID_OSK_CANCEL
@ WID_OSK_CANCEL
Cancel key.
Definition: osk_widget.h:17
WDF_NO_FOCUS
@ WDF_NO_FOCUS
This window won't get focus/make any other window lose focus when click.
Definition: window_gui.h:199
UnInitWindowSystem
void UnInitWindowSystem()
Close down the windowing system.
Definition: window.cpp:1805
VA_DISABLED
@ VA_DISABLED
Do not autoscroll when mouse is at edge of viewport.
Definition: window.cpp:46
white_border_interval
static IntervalTimer< TimerWindow > white_border_interval(std::chrono::milliseconds(30), [](auto) { if(_network_dedicated) return;for(Window *w :Window::Iterate()) { if((w->flags &WF_WHITE_BORDER) &&--w->white_border_timer==0) { CLRBITS(w->flags, WF_WHITE_BORDER);w->SetDirty();} } })
Blink all windows marked with a white border.
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
vehicle_base.h
zoom_func.h
Window::IsWidgetHighlighted
bool IsWidgetHighlighted(WidgetID widget_index) const
Gets the highlighted status of a widget.
Definition: window.cpp:273
WC_BOOTSTRAP
@ WC_BOOTSTRAP
Bootstrap; Window numbers:
Definition: window_type.h:650
Window::RaiseButtons
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition: window.cpp:526
WC_GENERATE_LANDSCAPE
@ WC_GENERATE_LANDSCAPE
Generate landscape (newgame); Window numbers:
Definition: window_type.h:456
WC_MESSAGE_HISTORY
@ WC_MESSAGE_HISTORY
News history list; Window numbers:
Definition: window_type.h:272
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
WC_OSK
@ WC_OSK
On Screen Keyboard; Window numbers:
Definition: window_type.h:162
WindowDesc::cls
WindowClass cls
Class of the window,.
Definition: window_gui.h:164
ViewportData::dest_scrollpos_y
int32_t dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition: window_gui.h:251
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:468
VSM_VIEWPORT_RMB_FIXED
@ VSM_VIEWPORT_RMB_FIXED
Viewport moves with mouse movement on holding right mouse button, cursor position is fixed.
Definition: settings_type.h:122
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition: widget_type.h:50
HandleKeypress
void HandleKeypress(uint keycode, char32_t key)
Handle keyboard input.
Definition: window.cpp:2567
Window::OnTimeout
virtual void OnTimeout()
Called when this window's timeout has been reached.
Definition: window_gui.h:743
newgrf_debug.h
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:310
WC_COMPANY
@ WC_COMPANY
Company view; Window numbers:
Definition: window_type.h:369
NWidgetCore::tool_tip
StringID tool_tip
Tooltip of the widget.
Definition: widget_type.h:380
GetWidgetFromPos
WidgetID GetWidgetFromPos(const Window *w, int x, int y)
Returns the index for the widget located at the given position relative to the window.
Definition: widget.cpp:266
MakeWindowNWidgetTree
std::unique_ptr< NWidgetBase > MakeWindowNWidgetTree(const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, NWidgetStacked **shade_select)
Make a nested widget tree for a window from a parts array.
Definition: widget.cpp:3164
NWidgetCore::SetLowered
void SetLowered(bool lowered)
Lower or raise the widget.
Definition: widget_type.h:414
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
Window::OnPlacePresize
virtual void OnPlacePresize([[maybe_unused]] Point pt, [[maybe_unused]] TileIndex tile)
The user moves over the map when a tile highlight mode has been set when the special mouse mode has b...
Definition: window_gui.h:839
Window::GetCaretPosition
virtual Point GetCaretPosition() const
Get the current caret position if an edit box has the focus.
Definition: window.cpp:379
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:680
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
EditBoxInGlobalFocus
bool EditBoxInGlobalFocus()
Check if an edit box is in global focus.
Definition: window.cpp:449
HandleAutoscroll
static void HandleAutoscroll()
If needed and switched on, perform auto scrolling (automatically moving window contents when mouse is...
Definition: window.cpp:2672
Window::OnHotkey
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: window.cpp:566
StartWindowDrag
static void StartWindowDrag(Window *w)
Start window dragging.
Definition: window.cpp:2261
Window::Window
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1757
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1040
Textbuf::InsertString
bool InsertString(const char *str, bool marked, const char *caret=nullptr, const char *insert_location=nullptr, const char *replacement_end=nullptr)
Insert a string into the text buffer.
Definition: textbuf.cpp:159
ResizeWindow
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
Resize the window.
Definition: window.cpp:2027
Window::nested_focus
const NWidgetCore * nested_focus
Currently focused nested widget, or nullptr if no nested widget has focus.
Definition: window_gui.h:313
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
GetWindowZPriority
static uint GetWindowZPriority(WindowClass wc)
Get the z-priority for a given window.
Definition: window.cpp:1261
WC_GRF_PARAMETERS
@ WC_GRF_PARAMETERS
NewGRF parameters; Window numbers:
Definition: window_type.h:181
Window::scheduled_invalidation_data
std::vector< int > scheduled_invalidation_data
Data of scheduled OnInvalidateData() calls.
Definition: window_gui.h:276
WC_SAVE_PRESET
@ WC_SAVE_PRESET
Save preset; Window numbers:
Definition: window_type.h:693
Window::OnEditboxChanged
virtual void OnEditboxChanged([[maybe_unused]] WidgetID widget)
The text in an editbox has been edited.
Definition: window_gui.h:765
Debug
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
_gui_scale
int _gui_scale
GUI scale, 100 is 100%.
Definition: gfx.cpp:62
Window::OnCTRLStateChange
virtual EventState OnCTRLStateChange()
The state of the control key has changed.
Definition: window_gui.h:655
Vehicle::x_pos
int32_t x_pos
x coordinate.
Definition: vehicle_base.h:300
Scrollbar::GetCount
uint16_t GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:704
WC_HIGHSCORE
@ WC_HIGHSCORE
Highscore; Window numbers:
Definition: window_type.h:656
NetworkReInitChatBoxSize
void NetworkReInitChatBoxSize()
Initialize all font-dependent chat box sizes.
Definition: network_chat_gui.cpp:102
Window::ProcessScheduledInvalidations
void ProcessScheduledInvalidations()
Process all scheduled invalidations.
Definition: window.cpp:3157
Window::OnMouseDrag
virtual void OnMouseDrag([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget)
An 'object' is being dragged at the provided position, highlight the target if possible.
Definition: window_gui.h:695
PHD_UP
@ PHD_UP
Above v is a safe position.
Definition: window.cpp:1935
gfx_func.h
WindowDesc::default_pos
WindowPosition default_pos
Preferred position of the window.
Definition: window_gui.h:163
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
RoundDivSU
constexpr int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
Definition: math_func.hpp:342
WC_MODAL_PROGRESS
@ WC_MODAL_PROGRESS
Progress report of landscape generation; Window numbers:
Definition: window_type.h:463
ScaleGUITrad
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:117
WF_SIZING_LEFT
@ WF_SIZING_LEFT
Window is being resized towards the left.
Definition: window_gui.h:226
NWidgetLeaf::InvalidateDimensionCache
static void InvalidateDimensionCache()
Reset the cached dimensions.
Definition: widget.cpp:2455
PositionStatusbar
int PositionStatusbar(Window *w)
(Re)position statusbar window at the screen.
Definition: window.cpp:3385
Window::SetShaded
void SetShaded(bool make_shaded)
Set the shaded state of the window to make_shaded.
Definition: window.cpp:996
ND_DROPDOWN_ACTIVE
@ ND_DROPDOWN_ACTIVE
Bit value of the 'dropdown active' flag.
Definition: widget_type.h:344
Scrollbar::UpdatePosition
bool UpdatePosition(int difference, ScrollbarStepping unit=SS_SMALL)
Updates the position of the first visible element by the given amount.
Definition: widget_type.h:806
WC_CONFIRM_POPUP_QUERY
@ WC_CONFIRM_POPUP_QUERY
Popup with confirm question; Window numbers:
Definition: window_type.h:130
MayBeShown
static bool MayBeShown(const Window *w)
Returns whether a window may be shown or not.
Definition: window.cpp:830
IsInsideBS
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Definition: math_func.hpp:252
PositionNewsMessage
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
Definition: window.cpp:3396
WC_QUERY_STRING
@ WC_QUERY_STRING
Query string window; Window numbers:
Definition: window_type.h:123
Viewport
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:22
Window::UnfocusFocusedWidget
void UnfocusFocusedWidget()
Makes no widget on this window have focus.
Definition: window.cpp:471
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
WindowDesc::ini_key
const char * ini_key
Key to store window defaults in openttd.cfg. nullptr if nothing shall be stored.
Definition: window_gui.h:166
ChangeVehicleViewports
void ChangeVehicleViewports(VehicleID from_index, VehicleID to_index)
Switches viewports following vehicles, which get autoreplaced.
Definition: window.cpp:3419
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
_input_events_this_tick
static int _input_events_this_tick
Local counter that is incremented each time an mouse input event is detected.
Definition: window.cpp:2666
WindowDesc::flags
uint32_t flags
Flags.
Definition: window_gui.h:167
WSM_PRESIZE
@ WSM_PRESIZE
Presizing mode (docks, tunnels).
Definition: window_gui.h:1037
ST_SMALLEST
@ ST_SMALLEST
Initialize nested widget tree to smallest size. Also updates current_x and current_y.
Definition: widget_type.h:118
settings_func.h
tilehighlight_func.h
WindowNumber
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:732
WC_BUY_COMPANY
@ WC_BUY_COMPANY
Buyout company (merger); Window numbers:
Definition: window_type.h:589
DescSorter
static bool DescSorter(WindowDesc *const &a, WindowDesc *const &b)
Sort WindowDesc by ini_key.
Definition: window.cpp:169
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
GUISettings::auto_scrolling
uint8_t auto_scrolling
scroll when moving mouse to the edge (see ViewportAutoscrolling)
Definition: settings_type.h:139
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1747
Window::ProcessHighlightedInvalidations
void ProcessHighlightedInvalidations()
Process all invalidation of highlighted widgets.
Definition: window.cpp:3169
Window::OnMouseWheel
virtual void OnMouseWheel([[maybe_unused]] int wheel)
The mouse wheel has been turned.
Definition: window_gui.h:722
CloseNonVitalWindows
void CloseNonVitalWindows()
Try to close a non-vital window.
Definition: window.cpp:3246
Window::nested_root
std::unique_ptr< NWidgetBase > nested_root
Root of the nested tree.
Definition: window_gui.h:315
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:73
ReInitAllWindows
void ReInitAllWindows(bool zoom_changed)
Re-initialize all windows.
Definition: window.cpp:3320
NWidgetBase::type
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:222
Window::ScheduleResize
void ScheduleResize()
Mark this window as resized and in need of OnResize() event.
Definition: window.cpp:3122
Window::HandleButtonClick
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
Definition: window.cpp:591
TileHighlightData::window_number
WindowNumber window_number
The WindowNumber of the window that is responsible for the selection mode.
Definition: tilehighlight_type.h:69
TIME_BETWEEN_DOUBLE_CLICK
const std::chrono::milliseconds TIME_BETWEEN_DOUBLE_CLICK(500)
Time between 2 left clicks before it becoming a double click.
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:306
_toolbar_width
uint _toolbar_width
Width of the toolbar, shared by statusbar.
Definition: toolbar_gui.cpp:70
WF_CENTERED
@ WF_CENTERED
Window is centered and shall stay centered after ReInit.
Definition: window_gui.h:232
WF_WHITE_BORDER
@ WF_WHITE_BORDER
Window white border counter bit mask.
Definition: window_gui.h:230
ViewportData::dest_scrollpos_x
int32_t dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition: window_gui.h:250
WindowDesc::pref_height
int16_t pref_height
User-preferred height of the window. Zero if unset.
Definition: window_gui.h:174
SpecialMouseMode
SpecialMouseMode
Mouse modes.
Definition: window_gui.h:1033
INVALID_VEHICLE
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
Definition: vehicle_type.h:54
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
Textbuf::bytes
uint16_t bytes
the current size of the string in bytes (including terminating '\0')
Definition: textbuf_type.h:35
Viewport::left
int left
Screen coordinate left edge of the viewport.
Definition: viewport_type.h:23
SBI_NEWS_DELETED
@ SBI_NEWS_DELETED
abort current news display (active news were deleted)
Definition: statusbar_gui.h:19
Window::OnDragDrop
virtual void OnDragDrop([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget)
A dragged 'object' has been released.
Definition: window_gui.h:702
INVALID_OWNER
@ INVALID_OWNER
An invalid owner.
Definition: company_type.h:29
Window::OnFocus
virtual void OnFocus()
The window has gained focus.
Definition: window.cpp:509
IniFile::SaveToDisk
bool SaveToDisk(const std::string &filename)
Save the Ini file's data to the disk.
Definition: ini.cpp:42
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:740
DispatchMouseWheelEvent
static void DispatchMouseWheelEvent(Window *w, NWidgetCore *nwid, int wheel)
Dispatch the mousewheel-action to the window.
Definition: window.cpp:799
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:135
QueryString::GetCharAtPosition
ptrdiff_t GetCharAtPosition(const Window *w, WidgetID wid, const Point &pt) const
Get the character that is rendered at a position.
Definition: misc_gui.cpp:894
RelocateAllWindows
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
Definition: window.cpp:3435
GetAutoPlacePosition
static Point GetAutoPlacePosition(int width, int height)
Find a good place for opening a new window of a given width and height.
Definition: window.cpp:1560
PickerWindowBase::Close
void Close([[maybe_unused]] int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:3504
PreventHiding
static void PreventHiding(int *nx, int *ny, const Rect &rect, const Window *v, int px, PreventHideDirection dir)
Do not allow hiding of the rectangle with base coordinates nx and ny behind window v.
Definition: window.cpp:1949
Window::DisableAllWidgetHighlight
void DisableAllWidgetHighlight()
Disable the highlighted status of all widgets.
Definition: window.cpp:225
WindowDesc::GetDefaultHeight
int16_t GetDefaultHeight() const
Determine default height of window.
Definition: window.cpp:148
Window::OnTooltip
virtual bool OnTooltip([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget, [[maybe_unused]] TooltipCloseCondition close_cond)
Event to display a custom tooltip.
Definition: window_gui.h:688
Scrollbar::GetCapacity
uint16_t GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:713
ProcessPendingPerformanceMeasurements
void ProcessPendingPerformanceMeasurements()
This drains the PFE_SOUND measurement data queue into _pf_data.
Definition: framerate_gui.cpp:1113
QueryString::GetBoundingRect
Rect GetBoundingRect(const Window *w, WidgetID wid, const char *from, const char *to) const
Get the bounding rectangle for a range of the query string.
Definition: misc_gui.cpp:863
GetMainViewTop
int GetMainViewTop()
Return the top of the main view available for general use.
Definition: window.cpp:2067
Window::ReInit
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:953
BlitterFactory::GetCurrentBlitter
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition: factory.hpp:138
HasModalProgress
bool HasModalProgress()
Check if we are currently in a modal progress state.
Definition: progress.h:17
DrawOverlappedWindow
static void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom)
Generate repaint events for the visible part of window w within the rectangle.
Definition: window.cpp:858
Game::NewEvent
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
Definition: game_core.cpp:146
Window::DeleteClosedWindows
static void DeleteClosedWindows()
Delete all closed windows.
Definition: window.cpp:65
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:322
CallWindowGameTickEvent
void CallWindowGameTickEvent()
Dispatch OnGameTick event over all windows.
Definition: window.cpp:3233
safeguards.h
GetToolbarAlignedWindowPosition
Point GetToolbarAlignedWindowPosition(int window_width)
Computer the position of the top-left corner of a window to be opened right under the toolbar.
Definition: window.cpp:1628
Window::LowerWidget
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition: window_gui.h:460
timer.h
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:303
WID_OSK_OK
@ WID_OSK_OK
Ok key.
Definition: osk_widget.h:18
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:294
_z_windows
WindowList _z_windows
List of windows opened at the screen sorted from the front to back.
Definition: window.cpp:57
WF_TIMEOUT
@ WF_TIMEOUT
Window timeout counter.
Definition: window_gui.h:222
CursorVars::fix_at
bool fix_at
mouse is moving, but cursor is not (used for scrolling)
Definition: gfx_type.h:120
WC_SHIPS_LIST
@ WC_SHIPS_LIST
Ships list; Window numbers:
Definition: window_type.h:320
WindowClass
WindowClass
Window classes.
Definition: window_type.h:44
WWT_LAST
@ WWT_LAST
Last Item. use WIDGETS_END to fill up padding!!
Definition: widget_type.h:74
Window::ShowNewGRFInspectWindow
virtual void ShowNewGRFInspectWindow() const
Show the NewGRF inspection window.
Definition: window_gui.h:855
Window::GetQueryString
const QueryString * GetQueryString(WidgetID widnum) const
Return the querystring associated to a editbox.
Definition: window.cpp:335
HandleCtrlChanged
void HandleCtrlChanged()
State of CONTROL key has changed.
Definition: window.cpp:2623
_mouse_hovering
bool _mouse_hovering
The mouse is hovering over the same point.
Definition: window.cpp:91
IConsoleResize
void IConsoleResize(Window *w)
Change the size of the in-game console window after the screen size changed, or the window state chan...
Definition: console_gui.cpp:359
_shift_pressed
bool _shift_pressed
Is Shift pressed?
Definition: gfx.cpp:38
CursorVars::wheel
int wheel
mouse wheel movement
Definition: gfx_type.h:119
PositionWindow
static int PositionWindow(Window *w, WindowClass clss, int setting)
(Re)position a window at the screen.
Definition: window.cpp:3351
HandleMouseOver
static void HandleMouseOver()
Report position of the mouse to the underlying window.
Definition: window.cpp:1908
DrawDirtyBlocks
void DrawDirtyBlocks()
Repaints the rectangle blocks which are marked as 'dirty'.
Definition: gfx.cpp:1416
NDB_SCROLLBAR_UP
@ NDB_SCROLLBAR_UP
Up-button is lowered bit.
Definition: widget_type.h:332
VehicleID
uint32_t VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
WDF_MODAL
@ WDF_MODAL
The window is a modal child of some other window, meaning the parent is 'inactive'.
Definition: window_gui.h:198
settings_type.h
PFE_DRAWING
@ PFE_DRAWING
Speed of drawing world and GUI.
Definition: framerate_type.h:57
VSM_MAP_RMB_FIXED
@ VSM_MAP_RMB_FIXED
Map moves with mouse movement on holding right mouse button, cursor position is fixed.
Definition: settings_type.h:123
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
WF_HIGHLIGHTED
@ WF_HIGHLIGHTED
Window has a widget that has a highlight.
Definition: window_gui.h:231
ScrollMainWindowTo
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
Definition: smallmap_gui.cpp:2007
FocusedWindowIsConsole
bool FocusedWindowIsConsole()
Check if a console is focused.
Definition: window.cpp:463
error.h
NWidgetCore::IsLowered
bool IsLowered() const
Return whether the widget is lowered.
Definition: widget_type.h:420
WC_TRAINS_LIST
@ WC_TRAINS_LIST
Trains list; Window numbers:
Definition: window_type.h:308
WDF_NO_CLOSE
@ WDF_NO_CLOSE
This window can't be interactively closed.
Definition: window_gui.h:200
WSM_DRAGDROP
@ WSM_DRAGDROP
Drag&drop an object.
Definition: window_gui.h:1035
Window::OnInit
virtual void OnInit()
Notification that the nested widget tree gets initialized.
Definition: window_gui.h:576
TimerManager::Elapsed
static bool Elapsed(TElapsed value)
Called when time for this timer elapsed.
Window::unshaded_size
Dimension unshaded_size
Last known unshaded size (only valid while shaded).
Definition: window_gui.h:318
_network_dedicated
bool _network_dedicated
are we a dedicated server?
Definition: network.cpp:68
GUISettings::scroll_mode
uint8_t scroll_mode
viewport scroll mode
Definition: settings_type.h:145
WindowDesc::SaveToConfig
static void SaveToConfig()
Save all WindowDesc settings to _windows_file.
Definition: window.cpp:178
stdafx.h
QueryString::GetCaretPosition
Point GetCaretPosition(const Window *w, WidgetID wid) const
Get the current caret position.
Definition: misc_gui.cpp:834
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
Window::SetFocusedWidget
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:487
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:208
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition: window.cpp:3144
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:201
viewport_func.h
Window::InsertTextString
virtual void InsertTextString(WidgetID wid, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end)
Insert a text string at the cursor position into the edit box widget.
Definition: window.cpp:2636
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
HandleMouseEvents
void HandleMouseEvents()
Handle a mouse event from the video driver.
Definition: window.cpp:2870
Window::AllWindows
Iterable ensemble of all valid Windows.
Definition: window_gui.h:907
Window::scheduled_resize
bool scheduled_resize
Set if window has been resized.
Definition: window_gui.h:277
WidgetType
WidgetType
Window widget types, nested widget types, and nested widget part types.
Definition: widget_type.h:48
Vehicle::z_pos
int32_t z_pos
z coordinate.
Definition: vehicle_base.h:302
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
DispatchRightClickEvent
static void DispatchRightClickEvent(Window *w, int x, int y)
Dispatch right mouse-button click in window.
Definition: window.cpp:742
IsGoodAutoPlace2
static bool IsGoodAutoPlace2(int left, int top, int width, int height, int toolbar_y, Point &pos)
Decide whether a given rectangle is a good place to open a mostly visible new window.
Definition: window.cpp:1521
HandleViewportScroll
static EventState HandleViewportScroll()
Handle viewport scrolling with the mouse.
Definition: window.cpp:2358
highlight_interval
static IntervalTimer< TimerWindow > highlight_interval(std::chrono::milliseconds(450), [](auto) { _window_highlight_colour=!_window_highlight_colour;})
Blink the window highlight colour constantly.
LocalGetWindowPlacement
static Point LocalGetWindowPlacement(const WindowDesc *desc, int16_t sm_width, int16_t sm_height, int window_number)
Compute the position of the top-left corner of a new window that is opened.
Definition: window.cpp:1653
Window::querystrings
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:314
_windows_file
std::string _windows_file
Config file to store WindowDesc.
Definition: window.cpp:102
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:28
VA_EVERY_VIEWPORT
@ VA_EVERY_VIEWPORT
Scroll all viewports at their edges.
Definition: window.cpp:49
GuiShowTooltips
void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, uint paramcount)
Shows a tooltip.
Definition: misc_gui.cpp:758
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:619
Window::OnMouseLoop
virtual void OnMouseLoop()
Called for every mouse loop run, which is at least once per (game) tick.
Definition: window_gui.h:728
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
ResizeInfo::step_width
uint step_width
Step-size of width resize changes.
Definition: window_gui.h:207
VSM_MAP_LMB
@ VSM_MAP_LMB
Map moves with mouse movement on holding left mouse button, cursor moves.
Definition: settings_type.h:125
NWidgetCore::disp_flags
NWidgetDisplay disp_flags
Flags that affect display and interaction with the widget.
Definition: widget_type.h:376
MAX_OFFSET_DOUBLE_CLICK
@ MAX_OFFSET_DOUBLE_CLICK
How much the mouse is allowed to move to call it a double click.
Definition: window.cpp:2711
IniFile
Ini file that supports both loading and saving.
Definition: ini_type.h:88
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:557
Window::OnRealtimeTick
virtual void OnRealtimeTick([[maybe_unused]] uint delta_ms)
Called periodically.
Definition: window_gui.h:738
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:236
ST_RESIZE
@ ST_RESIZE
Resize the nested widget tree.
Definition: widget_type.h:119
WindowDesc::default_width_trad
int16_t default_width_trad
Preferred initial width of the window (pixels at 1x zoom).
Definition: window_gui.h:183
Blitter::MoveTo
virtual void * MoveTo(void *video, int x, int y)=0
Move the destination pointer the requested amount x and y, keeping in mind any pitch and bpp of the r...
DeleteAllMessages
void DeleteAllMessages()
Delete all messages and close their corresponding window (if any).
Definition: window.cpp:3278
ViewportAutoscrolling
ViewportAutoscrolling
Values for _settings_client.gui.auto_scrolling.
Definition: window.cpp:45
Window::closed_windows
static std::vector< Window * > closed_windows
List of closed windows to delete.
Definition: window_gui.h:269
Window::CloseChildWindows
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition: window.cpp:1036
UnshowCriticalError
void UnshowCriticalError()
Unshow the critical error.
Definition: error_gui.cpp:349
abs
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:23
VA_MAIN_VIEWPORT_FULLSCREEN
@ VA_MAIN_VIEWPORT_FULLSCREEN
Scroll main viewport at edge when using fullscreen.
Definition: window.cpp:47
WC_SCEN_LAND_GEN
@ WC_SCEN_LAND_GEN
Landscape generation (in Scenario Editor); Window numbers:
Definition: window_type.h:449
video_driver.hpp
DispatchHoverEvent
static void DispatchHoverEvent(Window *w, int x, int y)
Dispatch hover of the mouse over a window.
Definition: window.cpp:771
NO_DIRECTORY
@ NO_DIRECTORY
A path without any base directory.
Definition: fileio_type.h:126
WC_NETWORK_WINDOW
@ WC_NETWORK_WINDOW
Network window; Window numbers:
Definition: window_type.h:472
NWidgetScrollbar
Nested widget to display and control a scrollbar in a window.
Definition: widget_type.h:866
GUISettings::toolbar_pos
uint8_t toolbar_pos
position of toolbars, 0=left, 1=center, 2=right
Definition: settings_type.h:153
GetMainWindow
Window * GetMainWindow()
Get the main window, i.e.
Definition: window.cpp:1128
WC_CONSOLE
@ WC_CONSOLE
Console; Window numbers:
Definition: window_type.h:644
framerate_type.h
InvalidateWindowClassesData
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition: window.cpp:3221
Window::GetTextBoundingRect
virtual Rect GetTextBoundingRect(const char *from, const char *to) const
Get the bounding rectangle for a text range if an edit box has the focus.
Definition: window.cpp:395
HotkeyList::CheckMatch
int CheckMatch(uint16_t keycode, bool global_only=false) const
Check if a keycode is bound to something.
Definition: hotkeys.cpp:309
WC_NETWORK_STATUS_WINDOW
@ WC_NETWORK_STATUS_WINDOW
Network status window; Window numbers:
Definition: window_type.h:485
Window::OnInvalidateData
virtual void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true)
Some data on this window has become invalid.
Definition: window_gui.h:780
WC_TOOLTIPS
@ WC_TOOLTIPS
Tooltip window; Window numbers:
Definition: window_type.h:116
NWidgetCore::scrollbar_index
WidgetID scrollbar_index
Index of an attached scrollbar.
Definition: widget_type.h:381
_window_highlight_colour
bool _window_highlight_colour
If false, highlight is white, otherwise the by the widget defined colour.
Definition: window.cpp:75
Window::OnPaint
virtual void OnPaint()
The window must be repainted.
Definition: window_gui.h:593
CursorVars::delta
Point delta
relative mouse movement in this tick
Definition: gfx_type.h:118
NWidgetStacked::SetDisplayedPlane
bool SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1304
AutoRestoreBackup
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Definition: backup_type.hpp:153
IniSaveWindowSettings
void IniSaveWindowSettings(IniFile &ini, const char *grpname, void *desc)
Save a WindowDesc to config.
Definition: settings.cpp:889
NWidgetBase::resize_y
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:226
WC_COMPANY_INFRASTRUCTURE
@ WC_COMPANY_INFRASTRUCTURE
Company infrastructure overview; Window numbers:
Definition: window_type.h:582
HKPR_CANCEL
@ HKPR_CANCEL
Escape key pressed.
Definition: textbuf_type.h:25
VpHandlePlaceSizingDrag
EventState VpHandlePlaceSizingDrag()
Handle the mouse while dragging for placement/resizing.
Definition: viewport.cpp:3366
EventState
EventState
State of handling an event.
Definition: window_type.h:738
InitDepotWindowBlockSizes
void InitDepotWindowBlockSizes()
Set the size of the blocks in the window so we can be sure that they are big enough for the vehicle s...
Definition: depot_gui.cpp:218
WindowDesc::pref_sticky
bool pref_sticky
Preferred stickyness.
Definition: window_gui.h:172
Window::mouse_capture_widget
WidgetID mouse_capture_widget
ID of current mouse capture widget (e.g. dragged scrollbar). -1 if no widget has mouse capture.
Definition: window_gui.h:320
WF_DRAGGING
@ WF_DRAGGING
Window is being dragged.
Definition: window_gui.h:224
GUISettings::window_soft_limit
uint8_t window_soft_limit
soft limit of maximum number of non-stickied non-vital windows (0 = no limit)
Definition: settings_type.h:156
WC_NETWORK_ASK_RELAY
@ WC_NETWORK_ASK_RELAY
Network ask relay window; Window numbers:
Definition: window_type.h:491
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition: window.cpp:1114
progress.h
Window::window_class
WindowClass window_class
Window class.
Definition: window_gui.h:295
GUISettings::scrollwheel_scrolling
uint8_t scrollwheel_scrolling
scrolling using the scroll wheel?
Definition: settings_type.h:169
scrollamt
static const int8_t scrollamt[16][2]
Describes all the different arrow key combinations the game allows when it is in scrolling mode.
Definition: window.cpp:2736
Window::OnRightClick
virtual bool OnRightClick([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget)
A click with the right mouse button has been made on the window.
Definition: window_gui.h:673
WC_MAIN_WINDOW
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition: window_type.h:51
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
Window::widget_lookup
WidgetLookup widget_lookup
Indexed access to the nested widget tree. Do not access directly, use Window::GetWidget() instead.
Definition: window_gui.h:316
Window::OnDropdownSelect
virtual void OnDropdownSelect([[maybe_unused]] WidgetID widget, [[maybe_unused]] int index)
A dropdown option associated to this window has been selected.
Definition: window_gui.h:757
IsGoodAutoPlace1
static bool IsGoodAutoPlace1(int left, int top, int width, int height, int toolbar_y, Point &pos)
Decide whether a given rectangle is a good place to open a completely visible new window.
Definition: window.cpp:1485
UpdateViewportPosition
void UpdateViewportPosition(Window *w, uint32_t delta_ms)
Update the viewport position being displayed.
Definition: viewport.cpp:1910
DispatchLeftClickEvent
static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
Dispatch left mouse-button (possibly double) click in window.
Definition: window.cpp:608
WC_ENDSCREEN
@ WC_ENDSCREEN
Endscreen; Window numbers:
Definition: window_type.h:662
company_func.h
PreventHideDirection
PreventHideDirection
Direction for moving the window.
Definition: window.cpp:1934
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition: querystring_gui.h:24
Window::UpdateQueryStringSize
void UpdateQueryStringSize()
Update size of all QueryStrings of this window.
Definition: window.cpp:355
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:304
Vehicle::y_pos
int32_t y_pos
y coordinate.
Definition: vehicle_base.h:301
IsPtInWindowViewport
Viewport * IsPtInWindowViewport(const Window *w, int x, int y)
Is a xy position inside the viewport of the window?
Definition: viewport.cpp:408
Window::RaiseWidget
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition: window_gui.h:469
NWidgetCore::index
const WidgetID index
Index of the nested widget (-1 means 'not used').
Definition: widget_type.h:378
network.h
NWidgetBase::SetDirty
virtual void SetDirty(const Window *w) const
Mark the widget as 'dirty' (in need of repaint).
Definition: widget.cpp:903
ChangeWindowOwner
void ChangeWindowOwner(Owner old_owner, Owner new_owner)
Change the owner of all the windows one company can take over from another company in the case of a c...
Definition: window.cpp:1189
Window::OnHover
virtual void OnHover([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget)
The mouse is hovering over a widget in the window, perform an action for it.
Definition: window_gui.h:680
WC_SEND_NETWORK_MSG
@ WC_SEND_NETWORK_MSG
Chatbox; Window numbers:
Definition: window_type.h:503
ViewportData::follow_vehicle
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
Definition: window_gui.h:247
window_func.h
HandleActiveWidget
static EventState HandleActiveWidget()
Handle active widget (mouse draggin on widget) with the mouse.
Definition: window.cpp:2325
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:305
WindowDesc::LoadFromConfig
static void LoadFromConfig()
Load all WindowDesc settings from _windows_file.
Definition: window.cpp:156
Viewport::zoom
ZoomLevel zoom
The zoom level of the viewport.
Definition: viewport_type.h:33
DrawOverlappedWindowForAll
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
From a rectangle that needs redrawing, find the windows that intersect with the rectangle.
Definition: window.cpp:920
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1548
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:140
TileHighlightData::window_class
WindowClass window_class
The WindowClass of the window that is responsible for the selection mode.
Definition: tilehighlight_type.h:68
HandleMouseDragDrop
static EventState HandleMouseDragDrop()
Handle dragging and dropping in mouse dragging mode (WSM_DRAGDROP).
Definition: window.cpp:1884
GUISettings::window_snap_radius
uint8_t window_snap_radius
windows snap at each other if closer than this
Definition: settings_type.h:155
IConsoleClose
void IConsoleClose()
Close the in-game console.
Definition: console_gui.cpp:393
_drag_delta
static Point _drag_delta
delta between mouse cursor and upper left corner of dragged window
Definition: window.cpp:52
_dragging_window
static bool _dragging_window
A window is being dragged or resized.
Definition: window.cpp:2084
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:237
ND_SCROLLBAR_UP
@ ND_SCROLLBAR_UP
Bit value of the 'scrollbar up' flag.
Definition: widget_type.h:345
NetworkDrawChatMessage
void NetworkDrawChatMessage()
Draw the chat message-box.
Definition: network_chat_gui.cpp:181
Window::GetRowFromWidget
int GetRowFromWidget(int clickpos, WidgetID widget, int padding, int line_height=-1) const
Compute the row of a widget that a user clicked in.
Definition: window.cpp:214
timer_window.h
_window_descs
std::vector< WindowDesc * > * _window_descs
List of all WindowDescs.
Definition: window.cpp:99
Window::scale
int scale
Scale of this window – used to determine how to resize.
Definition: window_gui.h:298
Window::window_desc
WindowDesc * window_desc
Window description.
Definition: window_gui.h:293
console_gui.h
PerformanceAccumulator::Reset
static void Reset(PerformanceElement elem)
Store the previous accumulator value and reset for a new cycle of accumulating measurements.
Definition: framerate_gui.cpp:327
TileVirtXY
static debug_inline TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition: map_func.h:416
ResetWindowSystem
void ResetWindowSystem()
Reset the windowing system, by means of shutting it down followed by re-initialization.
Definition: window.cpp:1819
ZOOM_LVL_NORMAL
@ ZOOM_LVL_NORMAL
The normal zoom level.
Definition: zoom_type.h:22
HandleWindowDragging
static EventState HandleWindowDragging()
Handle dragging/resizing of a window.
Definition: window.cpp:2090
PositionNetworkChatWindow
int PositionNetworkChatWindow(Window *w)
(Re)position network chat window at the screen.
Definition: window.cpp:3407
VideoDriver::EditBoxLostFocus
virtual void EditBoxLostFocus()
An edit box lost the input focus.
Definition: video_driver.hpp:152
CloseAllNonVitalWindows
void CloseAllNonVitalWindows()
It is possible that a stickied window gets to a position where the 'close' button is outside the gami...
Definition: window.cpp:3265
WindowDesc::parent_cls
WindowClass parent_cls
Class of the parent window.
Definition: window_gui.h:165
Window
Data structure for an opened window.
Definition: window_gui.h:267
QueryString::ACTION_DESELECT
static const int ACTION_DESELECT
Deselect editbox.
Definition: querystring_gui.h:23
InputLoop
void InputLoop()
Regular call from the global game loop.
Definition: window.cpp:2978
WC_STATUS_BAR
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
Definition: window_type.h:64
WC_NEWS_WINDOW
@ WC_NEWS_WINDOW
News window; Window numbers:
Definition: window_type.h:248
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:79
CloseConstructionWindows
void CloseConstructionWindows()
Close all windows that are used for construction of vehicle etc.
Definition: window.cpp:3290
Window::OnMouseOver
virtual void OnMouseOver([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget)
The mouse is currently moving over the window or has just moved outside of the window.
Definition: window_gui.h:716
WC_FINANCES
@ WC_FINANCES
Finances of a company; Window numbers:
Definition: window_type.h:528
console_func.h
HKPR_NOT_HANDLED
@ HKPR_NOT_HANDLED
Key does not affect editboxes.
Definition: textbuf_type.h:26
WC_ERRMSG
@ WC_ERRMSG
Error message; Window numbers:
Definition: window_type.h:110
Window::SetWidgetHighlight
void SetWidgetHighlight(WidgetID widget_index, TextColour highlighted_colour)
Sets the highlighted status of a widget.
Definition: window.cpp:243
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:356
WC_SCRIPT_SETTINGS
@ WC_SCRIPT_SETTINGS
Script settings; Window numbers:
Definition: window_type.h:175
_last_scroll_window
static Window * _last_scroll_window
Window of the last scroll event.
Definition: window.cpp:54
WindowDesc::GetDefaultWidth
int16_t GetDefaultWidth() const
Determine default width of window.
Definition: window.cpp:138
NWidgetLeaf::closebox_dimension
static Dimension closebox_dimension
Cached size of a closebox widget.
Definition: widget_type.h:899
IniLoadFile::LoadFromDisk
void LoadFromDisk(const std::string &filename, Subdirectory subdir)
Load the Ini file's data from the disk.
Definition: ini_load.cpp:187
WC_SCRIPT_LIST
@ WC_SCRIPT_LIST
Scripts list; Window numbers:
Definition: window_type.h:284
GetMainViewBottom
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition: window.cpp:2078
CallWindowRealtimeTickEvent
void CallWindowRealtimeTickEvent(uint delta_ms)
Dispatch OnRealtimeTick event over all windows.
Definition: window.cpp:3003
WWT_DEBUGBOX
@ WWT_DEBUGBOX
NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX)
Definition: widget_type.h:65
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
CursorVars::pos
Point pos
logical mouse position
Definition: gfx_type.h:117
WC_DROPDOWN_MENU
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
Definition: window_type.h:156
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1224
_right_button_clicked
bool _right_button_clicked
Is right mouse button clicked?
Definition: gfx.cpp:43
IsLocalCompany
bool IsLocalCompany()
Is the current company the local company?
Definition: company_func.h:47
ScaleByZoom
int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
Definition: zoom_func.h:22
Window::HandleEditBoxKey
EventState HandleEditBoxKey(WidgetID wid, char32_t key, uint16_t keycode)
Process keypress for editbox widget.
Definition: window.cpp:2478
WC_MAIN_TOOLBAR
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers:
Definition: window_type.h:58
WC_SPRITE_ALIGNER
@ WC_SPRITE_ALIGNER
Sprite aligner (debug); Window numbers:
Definition: window_type.h:681
ClrBit
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
SetWindowClassesDirty
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3112
WindowDesc::nwid_begin
const NWidgetPart * nwid_begin
Beginning of nested widget parts describing the window.
Definition: window_gui.h:168
WC_AIRCRAFT_LIST
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers:
Definition: window_type.h:326
SetWindowWidgetDirty
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, WidgetID widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
Definition: window.cpp:3099
Window::OnResize
virtual void OnResize()
Called after the window got resized.
Definition: window_gui.h:750
CursorVars::in_window
bool in_window
mouse inside this window, determines drawing logic
Definition: gfx_type.h:141
CLRBITS
#define CLRBITS(x, y)
Clears several bits in a variable.
Definition: bitmath_func.hpp:166
ini_type.h
WC_TEXTFILE
@ WC_TEXTFILE
textfile; Window numbers:
Definition: window_type.h:187
WindowDesc::hotkeys
HotkeyList * hotkeys
Hotkeys for the window.
Definition: window_gui.h:170
WC_STATION_LIST
@ WC_STATION_LIST
Station list; Window numbers:
Definition: window_type.h:302
NWidgetStacked::shown_plane
int shown_plane
Plane being displayed (for NWID_SELECTION only).
Definition: widget_type.h:498
WindowPosition
WindowPosition
How do we the window to be placed?
Definition: window_gui.h:139
Window::OnClick
virtual void OnClick([[maybe_unused]] Point pt, [[maybe_unused]] WidgetID widget, [[maybe_unused]] int click_count)
A click with the left mouse button has been made on the window.
Definition: window_gui.h:664
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3483
_scrolling_viewport
bool _scrolling_viewport
A viewport is being scrolled with the mouse.
Definition: window.cpp:90
WC_SMALLMAP
@ WC_SMALLMAP
Small map; Window numbers:
Definition: window_type.h:104
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:142
_left_button_clicked
bool _left_button_clicked
Is left mouse button clicked?
Definition: gfx.cpp:41
MaybeBringWindowToFront
static bool MaybeBringWindowToFront(Window *w)
Check if a window can be made relative top-most window, and if so do it.
Definition: window.cpp:2418
Textbuf::DeleteAll
void DeleteAll()
Delete every character in the textbuffer.
Definition: textbuf.cpp:113
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
network_func.h
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
GUISettings::hover_delay_ms
uint16_t hover_delay_ms
time required to activate a hover event, in milliseconds
Definition: settings_type.h:141
EnsureVisibleCaption
static void EnsureVisibleCaption(Window *w, int nx, int ny)
Make sure at least a part of the caption bar is still visible by moving the window if necessary.
Definition: window.cpp:1989
GUISettings::right_click_wnd_close
RightClickClose right_click_wnd_close
close window with right click
Definition: settings_type.h:172
SetupWidgetDimensions
void SetupWidgetDimensions()
Set up pre-scaled versions of Widget Dimensions.
Definition: widget.cpp:66
_right_button_down
bool _right_button_down
Is right mouse button pressed?
Definition: gfx.cpp:42
Window::white_border_timer
uint8_t white_border_timer
Timer value of the WF_WHITE_BORDER for flags.
Definition: window_gui.h:301
Window::OnKeyPress
virtual EventState OnKeyPress([[maybe_unused]] char32_t key, [[maybe_unused]] uint16_t keycode)
A key has been pressed.
Definition: window_gui.h:646
ND_SCROLLBAR_BTN
@ ND_SCROLLBAR_BTN
Bit value of the 'scrollbar up' or 'scrollbar down' flag.
Definition: widget_type.h:347
PFE_DRAWWORLD
@ PFE_DRAWWORLD
Time spent drawing world viewports in GUI.
Definition: framerate_type.h:58
WC_VEHICLE_ORDERS
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
Definition: window_type.h:212
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:635
VideoDriver::EditBoxGainedFocus
virtual void EditBoxGainedFocus()
An edit box gained the input focus.
Definition: video_driver.hpp:157
Window::InitializeData
void InitializeData(WindowNumber window_number)
Initializes the data (except the position and initial size) of a new Window.
Definition: window.cpp:1365
TileHighlightData::selend
Point selend
The location where the drag currently ends.
Definition: tilehighlight_type.h:61
NWID_BUTTON_DROPDOWN
@ NWID_BUTTON_DROPDOWN
Button with a drop-down.
Definition: widget_type.h:84
HandleToolbarHotkey
void HandleToolbarHotkey(int hotkey)
Handle Toolbar hotkey events - can come from a source like the MacBook Touch Bar.
Definition: window.cpp:2550
VA_MAIN_VIEWPORT
@ VA_MAIN_VIEWPORT
Scroll main viewport at edge.
Definition: window.cpp:48
Scrollbar::SetPosition
bool SetPosition(int position)
Sets the position of the first visible element.
Definition: widget_type.h:792
TileHighlightData::GetCallbackWnd
Window * GetCallbackWnd()
Get the window that started the current highlighting.
Definition: viewport.cpp:2582
Window::FindChildWindow
Window * FindChildWindow(WindowClass wc=WC_INVALID) const
Find the Window whose parent pointer points to this window.
Definition: window.cpp:1023
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:151
HKPR_CURSOR
@ HKPR_CURSOR
Non-text change, e.g. cursor position.
Definition: textbuf_type.h:23
TileHighlightData::Reset
void Reset()
Reset tile highlighting.
Definition: viewport.cpp:2561
news_func.h
Window::FindWindowPlacementAndResize
virtual void FindWindowPlacementAndResize(int def_width, int def_height)
Resize window towards the default size.
Definition: window.cpp:1421
hotkeys.h
QueryString::ACTION_NOTHING
static const int ACTION_NOTHING
Nothing.
Definition: querystring_gui.h:22
MIN_VISIBLE_TITLE_BAR
static const int MIN_VISIBLE_TITLE_BAR
The minimum number of pixels of the title bar must be visible in both the X or Y direction.
Definition: window.cpp:1931
Textbuf
Helper/buffer for input fields.
Definition: textbuf_type.h:30
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66
Window::GetWidget
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition: window_gui.h:971
Window::ProcessScheduledResize
void ProcessScheduledResize()
Process scheduled OnResize() event.
Definition: window.cpp:3130
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103