OpenTTD
Macros | Enumerations | Functions | Variables
window.cpp File Reference

Windowing system, widgets and events. More...

#include "stdafx.h"
#include <stdarg.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 "window_func.h"
#include "tilehighlight_func.h"
#include "network/network.h"
#include "querystring_gui.h"
#include "widgets/dropdown_func.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 "safeguards.h"

Go to the source code of this file.

Macros

#define scrollspeed   3
 

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, TIME_BETWEEN_DOUBLE_CLICK = 500, MAX_OFFSET_HOVER = 5
}
 

Functions

static int CDECL 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...
 
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...
 
static WindowFindChildWindow (const Window *w, WindowClass wc)
 Find the Window whose parent pointer points to this window. 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...
 
void DeleteWindowById (WindowClass cls, WindowNumber number, bool force)
 Delete a window by its class and window number (if it is open). More...
 
void DeleteWindowByClass (WindowClass cls)
 Delete all windows of a given class. More...
 
void DeleteCompanyWindows (CompanyID id)
 Delete 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)
 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 void AddWindowToZOrdering (Window *w)
 Adds a window to the z-ordering, according to its z-priority. More...
 
static void RemoveWindowFromZOrdering (Window *w)
 Removes a window from the z-ordering. 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 sm_width, int16 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. More...
 
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)
 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 EventState HandleScrollbarScrolling ()
 handle scrollbar scrolling 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 HandleKeypress (uint keycode, WChar 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...
 
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 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, byte 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 CallWindowTickEvent ()
 Dispatch WE_TICK event over all windows.
 
void DeleteNonVitalWindows ()
 Try to delete a non-vital window. More...
 
void DeleteAllNonVitalWindows ()
 It is possible that a stickied window gets to a position where the 'close' button is outside the gaming area. More...
 
void DeleteConstructionWindows ()
 Delete all windows that are used for construction of vehicle etc. More...
 
void HideVitalWindows ()
 Delete all always on-top windows to get an empty screen.
 
void ReInitAllWindows ()
 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 = NULL
 Window of the last #MOUSEOVER event.
 
static Window_last_scroll_window = NULL
 Window of the last scroll event.
 
Window_z_front_window = NULL
 List of windows opened at the screen sorted from the front. More...
 
Window_z_back_window = NULL
 List of windows opened at the screen sorted from the back. More...
 
bool _window_highlight_colour = false
 If false, highlight is white, otherwise the by the widget defined colour. More...
 
Window_focused_window
 
Point _cursorpos_drag_start
 
int _scrollbar_start_pos
 
int _scrollbar_size
 
byte _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.
 
static SmallVector< WindowDesc *, 16 > * _window_descs = NULL
 List of all WindowDescs. More...
 
char * _windows_file
 Config file to store WindowDesc.
 
static const int MIN_VISIBLE_TITLE_BAR = 13
 The minimum number of pixels of the title bar must be visible in both the X or Y direction.
 
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 scrollamt [16][2]
 Describes all the different arrow key combinations the game allows when it is in scrolling mode. More...
 

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.

TIME_BETWEEN_DOUBLE_CLICK 

Time between 2 left clicks before it becoming a double click, in ms.

MAX_OFFSET_HOVER 

Maximum mouse movement before stopping a hover event.

Definition at line 2765 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 2024 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 43 of file window.cpp.

Function Documentation

◆ AddWindowToZOrdering()

static void AddWindowToZOrdering ( Window w)
static

Adds a window to the z-ordering, according to its z-priority.

Parameters
wWindow to add

Definition at line 1349 of file window.cpp.

Referenced by BringWindowToFront(), and Window::InitializeData().

◆ BringWindowToFront()

static void BringWindowToFront ( Window w)
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

Definition at line 1422 of file window.cpp.

References AddWindowToZOrdering(), RemoveWindowFromZOrdering(), and Window::SetDirty().

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 1234 of file window.cpp.

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

Referenced by AllocateWindowDescFront(), DoSelectCompanyManagerFace(), CompanyWindow::OnClick(), ShowAIDebugWindow(), ShowCompanyFinances(), ShowDepotWindow(), ShowGenerateWorldProgress(), and ShowIndustryCargoesWindow().

◆ 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 3441 of file window.cpp.

◆ 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 1198 of file window.cpp.

◆ DeleteAllNonVitalWindows()

void DeleteAllNonVitalWindows ( )

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 3295 of file window.cpp.

References DeleteNonVitalWindows().

◆ DeleteCompanyWindows()

void DeleteCompanyWindows ( CompanyID  id)

Delete 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 deleted

Parameters
idcompany identifier

Definition at line 1172 of file window.cpp.

Referenced by Company::~Company().

◆ DeleteConstructionWindows()

void DeleteConstructionWindows ( )

Delete 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 3318 of file window.cpp.

◆ DeleteNonVitalWindows()

void DeleteNonVitalWindows ( )

Try to delete 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 3266 of file window.cpp.

Referenced by DeleteAllNonVitalWindows().

◆ DeleteWindowByClass()

void DeleteWindowByClass ( WindowClass  cls)

◆ DeleteWindowById()

void DeleteWindowById ( WindowClass  cls,
WindowNumber  number,
bool  force 
)

◆ 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 789 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 632 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 816 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 764 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 877 of file window.cpp.

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

◆ 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 937 of file window.cpp.

Referenced by CenterBounds().

◆ 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 455 of file window.cpp.

References Window::nested_focus, NWidgetBase::type, WC_CONSOLE, Window::window_class, and WWT_EDITBOX.

Referenced by HandleTextInput(), Window::InitializeData(), 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 2077 of file window.cpp.

References Clamp(), NWidgetBase::current_x, NWidgetBase::current_y, NWidgetBase::GetWidgetOfType(), MIN_VISIBLE_TITLE_BAR, Window::nested_root, NWidgetBase::pos_x, NWidgetBase::pos_y, and WWT_CAPTION.

◆ FindChildWindow()

static Window* FindChildWindow ( const Window w,
WindowClass  wc 
)
static

Find the Window whose parent pointer points to this window.

Parameters
wparent Window to find child of
wcWindow class of the window to remove; WC_INVALID if class does not matter
Returns
a Window pointer that is the child of w, or NULL otherwise

Definition at line 1033 of file window.cpp.

Referenced by Window::DeleteChildWindows().

◆ FindWindowByClass()

Window* FindWindowByClass ( WindowClass  cls)

Find any window by its class.

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

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

Definition at line 1121 of file window.cpp.

Referenced by UpdateNewGRFScanStatus().

◆ FindWindowById()

Window* FindWindowById ( WindowClass  cls,
WindowNumber  number 
)

◆ 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, NULL otherwise

Definition at line 1854 of file window.cpp.

Referenced by HandleMouseOver().

◆ 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 1639 of file window.cpp.

◆ 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 2163 of file window.cpp.

References FindWindowById(), and WC_STATUS_BAR.

Referenced by TooltipsWindow::OnInitialPosition().

◆ 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 2152 of file window.cpp.

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

Referenced by TooltipsWindow::OnInitialPosition().

◆ 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 1708 of file window.cpp.

References FindWindowById(), and WC_MAIN_TOOLBAR.

Referenced by TransparenciesWindow::OnInitialPosition(), and TerraformToolbarWindow::OnInitialPosition().

◆ 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 1271 of file window.cpp.

◆ HandleKeypress()

void HandleKeypress ( uint  keycode,
WChar  key 
)

Handle keyboard input.

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

Definition at line 2625 of file window.cpp.

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 1974 of file window.cpp.

References _left_button_down, _special_mouse_mode, ES_NOT_HANDLED, and WSM_DRAGDROP.

◆ HandleMouseOver()

static void HandleMouseOver ( )
static

Report position of the mouse to the underlying window.

Definition at line 1998 of file window.cpp.

References FindWindowFromPt().

◆ HandleScrollbarScrolling()

static EventState HandleScrollbarScrolling ( )
static

handle scrollbar scrolling with the mouse.

Returns
State of handling the event.

Definition at line 2384 of file window.cpp.

◆ 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 2713 of file window.cpp.

References EditBoxInGlobalFocus(), NWidgetCore::index, Window::InsertTextString(), Window::nested_focus, WC_CONSOLE, and Window::window_class.

Referenced by CancelIMEComposition(), and HandleIMEComposition().

◆ HandleViewportScroll()

static EventState HandleViewportScroll ( )
static

Handle viewport scrolling with the mouse.

Returns
State of handling the event.

Definition at line 2434 of file window.cpp.

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

◆ HandleWindowDragging()

static EventState HandleWindowDragging ( )
static

Handle dragging/resizing of a window.

Returns
State of handling the event.

Definition at line 2175 of file window.cpp.

References _dragging_window, _left_button_down, and ES_NOT_HANDLED.

◆ 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 default the invalidation is not considered to be called from GUI scope.

See InvalidateWindowData() for details on GUI-scope vs. command-scope.

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

Definition at line 3238 of file window.cpp.

Referenced by AddRemoveEngineFromAutoreplaceAndBuildWindows(), SmallMapWindow::BreakIndustryChainLink(), ClickChangeDateCheat(), ClickChangeMaxHlCheat(), ClickSetProdCheat(), CmdRemoveGoal(), CmdRemoveStoryPageElement(), CmdRenameVehicle(), CmdSellRailWagon(), CmdSetGoalCompleted(), CmdSetGoalProgress(), CmdSetGoalText(), CmdSetStoryPageDate(), CmdSetStoryPageTitle(), CmdUpdateStoryPageElement(), DecloneOrder(), DoScanNewGRFFiles(), InvalidateCompanyInfrastructureWindow(), InvalidateCompanyWindow(), InvalidateNewGRFChangeWindows(), IndustryCargoesWindow::NotifySmallmap(), AI::Rescan(), and SetNewLandscapeType().

◆ 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 3220 of file window.cpp.

Referenced by AddRemoveEngineFromAutoreplaceAndBuildWindows(), AircraftLeaveHangar(), ChangePopulation(), CmdAddSharedVehicleGroup(), CmdCompanyCtrl(), CmdConvertRail(), CmdRemoveAllVehiclesGroup(), CmdRemoveGoal(), CmdRenameTown(), CmdSellRailWagon(), CmdSetGoalCompleted(), CmdSetGoalProgress(), CmdSetGoalText(), CmdTownCargoGoal(), CmdTownGrowthRate(), CmdTownSetText(), Company::Company(), CreateSubsidy(), DeleteNewGRFInspectWindow(), DeleteStationIfEmpty(), DoScanNewGRFFiles(), InvalidateAutoreplaceWindow(), InvalidateNewGRFInspectWindow(), InvalidateVehicleOrder(), MoveToNextItem(), NormaliseTrainHead(), MainWindow::OnInvalidateData(), Industry::PostDestructor(), Town::PostDestructor(), BaseStation::PostDestructor(), Company::PostDestructor(), RemoveBuoy(), AI::Rescan(), ReverseTrainDirection(), UpdateNetworkGameWindow(), NetworkClientInfo::~NetworkClientInfo(), and NetworkContentDownloadStatusWindow::~NetworkContentDownloadStatusWindow().

◆ 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 1562 of file window.cpp.

◆ 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 1599 of file window.cpp.

◆ LocalGetWindowPlacement()

static Point LocalGetWindowPlacement ( const WindowDesc desc,
int16  sm_width,
int16  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 1733 of file window.cpp.

References _current_text_dir, NWidgetLeaf::closebox_dimension, FindWindowById(), FONT_HEIGHT_NORMAL, WindowDesc::GetDefaultHeight(), WindowDesc::GetDefaultWidth(), Window::height, Window::left, max(), WindowDesc::parent_cls, TD_RTL, Window::top, WC_BUILD_TOOLBAR, WC_SCEN_LAND_GEN, WD_CAPTIONTEXT_BOTTOM, WD_CAPTIONTEXT_TOP, 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 2494 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 849 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 NULL.
Returns
X coordinate of left edge of the repositioned toolbar window.

Definition at line 3396 of file window.cpp.

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

◆ PositionNetworkChatWindow()

int PositionNetworkChatWindow ( Window w)

(Re)position network chat window at the screen.

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

Definition at line 3429 of file window.cpp.

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

◆ PositionNewsMessage()

int PositionNewsMessage ( Window w)

(Re)position news message window at the screen.

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

Definition at line 3418 of file window.cpp.

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

◆ PositionStatusbar()

int PositionStatusbar ( Window w)

(Re)position statusbar window at the screen.

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

Definition at line 3407 of file window.cpp.

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

◆ 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 NULL.
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 3373 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 for MIN_VISIBLE_TITLE_BAR pixels (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 2039 of file window.cpp.

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

◆ ReInitAllWindows()

void ReInitAllWindows ( )

◆ RelocateAllWindows()

void RelocateAllWindows ( int  neww,
int  newh 
)

Relocate all windows to fit the new size of the game application screen.

Parameters
newwNew width of the game application screen
newhNew height of the game application screen.

Definition at line 3458 of file window.cpp.

Referenced by AllocateWindowDescFront().

◆ RemoveWindowFromZOrdering()

static void RemoveWindowFromZOrdering ( Window w)
static

Removes a window from the z-ordering.

Parameters
wWindow to remove

Definition at line 1398 of file window.cpp.

References Window::z_front.

Referenced by BringWindowToFront().

◆ ResizeWindow()

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

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 2116 of file window.cpp.

References _cur_resolution, Ceil(), NWidgetBase::current_x, NWidgetBase::current_y, Window::height, Window::left, max(), Window::nested_root, NWidgetBase::resize_x, NWidgetBase::resize_y, Window::SetDirty(), NWidgetBase::smallest_x, NWidgetBase::smallest_y, Window::top, and Window::width.

Referenced by NetworkClientListWindow::CheckClientListHeight().

◆ SetFocusedWindow()

void SetFocusedWindow ( Window w)

Set the window that has the focus.

Parameters
wThe window to set the focus on

Definition at line 432 of file window.cpp.

References Window::nested_focus, and NWidgetBase::SetDirty().

Referenced by Window::InitializeData(), SignListWindow::OnHotkey(), and Window::OnHotkey().

◆ SetWindowClassesDirty()

void SetWindowClassesDirty ( WindowClass  cls)

◆ SetWindowDirty()

void SetWindowDirty ( WindowClass  cls,
WindowNumber  number 
)

◆ SetWindowWidgetDirty()

void SetWindowWidgetDirty ( WindowClass  cls,
WindowNumber  number,
byte  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 3134 of file window.cpp.

Referenced by AircraftHandleDestTooFar(), CmdOpenCloseAirport(), CmdStartStopVehicle(), MarkTrainAsStuck(), NormaliseTrainHead(), GroundVehicle< RoadVehicle, VEH_ROAD >::SetLastSpeed(), UpdateAircraftSpeed(), and UpdateStationAcceptance().

◆ StartWindowDrag()

static void StartWindowDrag ( Window w)
static

Start window dragging.

Parameters
wWindow to start dragging

Definition at line 2349 of file window.cpp.

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

Referenced by Window::HandleButtonClick().

◆ 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 2367 of file window.cpp.

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

Referenced by Window::HandleButtonClick().

◆ VpHandlePlaceSizingDrag()

EventState VpHandlePlaceSizingDrag ( )

Handle the mouse while dragging for placement/resizing.

Returns
State of handling the event.

Definition at line 3107 of file viewport.cpp.

References _left_button_down, _special_mouse_mode, ES_HANDLED, ES_NOT_HANDLED, TileHighlightData::GetCallbackWnd(), Window::OnPlaceDrag(), ResetObjectToPlace(), TileHighlightData::select_method, TileHighlightData::select_proc, 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 2726 of file window.cpp.

◆ _window_descs

SmallVector<WindowDesc*, 16>* _window_descs = NULL
static

List of all WindowDescs.

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

Definition at line 84 of file window.cpp.

◆ _window_highlight_colour

bool _window_highlight_colour = false

If false, highlight is white, otherwise the by the widget defined colour.

Definition at line 60 of file window.cpp.

Referenced by UpdateWindows().

◆ _z_back_window

Window* _z_back_window = NULL

List of windows opened at the screen sorted from the back.

Definition at line 57 of file window.cpp.

◆ _z_front_window

Window* _z_front_window = NULL

List of windows opened at the screen sorted from the front.

Definition at line 55 of file window.cpp.

◆ scrollamt

const int8 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 2798 of file window.cpp.