OpenTTD Source: src/window.cpp Source File

OpenTTD Source 13.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 <stdarg.h>
12 #include "company_func.h"
13 #include "gfx_func.h"
14 #include "console_func.h"
15 #include "console_gui.h"
16 #include "viewport_func.h"
17 #include "progress.h"
18 #include "blitter/factory.hpp"
19 #include "zoom_func.h"
20 #include "vehicle_base.h"
21 #include "window_func.h"
22 #include "tilehighlight_func.h"
23 #include "network/network.h"
24 #include "querystring_gui.h"
25 #include "widgets/dropdown_func.h"
26 #include "strings_func.h"
27 #include "settings_type.h"
28 #include "settings_func.h"
29 #include "ini_type.h"
30 #include "newgrf_debug.h"
31 #include "hotkeys.h"
32 #include "toolbar_gui.h"
33 #include "statusbar_gui.h"
34 #include "error.h"
35 #include "game/game.hpp"
36 #include "video/video_driver.hpp"
37 #include "framerate_type.h"
38 #include "network/network_func.h"
39 #include "guitimer_func.h"
40 #include "news_func.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 static std::vector<WindowDesc*> *_window_descs = nullptr;
100
102 std::string _windows_file;
103
105 WindowDesc::WindowDesc(WindowPosition def_pos, const char *ini_key, int16 def_width_trad, int16 def_height_trad,
106 WindowClass window_class, WindowClass parent_class, uint32 flags,
107 const NWidgetPart *nwid_parts, int16 nwid_length, HotkeyList *hotkeys) :
108 default_pos(def_pos),
109 cls(window_class),
110 parent_cls(parent_class),
111 ini_key(ini_key),
112 flags(flags),
113 nwid_parts(nwid_parts),
114 nwid_length(nwid_length),
115 hotkeys(hotkeys),
116 pref_sticky(false),
117 pref_width(0),
118 pref_height(0),
119 default_width_trad(def_width_trad),
120 default_height_trad(def_height_trad)
121 {
122 if (_window_descs == nullptr) _window_descs = new std::vector<WindowDesc*>();
123 _window_descs->push_back(this);
124 }
125
126 WindowDesc::~WindowDesc()
127 {
128 _window_descs->erase(std::find(_window_descs->begin(), _window_descs->end(), this));
129 }
130
136 int16 WindowDesc::GetDefaultWidth() const
137 {
138 return this->pref_width != 0 ? this->pref_width : ScaleGUITrad(this->default_width_trad);
139 }
140
146 int16 WindowDesc::GetDefaultHeight() const
147 {
148 return this->pref_height != 0 ? this->pref_height : ScaleGUITrad(this->default_height_trad);
149 }
150
154 void WindowDesc::LoadFromConfig()
155 {
156 IniFile ini;
157 ini.LoadFromDisk(_windows_file, NO_DIRECTORY);
158 for (WindowDesc *wd : *_window_descs) {
159 if (wd->ini_key == nullptr) continue;
160 IniLoadWindowSettings(ini, wd->ini_key, wd);
161 }
162 }
163
167 static bool DescSorter(WindowDesc* const &a, WindowDesc* const &b)
168 {
169 if (a->ini_key != nullptr && b->ini_key != nullptr) return strcmp(a->ini_key, b->ini_key) < 0;
170 return a->ini_key != nullptr;
171 }
172
176 void WindowDesc::SaveToConfig()
177 {
178 /* Sort the stuff to get a nice ini file on first write */
179 std::sort(_window_descs->begin(), _window_descs->end(), DescSorter);
180
181 IniFile ini;
182 ini.LoadFromDisk(_windows_file, NO_DIRECTORY);
183 for (WindowDesc *wd : *_window_descs) {
184 if (wd->ini_key == nullptr) continue;
185 IniSaveWindowSettings(ini, wd->ini_key, wd);
186 }
187 ini.SaveToDisk(_windows_file);
188 }
189
193 void Window::ApplyDefaults()
194 {
195 if (this->nested_root != nullptr && this->nested_root->GetWidgetOfType(WWT_STICKYBOX) != nullptr) {
196 if (this->window_desc->pref_sticky) this->flags |= WF_STICKY;
197 } else {
198 /* There is no stickybox; clear the preference in case someone tried to be funny */
199 this->window_desc->pref_sticky = false;
200 }
201 }
202
212 int Window::GetRowFromWidget(int clickpos, int widget, int padding, int line_height) const
213 {
214 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(widget);
215 if (line_height < 0) line_height = wid->resize_y;
216 if (clickpos < (int)wid->pos_y + padding) return INT_MAX;
217 return (clickpos - (int)wid->pos_y - padding) / line_height;
218 }
219
223 void Window::DisableAllWidgetHighlight()
224 {
225 for (uint i = 0; i < this->nested_array_size; i++) {
226 NWidgetBase *nwid = this->GetWidget<NWidgetBase>(i);
227 if (nwid == nullptr) continue;
228
229 if (nwid->IsHighlighted()) {
230 nwid->SetHighlighted(TC_INVALID);
231 this->SetWidgetDirty(i);
232 }
233 }
234
235 CLRBITS(this->flags, WF_HIGHLIGHTED);
236 }
237
243 void Window::SetWidgetHighlight(byte widget_index, TextColour highlighted_colour)
244 {
245 assert(widget_index < this->nested_array_size);
246
247 NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget_index);
248 if (nwid == nullptr) return;
249
250 nwid->SetHighlighted(highlighted_colour);
251 this->SetWidgetDirty(widget_index);
252
253 if (highlighted_colour != TC_INVALID) {
254 /* If we set a highlight, the window has a highlight */
255 this->flags |= WF_HIGHLIGHTED;
256 } else {
257 /* If we disable a highlight, check all widgets if anyone still has a highlight */
258 bool valid = false;
259 for (uint i = 0; i < this->nested_array_size; i++) {
260 NWidgetBase *nwid = this->GetWidget<NWidgetBase>(i);
261 if (nwid == nullptr) continue;
262 if (!nwid->IsHighlighted()) continue;
263
264 valid = true;
265 }
266 /* If nobody has a highlight, disable the flag on the window */
267 if (!valid) CLRBITS(this->flags, WF_HIGHLIGHTED);
268 }
269 }
270
276 bool Window::IsWidgetHighlighted(byte widget_index) const
277 {
278 assert(widget_index < this->nested_array_size);
279
280 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget_index);
281 if (nwid == nullptr) return false;
282
283 return nwid->IsHighlighted();
284 }
285
293 void Window::OnDropdownClose(Point pt, int widget, int index, bool instant_close)
294 {
295 if (widget < 0) return;
296
297 if (instant_close) {
298 /* Send event for selected option if we're still
299 * on the parent button of the dropdown (behaviour of the dropdowns in the main toolbar). */
300 if (GetWidgetFromPos(this, pt.x, pt.y) == widget) {
301 this->OnDropdownSelect(widget, index);
302 }
303 }
304
305 /* Raise the dropdown button */
306 NWidgetCore *nwi2 = this->GetWidget<NWidgetCore>(widget);
307 if ((nwi2->type & WWT_MASK) == NWID_BUTTON_DROPDOWN) {
308 nwi2->disp_flags &= ~ND_DROPDOWN_ACTIVE;
309 } else {
310 this->RaiseWidget(widget);
311 }
312 this->SetWidgetDirty(widget);
313 }
314
320 const Scrollbar *Window::GetScrollbar(uint widnum) const
321 {
322 return this->GetWidget<NWidgetScrollbar>(widnum);
323 }
324
330 Scrollbar *Window::GetScrollbar(uint widnum)
331 {
332 return this->GetWidget<NWidgetScrollbar>(widnum);
333 }
334
340 const QueryString *Window::GetQueryString(uint widnum) const
341 {
342 auto query = this->querystrings.Find(widnum);
343 return query != this->querystrings.end() ? query->second : nullptr;
344 }
345
351 QueryString *Window::GetQueryString(uint widnum)
352 {
353 SmallMap<int, QueryString*>::Pair *query = this->querystrings.Find(widnum);
354 return query != this->querystrings.End() ? query->second : nullptr;
355 }
356
360 void Window::UpdateQueryStringSize()
361 {
362 for (auto &qs : this->querystrings)
363 {
364 qs.second->text.UpdateSize();
365 }
366 }
367
372 /* virtual */ const char *Window::GetFocusedText() const
373 {
374 if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) {
375 return this->GetQueryString(this->nested_focus->index)->GetText();
376 }
377
378 return nullptr;
379 }
380
385 /* virtual */ const char *Window::GetCaret() const
386 {
387 if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) {
388 return this->GetQueryString(this->nested_focus->index)->GetCaret();
389 }
390
391 return nullptr;
392 }
393
399 /* virtual */ const char *Window::GetMarkedText(size_t *length) const
400 {
401 if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) {
402 return this->GetQueryString(this->nested_focus->index)->GetMarkedText(length);
403 }
404
405 return nullptr;
406 }
407
412 /* virtual */ Point Window::GetCaretPosition() const
413 {
414 if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX && !this->querystrings.empty()) {
415 return this->GetQueryString(this->nested_focus->index)->GetCaretPosition(this, this->nested_focus->index);
416 }
417
418 Point pt = {0, 0};
419 return pt;
420 }
421
428 /* virtual */ Rect Window::GetTextBoundingRect(const char *from, const char *to) const
429 {
430 if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) {
431 return this->GetQueryString(this->nested_focus->index)->GetBoundingRect(this, this->nested_focus->index, from, to);
432 }
433
434 Rect r = {0, 0, 0, 0};
435 return r;
436 }
437
443 /* virtual */ const char *Window::GetTextCharacterAtPosition(const Point &pt) const
444 {
445 if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) {
446 return this->GetQueryString(this->nested_focus->index)->GetCharAtPosition(this, this->nested_focus->index, pt);
447 }
448
449 return nullptr;
450 }
451
456 void SetFocusedWindow(Window *w)
457 {
458 if (_focused_window == w) return;
459
460 /* Invalidate focused widget */
461 if (_focused_window != nullptr) {
462 if (_focused_window->nested_focus != nullptr) _focused_window->nested_focus->SetDirty(_focused_window);
463 }
464
465 /* Remember which window was previously focused */
466 Window *old_focused = _focused_window;
467 _focused_window = w;
468
469 /* So we can inform it that it lost focus */
470 if (old_focused != nullptr) old_focused->OnFocusLost();
471 if (_focused_window != nullptr) _focused_window->OnFocus();
472 }
473
479 bool EditBoxInGlobalFocus()
480 {
481 if (_focused_window == nullptr) return false;
482
483 /* The console does not have an edit box so a special case is needed. */
484 if (_focused_window->window_class == WC_CONSOLE) return true;
485
486 return _focused_window->nested_focus != nullptr && _focused_window->nested_focus->type == WWT_EDITBOX;
487 }
488
493 bool FocusedWindowIsConsole()
494 {
495 return _focused_window && _focused_window->window_class == WC_CONSOLE;
496 }
497
501 void Window::UnfocusFocusedWidget()
502 {
503 if (this->nested_focus != nullptr) {
504 if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus();
505
506 /* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */
507 this->nested_focus->SetDirty(this);
508 this->nested_focus = nullptr;
509 }
510 }
511
517 bool Window::SetFocusedWidget(int widget_index)
518 {
519 /* Do nothing if widget_index is already focused, or if it wasn't a valid widget. */
520 if ((uint)widget_index >= this->nested_array_size) return false;
521
522 assert(this->nested_array[widget_index] != nullptr); // Setting focus to a non-existing widget is a bad idea.
523 if (this->nested_focus != nullptr) {
524 if (this->GetWidget<NWidgetCore>(widget_index) == this->nested_focus) return false;
525
526 /* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */
527 this->nested_focus->SetDirty(this);
528 if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus();
529 }
530 this->nested_focus = this->GetWidget<NWidgetCore>(widget_index);
531 if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxGainedFocus();
532 return true;
533 }
534
538 void Window::OnFocus()
539 {
540 if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxGainedFocus();
541 }
542
546 void Window::OnFocusLost()
547 {
548 if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus();
549 }
550
558 void CDECL Window::SetWidgetsDisabledState(bool disab_stat, int widgets, ...)
559 {
560 va_list wdg_list;
561
562 va_start(wdg_list, widgets);
563
564 while (widgets != WIDGET_LIST_END) {
565 SetWidgetDisabledState(widgets, disab_stat);
566 widgets = va_arg(wdg_list, int);
567 }
568
569 va_end(wdg_list);
570 }
571
577 void CDECL Window::SetWidgetsLoweredState(bool lowered_stat, int widgets, ...)
578 {
579 va_list wdg_list;
580
581 va_start(wdg_list, widgets);
582
583 while (widgets != WIDGET_LIST_END) {
584 SetWidgetLoweredState(widgets, lowered_stat);
585 widgets = va_arg(wdg_list, int);
586 }
587
588 va_end(wdg_list);
589 }
590
595 void Window::RaiseButtons(bool autoraise)
596 {
597 for (uint i = 0; i < this->nested_array_size; i++) {
598 if (this->nested_array[i] == nullptr) continue;
599 WidgetType type = this->nested_array[i]->type;
600 if (((type & ~WWB_PUSHBUTTON) < WWT_LAST || type == NWID_PUSHBUTTON_DROPDOWN) &&
601 (!autoraise || (type & WWB_PUSHBUTTON) || type == WWT_EDITBOX) && this->IsWidgetLowered(i)) {
602 this->RaiseWidget(i);
603 this->SetWidgetDirty(i);
604 }
605 }
606
607 /* Special widgets without widget index */
608 NWidgetCore *wid = this->nested_root != nullptr ? (NWidgetCore*)this->nested_root->GetWidgetOfType(WWT_DEFSIZEBOX) : nullptr;
609 if (wid != nullptr) {
610 wid->SetLowered(false);
611 wid->SetDirty(this);
612 }
613 }
614
619 void Window::SetWidgetDirty(byte widget_index) const
620 {
621 /* Sometimes this function is called before the window is even fully initialized */
622 if (this->nested_array == nullptr) return;
623
624 this->nested_array[widget_index]->SetDirty(this);
625 }
626
632 EventState Window::OnHotkey(int hotkey)
633 {
634 if (hotkey < 0) return ES_NOT_HANDLED;
635
636 NWidgetCore *nw = this->GetWidget<NWidgetCore>(hotkey);
637 if (nw == nullptr || nw->IsDisabled()) return ES_NOT_HANDLED;
638
639 if (nw->type == WWT_EDITBOX) {
640 if (this->IsShaded()) return ES_NOT_HANDLED;
641
642 /* Focus editbox */
643 this->SetFocusedWidget(hotkey);
644 SetFocusedWindow(this);
645 } else {
646 /* Click button */
647 this->OnClick(Point(), hotkey, 1);
648 }
649 return ES_HANDLED;
650 }
651
657 void Window::HandleButtonClick(byte widget)
658 {
659 this->LowerWidget(widget);
660 this->SetTimeout();
661 this->SetWidgetDirty(widget);
662 }
663
664 static void StartWindowDrag(Window *w);
665 static void StartWindowSizing(Window *w, bool to_left);
666
674 static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
675 {
676 NWidgetCore *nw = w->nested_root->GetWidgetFromPos(x, y);
677 WidgetType widget_type = (nw != nullptr) ? nw->type : WWT_EMPTY;
678
679 bool focused_widget_changed = false;
680 /* If clicked on a window that previously did not have focus */
681 if (_focused_window != w && // We already have focus, right?
682 (w->window_desc->flags & WDF_NO_FOCUS) == 0 && // Don't lose focus to toolbars
683 widget_type != WWT_CLOSEBOX) { // Don't change focused window if 'X' (close button) was clicked
684 focused_widget_changed = true;
685 SetFocusedWindow(w);
686 }
687
688 if (nw == nullptr) return; // exit if clicked outside of widgets
689
690 /* don't allow any interaction if the button has been disabled */
691 if (nw->IsDisabled()) return;
692
693 int widget_index = nw->index;
694
695 /* Clicked on a widget that is not disabled.
696 * So unless the clicked widget is the caption bar, change focus to this widget.
697 * Exception: In the OSK we always want the editbox to stay focused. */
698 if (widget_type != WWT_CAPTION && w->window_class != WC_OSK) {
699 /* focused_widget_changed is 'now' only true if the window this widget
700 * is in gained focus. In that case it must remain true, also if the
701 * local widget focus did not change. As such it's the logical-or of
702 * both changed states.
703 *
704 * If this is not preserved, then the OSK window would be opened when
705 * a user has the edit box focused and then click on another window and
706 * then back again on the edit box (to type some text).
707 */
708 focused_widget_changed |= w->SetFocusedWidget(widget_index);
709 }
710
711 /* Close any child drop down menus. If the button pressed was the drop down
712 * list's own button, then we should not process the click any further. */
713 if (HideDropDownMenu(w) == widget_index && widget_index >= 0) return;
714
715 if ((widget_type & ~WWB_PUSHBUTTON) < WWT_LAST && (widget_type & WWB_PUSHBUTTON)) w->HandleButtonClick(widget_index);
716
717 Point pt = { x, y };
718
719 switch (widget_type) {
720 case NWID_VSCROLLBAR:
721 case NWID_HSCROLLBAR:
722 ScrollbarClickHandler(w, nw, x, y);
723 break;
724
725 case WWT_EDITBOX: {
726 QueryString *query = w->GetQueryString(widget_index);
727 if (query != nullptr) query->ClickEditBox(w, pt, widget_index, click_count, focused_widget_changed);
728 break;
729 }
730
731 case WWT_CLOSEBOX: // 'X'
732 w->Close();
733 return;
734
735 case WWT_CAPTION: // 'Title bar'
736 StartWindowDrag(w);
737 return;
738
739 case WWT_RESIZEBOX:
740 /* When the resize widget is on the left size of the window
741 * we assume that that button is used to resize to the left. */
742 StartWindowSizing(w, (int)nw->pos_x < (w->width / 2));
743 nw->SetDirty(w);
744 return;
745
746 case WWT_DEFSIZEBOX: {
747 if (_ctrl_pressed) {
748 w->window_desc->pref_width = w->width;
749 w->window_desc->pref_height = w->height;
750 } else {
751 int16 def_width = std::max<int16>(std::min<int16>(w->window_desc->GetDefaultWidth(), _screen.width), w->nested_root->smallest_x);
752 int16 def_height = std::max<int16>(std::min<int16>(w->window_desc->GetDefaultHeight(), _screen.height - 50), w->nested_root->smallest_y);
753
754 int dx = (w->resize.step_width == 0) ? 0 : def_width - w->width;
755 int dy = (w->resize.step_height == 0) ? 0 : def_height - w->height;
756 /* dx and dy has to go by step.. calculate it.
757 * The cast to int is necessary else dx/dy are implicitly casted to unsigned int, which won't work. */
758 if (w->resize.step_width > 1) dx -= dx % (int)w->resize.step_width;
759 if (w->resize.step_height > 1) dy -= dy % (int)w->resize.step_height;
760 ResizeWindow(w, dx, dy, false);
761 }
762
763 nw->SetLowered(true);
764 nw->SetDirty(w);
765 w->SetTimeout();
766 break;
767 }
768
769 case WWT_DEBUGBOX:
770 w->ShowNewGRFInspectWindow();
771 break;
772
773 case WWT_SHADEBOX:
774 nw->SetDirty(w);
775 w->SetShaded(!w->IsShaded());
776 return;
777
778 case WWT_STICKYBOX:
779 w->flags ^= WF_STICKY;
780 nw->SetDirty(w);
781 if (_ctrl_pressed) w->window_desc->pref_sticky = (w->flags & WF_STICKY) != 0;
782 return;
783
784 default:
785 break;
786 }
787
788 /* Widget has no index, so the window is not interested in it. */
789 if (widget_index < 0) return;
790
791 /* Check if the widget is highlighted; if so, disable highlight and dispatch an event to the GameScript */
792 if (w->IsWidgetHighlighted(widget_index)) {
793 w->SetWidgetHighlight(widget_index, TC_INVALID);
794 Game::NewEvent(new ScriptEventWindowWidgetClick((ScriptWindow::WindowClass)w->window_class, w->window_number, widget_index));
795 }
796
797 w->OnClick(pt, widget_index, click_count);
798 }
799
806 static void DispatchRightClickEvent(Window *w, int x, int y)
807 {
808 NWidgetCore *wid = w->nested_root->GetWidgetFromPos(x, y);
809 if (wid == nullptr) return;
810
811 Point pt = { x, y };
812
813 /* No widget to handle, or the window is not interested in it. */
814 if (wid->index >= 0) {
815 if (w->OnRightClick(pt, wid->index)) return;
816 }
817
818 /* Right-click close is enabled and there is a closebox */
819 if (_settings_client.gui.right_mouse_wnd_close && w->nested_root->GetWidgetOfType(WWT_CLOSEBOX)) {
820 w->Close();
821 } else if (_settings_client.gui.hover_delay_ms == 0 && !w->OnTooltip(pt, wid->index, TCC_RIGHT_CLICK) && wid->tool_tip != 0) {
822 GuiShowTooltips(w, wid->tool_tip, 0, nullptr, TCC_RIGHT_CLICK);
823 }
824 }
825
832 static void DispatchHoverEvent(Window *w, int x, int y)
833 {
834 NWidgetCore *wid = w->nested_root->GetWidgetFromPos(x, y);
835
836 /* No widget to handle */
837 if (wid == nullptr) return;
838
839 Point pt = { x, y };
840
841 /* Show the tooltip if there is any */
842 if (!w->OnTooltip(pt, wid->index, TCC_HOVER) && wid->tool_tip != 0) {
843 GuiShowTooltips(w, wid->tool_tip);
844 return;
845 }
846
847 /* Widget has no index, so the window is not interested in it. */
848 if (wid->index < 0) return;
849
850 w->OnHover(pt, wid->index);
851 }
852
860 static void DispatchMouseWheelEvent(Window *w, NWidgetCore *nwid, int wheel)
861 {
862 if (nwid == nullptr) return;
863
864 /* Using wheel on caption/shade-box shades or unshades the window. */
865 if (nwid->type == WWT_CAPTION || nwid->type == WWT_SHADEBOX) {
866 w->SetShaded(wheel < 0);
867 return;
868 }
869
870 /* Wheeling a vertical scrollbar. */
871 if (nwid->type == NWID_VSCROLLBAR) {
872 NWidgetScrollbar *sb = static_cast<NWidgetScrollbar *>(nwid);
873 if (sb->GetCount() > sb->GetCapacity()) {
874 if (sb->UpdatePosition(wheel)) w->SetDirty();
875 }
876 return;
877 }
878
879 /* Scroll the widget attached to the scrollbar. */
880 Scrollbar *sb = (nwid->scrollbar_index >= 0 ? w->GetScrollbar(nwid->scrollbar_index) : nullptr);
881 if (sb != nullptr && sb->GetCount() > sb->GetCapacity()) {
882 if (sb->UpdatePosition(wheel)) w->SetDirty();
883 }
884 }
885
891 static bool MayBeShown(const Window *w)
892 {
893 /* If we're not modal, everything is okay. */
894 if (!HasModalProgress()) return true;
895
896 switch (w->window_class) {
897 case WC_MAIN_WINDOW:
898 case WC_MODAL_PROGRESS:
899 case WC_CONFIRM_POPUP_QUERY:
900 return true;
901
902 default:
903 return false;
904 }
905 }
906
919 static void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom)
920 {
921 Window::IteratorToFront it(w);
922 ++it;
923 for (; !it.IsEnd(); ++it) {
924 const Window *v = *it;
925 if (MayBeShown(v) &&
926 right > v->left &&
927 bottom > v->top &&
928 left < v->left + v->width &&
929 top < v->top + v->height) {
930 /* v and rectangle intersect with each other */
931 int x;
932
933 if (left < (x = v->left)) {
934 DrawOverlappedWindow(w, left, top, x, bottom);
935 DrawOverlappedWindow(w, x, top, right, bottom);
936 return;
937 }
938
939 if (right > (x = v->left + v->width)) {
940 DrawOverlappedWindow(w, left, top, x, bottom);
941 DrawOverlappedWindow(w, x, top, right, bottom);
942 return;
943 }
944
945 if (top < (x = v->top)) {
946 DrawOverlappedWindow(w, left, top, right, x);
947 DrawOverlappedWindow(w, left, x, right, bottom);
948 return;
949 }
950
951 if (bottom > (x = v->top + v->height)) {
952 DrawOverlappedWindow(w, left, top, right, x);
953 DrawOverlappedWindow(w, left, x, right, bottom);
954 return;
955 }
956
957 return;
958 }
959 }
960
961 /* Setup blitter, and dispatch a repaint event to window *wz */
962 DrawPixelInfo *dp = _cur_dpi;
963 dp->width = right - left;
964 dp->height = bottom - top;
965 dp->left = left - w->left;
966 dp->top = top - w->top;
967 dp->pitch = _screen.pitch;
968 dp->dst_ptr = BlitterFactory::GetCurrentBlitter()->MoveTo(_screen.dst_ptr, left, top);
969 dp->zoom = ZOOM_LVL_NORMAL;
970 w->OnPaint();
971 }
972
981 void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
982 {
983 DrawPixelInfo *old_dpi = _cur_dpi;
984 DrawPixelInfo bk;
985 _cur_dpi = &bk;
986
987 for (Window *w : Window::IterateFromBack()) {
988 if (MayBeShown(w) &&
989 right > w->left &&
990 bottom > w->top &&
991 left < w->left + w->width &&
992 top < w->top + w->height) {
993 /* Window w intersects with the rectangle => needs repaint */
994 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));
995 }
996 }
997 _cur_dpi = old_dpi;
998 }
999
1004 void Window::SetDirty() const
1005 {
1006 AddDirtyBlock(this->left, this->top, this->left + this->width, this->top + this->height);
1007 }
1008
1015 void Window::ReInit(int rx, int ry)
1016 {
1017 this->SetDirty(); // Mark whole current window as dirty.
1018
1019 /* Save current size. */
1020 int window_width = this->width;
1021 int window_height = this->height;
1022
1023 this->OnInit();
1024 /* Re-initialize the window from the ground up. No need to change the nested_array, as all widgets stay where they are. */
1025 this->nested_root->SetupSmallestSize(this, false);
1026 this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, _current_text_dir == TD_RTL);
1027 this->width = this->nested_root->smallest_x;
1028 this->height = this->nested_root->smallest_y;
1029 this->resize.step_width = this->nested_root->resize_x;
1030 this->resize.step_height = this->nested_root->resize_y;
1031
1032 /* Resize as close to the original size + requested resize as possible. */
1033 window_width = std::max(window_width + rx, this->width);
1034 window_height = std::max(window_height + ry, this->height);
1035 int dx = (this->resize.step_width == 0) ? 0 : window_width - this->width;
1036 int dy = (this->resize.step_height == 0) ? 0 : window_height - this->height;
1037 /* dx and dy has to go by step.. calculate it.
1038 * The cast to int is necessary else dx/dy are implicitly casted to unsigned int, which won't work. */
1039 if (this->resize.step_width > 1) dx -= dx % (int)this->resize.step_width;
1040 if (this->resize.step_height > 1) dy -= dy % (int)this->resize.step_height;
1041
1042 ResizeWindow(this, dx, dy);
1043 /* ResizeWindow() does this->SetDirty() already, no need to do it again here. */
1044 }
1045
1051 void Window::SetShaded(bool make_shaded)
1052 {
1053 if (this->shade_select == nullptr) return;
1054
1055 int desired = make_shaded ? SZSP_HORIZONTAL : 0;
1056 if (this->shade_select->shown_plane != desired) {
1057 if (make_shaded) {
1058 if (this->nested_focus != nullptr) this->UnfocusFocusedWidget();
1059 this->unshaded_size.width = this->width;
1060 this->unshaded_size.height = this->height;
1061 this->shade_select->SetDisplayedPlane(desired);
1062 this->ReInit(0, -this->height);
1063 } else {
1064 this->shade_select->SetDisplayedPlane(desired);
1065 int dx = ((int)this->unshaded_size.width > this->width) ? (int)this->unshaded_size.width - this->width : 0;
1066 int dy = ((int)this->unshaded_size.height > this->height) ? (int)this->unshaded_size.height - this->height : 0;
1067 this->ReInit(dx, dy);
1068 }
1069 }
1070 }
1071
1078 static Window *FindChildWindow(const Window *w, WindowClass wc)
1079 {
1080 for (Window *v : Window::Iterate()) {
1081 if ((wc == WC_INVALID || wc == v->window_class) && v->parent == w) return v;
1082 }
1083
1084 return nullptr;
1085 }
1086
1091 void Window::CloseChildWindows(WindowClass wc) const
1092 {
1093 Window *child = FindChildWindow(this, wc);
1094 while (child != nullptr) {
1095 child->Close();
1096 child = FindChildWindow(this, wc);
1097 }
1098 }
1099
1103 void Window::Close()
1104 {
1105 /* Don't close twice. */
1106 if (*this->z_position == nullptr) return;
1107
1108 *this->z_position = nullptr;
1109
1110 if (_thd.window_class == this->window_class &&
1111 _thd.window_number == this->window_number) {
1112 ResetObjectToPlace();
1113 }
1114
1115 /* Prevent Mouseover() from resetting mouse-over coordinates on a non-existing window */
1116 if (_mouseover_last_w == this) _mouseover_last_w = nullptr;
1117
1118 /* We can't scroll the window when it's closed. */
1119 if (_last_scroll_window == this) _last_scroll_window = nullptr;
1120
1121 /* Make sure we don't try to access non-existing query strings. */
1122 this->querystrings.clear();
1123
1124 /* Make sure we don't try to access this window as the focused window when it doesn't exist anymore. */
1125 if (_focused_window == this) {
1126 this->OnFocusLost();
1127 _focused_window = nullptr;
1128 }
1129
1130 this->CloseChildWindows();
1131
1132 this->SetDirty();
1133
1134 Window::closed_windows.push_back(this);
1135 }
1136
1140 Window::~Window()
1141 {
1142 /* Make sure the window is closed, deletion is allowed only in Window::DeleteClosedWindows(). */
1143 assert(*this->z_position == nullptr);
1144
1145 if (this->viewport != nullptr) DeleteWindowViewport(this);
1146
1147 free(this->nested_array); // Contents is released through deletion of #nested_root.
1148 delete this->nested_root;
1149 }
1150
1157 Window *FindWindowById(WindowClass cls, WindowNumber number)
1158 {
1159 for (Window *w : Window::Iterate()) {
1160 if (w->window_class == cls && w->window_number == number) return w;
1161 }
1162
1163 return nullptr;
1164 }
1165
1172 Window *FindWindowByClass(WindowClass cls)
1173 {
1174 for (Window *w : Window::Iterate()) {
1175 if (w->window_class == cls) return w;
1176 }
1177
1178 return nullptr;
1179 }
1180
1187 void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
1188 {
1189 Window *w = FindWindowById(cls, number);
1190 if (w != nullptr && (force || (w->flags & WF_STICKY) == 0)) {
1191 w->Close();
1192 }
1193 }
1194
1199 void CloseWindowByClass(WindowClass cls)
1200 {
1201 /* Note: the container remains stable, even when deleting windows. */
1202 for (Window *w : Window::Iterate()) {
1203 if (w->window_class == cls) {
1204 w->Close();
1205 }
1206 }
1207 }
1208
1215 void CloseCompanyWindows(CompanyID id)
1216 {
1217 /* Note: the container remains stable, even when deleting windows. */
1218 for (Window *w : Window::Iterate()) {
1219 if (w->owner == id) {
1220 w->Close();
1221 }
1222 }
1223
1224 /* Also delete the company specific windows that don't have a company-colour. */
1225 CloseWindowById(WC_BUY_COMPANY, id);
1226 }
1227
1235 void ChangeWindowOwner(Owner old_owner, Owner new_owner)
1236 {
1237 for (Window *w : Window::Iterate()) {
1238 if (w->owner != old_owner) continue;
1239
1240 switch (w->window_class) {
1241 case WC_COMPANY_COLOUR:
1242 case WC_FINANCES:
1243 case WC_STATION_LIST:
1244 case WC_TRAINS_LIST:
1245 case WC_ROADVEH_LIST:
1246 case WC_SHIPS_LIST:
1247 case WC_AIRCRAFT_LIST:
1248 case WC_BUY_COMPANY:
1249 case WC_COMPANY:
1250 case WC_COMPANY_INFRASTRUCTURE:
1251 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().
1252 continue;
1253
1254 default:
1255 w->owner = new_owner;
1256 break;
1257 }
1258 }
1259 }
1260
1261 static void BringWindowToFront(Window *w, bool dirty = true);
1262
1270 Window *BringWindowToFrontById(WindowClass cls, WindowNumber number)
1271 {
1272 Window *w = FindWindowById(cls, number);
1273
1274 if (w != nullptr) {
1275 if (w->IsShaded()) w->SetShaded(false); // Restore original window size if it was shaded.
1276
1277 w->SetWhiteBorder();
1278 BringWindowToFront(w);
1279 w->SetDirty();
1280 }
1281
1282 return w;
1283 }
1284
1285 static inline bool IsVitalWindow(const Window *w)
1286 {
1287 switch (w->window_class) {
1288 case WC_MAIN_TOOLBAR:
1289 case WC_STATUS_BAR:
1290 case WC_NEWS_WINDOW:
1291 case WC_SEND_NETWORK_MSG:
1292 return true;
1293
1294 default:
1295 return false;
1296 }
1297 }
1298
1307 static uint GetWindowZPriority(WindowClass wc)
1308 {
1309 assert(wc != WC_INVALID);
1310
1311 uint z_priority = 0;
1312
1313 switch (wc) {
1314 case WC_ENDSCREEN:
1315 ++z_priority;
1316 FALLTHROUGH;
1317
1318 case WC_HIGHSCORE:
1319 ++z_priority;
1320 FALLTHROUGH;
1321
1322 case WC_TOOLTIPS:
1323 ++z_priority;
1324 FALLTHROUGH;
1325
1326 case WC_DROPDOWN_MENU:
1327 ++z_priority;
1328 FALLTHROUGH;
1329
1330 case WC_MAIN_TOOLBAR:
1331 case WC_STATUS_BAR:
1332 ++z_priority;
1333 FALLTHROUGH;
1334
1335 case WC_OSK:
1336 ++z_priority;
1337 FALLTHROUGH;
1338
1339 case WC_QUERY_STRING:
1340 case WC_SEND_NETWORK_MSG:
1341 ++z_priority;
1342 FALLTHROUGH;
1343
1344 case WC_ERRMSG:
1345 case WC_CONFIRM_POPUP_QUERY:
1346 case WC_NETWORK_ASK_RELAY:
1347 case WC_MODAL_PROGRESS:
1348 case WC_NETWORK_STATUS_WINDOW:
1349 case WC_SAVE_PRESET:
1350 ++z_priority;
1351 FALLTHROUGH;
1352
1353 case WC_GENERATE_LANDSCAPE:
1354 case WC_SAVELOAD:
1355 case WC_GAME_OPTIONS:
1356 case WC_CUSTOM_CURRENCY:
1357 case WC_NETWORK_WINDOW:
1358 case WC_GRF_PARAMETERS:
1359 case WC_AI_LIST:
1360 case WC_AI_SETTINGS:
1361 case WC_TEXTFILE:
1362 ++z_priority;
1363 FALLTHROUGH;
1364
1365 case WC_CONSOLE:
1366 ++z_priority;
1367 FALLTHROUGH;
1368
1369 case WC_NEWS_WINDOW:
1370 ++z_priority;
1371 FALLTHROUGH;
1372
1373 default:
1374 ++z_priority;
1375 FALLTHROUGH;
1376
1377 case WC_MAIN_WINDOW:
1378 return z_priority;
1379 }
1380 }
1381
1388 static void BringWindowToFront(Window *w, bool dirty)
1389 {
1390 auto priority = GetWindowZPriority(w->window_class);
1391 WindowList::iterator dest = _z_windows.begin();
1392 while (dest != _z_windows.end() && (*dest == nullptr || GetWindowZPriority((*dest)->window_class) <= priority)) ++dest;
1393
1394 if (dest != w->z_position) {
1395 _z_windows.splice(dest, _z_windows, w->z_position);
1396 }
1397
1398 if (dirty) w->SetDirty();
1399 }
1400
1408 void Window::InitializeData(WindowNumber window_number)
1409 {
1410 /* Set up window properties; some of them are needed to set up smallest size below */
1411 this->window_class = this->window_desc->cls;
1412 this->SetWhiteBorder();
1413 if (this->window_desc->default_pos == WDP_CENTER) this->flags |= WF_CENTERED;
1414 this->owner = INVALID_OWNER;
1415 this->nested_focus = nullptr;
1416 this->window_number = window_number;
1417
1418 this->OnInit();
1419 /* Initialize nested widget tree. */
1420 if (this->nested_array == nullptr) {
1421 this->nested_array = CallocT<NWidgetBase *>(this->nested_array_size);
1422 this->nested_root->SetupSmallestSize(this, true);
1423 } else {
1424 this->nested_root->SetupSmallestSize(this, false);
1425 }
1426 /* Initialize to smallest size. */
1427 this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, _current_text_dir == TD_RTL);
1428
1429 /* Further set up window properties,
1430 * this->left, this->top, this->width, this->height, this->resize.width, and this->resize.height are initialized later. */
1431 this->resize.step_width = this->nested_root->resize_x;
1432 this->resize.step_height = this->nested_root->resize_y;
1433
1434 /* Give focus to the opened window unless a text box
1435 * of focused window has focus (so we don't interrupt typing). But if the new
1436 * window has a text box, then take focus anyway. */
1437 if (!EditBoxInGlobalFocus() || this->nested_root->GetWidgetOfType(WWT_EDITBOX) != nullptr) SetFocusedWindow(this);
1438
1439 /* Insert the window into the correct location in the z-ordering. */
1440 BringWindowToFront(this, false);
1441 }
1442
1450 void Window::InitializePositionSize(int x, int y, int sm_width, int sm_height)
1451 {
1452 this->left = x;
1453 this->top = y;
1454 this->width = sm_width;
1455 this->height = sm_height;
1456 }
1457
1468 void Window::FindWindowPlacementAndResize(int def_width, int def_height)
1469 {
1470 def_width = std::max(def_width, this->width); // Don't allow default size to be smaller than smallest size
1471 def_height = std::max(def_height, this->height);
1472 /* Try to make windows smaller when our window is too small.
1473 * w->(width|height) is normally the same as min_(width|height),
1474 * but this way the GUIs can be made a little more dynamic;
1475 * one can use the same spec for multiple windows and those
1476 * can then determine the real minimum size of the window. */
1477 if (this->width != def_width || this->height != def_height) {
1478 /* Think about the overlapping toolbars when determining the minimum window size */
1479 int free_height = _screen.height;
1480 const Window *wt = FindWindowById(WC_STATUS_BAR, 0);
1481 if (wt != nullptr) free_height -= wt->height;
1482 wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
1483 if (wt != nullptr) free_height -= wt->height;
1484
1485 int enlarge_x = std::max(std::min(def_width - this->width, _screen.width - this->width), 0);
1486 int enlarge_y = std::max(std::min(def_height - this->height, free_height - this->height), 0);
1487
1488 /* X and Y has to go by step.. calculate it.
1489 * The cast to int is necessary else x/y are implicitly casted to
1490 * unsigned int, which won't work. */
1491 if (this->resize.step_width > 1) enlarge_x -= enlarge_x % (int)this->resize.step_width;
1492 if (this->resize.step_height > 1) enlarge_y -= enlarge_y % (int)this->resize.step_height;
1493
1494 ResizeWindow(this, enlarge_x, enlarge_y);
1495 /* ResizeWindow() calls this->OnResize(). */
1496 } else {
1497 /* Always call OnResize; that way the scrollbars and matrices get initialized. */
1498 this->OnResize();
1499 }
1500
1501 int nx = this->left;
1502 int ny = this->top;
1503
1504 if (nx + this->width > _screen.width) nx -= (nx + this->width - _screen.width);
1505
1506 const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
1507 ny = std::max(ny, (wt == nullptr || this == wt || this->top == 0) ? 0 : wt->height);
1508 nx = std::max(nx, 0);
1509
1510 if (this->viewport != nullptr) {
1511 this->viewport->left += nx - this->left;
1512 this->viewport->top += ny - this->top;
1513 }
1514 this->left = nx;
1515 this->top = ny;
1516
1517 this->SetDirty();
1518 }
1519
1532 static bool IsGoodAutoPlace1(int left, int top, int width, int height, int toolbar_y, Point &pos)
1533 {
1534 int right = width + left;
1535 int bottom = height + top;
1536
1537 if (left < 0 || top < toolbar_y || right > _screen.width || bottom > _screen.height) return false;
1538
1539 /* Make sure it is not obscured by any window. */
1540 for (const Window *w : Window::Iterate()) {
1541 if (w->window_class == WC_MAIN_WINDOW) continue;
1542
1543 if (right > w->left &&
1544 w->left + w->width > left &&
1545 bottom > w->top &&
1546 w->top + w->height > top) {
1547 return false;
1548 }
1549 }
1550
1551 pos.x = left;
1552 pos.y = top;
1553 return true;
1554 }
1555
1568 static bool IsGoodAutoPlace2(int left, int top, int width, int height, int toolbar_y, Point &pos)
1569 {
1570 bool rtl = _current_text_dir == TD_RTL;
1571
1572 /* Left part of the rectangle may be at most 1/4 off-screen,
1573 * right part of the rectangle may be at most 1/2 off-screen
1574 */
1575 if (rtl) {
1576 if (left < -(width >> 1) || left > _screen.width - (width >> 2)) return false;
1577 } else {
1578 if (left < -(width >> 2) || left > _screen.width - (width >> 1)) return false;
1579 }
1580
1581 /* Bottom part of the rectangle may be at most 1/4 off-screen */
1582 if (top < toolbar_y || top > _screen.height - (height >> 2)) return false;
1583
1584 /* Make sure it is not obscured by any window. */
1585 for (const Window *w : Window::Iterate()) {
1586 if (w->window_class == WC_MAIN_WINDOW) continue;
1587
1588 if (left + width > w->left &&
1589 w->left + w->width > left &&
1590 top + height > w->top &&
1591 w->top + w->height > top) {
1592 return false;
1593 }
1594 }
1595
1596 pos.x = left;
1597 pos.y = top;
1598 return true;
1599 }
1600
1607 static Point GetAutoPlacePosition(int width, int height)
1608 {
1609 Point pt;
1610
1611 bool rtl = _current_text_dir == TD_RTL;
1612
1613 /* First attempt, try top-left of the screen */
1614 const Window *main_toolbar = FindWindowByClass(WC_MAIN_TOOLBAR);
1615 const int toolbar_y = main_toolbar != nullptr ? main_toolbar->height : 0;
1616 if (IsGoodAutoPlace1(rtl ? _screen.width - width : 0, toolbar_y, width, height, toolbar_y, pt)) return pt;
1617
1618 /* Second attempt, try around all existing windows.
1619 * The new window must be entirely on-screen, and not overlap with an existing window.
1620 * Eight starting points are tried, two at each corner.
1621 */
1622 for (const Window *w : Window::Iterate()) {
1623 if (w->window_class == WC_MAIN_WINDOW) continue;
1624
1625 if (IsGoodAutoPlace1(w->left + w->width, w->top, width, height, toolbar_y, pt)) return pt;
1626 if (IsGoodAutoPlace1(w->left - width, w->top, width, height, toolbar_y, pt)) return pt;
1627 if (IsGoodAutoPlace1(w->left, w->top + w->height, width, height, toolbar_y, pt)) return pt;
1628 if (IsGoodAutoPlace1(w->left, w->top - height, width, height, toolbar_y, pt)) return pt;
1629 if (IsGoodAutoPlace1(w->left + w->width, w->top + w->height - height, width, height, toolbar_y, pt)) return pt;
1630 if (IsGoodAutoPlace1(w->left - width, w->top + w->height - height, width, height, toolbar_y, pt)) return pt;
1631 if (IsGoodAutoPlace1(w->left + w->width - width, w->top + w->height, width, height, toolbar_y, pt)) return pt;
1632 if (IsGoodAutoPlace1(w->left + w->width - width, w->top - height, width, height, toolbar_y, pt)) return pt;
1633 }
1634
1635 /* Third attempt, try around all existing windows.
1636 * The new window may be partly off-screen, and must not overlap with an existing window.
1637 * Only four starting points are tried.
1638 */
1639 for (const Window *w : Window::Iterate()) {
1640 if (w->window_class == WC_MAIN_WINDOW) continue;
1641
1642 if (IsGoodAutoPlace2(w->left + w->width, w->top, width, height, toolbar_y, pt)) return pt;
1643 if (IsGoodAutoPlace2(w->left - width, w->top, width, height, toolbar_y, pt)) return pt;
1644 if (IsGoodAutoPlace2(w->left, w->top + w->height, width, height, toolbar_y, pt)) return pt;
1645 if (IsGoodAutoPlace2(w->left, w->top - height, width, height, toolbar_y, pt)) return pt;
1646 }
1647
1648 /* Fourth and final attempt, put window at diagonal starting from (0, toolbar_y), try multiples
1649 * of the closebox
1650 */
1651 int left = rtl ? _screen.width - width : 0, top = toolbar_y;
1652 int offset_x = rtl ? -(int)NWidgetLeaf::closebox_dimension.width : (int)NWidgetLeaf::closebox_dimension.width;
1653 int offset_y = std::max<int>(NWidgetLeaf::closebox_dimension.height, FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.captiontext.Vertical());
1654
1655 restart:
1656 for (const Window *w : Window::Iterate()) {
1657 if (w->left == left && w->top == top) {
1658 left += offset_x;
1659 top += offset_y;
1660 goto restart;
1661 }
1662 }
1663
1664 pt.x = left;
1665 pt.y = top;
1666 return pt;
1667 }
1668
1675 Point GetToolbarAlignedWindowPosition(int window_width)
1676 {
1677 const Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
1678 assert(w != nullptr);
1679 Point pt = { _current_text_dir == TD_RTL ? w->left : (w->left + w->width) - window_width, w->top + w->height };
1680 return pt;
1681 }
1682
1700 static Point LocalGetWindowPlacement(const WindowDesc *desc, int16 sm_width, int16 sm_height, int window_number)
1701 {
1702 Point pt;
1703 const Window *w;
1704
1705 int16 default_width = std::max(desc->GetDefaultWidth(), sm_width);
1706 int16 default_height = std::max(desc->GetDefaultHeight(), sm_height);
1707
1708 if (desc->parent_cls != WC_NONE && (w = FindWindowById(desc->parent_cls, window_number)) != nullptr) {
1709 bool rtl = _current_text_dir == TD_RTL;
1710 if (desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) {
1711 pt.x = w->left + (rtl ? w->width - default_width : 0);
1712 pt.y = w->top + w->height;
1713 return pt;
1714 } else {
1715 /* Position child window with offset of closebox, but make sure that either closebox or resizebox is visible
1716 * - Y position: closebox of parent + closebox of child + statusbar
1717 * - X position: closebox on left/right, resizebox on right/left (depending on ltr/rtl)
1718 */
1719 int indent_y = std::max<int>(NWidgetLeaf::closebox_dimension.height, FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.captiontext.Vertical());
1720 if (w->top + 3 * indent_y < _screen.height) {
1721 pt.y = w->top + indent_y;
1722 int indent_close = NWidgetLeaf::closebox_dimension.width;
1723 int indent_resize = NWidgetLeaf::resizebox_dimension.width;
1724 if (_current_text_dir == TD_RTL) {
1725 pt.x = std::max(w->left + w->width - default_width - indent_close, 0);
1726 if (pt.x + default_width >= indent_close && pt.x + indent_resize <= _screen.width) return pt;
1727 } else {
1728 pt.x = std::min(w->left + indent_close, _screen.width - default_width);
1729 if (pt.x + default_width >= indent_resize && pt.x + indent_close <= _screen.width) return pt;
1730 }
1731 }
1732 }
1733 }
1734
1735 switch (desc->default_pos) {
1736 case WDP_ALIGN_TOOLBAR: // Align to the toolbar
1737 return GetToolbarAlignedWindowPosition(default_width);
1738
1739 case WDP_AUTO: // Find a good automatic position for the window
1740 return GetAutoPlacePosition(default_width, default_height);
1741
1742 case WDP_CENTER: // Centre the window horizontally
1743 pt.x = (_screen.width - default_width) / 2;
1744 pt.y = (_screen.height - default_height) / 2;
1745 break;
1746
1747 case WDP_MANUAL:
1748 pt.x = 0;
1749 pt.y = 0;
1750 break;
1751
1752 default:
1753 NOT_REACHED();
1754 }
1755
1756 return pt;
1757 }
1758
1759 /* virtual */ Point Window::OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
1760 {
1761 return LocalGetWindowPlacement(this->window_desc, sm_width, sm_height, window_number);
1762 }
1763
1771 void Window::CreateNestedTree(bool fill_nested)
1772 {
1773 int biggest_index = -1;
1774 this->nested_root = MakeWindowNWidgetTree(this->window_desc->nwid_parts, this->window_desc->nwid_length, &biggest_index, &this->shade_select);
1775 this->nested_array_size = (uint)(biggest_index + 1);
1776
1777 if (fill_nested) {
1778 this->nested_array = CallocT<NWidgetBase *>(this->nested_array_size);
1779 this->nested_root->FillNestedArray(this->nested_array, this->nested_array_size);
1780 }
1781 }
1782
1787 void Window::FinishInitNested(WindowNumber window_number)
1788 {
1789 this->InitializeData(window_number);
1790 this->ApplyDefaults();
1791 Point pt = this->OnInitialPosition(this->nested_root->smallest_x, this->nested_root->smallest_y, window_number);
1792 this->InitializePositionSize(pt.x, pt.y, this->nested_root->smallest_x, this->nested_root->smallest_y);
1793 this->FindWindowPlacementAndResize(this->window_desc->GetDefaultWidth(), this->window_desc->GetDefaultHeight());
1794 }
1795
1800 void Window::InitNested(WindowNumber window_number)
1801 {
1802 this->CreateNestedTree(false);
1803 this->FinishInitNested(window_number);
1804 }
1805
1810 Window::Window(WindowDesc *desc) : window_desc(desc), mouse_capture_widget(-1)
1811 {
1812 this->z_position = _z_windows.insert(_z_windows.end(), this);
1813 }
1814
1822 Window *FindWindowFromPt(int x, int y)
1823 {
1824 for (Window *w : Window::IterateFromFront()) {
1825 if (MayBeShown(w) && IsInsideBS(x, w->left, w->width) && IsInsideBS(y, w->top, w->height)) {
1826 return w;
1827 }
1828 }
1829
1830 return nullptr;
1831 }
1832
1836 void InitWindowSystem()
1837 {
1838 IConsoleClose();
1839
1840 _focused_window = nullptr;
1841 _mouseover_last_w = nullptr;
1842 _last_scroll_window = nullptr;
1843 _scrolling_viewport = false;
1844 _mouse_hovering = false;
1845
1846 NWidgetLeaf::InvalidateDimensionCache(); // Reset cached sizes of several widgets.
1847 NWidgetScrollbar::InvalidateDimensionCache();
1848
1849 ShowFirstError();
1850 }
1851
1855 void UnInitWindowSystem()
1856 {
1857 UnshowCriticalError();
1858
1859 for (Window *w : Window::Iterate()) w->Close();
1860
1861 Window::DeleteClosedWindows();
1862
1863 assert(_z_windows.empty());
1864 }
1865
1869 void ResetWindowSystem()
1870 {
1871 UnInitWindowSystem();
1872 InitWindowSystem();
1873 _thd.Reset();
1874 }
1875
1876 static void DecreaseWindowCounters()
1877 {
1878 static byte hundredth_tick_timeout = 100;
1879
1880 if (_scroller_click_timeout != 0) _scroller_click_timeout--;
1881 if (hundredth_tick_timeout != 0) hundredth_tick_timeout--;
1882
1883 for (Window *w : Window::Iterate()) {
1884 if (!_network_dedicated && hundredth_tick_timeout == 0) w->OnHundredthTick();
1885
1886 if (_scroller_click_timeout == 0) {
1887 /* Unclick scrollbar buttons if they are pressed. */
1888 for (uint i = 0; i < w->nested_array_size; i++) {
1889 NWidgetBase *nwid = w->nested_array[i];
1890 if (nwid != nullptr && (nwid->type == NWID_HSCROLLBAR || nwid->type == NWID_VSCROLLBAR)) {
1891 NWidgetScrollbar *sb = static_cast<NWidgetScrollbar*>(nwid);
1892 if (sb->disp_flags & (ND_SCROLLBAR_UP | ND_SCROLLBAR_DOWN)) {
1893 sb->disp_flags &= ~(ND_SCROLLBAR_UP | ND_SCROLLBAR_DOWN);
1894 w->mouse_capture_widget = -1;
1895 sb->SetDirty(w);
1896 }
1897 }
1898 }
1899 }
1900
1901 /* Handle editboxes */
1902 for (SmallMap<int, QueryString*>::Pair &pair : w->querystrings) {
1903 pair.second->HandleEditBox(w, pair.first);
1904 }
1905
1906 w->OnMouseLoop();
1907 }
1908
1909 for (Window *w : Window::Iterate()) {
1910 if ((w->flags & WF_TIMEOUT) && --w->timeout_timer == 0) {
1911 CLRBITS(w->flags, WF_TIMEOUT);
1912
1913 w->OnTimeout();
1914 w->RaiseButtons(true);
1915 }
1916 }
1917
1918 if (hundredth_tick_timeout == 0) hundredth_tick_timeout = 100;
1919 }
1920
1921 static void HandlePlacePresize()
1922 {
1923 if (_special_mouse_mode != WSM_PRESIZE) return;
1924
1925 Window *w = _thd.GetCallbackWnd();
1926 if (w == nullptr) return;
1927
1928 Point pt = GetTileBelowCursor();
1929 if (pt.x == -1) {
1930 _thd.selend.x = -1;
1931 return;
1932 }
1933
1934 w->OnPlacePresize(pt, TileVirtXY(pt.x, pt.y));
1935 }
1936
1941 static EventState HandleMouseDragDrop()
1942 {
1943 if (_special_mouse_mode != WSM_DRAGDROP) return ES_NOT_HANDLED;
1944
1945 if (_left_button_down && _cursor.delta.x == 0 && _cursor.delta.y == 0) return ES_HANDLED; // Dragging, but the mouse did not move.
1946
1947 Window *w = _thd.GetCallbackWnd();
1948 if (w != nullptr) {
1949 /* Send an event in client coordinates. */
1950 Point pt;
1951 pt.x = _cursor.pos.x - w->left;
1952 pt.y = _cursor.pos.y - w->top;
1953 if (_left_button_down) {
1954 w->OnMouseDrag(pt, GetWidgetFromPos(w, pt.x, pt.y));
1955 } else {
1956 w->OnDragDrop(pt, GetWidgetFromPos(w, pt.x, pt.y));
1957 }
1958 }
1959
1960 if (!_left_button_down) ResetObjectToPlace(); // Button released, finished dragging.
1961 return ES_HANDLED;
1962 }
1963
1965 static void HandleMouseOver()
1966 {
1967 Window *w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
1968
1969 /* We changed window, put an OnMouseOver event to the last window */
1970 if (_mouseover_last_w != nullptr && _mouseover_last_w != w) {
1971 /* Reset mouse-over coordinates of previous window */
1972 Point pt = { -1, -1 };
1973 _mouseover_last_w->OnMouseOver(pt, 0);
1974 }
1975
1976 /* _mouseover_last_w will get reset when the window is deleted, see DeleteWindow() */
1977 _mouseover_last_w = w;
1978
1979 if (w != nullptr) {
1980 /* send an event in client coordinates. */
1981 Point pt = { _cursor.pos.x - w->left, _cursor.pos.y - w->top };
1982 const NWidgetCore *widget = w->nested_root->GetWidgetFromPos(pt.x, pt.y);
1983 if (widget != nullptr) w->OnMouseOver(pt, widget->index);
1984 }
1985 }
1986
1988 static const int MIN_VISIBLE_TITLE_BAR = 13;
1989
1991 enum PreventHideDirection {
1992 PHD_UP,
1993 PHD_DOWN,
1994 };
1995
2006 static void PreventHiding(int *nx, int *ny, const Rect &rect, const Window *v, int px, PreventHideDirection dir)
2007 {
2008 if (v == nullptr) return;
2009
2010 const int min_visible = ScaleGUITrad(MIN_VISIBLE_TITLE_BAR);
2011
2012 int v_bottom = v->top + v->height;
2013 int v_right = v->left + v->width;
2014 int safe_y = (dir == PHD_UP) ? (v->top - min_visible - rect.top) : (v_bottom + min_visible - rect.bottom); // Compute safe vertical position.
2015
2016 if (*ny + rect.top <= v->top - min_visible) return; // Above v is enough space
2017 if (*ny + rect.bottom >= v_bottom + min_visible) return; // Below v is enough space
2018
2019 /* Vertically, the rectangle is hidden behind v. */
2020 if (*nx + rect.left + min_visible < v->left) { // At left of v.
2021 if (v->left < min_visible) *ny = safe_y; // But enough room, force it to a safe position.
2022 return;
2023 }
2024 if (*nx + rect.right - min_visible > v_right) { // At right of v.
2025 if (v_right > _screen.width - min_visible) *ny = safe_y; // Not enough room, force it to a safe position.
2026 return;
2027 }
2028
2029 /* Horizontally also hidden, force movement to a safe area. */
2030 if (px + rect.left < v->left && v->left >= min_visible) { // Coming from the left, and enough room there.
2031 *nx = v->left - min_visible - rect.left;
2032 } else if (px + rect.right > v_right && v_right <= _screen.width - min_visible) { // Coming from the right, and enough room there.
2033 *nx = v_right + min_visible - rect.right;
2034 } else {
2035 *ny = safe_y;
2036 }
2037 }
2038
2046 static void EnsureVisibleCaption(Window *w, int nx, int ny)
2047 {
2048 /* Search for the title bar rectangle. */
2049 Rect caption_rect;
2050 const NWidgetBase *caption = w->nested_root->GetWidgetOfType(WWT_CAPTION);
2051 if (caption != nullptr) {
2052 caption_rect = caption->GetCurrentRect();
2053
2054 const int min_visible = ScaleGUITrad(MIN_VISIBLE_TITLE_BAR);
2055
2056 /* Make sure the window doesn't leave the screen */
2057 nx = Clamp(nx, min_visible - caption_rect.right, _screen.width - min_visible - caption_rect.left);
2058 ny = Clamp(ny, 0, _screen.height - min_visible);
2059
2060 /* Make sure the title bar isn't hidden behind the main tool bar or the status bar. */
2061 PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_MAIN_TOOLBAR, 0), w->left, PHD_DOWN);
2062 PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_STATUS_BAR, 0), w->left, PHD_UP);
2063 }
2064
2065 if (w->viewport != nullptr) {
2066 w->viewport->left += nx - w->left;
2067 w->viewport->top += ny - w->top;
2068 }
2069
2070 w->left = nx;
2071 w->top = ny;
2072 }
2073
2084 void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
2085 {
2086 if (delta_x != 0 || delta_y != 0) {
2087 if (clamp_to_screen) {
2088 /* Determine the new right/bottom position. If that is outside of the bounds of
2089 * the resolution clamp it in such a manner that it stays within the bounds. */
2090 int new_right = w->left + w->width + delta_x;
2091 int new_bottom = w->top + w->height + delta_y;
2092 if (new_right >= (int)_screen.width) delta_x -= Ceil(new_right - _screen.width, std::max(1U, w->nested_root->resize_x));
2093 if (new_bottom >= (int)_screen.height) delta_y -= Ceil(new_bottom - _screen.height, std::max(1U, w->nested_root->resize_y));
2094 }
2095
2096 w->SetDirty();
2097
2098 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);
2099 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);
2100 assert(w->nested_root->resize_x == 0 || new_xinc % w->nested_root->resize_x == 0);
2101 assert(w->nested_root->resize_y == 0 || new_yinc % w->nested_root->resize_y == 0);
2102
2103 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);
2104 w->width = w->nested_root->current_x;
2105 w->height = w->nested_root->current_y;
2106 }
2107
2108 EnsureVisibleCaption(w, w->left, w->top);
2109
2110 /* Always call OnResize to make sure everything is initialised correctly if it needs to be. */
2111 w->OnResize();
2112 w->SetDirty();
2113 }
2114
2120 int GetMainViewTop()
2121 {
2122 Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
2123 return (w == nullptr) ? 0 : w->top + w->height;
2124 }
2125
2131 int GetMainViewBottom()
2132 {
2133 Window *w = FindWindowById(WC_STATUS_BAR, 0);
2134 return (w == nullptr) ? _screen.height : w->top;
2135 }
2136
2137 static bool _dragging_window;
2138
2143 static EventState HandleWindowDragging()
2144 {
2145 /* Get out immediately if no window is being dragged at all. */
2146 if (!_dragging_window) return ES_NOT_HANDLED;
2147
2148 /* If button still down, but cursor hasn't moved, there is nothing to do. */
2149 if (_left_button_down && _cursor.delta.x == 0 && _cursor.delta.y == 0) return ES_HANDLED;
2150
2151 /* Otherwise find the window... */
2152 for (Window *w : Window::Iterate()) {
2153 if (w->flags & WF_DRAGGING) {
2154 /* Stop the dragging if the left mouse button was released */
2155 if (!_left_button_down) {
2156 w->flags &= ~WF_DRAGGING;
2157 break;
2158 }
2159
2160 w->SetDirty();
2161
2162 int x = _cursor.pos.x + _drag_delta.x;
2163 int y = _cursor.pos.y + _drag_delta.y;
2164 int nx = x;
2165 int ny = y;
2166
2167 if (_settings_client.gui.window_snap_radius != 0) {
2168 int hsnap = _settings_client.gui.window_snap_radius;
2169 int vsnap = _settings_client.gui.window_snap_radius;
2170 int delta;
2171
2172 for (const Window *v : Window::Iterate()) {
2173 if (v == w) continue; // Don't snap at yourself
2174
2175 if (y + w->height > v->top && y < v->top + v->height) {
2176 /* Your left border <-> other right border */
2177 delta = abs(v->left + v->width - x);
2178 if (delta <= hsnap) {
2179 nx = v->left + v->width;
2180 hsnap = delta;
2181 }
2182
2183 /* Your right border <-> other left border */
2184 delta = abs(v->left - x - w->width);
2185 if (delta <= hsnap) {
2186 nx = v->left - w->width;
2187 hsnap = delta;
2188 }
2189 }
2190
2191 if (w->top + w->height >= v->top && w->top <= v->top + v->height) {
2192 /* Your left border <-> other left border */
2193 delta = abs(v->left - x);
2194 if (delta <= hsnap) {
2195 nx = v->left;
2196 hsnap = delta;
2197 }
2198
2199 /* Your right border <-> other right border */
2200 delta = abs(v->left + v->width - x - w->width);
2201 if (delta <= hsnap) {
2202 nx = v->left + v->width - w->width;
2203 hsnap = delta;
2204 }
2205 }
2206
2207 if (x + w->width > v->left && x < v->left + v->width) {
2208 /* Your top border <-> other bottom border */
2209 delta = abs(v->top + v->height - y);
2210 if (delta <= vsnap) {
2211 ny = v->top + v->height;
2212 vsnap = delta;
2213 }
2214
2215 /* Your bottom border <-> other top border */
2216 delta = abs(v->top - y - w->height);
2217 if (delta <= vsnap) {
2218 ny = v->top - w->height;
2219 vsnap = delta;
2220 }
2221 }
2222
2223 if (w->left + w->width >= v->left && w->left <= v->left + v->width) {
2224 /* Your top border <-> other top border */
2225 delta = abs(v->top - y);
2226 if (delta <= vsnap) {
2227 ny = v->top;
2228 vsnap = delta;
2229 }
2230
2231 /* Your bottom border <-> other bottom border */
2232 delta = abs(v->top + v->height - y - w->height);
2233 if (delta <= vsnap) {
2234 ny = v->top + v->height - w->height;
2235 vsnap = delta;
2236 }
2237 }
2238 }
2239 }
2240
2241 EnsureVisibleCaption(w, nx, ny);
2242
2243 w->SetDirty();
2244 return ES_HANDLED;
2245 } else if (w->flags & WF_SIZING) {
2246 /* Stop the sizing if the left mouse button was released */
2247 if (!_left_button_down) {
2248 w->flags &= ~WF_SIZING;
2249 w->SetDirty();
2250 break;
2251 }
2252
2253 /* Compute difference in pixels between cursor position and reference point in the window.
2254 * If resizing the left edge of the window, moving to the left makes the window bigger not smaller.
2255 */
2256 int x, y = _cursor.pos.y - _drag_delta.y;
2257 if (w->flags & WF_SIZING_LEFT) {
2258 x = _drag_delta.x - _cursor.pos.x;
2259 } else {
2260 x = _cursor.pos.x - _drag_delta.x;
2261 }
2262
2263 /* resize.step_width and/or resize.step_height may be 0, which means no resize is possible. */
2264 if (w->resize.step_width == 0) x = 0;
2265 if (w->resize.step_height == 0) y = 0;
2266
2267 /* Check the resize button won't go past the bottom of the screen */
2268 if (w->top + w->height + y > _screen.height) {
2269 y = _screen.height - w->height - w->top;
2270 }
2271
2272 /* X and Y has to go by step.. calculate it.
2273 * The cast to int is necessary else x/y are implicitly casted to
2274 * unsigned int, which won't work. */
2275 if (w->resize.step_width > 1) x -= x % (int)w->resize.step_width;
2276 if (w->resize.step_height > 1) y -= y % (int)w->resize.step_height;
2277
2278 /* Check that we don't go below the minimum set size */
2279 if ((int)w->width + x < (int)w->nested_root->smallest_x) {
2280 x = w->nested_root->smallest_x - w->width;
2281 }
2282 if ((int)w->height + y < (int)w->nested_root->smallest_y) {
2283 y = w->nested_root->smallest_y - w->height;
2284 }
2285
2286 /* Window already on size */
2287 if (x == 0 && y == 0) return ES_HANDLED;
2288
2289 /* Now find the new cursor pos.. this is NOT _cursor, because we move in steps. */
2290 _drag_delta.y += y;
2291 if ((w->flags & WF_SIZING_LEFT) && x != 0) {
2292 _drag_delta.x -= x; // x > 0 -> window gets longer -> left-edge moves to left -> subtract x to get new position.
2293 w->SetDirty();
2294 w->left -= x; // If dragging left edge, move left window edge in opposite direction by the same amount.
2295 /* ResizeWindow() below ensures marking new position as dirty. */
2296 } else {
2297 _drag_delta.x += x;
2298 }
2299
2300 /* ResizeWindow sets both pre- and after-size to dirty for redrawal */
2301 ResizeWindow(w, x, y);
2302 return ES_HANDLED;
2303 }
2304 }
2305
2306 _dragging_window = false;
2307 return ES_HANDLED;
2308 }
2309
2314 static void StartWindowDrag(Window *w)
2315 {
2316 w->flags |= WF_DRAGGING;
2317 w->flags &= ~WF_CENTERED;
2318 _dragging_window = true;
2319
2320 _drag_delta.x = w->left - _cursor.pos.x;
2321 _drag_delta.y = w->top - _cursor.pos.y;
2322
2323 BringWindowToFront(w);
2324 CloseWindowById(WC_DROPDOWN_MENU, 0);
2325 }
2326
2332 static void StartWindowSizing(Window *w, bool to_left)
2333 {
2334 w->flags |= to_left ? WF_SIZING_LEFT : WF_SIZING_RIGHT;
2335 w->flags &= ~WF_CENTERED;
2336 _dragging_window = true;
2337
2338 _drag_delta.x = _cursor.pos.x;
2339 _drag_delta.y = _cursor.pos.y;
2340
2341 BringWindowToFront(w);
2342 CloseWindowById(WC_DROPDOWN_MENU, 0);
2343 }
2344
2349 static void HandleScrollbarScrolling(Window *w)
2350 {
2351 int i;
2352 NWidgetScrollbar *sb = w->GetWidget<NWidgetScrollbar>(w->mouse_capture_widget);
2353 bool rtl = false;
2354
2355 if (sb->type == NWID_HSCROLLBAR) {
2356 i = _cursor.pos.x - _cursorpos_drag_start.x;
2357 rtl = _current_text_dir == TD_RTL;
2358 } else {
2359 i = _cursor.pos.y - _cursorpos_drag_start.y;
2360 }
2361
2362 if (sb->disp_flags & ND_SCROLLBAR_BTN) {
2363 if (_scroller_click_timeout == 1) {
2364 _scroller_click_timeout = 3;
2365 if (sb->UpdatePosition(rtl == HasBit(sb->disp_flags, NDB_SCROLLBAR_UP) ? 1 : -1)) w->SetDirty();
2366 }
2367 return;
2368 }
2369
2370 /* Find the item we want to move to and make sure it's inside bounds. */
2371 int pos = std::min(RoundDivSU(std::max(0, i + _scrollbar_start_pos) * sb->GetCount(), _scrollbar_size), std::max(0, sb->GetCount() - sb->GetCapacity()));
2372 if (rtl) pos = std::max(0, sb->GetCount() - sb->GetCapacity() - pos);
2373 if (pos != sb->GetPosition()) {
2374 sb->SetPosition(pos);
2375 w->SetDirty();
2376 }
2377 }
2378
2383 static EventState HandleActiveWidget()
2384 {
2385 for (Window *w : Window::Iterate()) {
2386 if (w->mouse_capture_widget >= 0) {
2387 /* Abort if no button is clicked any more. */
2388 if (!_left_button_down) {
2389 w->SetWidgetDirty(w->mouse_capture_widget);
2390 w->mouse_capture_widget = -1;
2391 return ES_HANDLED;
2392 }
2393
2394 /* Handle scrollbar internally, or dispatch click event */
2395 WidgetType type = w->GetWidget<NWidgetBase>(w->mouse_capture_widget)->type;
2396 if (type == NWID_VSCROLLBAR || type == NWID_HSCROLLBAR) {
2397 HandleScrollbarScrolling(w);
2398 } else {
2399 /* If cursor hasn't moved, there is nothing to do. */
2400 if (_cursor.delta.x == 0 && _cursor.delta.y == 0) return ES_HANDLED;
2401
2402 Point pt = { _cursor.pos.x - w->left, _cursor.pos.y - w->top };
2403 w->OnClick(pt, w->mouse_capture_widget, 0);
2404 }
2405 return ES_HANDLED;
2406 }
2407 }
2408
2409 return ES_NOT_HANDLED;
2410 }
2411
2416 static EventState HandleViewportScroll()
2417 {
2418 bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
2419
2420 if (!_scrolling_viewport) return ES_NOT_HANDLED;
2421
2422 /* When we don't have a last scroll window we are starting to scroll.
2423 * When the last scroll window and this are not the same we went
2424 * outside of the window and should not left-mouse scroll anymore. */
2425 if (_last_scroll_window == nullptr) _last_scroll_window = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
2426
2427 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))) {
2428 _cursor.fix_at = false;
2429 _scrolling_viewport = false;
2430 _last_scroll_window = nullptr;
2431 return ES_NOT_HANDLED;
2432 }
2433
2434 if (_last_scroll_window == FindWindowById(WC_MAIN_WINDOW, 0) && _last_scroll_window->viewport->follow_vehicle != INVALID_VEHICLE) {
2435 /* If the main window is following a vehicle, then first let go of it! */
2436 const Vehicle *veh = Vehicle::Get(_last_scroll_window->viewport->follow_vehicle);
2437 ScrollMainWindowTo(veh->x_pos, veh->y_pos, veh->z_pos, true); // This also resets follow_vehicle
2438 return ES_NOT_HANDLED;
2439 }
2440
2441 Point delta;
2442 if (scrollwheel_scrolling) {
2443 /* We are using scrollwheels for scrolling */
2444 delta.x = _cursor.h_wheel;
2445 delta.y = _cursor.v_wheel;
2446 _cursor.v_wheel = 0;
2447 _cursor.h_wheel = 0;
2448 } else {
2449 if (_settings_client.gui.scroll_mode != VSM_VIEWPORT_RMB_FIXED) {
2450 delta.x = -_cursor.delta.x;
2451 delta.y = -_cursor.delta.y;
2452 } else {
2453 delta.x = _cursor.delta.x;
2454 delta.y = _cursor.delta.y;
2455 }
2456 }
2457
2458 /* Create a scroll-event and send it to the window */
2459 if (delta.x != 0 || delta.y != 0) _last_scroll_window->OnScroll(delta);
2460
2461 _cursor.delta.x = 0;
2462 _cursor.delta.y = 0;
2463 return ES_HANDLED;
2464 }
2465
2476 static bool MaybeBringWindowToFront(Window *w)
2477 {
2478 bool bring_to_front = false;
2479
2480 if (w->window_class == WC_MAIN_WINDOW ||
2481 IsVitalWindow(w) ||
2482 w->window_class == WC_TOOLTIPS ||
2483 w->window_class == WC_DROPDOWN_MENU) {
2484 return true;
2485 }
2486
2487 /* Use unshaded window size rather than current size for shaded windows. */
2488 int w_width = w->width;
2489 int w_height = w->height;
2490 if (w->IsShaded()) {
2491 w_width = w->unshaded_size.width;
2492 w_height = w->unshaded_size.height;
2493 }
2494
2495 Window::IteratorToFront it(w);
2496 ++it;
2497 for (; !it.IsEnd(); ++it) {
2498 Window *u = *it;
2499 /* A modal child will prevent the activation of the parent window */
2500 if (u->parent == w && (u->window_desc->flags & WDF_MODAL)) {
2501 u->SetWhiteBorder();
2502 u->SetDirty();
2503 return false;
2504 }
2505
2506 if (u->window_class == WC_MAIN_WINDOW ||
2507 IsVitalWindow(u) ||
2508 u->window_class == WC_TOOLTIPS ||
2509 u->window_class == WC_DROPDOWN_MENU) {
2510 continue;
2511 }
2512
2513 /* Window sizes don't interfere, leave z-order alone */
2514 if (w->left + w_width <= u->left ||
2515 u->left + u->width <= w->left ||
2516 w->top + w_height <= u->top ||
2517 u->top + u->height <= w->top) {
2518 continue;
2519 }
2520
2521 bring_to_front = true;
2522 }
2523
2524 if (bring_to_front) BringWindowToFront(w);
2525 return true;
2526 }
2527
2536 EventState Window::HandleEditBoxKey(int wid, WChar key, uint16 keycode)
2537 {
2538 QueryString *query = this->GetQueryString(wid);
2539 if (query == nullptr) return ES_NOT_HANDLED;
2540
2541 int action = QueryString::ACTION_NOTHING;
2542
2543 switch (query->text.HandleKeyPress(key, keycode)) {
2544 case HKPR_EDITING:
2545 this->SetWidgetDirty(wid);
2546 this->OnEditboxChanged(wid);
2547 break;
2548
2549 case HKPR_CURSOR:
2550 this->SetWidgetDirty(wid);
2551 /* For the OSK also invalidate the parent window */
2552 if (this->window_class == WC_OSK) this->InvalidateData();
2553 break;
2554
2555 case HKPR_CONFIRM:
2556 if (this->window_class == WC_OSK) {
2557 this->OnClick(Point(), WID_OSK_OK, 1);
2558 } else if (query->ok_button >= 0) {
2559 this->OnClick(Point(), query->ok_button, 1);
2560 } else {
2561 action = query->ok_button;
2562 }
2563 break;
2564
2565 case HKPR_CANCEL:
2566 if (this->window_class == WC_OSK) {
2567 this->OnClick(Point(), WID_OSK_CANCEL, 1);
2568 } else if (query->cancel_button >= 0) {
2569 this->OnClick(Point(), query->cancel_button, 1);
2570 } else {
2571 action = query->cancel_button;
2572 }
2573 break;
2574
2575 case HKPR_NOT_HANDLED:
2576 return ES_NOT_HANDLED;
2577
2578 default: break;
2579 }
2580
2581 switch (action) {
2582 case QueryString::ACTION_DESELECT:
2583 this->UnfocusFocusedWidget();
2584 break;
2585
2586 case QueryString::ACTION_CLEAR:
2587 if (query->text.bytes <= 1) {
2588 /* If already empty, unfocus instead */
2589 this->UnfocusFocusedWidget();
2590 } else {
2591 query->text.DeleteAll();
2592 this->SetWidgetDirty(wid);
2593 this->OnEditboxChanged(wid);
2594 }
2595 break;
2596
2597 default:
2598 break;
2599 }
2600
2601 return ES_HANDLED;
2602 }
2603
2608 void HandleToolbarHotkey(int hotkey)
2609 {
2610 assert(HasModalProgress() || IsLocalCompany());
2611
2612 Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
2613 if (w != nullptr) {
2614 if (w->window_desc->hotkeys != nullptr) {
2615 if (hotkey >= 0 && w->OnHotkey(hotkey) == ES_HANDLED) return;
2616 }
2617 }
2618 }
2619
2625 void HandleKeypress(uint keycode, WChar key)
2626 {
2627 /* World generation is multithreaded and messes with companies.
2628 * But there is no company related window open anyway, so _current_company is not used. */
2629 assert(HasModalProgress() || IsLocalCompany());
2630
2631 /*
2632 * The Unicode standard defines an area called the private use area. Code points in this
2633 * area are reserved for private use and thus not portable between systems. For instance,
2634 * Apple defines code points for the arrow keys in this area, but these are only printable
2635 * on a system running OS X. We don't want these keys to show up in text fields and such,
2636 * and thus we have to clear the unicode character when we encounter such a key.
2637 */
2638 if (key >= 0xE000 && key <= 0xF8FF) key = 0;
2639
2640 /*
2641 * If both key and keycode is zero, we don't bother to process the event.
2642 */
2643 if (key == 0 && keycode == 0) return;
2644
2645 /* Check if the focused window has a focused editbox */
2646 if (EditBoxInGlobalFocus()) {
2647 /* All input will in this case go to the focused editbox */
2648 if (_focused_window->window_class == WC_CONSOLE) {
2649 if (_focused_window->OnKeyPress(key, keycode) == ES_HANDLED) return;
2650 } else {
2651 if (_focused_window->HandleEditBoxKey(_focused_window->nested_focus->index, key, keycode) == ES_HANDLED) return;
2652 }
2653 }
2654
2655 /* Call the event, start with the uppermost window, but ignore the toolbar. */
2656 for (Window *w : Window::IterateFromFront()) {
2657 if (w->window_class == WC_MAIN_TOOLBAR) continue;
2658 if (w->window_desc->hotkeys != nullptr) {
2659 int hotkey = w->window_desc->hotkeys->CheckMatch(keycode);
2660 if (hotkey >= 0 && w->OnHotkey(hotkey) == ES_HANDLED) return;
2661 }
2662 if (w->OnKeyPress(key, keycode) == ES_HANDLED) return;
2663 }
2664
2665 Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
2666 /* When there is no toolbar w is null, check for that */
2667 if (w != nullptr) {
2668 if (w->window_desc->hotkeys != nullptr) {
2669 int hotkey = w->window_desc->hotkeys->CheckMatch(keycode);
2670 if (hotkey >= 0 && w->OnHotkey(hotkey) == ES_HANDLED) return;
2671 }
2672 if (w->OnKeyPress(key, keycode) == ES_HANDLED) return;
2673 }
2674
2675 HandleGlobalHotkeys(key, keycode);
2676 }
2677
2681 void HandleCtrlChanged()
2682 {
2683 /* Call the event, start with the uppermost window. */
2684 for (Window *w : Window::IterateFromFront()) {
2685 if (w->OnCTRLStateChange() == ES_HANDLED) return;
2686 }
2687 }
2688
2694 /* virtual */ void Window::InsertTextString(int wid, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end)
2695 {
2696 QueryString *query = this->GetQueryString(wid);
2697 if (query == nullptr) return;
2698
2699 if (query->text.InsertString(str, marked, caret, insert_location, replacement_end) || marked) {
2700 this->SetWidgetDirty(wid);
2701 this->OnEditboxChanged(wid);
2702 }
2703 }
2704
2711 void HandleTextInput(const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end)
2712 {
2713 if (!EditBoxInGlobalFocus()) return;
2714
2715 _focused_window->InsertTextString(_focused_window->window_class == WC_CONSOLE ? 0 : _focused_window->nested_focus->index, str, marked, caret, insert_location, replacement_end);
2716 }
2717
2724 static int _input_events_this_tick = 0;
2725
2730 static void HandleAutoscroll()
2731 {
2732 if (_game_mode == GM_MENU || HasModalProgress()) return;
2733 if (_settings_client.gui.auto_scrolling == VA_DISABLED) return;
2734 if (_settings_client.gui.auto_scrolling == VA_MAIN_VIEWPORT_FULLSCREEN && !_fullscreen) return;
2735
2736 int x = _cursor.pos.x;
2737 int y = _cursor.pos.y;
2738 Window *w = FindWindowFromPt(x, y);
2739 if (w == nullptr || w->flags & WF_DISABLE_VP_SCROLL) return;
2740 if (_settings_client.gui.auto_scrolling != VA_EVERY_VIEWPORT && w->window_class != WC_MAIN_WINDOW) return;
2741
2742 Viewport *vp = IsPtInWindowViewport(w, x, y);
2743 if (vp == nullptr) return;
2744
2745 x -= vp->left;
2746 y -= vp->top;
2747
2748 /* here allows scrolling in both x and y axis */
2749 static const int SCROLLSPEED = 3;
2750 if (x - 15 < 0) {
2751 w->viewport->dest_scrollpos_x += ScaleByZoom((x - 15) * SCROLLSPEED, vp->zoom);
2752 } else if (15 - (vp->width - x) > 0) {
2753 w->viewport->dest_scrollpos_x += ScaleByZoom((15 - (vp->width - x)) * SCROLLSPEED, vp->zoom);
2754 }
2755 if (y - 15 < 0) {
2756 w->viewport->dest_scrollpos_y += ScaleByZoom((y - 15) * SCROLLSPEED, vp->zoom);
2757 } else if (15 - (vp->height - y) > 0) {
2758 w->viewport->dest_scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * SCROLLSPEED, vp->zoom);
2759 }
2760 }
2761
2762 enum MouseClick {
2763 MC_NONE = 0,
2764 MC_LEFT,
2765 MC_RIGHT,
2766 MC_DOUBLE_LEFT,
2767 MC_HOVER,
2768
2769 MAX_OFFSET_DOUBLE_CLICK = 5,
2770 MAX_OFFSET_HOVER = 5,
2771 };
2772 extern EventState VpHandlePlaceSizingDrag();
2773
2774 const std::chrono::milliseconds TIME_BETWEEN_DOUBLE_CLICK(500);
2775
2776 static void ScrollMainViewport(int x, int y)
2777 {
2778 if (_game_mode != GM_MENU) {
2779 Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
2780 assert(w);
2781
2782 w->viewport->dest_scrollpos_x += ScaleByZoom(x, w->viewport->zoom);
2783 w->viewport->dest_scrollpos_y += ScaleByZoom(y, w->viewport->zoom);
2784 }
2785 }
2786
2796 static const int8 scrollamt[16][2] = {
2797 { 0, 0},
2798 {-2, 0},
2799 { 0, -2},
2800 {-2, -1},
2801 { 2, 0},
2802 { 0, 0},
2803 { 2, -1},
2804 { 0, -2},
2805 { 0, 2},
2806 {-2, 1},
2807 { 0, 0},
2808 {-2, 0},
2809 { 2, 1},
2810 { 0, 2},
2811 { 2, 0},
2812 { 0, 0},
2813 };
2814
2815 static void HandleKeyScrolling()
2816 {
2817 /*
2818 * Check that any of the dirkeys is pressed and that the focused window
2819 * doesn't have an edit-box as focused widget.
2820 */
2821 if (_dirkeys && !EditBoxInGlobalFocus()) {
2822 int factor = _shift_pressed ? 50 : 10;
2823 ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor);
2824 }
2825 }
2826
2827 static void MouseLoop(MouseClick click, int mousewheel)
2828 {
2829 /* World generation is multithreaded and messes with companies.
2830 * But there is no company related window open anyway, so _current_company is not used. */
2831 assert(HasModalProgress() || IsLocalCompany());
2832
2833 HandlePlacePresize();
2834 UpdateTileSelection();
2835
2836 if (VpHandlePlaceSizingDrag() == ES_HANDLED) return;
2837 if (HandleMouseDragDrop() == ES_HANDLED) return;
2838 if (HandleWindowDragging() == ES_HANDLED) return;
2839 if (HandleActiveWidget() == ES_HANDLED) return;
2840 if (HandleViewportScroll() == ES_HANDLED) return;
2841
2842 HandleMouseOver();
2843
2844 bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
2845 if (click == MC_NONE && mousewheel == 0 && !scrollwheel_scrolling) return;
2846
2847 int x = _cursor.pos.x;
2848 int y = _cursor.pos.y;
2849 Window *w = FindWindowFromPt(x, y);
2850 if (w == nullptr) return;
2851
2852 if (click != MC_HOVER && !MaybeBringWindowToFront(w)) return;
2853 Viewport *vp = IsPtInWindowViewport(w, x, y);
2854
2855 /* Don't allow any action in a viewport if either in menu or when having a modal progress window */
2856 if (vp != nullptr && (_game_mode == GM_MENU || HasModalProgress())) return;
2857
2858 if (mousewheel != 0) {
2859 /* Send mousewheel event to window, unless we're scrolling a viewport or the map */
2860 if (!scrollwheel_scrolling || (vp == nullptr && w->window_class != WC_SMALLMAP)) w->OnMouseWheel(mousewheel);
2861
2862 /* Dispatch a MouseWheelEvent for widgets if it is not a viewport */
2863 if (vp == nullptr) DispatchMouseWheelEvent(w, w->nested_root->GetWidgetFromPos(x - w->left, y - w->top), mousewheel);
2864 }
2865
2866 if (vp != nullptr) {
2867 if (scrollwheel_scrolling && !(w->flags & WF_DISABLE_VP_SCROLL)) {
2868 _scrolling_viewport = true;
2869 _cursor.fix_at = true;
2870 return;
2871 }
2872
2873 switch (click) {
2874 case MC_DOUBLE_LEFT:
2875 case MC_LEFT:
2876 if (HandleViewportClicked(vp, x, y)) return;
2877 if (!(w->flags & WF_DISABLE_VP_SCROLL) &&
2878 _settings_client.gui.scroll_mode == VSM_MAP_LMB) {
2879 _scrolling_viewport = true;
2880 _cursor.fix_at = false;
2881 return;
2882 }
2883 break;
2884
2885 case MC_RIGHT:
2886 if (!(w->flags & WF_DISABLE_VP_SCROLL) &&
2887 _settings_client.gui.scroll_mode != VSM_MAP_LMB) {
2888 _scrolling_viewport = true;
2889 _cursor.fix_at = (_settings_client.gui.scroll_mode == VSM_VIEWPORT_RMB_FIXED ||
2890 _settings_client.gui.scroll_mode == VSM_MAP_RMB_FIXED);
2891 DispatchRightClickEvent(w, x - w->left, y - w->top);
2892 return;
2893 }
2894 break;
2895
2896 default:
2897 break;
2898 }
2899 }
2900
2901 switch (click) {
2902 case MC_LEFT:
2903 case MC_DOUBLE_LEFT:
2904 DispatchLeftClickEvent(w, x - w->left, y - w->top, click == MC_DOUBLE_LEFT ? 2 : 1);
2905 return;
2906
2907 default:
2908 if (!scrollwheel_scrolling || w == nullptr || w->window_class != WC_SMALLMAP) break;
2909 /* We try to use the scrollwheel to scroll since we didn't touch any of the buttons.
2910 * Simulate a right button click so we can get started. */
2911 FALLTHROUGH;
2912
2913 case MC_RIGHT:
2914 DispatchRightClickEvent(w, x - w->left, y - w->top);
2915 return;
2916
2917 case MC_HOVER:
2918 DispatchHoverEvent(w, x - w->left, y - w->top);
2919 break;
2920 }
2921
2922 /* We're not doing anything with 2D scrolling, so reset the value. */
2923 _cursor.h_wheel = 0;
2924 _cursor.v_wheel = 0;
2925 }
2926
2930 void HandleMouseEvents()
2931 {
2932 /* World generation is multithreaded and messes with companies.
2933 * But there is no company related window open anyway, so _current_company is not used. */
2934 assert(HasModalProgress() || IsLocalCompany());
2935
2936 /* Handle sprite picker before any GUI interaction */
2937 if (_newgrf_debug_sprite_picker.mode == SPM_REDRAW && _input_events_this_tick == 0) {
2938 /* We are done with the last draw-frame, so we know what sprites we
2939 * clicked on. Reset the picker mode and invalidate the window. */
2940 _newgrf_debug_sprite_picker.mode = SPM_NONE;
2941 InvalidateWindowData(WC_SPRITE_ALIGNER, 0, 1);
2942 }
2943
2944 static std::chrono::steady_clock::time_point double_click_time = {};
2945 static Point double_click_pos = {0, 0};
2946
2947 /* Mouse event? */
2948 MouseClick click = MC_NONE;
2949 if (_left_button_down && !_left_button_clicked) {
2950 click = MC_LEFT;
2951 if (std::chrono::steady_clock::now() <= double_click_time + TIME_BETWEEN_DOUBLE_CLICK &&
2952 double_click_pos.x != 0 && abs(_cursor.pos.x - double_click_pos.x) < MAX_OFFSET_DOUBLE_CLICK &&
2953 double_click_pos.y != 0 && abs(_cursor.pos.y - double_click_pos.y) < MAX_OFFSET_DOUBLE_CLICK) {
2954 click = MC_DOUBLE_LEFT;
2955 }
2956 double_click_time = std::chrono::steady_clock::now();
2957 double_click_pos = _cursor.pos;
2958 _left_button_clicked = true;
2959 _input_events_this_tick++;
2960 } else if (_right_button_clicked) {
2961 _right_button_clicked = false;
2962 click = MC_RIGHT;
2963 _input_events_this_tick++;
2964 }
2965
2966 int mousewheel = 0;
2967 if (_cursor.wheel) {
2968 mousewheel = _cursor.wheel;
2969 _cursor.wheel = 0;
2970 _input_events_this_tick++;
2971 }
2972
2973 static std::chrono::steady_clock::time_point hover_time = {};
2974 static Point hover_pos = {0, 0};
2975
2976 if (_settings_client.gui.hover_delay_ms > 0) {
2977 if (!_cursor.in_window || click != MC_NONE || mousewheel != 0 || _left_button_down || _right_button_down ||
2978 hover_pos.x == 0 || abs(_cursor.pos.x - hover_pos.x) >= MAX_OFFSET_HOVER ||
2979 hover_pos.y == 0 || abs(_cursor.pos.y - hover_pos.y) >= MAX_OFFSET_HOVER) {
2980 hover_pos = _cursor.pos;
2981 hover_time = std::chrono::steady_clock::now();
2982 _mouse_hovering = false;
2983 } else if (!_mouse_hovering) {
2984 if (std::chrono::steady_clock::now() > hover_time + std::chrono::milliseconds(_settings_client.gui.hover_delay_ms)) {
2985 click = MC_HOVER;
2986 _input_events_this_tick++;
2987 _mouse_hovering = true;
2988 hover_time = std::chrono::steady_clock::now();
2989 }
2990 }
2991 }
2992
2993 if (click == MC_LEFT && _newgrf_debug_sprite_picker.mode == SPM_WAIT_CLICK) {
2994 /* Mark whole screen dirty, and wait for the next realtime tick, when drawing is finished. */
2995 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
2996 _newgrf_debug_sprite_picker.clicked_pixel = blitter->MoveTo(_screen.dst_ptr, _cursor.pos.x, _cursor.pos.y);
2997 _newgrf_debug_sprite_picker.sprites.clear();
2998 _newgrf_debug_sprite_picker.mode = SPM_REDRAW;
2999 MarkWholeScreenDirty();
3000 } else {
3001 MouseLoop(click, mousewheel);
3002 }
3003
3004 /* We have moved the mouse the required distance,
3005 * no need to move it at any later time. */
3006 _cursor.delta.x = 0;
3007 _cursor.delta.y = 0;
3008 }
3009
3013 static void CheckSoftLimit()
3014 {
3015 if (_settings_client.gui.window_soft_limit == 0) return;
3016
3017 for (;;) {
3018 uint deletable_count = 0;
3019 Window *last_deletable = nullptr;
3020 for (Window *w : Window::IterateFromFront()) {
3021 if (w->window_class == WC_MAIN_WINDOW || IsVitalWindow(w) || (w->flags & WF_STICKY)) continue;
3022
3023 last_deletable = w;
3024 deletable_count++;
3025 }
3026
3027 /* We've not reached the soft limit yet. */
3028 if (deletable_count <= _settings_client.gui.window_soft_limit) break;
3029
3030 assert(last_deletable != nullptr);
3031 last_deletable->Close();
3032 }
3033 }
3034
3038 void InputLoop()
3039 {
3040 /* World generation is multithreaded and messes with companies.
3041 * But there is no company related window open anyway, so _current_company is not used. */
3042 assert(HasModalProgress() || IsLocalCompany());
3043
3044 CheckSoftLimit();
3045
3046 /* Process scheduled window deletion. */
3047 Window::DeleteClosedWindows();
3048
3049 if (_input_events_this_tick != 0) {
3050 /* The input loop is called only once per GameLoop() - so we can clear the counter here */
3051 _input_events_this_tick = 0;
3052 /* there were some inputs this tick, don't scroll ??? */
3053 return;
3054 }
3055
3056 /* HandleMouseEvents was already called for this tick */
3057 HandleMouseEvents();
3058 }
3059
3063 void CallWindowRealtimeTickEvent(uint delta_ms)
3064 {
3065 for (Window *w : Window::Iterate()) {
3066 w->OnRealtimeTick(delta_ms);
3067 }
3068 }
3069
3073 void UpdateWindows()
3074 {
3075 static std::chrono::steady_clock::time_point last_time = std::chrono::steady_clock::now();
3076 uint delta_ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - last_time).count();
3077
3078 if (delta_ms == 0) return;
3079
3080 last_time = std::chrono::steady_clock::now();
3081
3082 PerformanceMeasurer framerate(PFE_DRAWING);
3083 PerformanceAccumulator::Reset(PFE_DRAWWORLD);
3084
3085 extern void ProcessPendingPerformanceMeasurements();
3086 ProcessPendingPerformanceMeasurements();
3087
3088 CallWindowRealtimeTickEvent(delta_ms);
3089
3090 static GUITimer network_message_timer = GUITimer(1);
3091 if (network_message_timer.Elapsed(delta_ms)) {
3092 network_message_timer.SetInterval(1000);
3093 NetworkChatMessageLoop();
3094 }
3095
3096 /* Process invalidations before anything else. */
3097 for (Window *w : Window::Iterate()) {
3098 w->ProcessScheduledInvalidations();
3099 w->ProcessHighlightedInvalidations();
3100 }
3101
3102 static GUITimer window_timer = GUITimer(1);
3103 if (window_timer.Elapsed(delta_ms)) {
3104 if (_network_dedicated) window_timer.SetInterval(MILLISECONDS_PER_TICK);
3105
3106 extern int _caret_timer;
3107 _caret_timer += 3;
3108 CursorTick();
3109
3110 HandleKeyScrolling();
3111 HandleAutoscroll();
3112 DecreaseWindowCounters();
3113 }
3114
3115 static GUITimer highlight_timer = GUITimer(1);
3116 if (highlight_timer.Elapsed(delta_ms)) {
3117 highlight_timer.SetInterval(450);
3118 _window_highlight_colour = !_window_highlight_colour;
3119 }
3120
3121 if (!_pause_mode || _game_mode == GM_EDITOR || _settings_game.construction.command_pause_level > CMDPL_NO_CONSTRUCTION) MoveAllTextEffects(delta_ms);
3122
3123 /* Skip the actual drawing on dedicated servers without screen.
3124 * But still empty the invalidation queues above. */
3125 if (_network_dedicated) return;
3126
3127 if (window_timer.HasElapsed()) {
3128 window_timer.SetInterval(MILLISECONDS_PER_TICK);
3129
3130 for (Window *w : Window::Iterate()) {
3131 if ((w->flags & WF_WHITE_BORDER) && --w->white_border_timer == 0) {
3132 CLRBITS(w->flags, WF_WHITE_BORDER);
3133 w->SetDirty();
3134 }
3135 }
3136 }
3137
3138 DrawDirtyBlocks();
3139
3140 for (Window *w : Window::Iterate()) {
3141 /* Update viewport only if window is not shaded. */
3142 if (w->viewport != nullptr && !w->IsShaded()) UpdateViewportPosition(w);
3143 }
3144 NetworkDrawChatMessage();
3145 /* Redraw mouse cursor in case it was hidden */
3146 DrawMouseCursor();
3147 }
3148
3154 void SetWindowDirty(WindowClass cls, WindowNumber number)
3155 {
3156 for (const Window *w : Window::Iterate()) {
3157 if (w->window_class == cls && w->window_number == number) w->SetDirty();
3158 }
3159 }
3160
3167 void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_index)
3168 {
3169 for (const Window *w : Window::Iterate()) {
3170 if (w->window_class == cls && w->window_number == number) {
3171 w->SetWidgetDirty(widget_index);
3172 }
3173 }
3174 }
3175
3180 void SetWindowClassesDirty(WindowClass cls)
3181 {
3182 for (const Window *w : Window::Iterate()) {
3183 if (w->window_class == cls) w->SetDirty();
3184 }
3185 }
3186
3192 void Window::InvalidateData(int data, bool gui_scope)
3193 {
3194 this->SetDirty();
3195 if (!gui_scope) {
3196 /* Schedule GUI-scope invalidation for next redraw. */
3197 this->scheduled_invalidation_data.push_back(data);
3198 }
3199 this->OnInvalidateData(data, gui_scope);
3200 }
3201
3205 void Window::ProcessScheduledInvalidations()
3206 {
3207 for (int data : this->scheduled_invalidation_data) {
3208 if (this->window_class == WC_INVALID) break;
3209 this->OnInvalidateData(data, true);
3210 }
3211 this->scheduled_invalidation_data.clear();
3212 }
3213
3217 void Window::ProcessHighlightedInvalidations()
3218 {
3219 if ((this->flags & WF_HIGHLIGHTED) == 0) return;
3220
3221 for (uint i = 0; i < this->nested_array_size; i++) {
3222 if (this->IsWidgetHighlighted(i)) this->SetWidgetDirty(i);
3223 }
3224 }
3225
3252 void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
3253 {
3254 for (Window *w : Window::Iterate()) {
3255 if (w->window_class == cls && w->window_number == number) {
3256 w->InvalidateData(data, gui_scope);
3257 }
3258 }
3259 }
3260
3269 void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
3270 {
3271 for (Window *w : Window::Iterate()) {
3272 if (w->window_class == cls) {
3273 w->InvalidateData(data, gui_scope);
3274 }
3275 }
3276 }
3277
3281 void CallWindowGameTickEvent()
3282 {
3283 for (Window *w : Window::Iterate()) {
3284 w->OnGameTick();
3285 }
3286 }
3287
3294 void CloseNonVitalWindows()
3295 {
3296 /* Note: the container remains stable, even when deleting windows. */
3297 for (Window *w : Window::Iterate()) {
3298 if (w->window_class != WC_MAIN_WINDOW &&
3299 w->window_class != WC_SELECT_GAME &&
3300 w->window_class != WC_MAIN_TOOLBAR &&
3301 w->window_class != WC_STATUS_BAR &&
3302 w->window_class != WC_TOOLTIPS &&
3303 (w->flags & WF_STICKY) == 0) { // do not delete windows which are 'pinned'
3304
3305 w->Close();
3306 }
3307 }
3308 }
3309
3317 void CloseAllNonVitalWindows()
3318 {
3319 /* Close every window except for stickied ones, then sticky ones as well */
3320 CloseNonVitalWindows();
3321
3322 /* Note: the container remains stable, even when closing windows. */
3323 for (Window *w : Window::Iterate()) {
3324 if (w->flags & WF_STICKY) {
3325 w->Close();
3326 }
3327 }
3328 }
3329
3333 void DeleteAllMessages()
3334 {
3335 InitNewsItemStructs();
3336 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar
3337 InvalidateWindowData(WC_MESSAGE_HISTORY, 0); // invalidate the message history
3338 CloseWindowById(WC_NEWS_WINDOW, 0); // close newspaper or general message window if shown
3339 }
3340
3345 void CloseConstructionWindows()
3346 {
3347 /* Note: the container remains stable, even when deleting windows. */
3348 for (Window *w : Window::Iterate()) {
3349 if (w->window_desc->flags & WDF_CONSTRUCTION) {
3350 w->Close();
3351 }
3352 }
3353
3354 for (const Window *w : Window::Iterate()) w->SetDirty();
3355 }
3356
3358 void HideVitalWindows()
3359 {
3360 CloseWindowById(WC_MAIN_TOOLBAR, 0);
3361 CloseWindowById(WC_STATUS_BAR, 0);
3362 }
3363
3364 void ReInitWindow(Window *w, bool zoom_changed)
3365 {
3366 if (w == nullptr) return;
3367 if (zoom_changed) {
3368 w->nested_root->AdjustPaddingForZoom();
3369 w->UpdateQueryStringSize();
3370 }
3371 w->ReInit();
3372 }
3373
3375 void ReInitAllWindows(bool zoom_changed)
3376 {
3377 SetupWidgetDimensions();
3378 NWidgetLeaf::InvalidateDimensionCache(); // Reset cached sizes of several widgets.
3379 NWidgetScrollbar::InvalidateDimensionCache();
3380
3381 extern void InitDepotWindowBlockSizes();
3382 InitDepotWindowBlockSizes();
3383
3384 /* When _gui_zoom has changed, we need to resize toolbar and statusbar first,
3385 * so EnsureVisibleCaption uses the updated size information. */
3386 ReInitWindow(FindWindowById(WC_MAIN_TOOLBAR, 0), zoom_changed);
3387 ReInitWindow(FindWindowById(WC_STATUS_BAR, 0), zoom_changed);
3388 for (Window *w : Window::Iterate()) {
3389 if (w->window_class == WC_MAIN_TOOLBAR || w->window_class == WC_STATUS_BAR) continue;
3390 ReInitWindow(w, zoom_changed);
3391 }
3392
3393 void NetworkReInitChatBoxSize();
3394 NetworkReInitChatBoxSize();
3395
3396 /* Make sure essential parts of all windows are visible */
3397 RelocateAllWindows(_screen.width, _screen.height);
3398 MarkWholeScreenDirty();
3399 }
3400
3408 static int PositionWindow(Window *w, WindowClass clss, int setting)
3409 {
3410 if (w == nullptr || w->window_class != clss) {
3411 w = FindWindowById(clss, 0);
3412 }
3413 if (w == nullptr) return 0;
3414
3415 int old_left = w->left;
3416 switch (setting) {
3417 case 1: w->left = (_screen.width - w->width) / 2; break;
3418 case 2: w->left = _screen.width - w->width; break;
3419 default: w->left = 0; break;
3420 }
3421 if (w->viewport != nullptr) w->viewport->left += w->left - old_left;
3422 AddDirtyBlock(0, w->top, _screen.width, w->top + w->height); // invalidate the whole row
3423 return w->left;
3424 }
3425
3431 int PositionMainToolbar(Window *w)
3432 {
3433 Debug(misc, 5, "Repositioning Main Toolbar...");
3434 return PositionWindow(w, WC_MAIN_TOOLBAR, _settings_client.gui.toolbar_pos);
3435 }
3436
3442 int PositionStatusbar(Window *w)
3443 {
3444 Debug(misc, 5, "Repositioning statusbar...");
3445 return PositionWindow(w, WC_STATUS_BAR, _settings_client.gui.statusbar_pos);
3446 }
3447
3453 int PositionNewsMessage(Window *w)
3454 {
3455 Debug(misc, 5, "Repositioning news message...");
3456 return PositionWindow(w, WC_NEWS_WINDOW, _settings_client.gui.statusbar_pos);
3457 }
3458
3464 int PositionNetworkChatWindow(Window *w)
3465 {
3466 Debug(misc, 5, "Repositioning network chat window...");
3467 return PositionWindow(w, WC_SEND_NETWORK_MSG, _settings_client.gui.statusbar_pos);
3468 }
3469
3470
3476 void ChangeVehicleViewports(VehicleID from_index, VehicleID to_index)
3477 {
3478 for (const Window *w : Window::Iterate()) {
3479 if (w->viewport != nullptr && w->viewport->follow_vehicle == from_index) {
3480 w->viewport->follow_vehicle = to_index;
3481 w->SetDirty();
3482 }
3483 }
3484 }
3485
3486
3492 void RelocateAllWindows(int neww, int newh)
3493 {
3494 CloseWindowById(WC_DROPDOWN_MENU, 0);
3495
3496 for (Window *w : Window::Iterate()) {
3497 int left, top;
3498 /* XXX - this probably needs something more sane. For example specifying
3499 * in a 'backup'-desc that the window should always be centered. */
3500 switch (w->window_class) {
3501 case WC_MAIN_WINDOW:
3502 case WC_BOOTSTRAP:
3503 ResizeWindow(w, neww, newh);
3504 continue;
3505
3506 case WC_MAIN_TOOLBAR:
3507 ResizeWindow(w, std::min<uint>(neww, _toolbar_width) - w->width, 0, false);
3508
3509 top = w->top;
3510 left = PositionMainToolbar(w); // changes toolbar orientation
3511 break;
3512
3513 case WC_NEWS_WINDOW:
3514 top = newh - w->height;
3515 left = PositionNewsMessage(w);
3516 break;
3517
3518 case WC_STATUS_BAR:
3519 ResizeWindow(w, std::min<uint>(neww, _toolbar_width) - w->width, 0, false);
3520
3521 top = newh - w->height;
3522 left = PositionStatusbar(w);
3523 break;
3524
3525 case WC_SEND_NETWORK_MSG:
3526 ResizeWindow(w, std::min<uint>(neww, _toolbar_width) - w->width, 0, false);
3527
3528 top = newh - w->height - FindWindowById(WC_STATUS_BAR, 0)->height;
3529 left = PositionNetworkChatWindow(w);
3530 break;
3531
3532 case WC_CONSOLE:
3533 IConsoleResize(w);
3534 continue;
3535
3536 default: {
3537 if (w->flags & WF_CENTERED) {
3538 top = (newh - w->height) >> 1;
3539 left = (neww - w->width) >> 1;
3540 break;
3541 }
3542
3543 left = w->left;
3544 if (left + (w->width >> 1) >= neww) left = neww - w->width;
3545 if (left < 0) left = 0;
3546
3547 top = w->top;
3548 if (top + (w->height >> 1) >= newh) top = newh - w->height;
3549 break;
3550 }
3551 }
3552
3553 EnsureVisibleCaption(w, left, top);
3554 }
3555 }
3556
3561 void PickerWindowBase::Close()
3562 {
3563 ResetObjectToPlace();
3564 this->Window::Close();
3565 }
_dirkeys
byte _dirkeys
1 = left, 2 = up, 4 = right, 8 = down
Definition: gfx.cpp:34
game.hpp
NewGrfDebugSpritePicker::clicked_pixel
void * clicked_pixel
Clicked pixel (pointer to blitter buffer)
Definition: newgrf_debug.h:28
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:720
ShowFirstError
void ShowFirstError()
Show the first error of the queue.
Definition: error_gui.cpp:342
Window::WindowIterator
Iterator to iterate all valid Windows.
Definition: window_gui.h:758
WC_CUSTOM_CURRENCY
@ WC_CUSTOM_CURRENCY
Custom currency; Window numbers:
Definition: window_type.h:612
WC_SAVELOAD
@ WC_SAVELOAD
Saveload window; Window numbers:
Definition: window_type.h:137
ScrollbarClickHandler
void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
Special handling for the scrollbar widget type.
Definition: widget.cpp:375
PickerWindowBase::Close
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:3561
Window::SetTimeout
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:295
WC_ROADVEH_LIST
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
Definition: window_type.h:307
MAX_OFFSET_HOVER
@ MAX_OFFSET_HOVER
Maximum mouse movement before stopping a hover event.
Definition: window.cpp:2770
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:3252
HideVitalWindows
void HideVitalWindows()
Close all always on-top windows to get an empty screen.
Definition: window.cpp:3358
factory.hpp
FindWindowFromPt
Window * FindWindowFromPt(int x, int y)
Do a search for a window at specific coordinates.
Definition: window.cpp:1822
WC_INVALID
@ WC_INVALID
Invalid window.
Definition: window_type.h:700
NWidgetCore::IsDisabled
bool IsDisabled() const
Return whether the widget is disabled.
Definition: widget_type.h:393
_mouseover_last_w
static Window * _mouseover_last_w
Window of the last OnMouseOver event.
Definition: window.cpp:53
Pool::PoolItem<&_vehicle_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
WC_BUILD_TOOLBAR
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition: window_type.h:66
MouseClick
MouseClick
Definition: window.cpp:2762
QueryString::ok_button
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Definition: querystring_gui.h:27
Window::timeout_timer
uint8 timeout_timer
Timer value of the WF_TIMEOUT for flags.
Definition: window_gui.h:243
Window::OnHundredthTick
virtual void OnHundredthTick()
Called once every 100 (game) ticks, or once every 3s, whichever comes last.
Definition: window_gui.h:629
HKPR_EDITING
@ HKPR_EDITING
Textbuf content changed.
Definition: textbuf_type.h:22
WChar
char32_t WChar
Type for wide characters, i.e.
Definition: string_type.h:36
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:1724
Vehicle::y_pos
int32 y_pos
y coordinate.
Definition: vehicle_base.h:284
WF_SIZING
@ WF_SIZING
Window is being resized.
Definition: window_gui.h:173
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3154
CheckSoftLimit
static void CheckSoftLimit()
Check the soft limit of deletable (non vital, non sticky) windows.
Definition: window.cpp:3013
UpdateTileSelection
void UpdateTileSelection()
Updates tile highlighting for all cases.
Definition: viewport.cpp:2543
querystring_gui.h
Window::OnEditboxChanged
virtual void OnEditboxChanged(int widget)
The text in an editbox has been edited.
Definition: window_gui.h:661
Window::SetWhiteBorder
void SetWhiteBorder()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:304
HotkeyList
List of hotkeys for a window.
Definition: hotkeys.h:40
FindChildWindow
static Window * FindChildWindow(const Window *w, WindowClass wc)
Find the Window whose parent pointer points to this window.
Definition: window.cpp:1078
QueryString::GetText
const char * GetText() const
Get the current text.
Definition: querystring_gui.h:63
SetFocusedWindow
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Definition: window.cpp:456
Vehicle::x_pos
int32 x_pos
x coordinate.
Definition: vehicle_base.h:283
Window::~Window
virtual ~Window()
Remove window and all its child windows from the window stack.
Definition: window.cpp:1140
Scrollbar::GetCapacity
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:667
Window::nested_root
NWidgetBase * nested_root
Root of the nested tree.
Definition: window_gui.h:258
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:830
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:320
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:144
PositionMainToolbar
int PositionMainToolbar(Window *w)
(Re)position main toolbar window at the screen.
Definition: window.cpp:3431
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:261
WF_SIZING_RIGHT
@ WF_SIZING_RIGHT
Window is being resized towards the right.
Definition: window_gui.h:171
dropdown_func.h
Window::OnHover
virtual void OnHover(Point pt, int widget)
The mouse is hovering over a widget in the window, perform an action for it.
Definition: window_gui.h:569
_special_mouse_mode
SpecialMouseMode _special_mouse_mode
Mode of the mouse.
Definition: window.cpp:93
WID_OSK_OK
@ WID_OSK_OK
Ok key.
Definition: osk_widget.h:18
toolbar_gui.h
_left_button_down
bool _left_button_down
Is left mouse button pressed?
Definition: gfx.cpp:41
guitimer_func.h
statusbar_gui.h
Window::ApplyDefaults
virtual void ApplyDefaults()
Read default values from WindowDesc configuration an apply them to the window.
Definition: window.cpp:193
Window::ReInit
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:1015
scrollamt
static const int8 scrollamt[16][2]
Describes all the different arrow key combinations the game allows when it is in scrolling mode.
Definition: window.cpp:2796
CloseCompanyWindows
void CloseCompanyWindows(CompanyID id)
Close all windows of a company.
Definition: window.cpp:1215
LocalGetWindowPlacement
static Point LocalGetWindowPlacement(const WindowDesc *desc, int16 sm_width, int16 sm_height, int window_number)
Compute the position of the top-left corner of a new window that is opened.
Definition: window.cpp:1700
ND_SCROLLBAR_DOWN
@ ND_SCROLLBAR_DOWN
Bit value of the 'scrollbar down' flag.
Definition: widget_type.h:305
NWID_HSCROLLBAR
@ NWID_HSCROLLBAR
Horizontal scrollbar.
Definition: widget_type.h:81
WC_COMPANY_COLOUR
@ WC_COMPANY_COLOUR
Company colour selection; Window numbers:
Definition: window_type.h:223
Blitter
How all blitters should look like.
Definition: base.hpp:28
IniLoadWindowSettings
void IniLoadWindowSettings(IniFile &ini, const char *grpname, void *desc)
Load a WindowDesc from config.
Definition: settings.cpp:786
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:1450
HandleScrollbarScrolling
static void HandleScrollbarScrolling(Window *w)
Handle scrollbar scrolling with the mouse.
Definition: window.cpp:2349
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:2711
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
WC_SELECT_GAME
@ WC_SELECT_GAME
Select game window; Window numbers:
Definition: window_type.h:435
Viewport::width
int width
Screen width of the viewport.
Definition: viewport_type.h:25
Vehicle::z_pos
int32 z_pos
z coordinate.
Definition: vehicle_base.h:285
PHD_DOWN
@ PHD_DOWN
Below v is a safe position.
Definition: window.cpp:1993
WF_DISABLE_VP_SCROLL
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
Definition: window_gui.h:175
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:255
_newgrf_debug_sprite_picker
NewGrfDebugSpritePicker _newgrf_debug_sprite_picker
The sprite picker.
Definition: newgrf_debug_gui.cpp:48
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:63
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1771
NewGrfDebugSpritePicker::sprites
std::vector< SpriteID > sprites
Sprites found.
Definition: newgrf_debug.h:29
WDP_ALIGN_TOOLBAR
@ WDP_ALIGN_TOOLBAR
Align toward the toolbar.
Definition: window_gui.h:92
InitWindowSystem
void InitWindowSystem()
(re)initialize the windowing system
Definition: window.cpp:1836
NewGrfDebugSpritePicker::mode
NewGrfDebugSpritePickerMode mode
Current state.
Definition: newgrf_debug.h:27
Window::OnGameTick
virtual void OnGameTick()
Called once per (game) tick.
Definition: window_gui.h:622
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:174
UpdateWindows
void UpdateWindows()
Update the continuously changing contents of the windows, such as the viewports.
Definition: window.cpp:3073
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1157
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
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:2332
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:1388
valid
uint8 valid
Bits indicating what variable is valid (for each bit, 0 is invalid, 1 is valid).
Definition: newgrf_station.cpp:248
WDF_NO_FOCUS
@ WDF_NO_FOCUS
This window won't get focus/make any other window lose focus when click.
Definition: window_gui.h:146
UnInitWindowSystem
void UnInitWindowSystem()
Close down the windowing system.
Definition: window.cpp:1855
VA_DISABLED
@ VA_DISABLED
Do not autoscroll when mouse is at edge of viewport.
Definition: window.cpp:46
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
GUISettings::window_soft_limit
uint8 window_soft_limit
soft limit of maximum number of non-stickied non-vital windows (0 = no limit)
Definition: settings_type.h:133
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:257
vehicle_base.h
Window::OnInvalidateData
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition: window_gui.h:676
zoom_func.h
WC_BOOTSTRAP
@ WC_BOOTSTRAP
Bootstrap; Window numbers:
Definition: window_type.h:637
Window::RaiseButtons
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition: window.cpp:595
WC_GENERATE_LANDSCAPE
@ WC_GENERATE_LANDSCAPE
Generate landscape (newgame); Window numbers:
Definition: window_type.h:449
WC_MESSAGE_HISTORY
@ WC_MESSAGE_HISTORY
News history list; Window numbers:
Definition: window_type.h:265
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
Window::SetWidgetHighlight
void SetWidgetHighlight(byte widget_index, TextColour highlighted_colour)
Sets the highlighted status of a widget.
Definition: window.cpp:243
WC_OSK
@ WC_OSK
On Screen Keyboard; Window numbers:
Definition: window_type.h:155
WindowDesc::cls
WindowClass cls
Class of the window,.
Definition: window_gui.h:111
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:425
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:99
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
Window::OnTimeout
virtual void OnTimeout()
Called when this window's timeout has been reached.
Definition: window_gui.h:639
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:253
NWidgetBase::FillNestedArray
virtual void FillNestedArray(NWidgetBase **array, uint length)=0
Window::OnDropdownClose
virtual void OnDropdownClose(Point pt, int widget, int index, bool instant_close)
A dropdown window associated to this window has been closed.
Definition: window.cpp:293
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:713
WC_COMPANY
@ WC_COMPANY
Company view; Window numbers:
Definition: window_type.h:362
NWidgetCore::tool_tip
StringID tool_tip
Tooltip of the widget.
Definition: widget_type.h:339
NWidgetCore::SetLowered
void SetLowered(bool lowered)
Lower or raise the widget.
Definition: widget_type.h:372
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:224
QueryString::GetCharAtPosition
const char * GetCharAtPosition(const Window *w, int wid, const Point &pt) const
Get the character that is rendered at a position.
Definition: misc_gui.cpp:912
Window::HandleButtonClick
void HandleButtonClick(byte widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
Definition: window.cpp:657
Window::GetCaretPosition
virtual Point GetCaretPosition() const
Get the current caret position if an edit box has the focus.
Definition: window.cpp:412
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
NWidgetBase::smallest_y
uint smallest_y
Smallest vertical size of the widget in a filled window.
Definition: widget_type.h:194
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:634
GUISettings::toolbar_pos
uint8 toolbar_pos
position of toolbars, 0=left, 1=center, 2=right
Definition: settings_type.h:130
EditBoxInGlobalFocus
bool EditBoxInGlobalFocus()
Check if an edit box is in global focus.
Definition: window.cpp:479
HandleAutoscroll
static void HandleAutoscroll()
If needed and switched on, perform auto scrolling (automatically moving window contents when mouse is...
Definition: window.cpp:2730
Window::OnHotkey
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: window.cpp:632
StartWindowDrag
static void StartWindowDrag(Window *w)
Start window dragging.
Definition: window.cpp:2314
IsLocalCompany
static bool IsLocalCompany()
Is the current company the local company?
Definition: company_func.h:43
HandleKeypress
void HandleKeypress(uint keycode, WChar key)
Handle keyboard input.
Definition: window.cpp:2625
Window::Window
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1810
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:973
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:162
Window::nested_focus
const NWidgetCore * nested_focus
Currently focused nested widget, or nullptr if no nested widget has focus.
Definition: window_gui.h:256
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:1307
WC_GRF_PARAMETERS
@ WC_GRF_PARAMETERS
NewGRF parameters; Window numbers:
Definition: window_type.h:174
Window::scheduled_invalidation_data
std::vector< int > scheduled_invalidation_data
Data of scheduled OnInvalidateData() calls.
Definition: window_gui.h:222
Window::IsWidgetHighlighted
bool IsWidgetHighlighted(byte widget_index) const
Gets the highlighted status of a widget.
Definition: window.cpp:276
WC_SAVE_PRESET
@ WC_SAVE_PRESET
Save preset; Window numbers:
Definition: window_type.h:680
Window::GetCaret
virtual const char * GetCaret() const
Get the string at the caret if an edit box has the focus.
Definition: window.cpp:385
Window::OnCTRLStateChange
virtual EventState OnCTRLStateChange()
The state of the control key has changed.
Definition: window_gui.h:544
Window::GetTextCharacterAtPosition
virtual const char * GetTextCharacterAtPosition(const Point &pt) const
Get the character that is rendered at a position by the focused edit box.
Definition: window.cpp:443
Window::querystrings
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:257
SmallMap
Implementation of simple mapping class.
Definition: smallmap_type.hpp:26
WC_HIGHSCORE
@ WC_HIGHSCORE
Highscore; Window numbers:
Definition: window_type.h:643
NetworkReInitChatBoxSize
void NetworkReInitChatBoxSize()
Initialize all font-dependent chat box sizes.
Definition: network_chat_gui.cpp:107
Window::ProcessScheduledInvalidations
void ProcessScheduledInvalidations()
Process all scheduled invalidations.
Definition: window.cpp:3205
WindowDesc::default_width_trad
int16 default_width_trad
Preferred initial width of the window (pixels at 1x zoom).
Definition: window_gui.h:130
PHD_UP
@ PHD_UP
Above v is a safe position.
Definition: window.cpp:1992
gfx_func.h
WindowDesc::default_pos
WindowPosition default_pos
Preferred position of the window.
Definition: window_gui.h:110
WindowDesc
High level window description.
Definition: window_gui.h:102
WC_MODAL_PROGRESS
@ WC_MODAL_PROGRESS
Progress report of landscape generation; Window numbers:
Definition: window_type.h:456
SetWindowWidgetDirty
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
Definition: window.cpp:3167
WF_SIZING_LEFT
@ WF_SIZING_LEFT
Window is being resized towards the left.
Definition: window_gui.h:172
NWidgetLeaf::InvalidateDimensionCache
static void InvalidateDimensionCache()
Reset the cached dimensions.
Definition: widget.cpp:2544
PositionStatusbar
int PositionStatusbar(Window *w)
(Re)position statusbar window at the screen.
Definition: window.cpp:3442
Window::SetShaded
void SetShaded(bool make_shaded)
Set the shaded state of the window to make_shaded.
Definition: window.cpp:1051
Window::GetWidget
const NWID * GetWidget(uint widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition: window_gui.h:865
ND_DROPDOWN_ACTIVE
@ ND_DROPDOWN_ACTIVE
Bit value of the 'dropdown active' flag.
Definition: widget_type.h:303
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:761
GUISettings::scrollwheel_scrolling
uint8 scrollwheel_scrolling
scrolling using the scroll wheel?
Definition: settings_type.h:146
WC_CONFIRM_POPUP_QUERY
@ WC_CONFIRM_POPUP_QUERY
Popup with confirm question; Window numbers:
Definition: window_type.h:123
Window::OnFocusLost
virtual void OnFocusLost()
Called when window loses focus.
Definition: window.cpp:546
MayBeShown
static bool MayBeShown(const Window *w)
Returns whether a window may be shown or not.
Definition: window.cpp:891
PositionNewsMessage
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
Definition: window.cpp:3453
WC_QUERY_STRING
@ WC_QUERY_STRING
Query string window; Window numbers:
Definition: window_type.h:116
Viewport
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:22
GUITimer
Definition: guitimer_func.h:13
Window::UnfocusFocusedWidget
void UnfocusFocusedWidget()
Makes no widget on this window have focus.
Definition: window.cpp:501
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:90
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:113
ChangeVehicleViewports
void ChangeVehicleViewports(VehicleID from_index, VehicleID to_index)
Switches viewports following vehicles, which get autoreplaced.
Definition: window.cpp:3476
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:251
_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:2724
WSM_PRESIZE
@ WSM_PRESIZE
Presizing mode (docks, tunnels).
Definition: window_gui.h:925
ST_SMALLEST
@ ST_SMALLEST
Initialize nested widget tree to smallest size. Also updates current_x and current_y.
Definition: widget_type.h:112
GuiShowTooltips
void GuiShowTooltips(Window *parent, StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip)
Shows a tooltip.
Definition: misc_gui.cpp:773
settings_func.h
Scrollbar::GetCount
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:658
tilehighlight_func.h
WC_BUY_COMPANY
@ WC_BUY_COMPANY
Buyout company (merger); Window numbers:
Definition: window_type.h:576
DescSorter
static bool DescSorter(WindowDesc *const &a, WindowDesc *const &b)
Sort WindowDesc by ini_key.
Definition: window.cpp:167
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1800
Window::ProcessHighlightedInvalidations
void ProcessHighlightedInvalidations()
Process all invalidation of highlighted widgets.
Definition: window.cpp:3217
CloseNonVitalWindows
void CloseNonVitalWindows()
Try to close a non-vital window.
Definition: window.cpp:3294
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:69
ReInitAllWindows
void ReInitAllWindows(bool zoom_changed)
Re-initialize all windows.
Definition: window.cpp:3375
NWidgetBase::type
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:185
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:249
_toolbar_width
uint _toolbar_width
Width of the toolbar, shared by statusbar.
Definition: toolbar_gui.cpp:67
WF_CENTERED
@ WF_CENTERED
Window is centered and shall stay centered after ReInit.
Definition: window_gui.h:178
WF_WHITE_BORDER
@ WF_WHITE_BORDER
Window white border counter bit mask.
Definition: window_gui.h:176
SpecialMouseMode
SpecialMouseMode
Mouse modes.
Definition: window_gui.h:921
INVALID_VEHICLE
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
Definition: vehicle_type.h:55
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1004
Viewport::left
int left
Screen coordinate left edge of the viewport.
Definition: viewport_type.h:23
NWidgetBase::smallest_x
uint smallest_x
Smallest horizontal size of the widget in a filled window.
Definition: widget_type.h:193
SBI_NEWS_DELETED
@ SBI_NEWS_DELETED
abort current news display (active news were deleted)
Definition: statusbar_gui.h:19
NWidgetBase::AssignSizePosition
virtual void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)=0
IsInsideBS
static 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:188
QueryString::GetBoundingRect
Rect GetBoundingRect(const Window *w, int wid, const char *from, const char *to) const
Get the bounding rectangle for a range of the query string.
Definition: misc_gui.cpp:881
NWidgetBase::GetWidgetOfType
virtual NWidgetBase * GetWidgetOfType(WidgetType tp)
Retrieve a widget by its type.
Definition: widget.cpp:1044
INVALID_OWNER
@ INVALID_OWNER
An invalid owner.
Definition: company_type.h:29
Window::OnFocus
virtual void OnFocus()
Called when window gains focus.
Definition: window.cpp:538
IniFile::SaveToDisk
bool SaveToDisk(const std::string &filename)
Save the Ini file's data to the disk.
Definition: ini.cpp:46
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:721
DispatchMouseWheelEvent
static void DispatchMouseWheelEvent(Window *w, NWidgetCore *nwid, int wheel)
Dispatch the mousewheel-action to the window.
Definition: window.cpp:860
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:126
RelocateAllWindows
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
Definition: window.cpp:3492
Window::HandleEditBoxKey
EventState HandleEditBoxKey(int wid, WChar key, uint16 keycode)
Process keypress for editbox widget.
Definition: window.cpp:2536
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:1607
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:2006
GetWidgetFromPos
int 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:399
Window::DisableAllWidgetHighlight
void DisableAllWidgetHighlight()
Disable the highlighted status of all widgets.
Definition: window.cpp:223
_pause_mode
PauseMode _pause_mode
The current pause mode.
Definition: gfx.cpp:50
ProcessPendingPerformanceMeasurements
void ProcessPendingPerformanceMeasurements()
This drains the PFE_SOUND measurement data queue into _pf_data.
Definition: framerate_gui.cpp:1111
GetMainViewTop
int GetMainViewTop()
Return the top of the main view available for general use.
Definition: window.cpp:2120
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
BlitterFactory::GetCurrentBlitter
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition: factory.hpp:141
Window::GetQueryString
const QueryString * GetQueryString(uint widnum) const
Return the querystring associated to a editbox.
Definition: window.cpp:340
Window::OnDropdownSelect
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
Definition: window_gui.h:653
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:919
WindowDesc::GetDefaultWidth
int16 GetDefaultWidth() const
Determine default width of window.
Definition: window.cpp:136
Game::NewEvent
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
Definition: game_core.cpp:146
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:321
Window::DeleteClosedWindows
static void DeleteClosedWindows()
Delete all closed windows.
Definition: window.cpp:65
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:266
CallWindowGameTickEvent
void CallWindowGameTickEvent()
Dispatch OnGameTick event over all windows.
Definition: window.cpp:3281
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:1675
GUISettings::hover_delay_ms
uint16 hover_delay_ms
time required to activate a hover event, in milliseconds
Definition: settings_type.h:118
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:246
Window::OnDragDrop
virtual void OnDragDrop(Point pt, int widget)
A dragged 'object' has been released.
Definition: window_gui.h:591
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:239
_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:168
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:313
WindowClass
WindowClass
Window classes.
Definition: window_type.h:37
WWT_LAST
@ WWT_LAST
Last Item. use WIDGETS_END to fill up padding!!
Definition: widget_type.h:70
Window::ShowNewGRFInspectWindow
virtual void ShowNewGRFInspectWindow() const
Show the NewGRF inspection window.
Definition: window_gui.h:751
HandleCtrlChanged
void HandleCtrlChanged()
State of CONTROL key has changed.
Definition: window.cpp:2681
_mouse_hovering
bool _mouse_hovering
The mouse is hovering over the same point.
Definition: window.cpp:91
WindowDesc::default_height_trad
int16 default_height_trad
Preferred initial height of the window (pixels at 1x zoom).
Definition: window_gui.h:131
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:378
_shift_pressed
bool _shift_pressed
Is Shift pressed?
Definition: gfx.cpp:39
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:3408
HandleMouseOver
static void HandleMouseOver()
Report position of the mouse to the underlying window.
Definition: window.cpp:1965
DrawDirtyBlocks
void DrawDirtyBlocks()
Repaints the rectangle blocks which are marked as 'dirty'.
Definition: gfx.cpp:1635
NDB_SCROLLBAR_UP
@ NDB_SCROLLBAR_UP
Up-button is lowered bit.
Definition: widget_type.h:292
WDF_MODAL
@ WDF_MODAL
The window is a modal child of some other window, meaning the parent is 'inactive'.
Definition: window_gui.h:145
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:100
WindowDesc::GetDefaultHeight
int16 GetDefaultHeight() const
Determine default height of window.
Definition: window.cpp:146
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:177
ScrollMainWindowTo
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
Definition: smallmap_gui.cpp:1883
WindowDesc::nwid_parts
const NWidgetPart * nwid_parts
Nested widget parts describing the window.
Definition: window_gui.h:115
FocusedWindowIsConsole
bool FocusedWindowIsConsole()
Check if a console is focused.
Definition: window.cpp:493
error.h
ViewportData::dest_scrollpos_y
int32 dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition: window_gui.h:197
WC_TRAINS_LIST
@ WC_TRAINS_LIST
Trains list; Window numbers:
Definition: window_type.h:301
WSM_DRAGDROP
@ WSM_DRAGDROP
Drag&drop an object.
Definition: window_gui.h:923
Window::OnInit
virtual void OnInit()
Notification that the nested widget tree gets initialized.
Definition: window_gui.h:472
Window::unshaded_size
Dimension unshaded_size
Last known unshaded size (only valid while shaded).
Definition: window_gui.h:262
_network_dedicated
bool _network_dedicated
are we a dedicated server?
Definition: network.cpp:61
WindowDesc::SaveToConfig
static void SaveToConfig()
Save all WindowDesc settings to _windows_file.
Definition: window.cpp:176
Window::SetFocusedWidget
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:517
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:241
RoundDivSU
static int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
Definition: math_func.hpp:276
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:154
WindowDesc::WindowDesc
WindowDesc(WindowPosition default_pos, const char *ini_key, int16 def_width_trad, int16 def_height_trad, WindowClass window_class, WindowClass parent_class, uint32 flags, const NWidgetPart *nwid_parts, int16 nwid_length, HotkeyList *hotkeys=nullptr)
Window description constructor.
Definition: window.cpp:105
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:3192
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:202
NWidgetStacked::SetDisplayedPlane
void SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1409
viewport_func.h
Window::mouse_capture_widget
int mouse_capture_widget
Widgetindex of current mouse capture widget (e.g. dragged scrollbar). -1 if no widget has mouse captu...
Definition: window_gui.h:264
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:197
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
HandleMouseEvents
void HandleMouseEvents()
Handle a mouse event from the video driver.
Definition: window.cpp:2930
Window::AllWindows
Iterable ensemble of all valid Windows.
Definition: window_gui.h:803
GUISettings::statusbar_pos
uint8 statusbar_pos
position of statusbar, 0=left, 1=center, 2=right
Definition: settings_type.h:131
Window::nested_array
NWidgetBase ** nested_array
Array of pointers into the tree. Do not access directly, use Window::GetWidget() instead.
Definition: window_gui.h:259
WidgetType
WidgetType
Window widget types, nested widget types, and nested widget part types.
Definition: widget_type.h:44
Window::OnPlacePresize
virtual void OnPlacePresize(Point pt, TileIndex tile)
The user moves over the map when a tile highlight mode has been set when the special mouse mode has b...
Definition: window_gui.h:735
QueryString::GetCaret
const char * GetCaret() const
Get the position of the caret in the text buffer.
Definition: querystring_gui.h:72
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
NWidgetBase::GetWidgetFromPos
virtual NWidgetCore * GetWidgetFromPos(int x, int y)=0
DispatchRightClickEvent
static void DispatchRightClickEvent(Window *w, int x, int y)
Dispatch right mouse-button click in window.
Definition: window.cpp:806
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:1568
HandleViewportScroll
static EventState HandleViewportScroll()
Handle viewport scrolling with the mouse.
Definition: window.cpp:2416
Window::OnClick
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: window_gui.h:553
Textbuf::bytes
uint16 bytes
the current size of the string in bytes (including terminating '\0')
Definition: textbuf_type.h:35
_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
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:606
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
Window::OnMouseLoop
virtual void OnMouseLoop()
Called for every mouse loop run, which is at least once per (game) tick.
Definition: window_gui.h:617
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
ScaleByZoom
static 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
ResizeInfo::step_width
uint step_width
Step-size of width resize changes.
Definition: window_gui.h:153
VSM_MAP_LMB
@ VSM_MAP_LMB
Map moves with mouse movement on holding left mouse button, cursor moves.
Definition: settings_type.h:102
NWidgetCore::disp_flags
NWidgetDisplay disp_flags
Flags that affect display and interaction with the widget.
Definition: widget_type.h:335
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:2769
Window::OnMouseWheel
virtual void OnMouseWheel(int wheel)
The mouse wheel has been turned.
Definition: window_gui.h:611
IniFile
Ini file that supports both loading and saving.
Definition: ini_type.h:89
WindowDesc::flags
uint32 flags
Flags.
Definition: window_gui.h:114
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:455
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:199
ST_RESIZE
@ ST_RESIZE
Resize the nested widget tree.
Definition: widget_type.h:113
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...
HideDropDownMenu
int HideDropDownMenu(Window *pw)
Delete the drop-down menu from window pw.
Definition: dropdown.cpp:505
DeleteAllMessages
void DeleteAllMessages()
Delete all messages and close their corresponding window (if any).
Definition: window.cpp:3333
WIDGET_LIST_END
static const int WIDGET_LIST_END
indicate the end of widgets' list for vararg functions
Definition: widget_type.h:20
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:215
Window::CloseChildWindows
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition: window.cpp:1091
UnshowCriticalError
void UnshowCriticalError()
Unshow the critical error.
Definition: error_gui.cpp:356
VA_MAIN_VIEWPORT_FULLSCREEN
@ VA_MAIN_VIEWPORT_FULLSCREEN
Scroll main viewport at edge when using fullscreen.
Definition: window.cpp:47
WC_AI_LIST
@ WC_AI_LIST
AI list; Window numbers:
Definition: window_type.h:277
Window::SetWidgetsLoweredState
void CDECL SetWidgetsLoweredState(bool lowered_stat, int widgets,...)
Sets the lowered/raised status of a list of widgets.
Definition: window.cpp:577
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:206
Window::OnTooltip
virtual bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond)
Event to display a custom tooltip.
Definition: window_gui.h:577
WC_SCEN_LAND_GEN
@ WC_SCEN_LAND_GEN
Landscape generation (in Scenario Editor); Window numbers:
Definition: window_type.h:442
video_driver.hpp
DispatchHoverEvent
static void DispatchHoverEvent(Window *w, int x, int y)
Dispatch hover of the mouse over a window.
Definition: window.cpp:832
NO_DIRECTORY
@ NO_DIRECTORY
A path without any base directory.
Definition: fileio_type.h:125
WC_NETWORK_WINDOW
@ WC_NETWORK_WINDOW
Network window; Window numbers:
Definition: window_type.h:465
NWidgetScrollbar
Nested widget to display and control a scrollbar in a window.
Definition: widget_type.h:798
WC_CONSOLE
@ WC_CONSOLE
Console; Window numbers:
Definition: window_type.h:631
CloseWindowByClass
void CloseWindowByClass(WindowClass cls)
Close all windows of a given class.
Definition: window.cpp:1199
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:3269
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:428
WC_NETWORK_STATUS_WINDOW
@ WC_NETWORK_STATUS_WINDOW
Network status window; Window numbers:
Definition: window_type.h:478
WC_TOOLTIPS
@ WC_TOOLTIPS
Tooltip window; Window numbers:
Definition: window_type.h:109
WC_AI_SETTINGS
@ WC_AI_SETTINGS
AI settings; Window numbers:
Definition: window_type.h:168
_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:489
CursorVars::delta
Point delta
relative mouse movement in this tick
Definition: gfx_type.h:118
Window::SetWidgetsDisabledState
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
Definition: window.cpp:558
IniSaveWindowSettings
void IniSaveWindowSettings(IniFile &ini, const char *grpname, void *desc)
Save a WindowDesc to config.
Definition: settings.cpp:797
NWidgetBase::resize_y
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:189
Window::IsWidgetLowered
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:422
QueryString::GetMarkedText
const char * GetMarkedText(size_t *length) const
Get the currently marked text.
Definition: querystring_gui.h:82
WC_COMPANY_INFRASTRUCTURE
@ WC_COMPANY_INFRASTRUCTURE
Company infrastructure overview; Window numbers:
Definition: window_type.h:569
HKPR_CANCEL
@ HKPR_CANCEL
Escape key pressed.
Definition: textbuf_type.h:25
WID_OSK_CANCEL
@ WID_OSK_CANCEL
Cancel key.
Definition: osk_widget.h:17
VpHandlePlaceSizingDrag
EventState VpHandlePlaceSizingDrag()
Handle the mouse while dragging for placement/resizing.
Definition: viewport.cpp:3317
Window::OnMouseOver
virtual void OnMouseOver(Point pt, int widget)
The mouse is currently moving over the window or has just moved outside of the window.
Definition: window_gui.h:605
EventState
EventState
State of handling an event.
Definition: window_type.h:719
UpdateViewportPosition
void UpdateViewportPosition(Window *w)
Update the viewport position being displayed.
Definition: viewport.cpp:1874
WindowDesc::pref_sticky
bool pref_sticky
Preferred stickyness.
Definition: window_gui.h:119
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:676
WF_DRAGGING
@ WF_DRAGGING
Window is being dragged.
Definition: window_gui.h:170
WC_NETWORK_ASK_RELAY
@ WC_NETWORK_ASK_RELAY
Network ask relay window; Window numbers:
Definition: window_type.h:484
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition: window.cpp:1172
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:219
progress.h
NetworkChatMessageLoop
void NetworkChatMessageLoop()
Check if a message is expired.
Definition: network_chat_gui.cpp:174
Window::window_class
WindowClass window_class
Window class.
Definition: window_gui.h:240
WC_MAIN_WINDOW
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition: window_type.h:44
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1787
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:1532
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:674
WC_ENDSCREEN
@ WC_ENDSCREEN
Endscreen; Window numbers:
Definition: window_type.h:649
company_func.h
PreventHideDirection
PreventHideDirection
Direction for moving the window.
Definition: window.cpp:1991
HotkeyList::CheckMatch
int CheckMatch(uint16 keycode, bool global_only=false) const
Check if a keycode is bound to something.
Definition: hotkeys.cpp:325
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:360
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:247
abs
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:21
IsPtInWindowViewport
Viewport * IsPtInWindowViewport(const Window *w, int x, int y)
Is a xy position inside the viewport of the window?
Definition: viewport.cpp:402
GUITimer::Elapsed
bool Elapsed(uint delta)
Test if a timer has elapsed.
Definition: guitimer_func.h:55
VehicleID
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
Ceil
static uint Ceil(uint a, uint b)
Computes ceil(a / b) * b for non-negative a and b.
Definition: math_func.hpp:265
NWidgetCore::scrollbar_index
int scrollbar_index
Index of an attached scrollbar.
Definition: widget_type.h:340
network.h
NWidgetBase::SetDirty
virtual void SetDirty(const Window *w) const
Mark the widget as 'dirty' (in need of repaint).
Definition: widget.cpp:1024
Window::OnMouseDrag
virtual void OnMouseDrag(Point pt, int widget)
An 'object' is being dragged at the provided position, highlight the target if possible.
Definition: window_gui.h:584
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:1235
SmallMap::Find
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
Definition: smallmap_type.hpp:41
WC_SEND_NETWORK_MSG
@ WC_SEND_NETWORK_MSG
Chatbox; Window numbers:
Definition: window_type.h:490
ViewportData::follow_vehicle
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
Definition: window_gui.h:193
MILLISECONDS_PER_TICK
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
Definition: gfx_type.h:317
Window::OnInitialPosition
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
Compute the initial position of the window.
Definition: window.cpp:1759
window_func.h
HandleActiveWidget
static EventState HandleActiveWidget()
Handle active widget (mouse draggin on widget) with the mouse.
Definition: window.cpp:2383
Debug
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:248
WindowDesc::LoadFromConfig
static void LoadFromConfig()
Load all WindowDesc settings from _windows_file.
Definition: window.cpp:154
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:981
ViewportData::dest_scrollpos_x
int32 dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition: window_gui.h:196
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1767
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:89
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:1941
IConsoleClose
void IConsoleClose()
Close the in-game console.
Definition: console_gui.cpp:412
_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:2137
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1187
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:200
ND_SCROLLBAR_UP
@ ND_SCROLLBAR_UP
Bit value of the 'scrollbar up' flag.
Definition: widget_type.h:304
NetworkDrawChatMessage
void NetworkDrawChatMessage()
Draw the chat message-box.
Definition: network_chat_gui.cpp:188
Window::InsertTextString
virtual void InsertTextString(int 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:2694
QueryString::GetCaretPosition
Point GetCaretPosition(const Window *w, int wid) const
Get the current caret position.
Definition: misc_gui.cpp:852
_window_descs
static std::vector< WindowDesc * > * _window_descs
List of all WindowDescs.
Definition: window.cpp:99
Window::window_desc
WindowDesc * window_desc
Window description.
Definition: window_gui.h:238
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
Window::OnRealtimeTick
virtual void OnRealtimeTick(uint delta_ms)
Called periodically.
Definition: window_gui.h:634
ResetWindowSystem
void ResetWindowSystem()
Reset the windowing system, by means of shutting it down followed by re-initialization.
Definition: window.cpp:1869
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:2143
PositionNetworkChatWindow
int PositionNetworkChatWindow(Window *w)
(Re)position network chat window at the screen.
Definition: window.cpp:3464
VideoDriver::EditBoxLostFocus
virtual void EditBoxLostFocus()
An edit box lost the input focus.
Definition: video_driver.hpp:153
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:588
GUISettings::auto_scrolling
uint8 auto_scrolling
scroll when moving mouse to the edge (see ViewportAutoscrolling)
Definition: settings_type.h:116
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:3317
WindowDesc::parent_cls
WindowClass parent_cls
Class of the parent window.
Definition: window_gui.h:112
Window
Data structure for an opened window.
Definition: window_gui.h:213
QueryString::ACTION_DESELECT
static const int ACTION_DESELECT
Deselect editbox.
Definition: querystring_gui.h:23
Window::RaiseWidget
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:412
InputLoop
void InputLoop()
Regular call from the global game loop.
Definition: window.cpp:3038
WC_STATUS_BAR
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
Definition: window_type.h:57
GUISettings::scroll_mode
uint8 scroll_mode
viewport scroll mode
Definition: settings_type.h:122
WC_NEWS_WINDOW
@ WC_NEWS_WINDOW
News window; Window numbers:
Definition: window_type.h:241
Window::OnRightClick
virtual bool OnRightClick(Point pt, int widget)
A click with the right mouse button has been made on the window.
Definition: window_gui.h:562
HasModalProgress
static bool HasModalProgress()
Check if we are currently in a modal progress state.
Definition: progress.h:17
CloseConstructionWindows
void CloseConstructionWindows()
Close all windows that are used for construction of vehicle etc.
Definition: window.cpp:3345
WC_FINANCES
@ WC_FINANCES
Finances of a company; Window numbers:
Definition: window_type.h:515
console_func.h
Window::OnScroll
virtual void OnScroll(Point delta)
Handle the request for (viewport) scrolling.
Definition: window_gui.h:597
HKPR_NOT_HANDLED
@ HKPR_NOT_HANDLED
Key does not affect editboxes.
Definition: textbuf_type.h:26
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
ConstructionSettings::command_pause_level
uint8 command_pause_level
level/amount of commands that can't be executed while paused
Definition: settings_type.h:356
WC_ERRMSG
@ WC_ERRMSG
Error message; Window numbers:
Definition: window_type.h:103
Window::nested_array_size
uint nested_array_size
Size of the nested array.
Definition: window_gui.h:260
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:470
NWidgetCore::index
int index
Index of the nested widget in the widget array of the window (-1 means 'not used').
Definition: widget_type.h:337
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:314
_last_scroll_window
static Window * _last_scroll_window
Window of the last scroll event.
Definition: window.cpp:54
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:619
NWidgetLeaf::closebox_dimension
static Dimension closebox_dimension
Cached size of a closebox widget.
Definition: widget_type.h:831
IniLoadFile::LoadFromDisk
void LoadFromDisk(const std::string &filename, Subdirectory subdir)
Load the Ini file's data from the disk.
Definition: ini_load.cpp:215
GetMainViewBottom
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition: window.cpp:2131
CallWindowRealtimeTickEvent
void CallWindowRealtimeTickEvent(uint delta_ms)
Dispatch OnRealtimeTick event over all windows.
Definition: window.cpp:3063
WWT_DEBUGBOX
@ WWT_DEBUGBOX
NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX)
Definition: widget_type.h:61
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
CursorVars::pos
Point pos
logical mouse position
Definition: gfx_type.h:117
Window::LowerWidget
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Definition: window_gui.h:403
WC_DROPDOWN_MENU
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
Definition: window_type.h:149
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1270
_right_button_clicked
bool _right_button_clicked
Is right mouse button clicked?
Definition: gfx.cpp:44
NWidgetBase::resize_x
uint resize_x
Horizontal resize step (0 means not resizable).
Definition: widget_type.h:188
Window::GetMarkedText
virtual const char * GetMarkedText(size_t *length) const
Get the range of the currently marked input text.
Definition: window.cpp:399
WC_MAIN_TOOLBAR
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers:
Definition: window_type.h:51
WC_SPRITE_ALIGNER
@ WC_SPRITE_ALIGNER
Sprite aligner (debug); Window numbers:
Definition: window_type.h:668
SetWindowClassesDirty
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3180
WC_AIRCRAFT_LIST
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers:
Definition: window_type.h:319
Window::GetRowFromWidget
int GetRowFromWidget(int clickpos, int widget, int padding, int line_height=-1) const
Compute the row of a widget that a user clicked in.
Definition: window.cpp:212
Window::OnResize
virtual void OnResize()
Called after the window got resized.
Definition: window_gui.h:646
CMDPL_NO_CONSTRUCTION
@ CMDPL_NO_CONSTRUCTION
No construction actions may be executed.
Definition: command_type.h:411
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
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:196
WC_TEXTFILE
@ WC_TEXTFILE
textfile; Window numbers:
Definition: window_type.h:180
WindowDesc::hotkeys
HotkeyList * hotkeys
Hotkeys for the window.
Definition: window_gui.h:117
WC_STATION_LIST
@ WC_STATION_LIST
Station list; Window numbers:
Definition: window_type.h:295
NWidgetStacked::shown_plane
int shown_plane
Plane being displayed (for NWID_SELECTION only).
Definition: widget_type.h:457
WindowPosition
WindowPosition
How do we the window to be placed?
Definition: window_gui.h:88
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3434
_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:97
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:91
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:382
_left_button_clicked
bool _left_button_clicked
Is left mouse button clicked?
Definition: gfx.cpp:42
WindowDesc::pref_height
int16 pref_height
User-preferred height of the window. Zero if unset.
Definition: window_gui.h:121
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:2476
Textbuf::DeleteAll
void CDECL void DeleteAll()
Delete every character in the textbuffer.
Definition: textbuf.cpp:116
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:49
MakeWindowNWidgetTree
NWidgetContainer * MakeWindowNWidgetTree(const NWidgetPart *parts, int count, int *biggest_index, NWidgetStacked **shade_select)
Make a nested widget tree for a window from a parts array.
Definition: widget.cpp:3272
Window::white_border_timer
uint8 white_border_timer
Timer value of the WF_WHITE_BORDER for flags.
Definition: window_gui.h:244
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:2046
SetupWidgetDimensions
void SetupWidgetDimensions()
Set up pre-scaled versions of Widget Dimensions.
Definition: widget.cpp:199
_right_button_down
bool _right_button_down
Is right mouse button pressed?
Definition: gfx.cpp:43
ND_SCROLLBAR_BTN
@ ND_SCROLLBAR_BTN
Bit value of the 'scrollbar up' or 'scrollbar down' flag.
Definition: widget_type.h:306
PFE_DRAWWORLD
@ PFE_DRAWWORLD
Time spent drawing world viewports in GUI.
Definition: framerate_type.h:58
GUISettings::window_snap_radius
uint8 window_snap_radius
windows snap at each other if closer than this
Definition: settings_type.h:132
WindowDesc::pref_width
int16 pref_width
User-preferred width of the window. Zero if unset.
Definition: window_gui.h:120
WC_VEHICLE_ORDERS
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
Definition: window_type.h:205
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:604
VideoDriver::EditBoxGainedFocus
virtual void EditBoxGainedFocus()
An edit box gained the input focus.
Definition: video_driver.hpp:158
Window::InitializeData
void InitializeData(WindowNumber window_number)
Initializes the data (except the position and initial size) of a new Window.
Definition: window.cpp:1408
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:80
HandleToolbarHotkey
void HandleToolbarHotkey(int hotkey)
Handle Toolbar hotkey events - can come from a source like the MacBook Touch Bar.
Definition: window.cpp:2608
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:747
TileHighlightData::GetCallbackWnd
Window * GetCallbackWnd()
Get the window that started the current highlighting.
Definition: viewport.cpp:2529
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:155
GUISettings::right_mouse_wnd_close
bool right_mouse_wnd_close
close window with right click
Definition: settings_type.h:149
Window::GetFocusedText
virtual const char * GetFocusedText() const
Get the current input text if an edit box has the focus.
Definition: window.cpp:372
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:2508
TileVirtXY
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition: map_func.h:194
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition: widget.cpp:168
news_func.h
Window::FindWindowPlacementAndResize
virtual void FindWindowPlacementAndResize(int def_width, int def_height)
Resize window towards the default size.
Definition: window.cpp:1468
hotkeys.h
ResizeWindow
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
Definition: window.cpp:2084
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:1988
Window::OnKeyPress
virtual EventState OnKeyPress(WChar key, uint16 keycode)
A key has been pressed.
Definition: window_gui.h:535
NWidgetBase::SetupSmallestSize
virtual void SetupSmallestSize(Window *w, bool init_array)=0
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
Window::Close
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1103