OpenTTD Source  20240915-master-g3784a3d3d6
window.cpp File Reference
#include "stdafx.h"
#include "company_func.h"
#include "gfx_func.h"
#include "console_func.h"
#include "console_gui.h"
#include "viewport_func.h"
#include "progress.h"
#include "blitter/factory.hpp"
#include "zoom_func.h"
#include "vehicle_base.h"
#include "depot_func.h"
#include "window_func.h"
#include "tilehighlight_func.h"
#include "network/network.h"
#include "querystring_gui.h"
#include "strings_func.h"
#include "settings_type.h"
#include "settings_func.h"
#include "ini_type.h"
#include "newgrf_debug.h"
#include "hotkeys.h"
#include "toolbar_gui.h"
#include "statusbar_gui.h"
#include "error.h"
#include "game/game.hpp"
#include "video/video_driver.hpp"
#include "framerate_type.h"
#include "network/network_func.h"
#include "news_func.h"
#include "timer/timer.h"
#include "timer/timer_window.h"
#include "safeguards.h"

Go to the source code of this file.

Enumerations

enum  ViewportAutoscrolling { VA_DISABLED, VA_MAIN_VIEWPORT_FULLSCREEN, VA_MAIN_VIEWPORT, VA_EVERY_VIEWPORT }
 Values for _settings_client.gui.auto_scrolling. More...
 
enum  PreventHideDirection { PHD_UP, PHD_DOWN }
 Direction for moving the window. More...
 
enum  MouseClick {
  MC_NONE = 0, MC_LEFT, MC_RIGHT, MC_DOUBLE_LEFT,
  MC_HOVER, MAX_OFFSET_DOUBLE_CLICK = 5, MAX_OFFSET_HOVER = 5
}
 

Functions

static bool DescSorter (WindowDesc *const &a, WindowDesc *const &b)
 Sort WindowDesc by ini_key.
 
void SetFocusedWindow (Window *w)
 Set the window that has the focus. More...
 
bool EditBoxInGlobalFocus ()
 Check if an edit box is in global focus. More...
 
bool FocusedWindowIsConsole ()
 Check if a console is focused. More...
 
static void StartWindowDrag (Window *w)
 Start window dragging. More...
 
static void StartWindowSizing (Window *w, bool to_left)
 Start resizing a window. More...
 
static void DispatchLeftClickEvent (Window *w, int x, int y, int click_count)
 Dispatch left mouse-button (possibly double) click in window. More...
 
static void DispatchRightClickEvent (Window *w, int x, int y)
 Dispatch right mouse-button click in window. More...
 
static void DispatchHoverEvent (Window *w, int x, int y)
 Dispatch hover of the mouse over a window. More...
 
static void DispatchMouseWheelEvent (Window *w, NWidgetCore *nwid, int wheel)
 Dispatch the mousewheel-action to the window. More...
 
static bool MayBeShown (const Window *w)
 Returns whether a window may be shown or not. More...
 
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. More...
 
void DrawOverlappedWindowForAll (int left, int top, int right, int bottom)
 From a rectangle that needs redrawing, find the windows that intersect with the rectangle. More...
 
WindowFindWindowById (WindowClass cls, WindowNumber number)
 Find a window by its class and window number. More...
 
WindowFindWindowByClass (WindowClass cls)
 Find any window by its class. More...
 
WindowGetMainWindow ()
 Get the main window, i.e. More...
 
void CloseWindowById (WindowClass cls, WindowNumber number, bool force, int data)
 Close a window by its class and window number (if it is open). More...
 
void CloseWindowByClass (WindowClass cls, int data)
 Close all windows of a given class. More...
 
void CloseCompanyWindows (CompanyID id)
 Close all windows of a company. More...
 
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 company merger. More...
 
static void BringWindowToFront (Window *w, bool dirty)
 On clicking on a window, make it the frontmost window of all windows with an equal or lower z-priority. More...
 
WindowBringWindowToFrontById (WindowClass cls, WindowNumber number)
 Find a window and make it the relative top-window on the screen. More...
 
static bool IsVitalWindow (const Window *w)
 
static uint GetWindowZPriority (WindowClass wc)
 Get the z-priority for a given window. More...
 
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. More...
 
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. More...
 
static Point GetAutoPlacePosition (int width, int height)
 Find a good place for opening a new window of a given width and height. More...
 
Point GetToolbarAlignedWindowPosition (int window_width)
 Computer the position of the top-left corner of a window to be opened right under the toolbar. More...
 
static Point LocalGetWindowPlacement (const WindowDesc &desc, int16_t sm_width, int16_t sm_height, int window_number)
 Compute the position of the top-left corner of a new window that is opened. More...
 
WindowFindWindowFromPt (int x, int y)
 Do a search for a window at specific coordinates. More...
 
void InitWindowSystem ()
 (re)initialize the windowing system
 
void UnInitWindowSystem ()
 Close down the windowing system.
 
void ResetWindowSystem ()
 Reset the windowing system, by means of shutting it down followed by re-initialization.
 
static void DecreaseWindowCounters ()
 
static void HandlePlacePresize ()
 
static EventState HandleMouseDragDrop ()
 Handle dragging and dropping in mouse dragging mode (WSM_DRAGDROP). More...
 
static void HandleMouseOver ()
 Report position of the mouse to the underlying window.
 
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. More...
 
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. More...
 
void ResizeWindow (Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
 Resize the window. More...
 
int GetMainViewTop ()
 Return the top of the main view available for general use. More...
 
int GetMainViewBottom ()
 Return the bottom of the main view available for general use. More...
 
static EventState HandleWindowDragging ()
 Handle dragging/resizing of a window. More...
 
static void HandleScrollbarScrolling (Window *w)
 Handle scrollbar scrolling with the mouse. More...
 
static EventState HandleActiveWidget ()
 Handle active widget (mouse draggin on widget) with the mouse. More...
 
static EventState HandleViewportScroll ()
 Handle viewport scrolling with the mouse. More...
 
static bool MaybeBringWindowToFront (Window *w)
 Check if a window can be made relative top-most window, and if so do it. More...
 
void HandleToolbarHotkey (int hotkey)
 Handle Toolbar hotkey events - can come from a source like the MacBook Touch Bar. More...
 
void HandleKeypress (uint keycode, char32_t key)
 Handle keyboard input. More...
 
void HandleCtrlChanged ()
 State of CONTROL key has changed.
 
void HandleTextInput (const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end)
 Handle text input. More...
 
static void HandleAutoscroll ()
 If needed and switched on, perform auto scrolling (automatically moving window contents when mouse is near edge of the window).
 
EventState VpHandlePlaceSizingDrag ()
 Handle the mouse while dragging for placement/resizing. More...
 
const std::chrono::milliseconds TIME_BETWEEN_DOUBLE_CLICK (500)
 Time between 2 left clicks before it becoming a double click.
 
static void ScrollMainViewport (int x, int y)
 
static void HandleKeyScrolling ()
 
static void MouseLoop (MouseClick click, int mousewheel)
 
void HandleMouseEvents ()
 Handle a mouse event from the video driver.
 
static void CheckSoftLimit ()
 Check the soft limit of deletable (non vital, non sticky) windows.
 
void InputLoop ()
 Regular call from the global game loop.
 
void CallWindowRealtimeTickEvent (uint delta_ms)
 Dispatch OnRealtimeTick event over all windows.
 
void UpdateWindows ()
 Update the continuously changing contents of the windows, such as the viewports.
 
void SetWindowDirty (WindowClass cls, WindowNumber number)
 Mark window as dirty (in need of repainting) More...
 
void SetWindowWidgetDirty (WindowClass cls, WindowNumber number, WidgetID widget_index)
 Mark a particular widget in a particular window as dirty (in need of repainting) More...
 
void SetWindowClassesDirty (WindowClass cls)
 Mark all windows of a particular class as dirty (in need of repainting) More...
 
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-computing) More...
 
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 default the invalidation is not considered to be called from GUI scope. More...
 
void CallWindowGameTickEvent ()
 Dispatch OnGameTick event over all windows.
 
void CloseNonVitalWindows ()
 Try to close a non-vital window. More...
 
void CloseAllNonVitalWindows ()
 It is possible that a stickied window gets to a position where the 'close' button is outside the gaming area. More...
 
void DeleteAllMessages ()
 Delete all messages and close their corresponding window (if any).
 
void CloseConstructionWindows ()
 Close all windows that are used for construction of vehicle etc. More...
 
void HideVitalWindows ()
 Close all always on-top windows to get an empty screen.
 
void ReInitWindow (Window *w, bool zoom_changed)
 
void ReInitAllWindows (bool zoom_changed)
 Re-initialize all windows. More...
 
static int PositionWindow (Window *w, WindowClass clss, int setting)
 (Re)position a window at the screen. More...
 
int PositionMainToolbar (Window *w)
 (Re)position main toolbar window at the screen. More...
 
int PositionStatusbar (Window *w)
 (Re)position statusbar window at the screen. More...
 
int PositionNewsMessage (Window *w)
 (Re)position news message window at the screen. More...
 
int PositionNetworkChatWindow (Window *w)
 (Re)position network chat window at the screen. More...
 
void ChangeVehicleViewports (VehicleID from_index, VehicleID to_index)
 Switches viewports following vehicles, which get autoreplaced. More...
 
void RelocateAllWindows (int neww, int newh)
 Relocate all windows to fit the new size of the game application screen. More...
 

Variables

static Point _drag_delta
 delta between mouse cursor and upper left corner of dragged window
 
static Window_mouseover_last_w = nullptr
 Window of the last OnMouseOver event.
 
static Window_last_scroll_window = nullptr
 Window of the last scroll event.
 
WindowList _z_windows
 List of windows opened at the screen sorted from the front to back.
 
bool _window_highlight_colour = false
 If false, highlight is white, otherwise the by the widget defined colour.
 
Window_focused_window
 
Point _cursorpos_drag_start
 
int _scrollbar_start_pos
 
int _scrollbar_size
 
uint8_t _scroller_click_timeout = 0
 
bool _scrolling_viewport
 A viewport is being scrolled with the mouse.
 
bool _mouse_hovering
 The mouse is hovering over the same point.
 
SpecialMouseMode _special_mouse_mode
 Mode of the mouse.
 
std::vector< WindowDesc * > * _window_descs = nullptr
 List of all WindowDescs. More...
 
std::string _windows_file
 Config file to store WindowDesc.
 
static bool _dragging_window
 A window is being dragged or resized.
 
static int _input_events_this_tick = 0
 Local counter that is incremented each time an mouse input event is detected. More...
 
static const int8_t scrollamt [16][2]
 Describes all the different arrow key combinations the game allows when it is in scrolling mode. More...
 
static IntervalTimer< TimerWindowwindow_interval (std::chrono::milliseconds(30), [](auto) { extern int _caret_timer;_caret_timer+=3;CursorTick();HandleKeyScrolling();HandleAutoscroll();DecreaseWindowCounters();})
 Update various of window-related information on a regular interval.
 
static IntervalTimer< TimerWindowhighlight_interval (std::chrono::milliseconds(450), [](auto) { _window_highlight_colour=!_window_highlight_colour;})
 Blink the window highlight colour constantly.
 
static IntervalTimer< TimerWindowwhite_border_interval (std::chrono::milliseconds(30), [](auto) { if(_network_dedicated) return;for(Window *w :Window::Iterate()) { if((w->flags &WF_WHITE_BORDER) &&--w->white_border_timer==0) { CLRBITS(w->flags, WF_WHITE_BORDER);w->SetDirty();} } })
 Blink all windows marked with a white border.
 

Detailed Description

Windowing system, widgets and events

Definition in file window.cpp.

Enumeration Type Documentation

◆ MouseClick

enum MouseClick
Enumerator
MAX_OFFSET_DOUBLE_CLICK 

How much the mouse is allowed to move to call it a double click.

MAX_OFFSET_HOVER 

Maximum mouse movement before stopping a hover event.

Definition at line 2704 of file window.cpp.

◆ PreventHideDirection

Direction for moving the window.

Enumerator
PHD_UP 

Above v is a safe position.

PHD_DOWN 

Below v is a safe position.

Definition at line 1930 of file window.cpp.

◆ ViewportAutoscrolling

Values for _settings_client.gui.auto_scrolling.

Enumerator
VA_DISABLED 

Do not autoscroll when mouse is at edge of viewport.

VA_MAIN_VIEWPORT_FULLSCREEN 

Scroll main viewport at edge when using fullscreen.

VA_MAIN_VIEWPORT 

Scroll main viewport at edge.

VA_EVERY_VIEWPORT 

Scroll all viewports at their edges.

Definition at line 45 of file window.cpp.

Function Documentation

◆ BringWindowToFront()

static void BringWindowToFront ( Window w,
bool  dirty 
)
static

On clicking on a window, make it the frontmost window of all windows with an equal or lower z-priority.

The window is marked dirty for a repaint

Parameters
wwindow that is put into the relative foreground
dirtywhether to mark the window dirty

Definition at line 1344 of file window.cpp.

References _z_windows, GetWindowZPriority(), Window::SetDirty(), and Window::window_class.

Referenced by BringWindowToFrontById().

◆ BringWindowToFrontById()

Window* BringWindowToFrontById ( WindowClass  cls,
WindowNumber  number 
)

Find a window and make it the relative top-window on the screen.

The window gets unshaded if it was shaded, and a white border is drawn at its edges for a brief period of time to visualize its "activation".

Parameters
clsWindowClass of the window to activate
numberWindowNumber of the window to activate
Returns
a pointer to the window thus activated

Definition at line 1223 of file window.cpp.

References BringWindowToFront(), FindWindowById(), Window::IsShaded(), Window::SetDirty(), Window::SetShaded(), and Window::SetWhiteBorder().

Referenced by AllocateWindowDescFront(), DoSelectCompanyManagerFace(), ShowBuyCompanyDialog(), ShowCompanyFinances(), ShowDepotWindow(), ShowGenerateWorldProgress(), ShowIndustryCargoesWindow(), and ShowScriptDebugWindow().

◆ ChangeVehicleViewports()

void ChangeVehicleViewports ( VehicleID  from_index,
VehicleID  to_index 
)

Switches viewports following vehicles, which get autoreplaced.

Parameters
from_indexthe old vehicle ID
to_indexthe new vehicle ID

Definition at line 3424 of file window.cpp.

References ViewportData::follow_vehicle, Window::SetDirty(), and Window::viewport.

◆ 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 company merger.

Do not change ownership of windows that need to be deleted once takeover is complete

Parameters
old_owneroriginal owner of the window
new_ownerthe new owner of the window

Definition at line 1188 of file window.cpp.

References WC_AIRCRAFT_LIST, WC_BUY_COMPANY, WC_COMPANY, WC_COMPANY_COLOUR, WC_COMPANY_INFRASTRUCTURE, WC_FINANCES, WC_ROADVEH_LIST, WC_SHIPS_LIST, WC_STATION_LIST, WC_TRAINS_LIST, and WC_VEHICLE_ORDERS.

◆ CloseAllNonVitalWindows()

void CloseAllNonVitalWindows ( )

It is possible that a stickied window gets to a position where the 'close' button is outside the gaming area.

You cannot close it then; except with this function. It closes all windows calling the standard function, then, does a little hacked loop of closing all stickied windows. Note that standard windows (status bar, etc.) are not stickied, so these aren't affected

Definition at line 3269 of file window.cpp.

References Window::Close(), WindowDesc::flags, WDF_NO_CLOSE, and Window::window_desc.

◆ CloseCompanyWindows()

void CloseCompanyWindows ( CompanyID  id)

Close all windows of a company.

We identify windows of a company by looking at the caption colour. If it is equal to the company ID then we say the window belongs to the company and should be closed

Parameters
idcompany identifier

Definition at line 1168 of file window.cpp.

References CloseWindowById(), and WC_BUY_COMPANY.

Referenced by Company::~Company().

◆ CloseConstructionWindows()

void CloseConstructionWindows ( )

Close all windows that are used for construction of vehicle etc.

Once done with that invalidate the others to ensure they get refreshed too.

Definition at line 3294 of file window.cpp.

References Window::Close(), WindowDesc::flags, Window::SetDirty(), WDF_CONSTRUCTION, and Window::window_desc.

Referenced by SetLocalCompany().

◆ CloseNonVitalWindows()

void CloseNonVitalWindows ( )

Try to close a non-vital window.

Non-vital windows are windows other than the game selection, main toolbar, status bar, toolbar menu, and tooltip windows. Stickied windows are also considered vital.

Definition at line 3250 of file window.cpp.

References Window::Close(), WindowDesc::flags, Window::flags, WDF_NO_CLOSE, WF_STICKY, and Window::window_desc.

◆ CloseWindowByClass()

◆ CloseWindowById()

◆ DispatchHoverEvent()

static void DispatchHoverEvent ( Window w,
int  x,
int  y 
)
static

Dispatch hover of the mouse over a window.

Parameters
wWindow to dispatch event in.
xX coordinate of the click.
yY coordinate of the click.

Definition at line 770 of file window.cpp.

◆ DispatchLeftClickEvent()

static void DispatchLeftClickEvent ( Window w,
int  x,
int  y,
int  click_count 
)
static

Dispatch left mouse-button (possibly double) click in window.

Parameters
wWindow to dispatch event in
xX coordinate of the click
yY coordinate of the click
click_countNumber of fast consecutive clicks at same position

< Index of the widget

Definition at line 607 of file window.cpp.

◆ DispatchMouseWheelEvent()

static void DispatchMouseWheelEvent ( Window w,
NWidgetCore nwid,
int  wheel 
)
static

Dispatch the mousewheel-action to the window.

The window will scroll any compatible scrollbars if the mouse is pointed over the bar or its contents

Parameters
wWindow
nwidthe widget where the scrollwheel was used
wheelscroll up or down

Definition at line 798 of file window.cpp.

References Scrollbar::GetCapacity(), Scrollbar::GetCount(), Window::GetScrollbar(), NWID_VSCROLLBAR, NWidgetCore::scrollbar_index, Window::SetDirty(), Window::SetShaded(), NWidgetBase::type, Scrollbar::UpdatePosition(), WWT_CAPTION, and WWT_SHADEBOX.

◆ DispatchRightClickEvent()

static void DispatchRightClickEvent ( Window w,
int  x,
int  y 
)
static

Dispatch right mouse-button click in window.

Parameters
wWindow to dispatch event in
xX coordinate of the click
yY coordinate of the click

Definition at line 741 of file window.cpp.

◆ DrawOverlappedWindow()

static void DrawOverlappedWindow ( Window w,
int  left,
int  top,
int  right,
int  bottom 
)
static

Generate repaint events for the visible part of window w within the rectangle.

The function goes recursively upwards in the window stack, and splits the rectangle into multiple pieces at the window edges, so obscured parts are not redrawn.

Parameters
wWindow that needs to be repainted
leftLeft edge of the rectangle that should be repainted
topTop edge of the rectangle that should be repainted
rightRight edge of the rectangle that should be repainted
bottomBottom edge of the rectangle that should be repainted

Definition at line 857 of file window.cpp.

References Window::height, Window::left, MayBeShown(), Window::top, and Window::width.

◆ 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.

These windows should be re-painted.

Parameters
leftLeft edge of the rectangle that should be repainted
topTop edge of the rectangle that should be repainted
rightRight edge of the rectangle that should be repainted
bottomBottom edge of the rectangle that should be repainted

Definition at line 919 of file window.cpp.

◆ EditBoxInGlobalFocus()

bool EditBoxInGlobalFocus ( )

Check if an edit box is in global focus.

That is if focused window has a edit box as focused widget, or if a console is focused.

Returns
returns true if an edit box is in global focus or if the focused window is a console, else false

Definition at line 448 of file window.cpp.

Referenced by HandleKeypress(), HandleTextInput(), VideoDriver_Win32Base::PollEvent(), SetCandidatePos(), and SetCompositionPos().

◆ EnsureVisibleCaption()

static void EnsureVisibleCaption ( Window w,
int  nx,
int  ny 
)
static

Make sure at least a part of the caption bar is still visible by moving the window if necessary.

Parameters
wThe window to check.
nxThe proposed new x-location of the window.
nyThe proposed new y-location of the window.

Definition at line 1985 of file window.cpp.

References Clamp(), Rect::Height(), Window::nested_root, and WWT_CAPTION.

Referenced by RelocateAllWindows().

◆ FindWindowByClass()

Window* FindWindowByClass ( WindowClass  cls)

Find any window by its class.

Useful when searching for a window that uses the window number as a WindowClass, like WC_SEND_NETWORK_MSG.

Parameters
clsWindow class
Returns
Pointer to the found window, or nullptr if not available

Definition at line 1113 of file window.cpp.

Referenced by GetAutoPlacePosition(), NetworkDrawChatMessage(), ShowScriptDebugWindow(), and UpdateNewGRFScanStatus().

◆ FindWindowById()

◆ FindWindowFromPt()

Window* FindWindowFromPt ( int  x,
int  y 
)

Do a search for a window at specific coordinates.

For this we start at the topmost window, obviously and work our way down to the bottom

Parameters
xposition x to query
yposition y to query
Returns
a pointer to the found window if any, nullptr otherwise

Definition at line 1768 of file window.cpp.

Referenced by HandleMouseOver().

◆ FocusedWindowIsConsole()

bool FocusedWindowIsConsole ( )

Check if a console is focused.

Returns
returns true if the focused window is a console, else false

Definition at line 462 of file window.cpp.

◆ GetAutoPlacePosition()

static Point GetAutoPlacePosition ( int  width,
int  height 
)
static

Find a good place for opening a new window of a given width and height.

Parameters
widthWidth of the new window
heightHeight of the new window
Returns
Top-left coordinate of the new window

Definition at line 1559 of file window.cpp.

References _current_text_dir, FindWindowByClass(), Window::height, IsGoodAutoPlace1(), TD_RTL, and WC_MAIN_TOOLBAR.

◆ GetMainViewBottom()

int GetMainViewBottom ( )

Return the bottom of the main view available for general use.

Returns
The vertical coordinate of the first unusable row, so 'top + height <= bottom' gives the correct result.
Note
At and below the bottom y coordinate is often the status bar.

Definition at line 2073 of file window.cpp.

References FindWindowById(), and WC_STATUS_BAR.

Referenced by DropdownWindow::UpdateSizeAndPosition().

◆ GetMainViewTop()

int GetMainViewTop ( )

Return the top of the main view available for general use.

Returns
Uppermost vertical coordinate available.
Note
Above the upper y coordinate is often the main toolbar.

Definition at line 2062 of file window.cpp.

References FindWindowById(), Window::height, Window::top, and WC_MAIN_TOOLBAR.

Referenced by DropdownWindow::UpdateSizeAndPosition().

◆ GetMainWindow()

Window* GetMainWindow ( )

Get the main window, i.e.

FindWindowById(WC_MAIN_WINDOW, 0). If the main window is not available, this function will trigger an assert.

Returns
Pointer to the main window.

Definition at line 1127 of file window.cpp.

References FindWindowById(), and WC_MAIN_WINDOW.

Referenced by DEF_CONSOLE_CMD(), SmallMapWindow::DrawMapIndicators(), VehicleViewWindow::OnHotkey(), MainToolbarWindow::OnInvalidateData(), ScenarioEditorToolbarWindow::OnInvalidateData(), SetupScreenshotViewport(), ShowNetworkAskRelay(), ShowNetworkAskSurvey(), ShowQuery(), and SmallMapWindow::SmallMapCenterOnCurrentPos().

◆ GetToolbarAlignedWindowPosition()

Point GetToolbarAlignedWindowPosition ( int  window_width)

Computer the position of the top-left corner of a window to be opened right under the toolbar.

Parameters
window_widththe width of the window to get the position for
Returns
Coordinate of the top-left corner of the new window.

Definition at line 1627 of file window.cpp.

References _current_text_dir, FindWindowById(), Window::height, Window::left, TD_RTL, Window::top, WC_MAIN_TOOLBAR, and Window::width.

◆ GetWindowZPriority()

static uint GetWindowZPriority ( WindowClass  wc)
static

Get the z-priority for a given window.

This is used in comparison with other z-priority values; a window with a given z-priority will appear above other windows with a lower value, and below those with a higher one (the ordering within z-priorities is arbitrary).

Parameters
wcThe window class of window to get the z-priority for
Precondition
wc != WC_INVALID
Returns
The window's z-priority

Definition at line 1260 of file window.cpp.

References WC_CONFIRM_POPUP_QUERY, WC_CONSOLE, WC_CUSTOM_CURRENCY, WC_DROPDOWN_MENU, WC_ENDSCREEN, WC_ERRMSG, WC_GAME_OPTIONS, WC_GENERATE_LANDSCAPE, WC_GRF_PARAMETERS, WC_HIGHSCORE, WC_INVALID, WC_MAIN_TOOLBAR, WC_MAIN_WINDOW, WC_MODAL_PROGRESS, WC_NETWORK_ASK_RELAY, WC_NETWORK_STATUS_WINDOW, WC_NETWORK_WINDOW, WC_NEWS_WINDOW, WC_OSK, WC_QUERY_STRING, WC_SAVE_PRESET, WC_SAVELOAD, WC_SCRIPT_LIST, WC_SCRIPT_SETTINGS, WC_SEND_NETWORK_MSG, WC_STATUS_BAR, WC_TEXTFILE, and WC_TOOLTIPS.

Referenced by BringWindowToFront().

◆ HandleActiveWidget()

static EventState HandleActiveWidget ( )
static

Handle active widget (mouse draggin on widget) with the mouse.

Returns
State of handling the event.

Definition at line 2320 of file window.cpp.

References _left_button_down, ES_HANDLED, Window::GetWidget(), HandleScrollbarScrolling(), Window::mouse_capture_widget, NWID_HSCROLLBAR, NWID_VSCROLLBAR, and Window::SetWidgetDirty().

◆ HandleKeypress()

void HandleKeypress ( uint  keycode,
char32_t  key 
)

Handle keyboard input.

Parameters
keycodeVirtual keycode of the key.
keyUnicode character of the key.

Definition at line 2562 of file window.cpp.

References EditBoxInGlobalFocus(), HasModalProgress(), and IsLocalCompany().

Referenced by HandleCharMsg().

◆ HandleMouseDragDrop()

static EventState HandleMouseDragDrop ( )
static

Handle dragging and dropping in mouse dragging mode (WSM_DRAGDROP).

Returns
State of handling the event.

Definition at line 1883 of file window.cpp.

References _left_button_down, _special_mouse_mode, ES_NOT_HANDLED, and WSM_DRAGDROP.

◆ HandleScrollbarScrolling()

static void HandleScrollbarScrolling ( Window w)
static

Handle scrollbar scrolling with the mouse.

Parameters
wwindow with active scrollbar.

Definition at line 2289 of file window.cpp.

References Window::GetWidget(), Window::mouse_capture_widget, NWID_HSCROLLBAR, and NWidgetBase::type.

Referenced by HandleActiveWidget().

◆ HandleTextInput()

void HandleTextInput ( const char *  str,
bool  marked,
const char *  caret,
const char *  insert_location,
const char *  replacement_end 
)

Handle text input.

Parameters
strText string to input.
markedIs the input a marked composition string from an IME?
caretMove the caret to this point in the insertion string.

Definition at line 2648 of file window.cpp.

References EditBoxInGlobalFocus().

Referenced by CancelIMEComposition().

◆ HandleToolbarHotkey()

void HandleToolbarHotkey ( int  hotkey)

Handle Toolbar hotkey events - can come from a source like the MacBook Touch Bar.

Parameters
hotkeyHotkey code

Definition at line 2545 of file window.cpp.

References ES_HANDLED, FindWindowById(), HasModalProgress(), WindowDesc::hotkeys, IsLocalCompany(), Window::OnHotkey(), WC_MAIN_TOOLBAR, and Window::window_desc.

◆ HandleViewportScroll()

static EventState HandleViewportScroll ( )
static

Handle viewport scrolling with the mouse.

Returns
State of handling the event.

Definition at line 2353 of file window.cpp.

References _settings_client, ClientSettings::gui, GUISettings::scrollwheel_scrolling, and SWS_SCROLL_MAP.

◆ HandleWindowDragging()

static EventState HandleWindowDragging ( )
static

Handle dragging/resizing of a window.

Returns
State of handling the event.

Definition at line 2085 of file window.cpp.

References _dragging_window, _left_button_down, and ES_NOT_HANDLED.

◆ InvalidateWindowClassesData()

◆ 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-computing)

Note that by default the invalidation is not considered to be called from GUI scope. That means only a part of invalidation is executed immediately. The rest is scheduled for the next redraw. The asynchronous execution is important to prevent GUI code being executed from command scope. When not in GUI-scope:

  • OnInvalidateData() may not do test-runs on commands, as they might affect the execution of the command which triggered the invalidation. (town rating and such)
  • OnInvalidateData() may not rely on _current_company == _local_company. This implies that no NewGRF callbacks may be run.

However, when invalidations are scheduled, then multiple calls may be scheduled before execution starts. Earlier scheduled invalidations may be called with invalidation-data, which is already invalid at the point of execution. That means some stuff requires to be executed immediately in command scope, while not everything may be executed in command scope. While GUI-scope calls have no restrictions on what they may do, they cannot assume the game to still be in the state when the invalidation was scheduled; passed IDs may have got invalid in the mean time.

Finally, note that invalidations triggered from commands or the game loop result in OnInvalidateData() being called twice. Once in command-scope, once in GUI-scope. So make sure to not process differential-changes twice.

Parameters
clsWindow class
numberWindow number within the class
dataThe data to invalidate with
gui_scopeWhether the call is done from GUI scope

Definition at line 3208 of file window.cpp.

References Window::InvalidateData(), Window::window_class, and Window::window_number.

Referenced by ServerNetworkGameSocketHandler::AcceptConnection(), AcceptEnginePreview(), AddRemoveEngineFromAutoreplaceAndBuildWindows(), AircraftLeaveHangar(), Subsidy::AwardTo(), MusicSystem::ChangeMusicSet(), ChangePopulation(), CmdAddSharedVehicleGroup(), CmdCompanyCtrl(), CmdConvertRail(), CmdCreateGoal(), CmdCreateLeagueTableElement(), CmdDeleteGroup(), CmdIndustrySetText(), CmdRemoveAllVehiclesGroup(), CmdRemoveGoal(), CmdRemoveLeagueTableElement(), CmdRemoveStoryPage(), CmdRenameTown(), CmdSellRailWagon(), CmdSetGoalCompleted(), CmdSetGoalProgress(), CmdSetGoalText(), CmdTownCargoGoal(), CmdTownSetText(), CmdUpdateLeagueTableElementData(), CmdUpdateLeagueTableElementScore(), CreateSubsidy(), DeleteAllMessages(), DeleteNewGRFInspectWindow(), DeleteNews(), DeleteNewsItem(), DeleteStationIfEmpty(), DeleteSubsidyWith(), DoScanNewGRFFiles(), EnableEngineForCompany(), InvalidateAutoreplaceWindow(), InvalidateNewGRFInspectWindow(), InvalidateVehicleOrder(), NetworkChatWindow::NetworkChatWindow(), NewVehicleAvailable(), MusicSystem::Next(), NormaliseTrainHead(), MainWindow::OnInvalidateData(), MusicSystem::PlaylistRemove(), Town::PostDestructor(), Company::PostDestructor(), BaseStation::PostDestructor(), Industry::PostDestructor(), MusicSystem::Prev(), ClientNetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE(), RemoveBuoy(), AI::Rescan(), SaveFileDone(), SaveFileStart(), SetLocalCompany(), MusicSystem::Stop(), MusicSystem::Unshuffle(), UpdateClientConfigValues(), UpdateNetworkGameWindow(), NetworkClientInfo::~NetworkClientInfo(), and ServerNetworkGameSocketHandler::~ServerNetworkGameSocketHandler().

◆ IsGoodAutoPlace1()

static bool IsGoodAutoPlace1 ( int  left,
int  top,
int  width,
int  height,
int  toolbar_y,
Point pos 
)
static

Decide whether a given rectangle is a good place to open a completely visible new window.

The new window should be within screen borders, and not overlap with another already existing window (except for the main window in the background).

Parameters
leftLeft edge of the rectangle
topTop edge of the rectangle
widthWidth of the rectangle
heightHeight of the rectangle
toolbar_yHeight of main toolbar
posIf rectangle is good, use this parameter to return the top-left corner of the new window
Returns
Boolean indication that the rectangle is a good place for the new window

Definition at line 1484 of file window.cpp.

Referenced by GetAutoPlacePosition().

◆ IsGoodAutoPlace2()

static bool IsGoodAutoPlace2 ( int  left,
int  top,
int  width,
int  height,
int  toolbar_y,
Point pos 
)
static

Decide whether a given rectangle is a good place to open a mostly visible new window.

The new window should be mostly within screen borders, and not overlap with another already existing window (except for the main window in the background).

Parameters
leftLeft edge of the rectangle
topTop edge of the rectangle
widthWidth of the rectangle
heightHeight of the rectangle
toolbar_yHeight of main toolbar
posIf rectangle is good, use this parameter to return the top-left corner of the new window
Returns
Boolean indication that the rectangle is a good place for the new window

Definition at line 1520 of file window.cpp.

References _current_text_dir, and TD_RTL.

◆ LocalGetWindowPlacement()

static Point LocalGetWindowPlacement ( const WindowDesc desc,
int16_t  sm_width,
int16_t  sm_height,
int  window_number 
)
static

Compute the position of the top-left corner of a new window that is opened.

By default position a child window at an offset of 10/10 of its parent. With the exception of WC_BUILD_TOOLBAR (build railway/roads/ship docks/airports) and WC_SCEN_LAND_GEN (landscaping). Whose child window has an offset of 0/toolbar-height of its parent. So it's exactly under the parent toolbar and no buttons will be covered. However if it falls too extremely outside window positions, reposition it to an automatic place.

Parameters
*descThe pointer to the WindowDesc to be created.
sm_widthSmallest width of the window.
sm_heightSmallest height of the window.
window_numberThe window number of the new window.
Returns
Coordinate of the top-left corner of the new window.

Definition at line 1652 of file window.cpp.

References _current_text_dir, NWidgetLeaf::closebox_dimension, FindWindowById(), FS_NORMAL, GetCharacterHeight(), WindowDesc::GetDefaultHeight(), WindowDesc::GetDefaultWidth(), Window::height, Window::left, WindowDesc::parent_cls, WidgetDimensions::scaled, TD_RTL, Window::top, WC_BUILD_TOOLBAR, WC_NONE, WC_SCEN_LAND_GEN, and Window::width.

Referenced by Window::OnInitialPosition().

◆ MaybeBringWindowToFront()

static bool MaybeBringWindowToFront ( Window w)
static

Check if a window can be made relative top-most window, and if so do it.

If a window does not obscure any other windows, it will not be brought to the foreground. Also if the only obscuring windows are so-called system-windows, the window will not be moved. The function will return false when a child window of this window is a modal-popup; function returns a false and child window gets a white border

Parameters
wWindow to bring relatively on-top
Returns
false if the window has an active modal child, true otherwise

Definition at line 2413 of file window.cpp.

References WC_MAIN_WINDOW, and Window::window_class.

◆ MayBeShown()

static bool MayBeShown ( const Window w)
static

Returns whether a window may be shown or not.

Parameters
wThe window to consider.
Returns
True iff it may be shown, otherwise false.

< The background, i.e. the game.

< The actual progress window.

< The abort window.

Definition at line 829 of file window.cpp.

References HasModalProgress(), WC_CONFIRM_POPUP_QUERY, WC_MAIN_WINDOW, WC_MODAL_PROGRESS, and Window::window_class.

Referenced by DrawOverlappedWindow().

◆ PositionMainToolbar()

int PositionMainToolbar ( Window w)

(Re)position main toolbar window at the screen.

Parameters
wWindow structure of the main toolbar window, may also be nullptr.
Returns
X coordinate of left edge of the repositioned toolbar window.

Definition at line 3379 of file window.cpp.

References _settings_client, Debug, ClientSettings::gui, PositionWindow(), GUISettings::toolbar_pos, and WC_MAIN_TOOLBAR.

Referenced by RelocateAllWindows().

◆ PositionNetworkChatWindow()

int PositionNetworkChatWindow ( Window w)

(Re)position network chat window at the screen.

Parameters
wWindow structure of the network chat window, may also be nullptr.
Returns
X coordinate of left edge of the repositioned network chat window.

Definition at line 3412 of file window.cpp.

References _settings_client, Debug, ClientSettings::gui, PositionWindow(), GUISettings::statusbar_pos, and WC_SEND_NETWORK_MSG.

Referenced by NetworkChatWindow::NetworkChatWindow(), and RelocateAllWindows().

◆ PositionNewsMessage()

int PositionNewsMessage ( Window w)

(Re)position news message window at the screen.

Parameters
wWindow structure of the news message window, may also be nullptr.
Returns
X coordinate of left edge of the repositioned news message.

Definition at line 3401 of file window.cpp.

References _settings_client, Debug, ClientSettings::gui, PositionWindow(), GUISettings::statusbar_pos, and WC_NEWS_WINDOW.

Referenced by RelocateAllWindows().

◆ PositionStatusbar()

int PositionStatusbar ( Window w)

(Re)position statusbar window at the screen.

Parameters
wWindow structure of the statusbar window, may also be nullptr.
Returns
X coordinate of left edge of the repositioned statusbar.

Definition at line 3390 of file window.cpp.

References _settings_client, Debug, ClientSettings::gui, PositionWindow(), GUISettings::statusbar_pos, and WC_STATUS_BAR.

Referenced by RelocateAllWindows().

◆ PositionWindow()

static int PositionWindow ( Window w,
WindowClass  clss,
int  setting 
)
static

(Re)position a window at the screen.

Parameters
wWindow structure of the window, may also be nullptr.
clssThe class of the window to position.
settingThe actual setting used for the window's position.
Returns
X coordinate of left edge of the repositioned window.

Definition at line 3356 of file window.cpp.

References FindWindowById(), Window::left, and Window::window_class.

Referenced by PositionMainToolbar(), PositionNetworkChatWindow(), PositionNewsMessage(), and PositionStatusbar().

◆ PreventHiding()

static void PreventHiding ( int *  nx,
int *  ny,
const Rect rect,
const Window v,
int  px,
PreventHideDirection  dir 
)
static

Do not allow hiding of the rectangle with base coordinates nx and ny behind window v.

If needed, move the window base coordinates to keep it visible.

Parameters
nxBase horizontal coordinate of the rectangle.
nyBase vertical coordinate of the rectangle.
rectRectangle that must stay visible (horizontally, vertically, or both)
vWindow lying in front of the rectangle.
pxPrevious horizontal base coordinate.
dirIf no room horizontally, move the rectangle to the indicated position.

Definition at line 1945 of file window.cpp.

References Rect::Height(), Window::height, Window::left, PHD_UP, Window::top, and Window::width.

◆ ReInitAllWindows()

void ReInitAllWindows ( bool  zoom_changed)

Re-initialize all windows.

Parameters
zoom_changedSet if windows are being re-initialized due to a zoom level changed.

Definition at line 3324 of file window.cpp.

References InitDepotWindowBlockSizes(), NWidgetLeaf::InvalidateDimensionCache(), and SetupWidgetDimensions().

Referenced by InvalidateNewGRFChangeWindows(), NewGRFConfirmationCallback(), and GameOptionsWindow::OnMouseLoop().

◆ RelocateAllWindows()

void RelocateAllWindows ( int  neww,
int  newh 
)

◆ ResizeWindow()

void ResizeWindow ( Window w,
int  delta_x,
int  delta_y,
bool  clamp_to_screen,
bool  schedule_resize 
)

Resize the window.

Update all the widgets of a window based on their resize flags Both the areas of the old window and the new sized window are set dirty ensuring proper redrawal.

Parameters
wWindow to resize
delta_xDelta x-size of changed window (positive if larger, etc.)
delta_yDelta y-size of changed window
clamp_to_screenWhether to make sure the whole window stays visible

Definition at line 2022 of file window.cpp.

References Window::height, Window::left, Window::top, and Window::width.

Referenced by Window::ReInit(), and RelocateAllWindows().

◆ SetFocusedWindow()

void SetFocusedWindow ( Window w)

Set the window that has the focus.

Parameters
wThe window to set the focus on

Definition at line 422 of file window.cpp.

Referenced by PickerWindow::OnHotkey(), SignListWindow::OnHotkey(), Window::OnHotkey(), TownDirectoryWindow::OnHotkey(), IndustryDirectoryWindow::OnHotkey(), and BuildVehicleWindow::OnHotkey().

◆ SetWindowClassesDirty()

void SetWindowClassesDirty ( WindowClass  cls)

Mark all windows of a particular class as dirty (in need of repainting)

Parameters
clsWindow class

Definition at line 3116 of file window.cpp.

References Window::SetDirty(), and Window::window_class.

Referenced by AircraftLeaveHangar(), CalendarEnginesMonthlyLoop(), IntSettingDesc::ChangeValue(), CheckTrainStayInDepot(), CmdRenameDepot(), RedrawSmallmap(), AI::Rescan(), and VehicleEnterDepot().

◆ SetWindowDirty()

◆ SetWindowWidgetDirty()

void SetWindowWidgetDirty ( WindowClass  cls,
WindowNumber  number,
WidgetID  widget_index 
)

Mark a particular widget in a particular window as dirty (in need of repainting)

Parameters
clsWindow class
numberWindow number in that class
widget_indexIndex number of the widget that needs repainting

Definition at line 3103 of file window.cpp.

References Window::SetWidgetDirty(), Window::window_class, and Window::window_number.

Referenced by AircraftHandleDestTooFar(), CmdOpenCloseAirport(), Vehicle::Crash(), Vehicle::HandlePathfindingResult(), InvalidateCompanyWindows(), MarkTrainAsStuck(), NormaliseTrainHead(), GroundVehicle< RoadVehicle, VEH_ROAD >::SetLastSpeed(), ShipAccelerate(), ShipMoveUpDownOnLock(), TryPathReserve(), UpdateAircraftSpeed(), and UpdateStationAcceptance().

◆ StartWindowDrag()

static void StartWindowDrag ( Window w)
static

Start window dragging.

Parameters
wWindow to start dragging

Definition at line 2256 of file window.cpp.

References _drag_delta, _dragging_window, Window::flags, Window::left, WF_CENTERED, and WF_DRAGGING.

◆ StartWindowSizing()

static void StartWindowSizing ( Window w,
bool  to_left 
)
static

Start resizing a window.

Parameters
wWindow to start resizing.
to_leftWhether to drag towards the left or not

Definition at line 2273 of file window.cpp.

References _drag_delta, _dragging_window, Window::flags, WF_CENTERED, WF_SIZING_LEFT, and WF_SIZING_RIGHT.

◆ VpHandlePlaceSizingDrag()

EventState VpHandlePlaceSizingDrag ( )

Handle the mouse while dragging for placement/resizing.

Returns
State of handling the event.

Definition at line 3378 of file viewport.cpp.

References _special_mouse_mode, ES_NOT_HANDLED, WSM_DRAGGING, and WSM_SIZING.

Variable Documentation

◆ _input_events_this_tick

int _input_events_this_tick = 0
static

Local counter that is incremented each time an mouse input event is detected.

The counter is used to stop auto-scrolling.

See also
HandleAutoscroll()
HandleMouseEvents()

Definition at line 2661 of file window.cpp.

Referenced by InputLoop().

◆ _window_descs

std::vector<WindowDesc*>* _window_descs = nullptr

List of all WindowDescs.

List of WindowDescs.

This is a pointer to ensure initialisation order with the various static WindowDesc instances.

Definition at line 99 of file window.cpp.

Referenced by WindowDesc::LoadFromConfig(), WindowDesc::SaveToConfig(), and WindowDesc::WindowDesc().

◆ scrollamt

const int8_t scrollamt[16][2]
static
Initial value:
= {
{ 0, 0},
{-2, 0},
{ 0, -2},
{-2, -1},
{ 2, 0},
{ 0, 0},
{ 2, -1},
{ 0, -2},
{ 0, 2},
{-2, 1},
{ 0, 0},
{-2, 0},
{ 2, 1},
{ 0, 2},
{ 2, 0},
{ 0, 0},
}

Describes all the different arrow key combinations the game allows when it is in scrolling mode.

The real arrow keys are bitwise numbered as 1 = left 2 = up 4 = right 8 = down

Definition at line 2736 of file window.cpp.