# window.cpp File Reference

Windowing system, widgets and events. More...

`#include "stdafx.h"`
`#include <stdarg.h>`
`#include "openttd.h"`
`#include "company_func.h"`
`#include "gfx_func.h"`
`#include "console_func.h"`
`#include "console_gui.h"`
`#include "viewport_func.h"`
`#include "variables.h"`
`#include "genworld.h"`
`#include "blitter/factory.hpp"`
`#include "zoom_func.h"`
`#include "map_func.h"`
`#include "vehicle_base.h"`
`#include "settings_type.h"`
`#include "cheat_type.h"`
`#include "window_func.h"`
`#include "tilehighlight_func.h"`
`#include "network/network.h"`
`#include "querystring_gui.h"`
`#include "widgets/dropdown_func.h"`
`#include "table/sprites.h"`

Go to the source code of this file.

## Defines
#define | scrollspeed 3
## Enumerations
enum | MouseClick { MC_NONE = 0, MC_LEFT, MC_RIGHT, MC_DOUBLE_LEFT, MAX_OFFSET_DOUBLE_CLICK = 5, TIME_BETWEEN_DOUBLE_CLICK = 500 }
## Functions
void | SetFocusedWindow (Window *w)
| Set the window that has the focus.
const Widget * | GetGloballyFocusedWidget ()
| Gets the globally focused widget.
bool | EditBoxInGlobalFocus ()
| Check if an edit box is in global focus.
static void | StartWindowDrag (Window *w)
| Start window dragging.
static void | StartWindowSizing (Window *w)
| Start resizing a window.
static void | DispatchLeftClickEvent (Window *w, int x, int y, bool double_click)
| Dispatch left mouse-button (possibly double) click in window.
static void | DispatchRightClickEvent (Window *w, int x, int y)
| Dispatch right mouse-button click in window.
static void | DispatchMouseWheelEvent (Window *w, int widget, int wheel)
| Dispatch the mousewheel-action to the window.
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.
void | DrawOverlappedWindowForAll (int left, int top, int right, int bottom)
| From a rectangle that needs redrawing, find the windows that intersect with the rectangle.
void | SetWindowDirty (const Window *w)
| Mark entire window as dirty (in need of re-paint).
static Window * | FindChildWindow (const Window *w)
| Find the Window whose parent pointer points to this window.
Window * | FindWindowById (WindowClass cls, WindowNumber number)
| Find a window by its class and window number.
void | DeleteWindowById (WindowClass cls, WindowNumber number, bool force)
| Delete a window by its class and window number (if it is open).
void | DeleteWindowByClass (WindowClass cls)
| Delete all windows of a given class.
void | DeleteCompanyWindows (CompanyID id)
| Delete all windows of a company.
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.
static void | BringWindowToFront (Window *w)
| On clicking on a window, make it the frontmost window of all.
Window * | BringWindowToFrontById (WindowClass cls, WindowNumber number)
| Find a window and make it the top-window on the screen.
static bool | IsVitalWindow (const Window *w)
static void | AssignWidgetToWindow (Window *w, const Widget *widget)
| Assign widgets to a new window by initialising its widget pointers, and by copying the widget array widget to `w->widget` to allow for resizable windows.
static bool | IsGoodAutoPlace1 (int left, int top, int width, int height, Point &pos)
| Decide whether a given rectangle is a good place to open a completely visible new window.
static bool | IsGoodAutoPlace2 (int left, int top, int width, int height, Point &pos)
| Decide whether a given rectangle is a good place to open a mostly visible new window.
static Point | GetAutoPlacePosition (int width, int height)
| Find a good place for opening a new window of a given width and height.
static Point | LocalGetWindowPlacement (const WindowDesc *desc, int window_number)
| Compute the position of the top-left corner of a new window that is opened.
Window * | FindWindowFromPt (int x, int y)
| Do a search for a window at specific coordinates.
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 ()
Window * | GetCallbackWnd ()
static void | HandlePlacePresize ()
static bool | HandleDragDrop ()
static bool | HandleMouseOver ()
void | ResizeWindow (Window *w, int x, int y)
| Resize the window.
static bool | HandleWindowDragging ()
static bool | HandleScrollbarScrolling ()
static bool | HandleViewportScroll ()
static bool | MaybeBringWindowToFront (Window *w)
| Check if a window can be made top-most window, and if so do it.
void | HandleKeypress (uint32 raw_key)
| Handle keyboard input.
void | HandleCtrlChanged ()
| State of CONTROL key has changed.
static void | HandleAutoscroll ()
| If needed and switched on, perform auto scrolling (automatically moving window contents when mouse is near edge of the window).
bool | VpHandlePlaceSizingDrag ()
| Handle the mouse while dragging for placement/resizing.
static void | ScrollMainViewport (int x, int y)
static void | HandleKeyScrolling ()
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 | InvalidateWindow (WindowClass cls, WindowNumber number)
| Mark window as dirty (in need of repainting).
void | InvalidateWindowWidget (WindowClass cls, WindowNumber number, byte widget_index)
| Mark a particular widget in a particular window as dirty (in need of repainting).
void | InvalidateWindowClasses (WindowClass cls)
| Mark all windows of a particular class as dirty (in need of repainting).
void | InvalidateThisWindowData (Window *w, int data)
| Mark window data as invalid (in need of re-computing).
void | InvalidateWindowData (WindowClass cls, WindowNumber number, int data)
| Mark window data of the window of a given class and specific window number as invalid (in need of re-computing).
void | InvalidateWindowClassesData (WindowClass cls, int data)
| Mark window data of all windows of a given class as invalid (in need of re-computing).
void | CallWindowTickEvent ()
| Dispatch WE_TICK event over all windows.
void | DeleteNonVitalWindows ()
| Try to delete a non-vital window.
void | DeleteAllNonVitalWindows ()
| It is possible that a stickied window gets to a position where the 'close' button is outside the gaming area.
void | DeleteConstructionWindows ()
| Delete all windows that are used for construction of vehicle etc.
void | HideVitalWindows ()
| Delete all always on-top windows to get an empty screen.
int | PositionMainToolbar (Window *w)
| (Re)position main toolbar window at the screen
void | SetVScrollCount (Window *w, int num)
| Set the number of items of the vertical scrollbar.
void | SetVScroll2Count (Window *w, int num)
| Set the number of items of the second vertical scrollbar.
void | SetHScrollCount (Window *w, int num)
| Set the number of items of the horizontal scrollbar.
void | RelocateAllWindows (int neww, int newh)
| Relocate all windows to fit the new size of the game application screen.
## 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.
Window * | _z_front_window = NULL
| List of windows opened at the screen sorted from the front.
Window * | _z_back_window = NULL
| List of windows opened at the screen sorted from the back.
Window * | _focused_window
Point | _cursorpos_drag_start
int | _scrollbar_start_pos
int | _scrollbar_size
byte | _scroller_click_timeout
bool | _scrolling_scrollbar
bool | _scrolling_viewport
byte | _special_mouse_mode
static bool | _dragging_window
static int | _input_events_this_tick = 0
| Local counter that is incremented each time an mouse input event is detected.
static const int8 | scrollamt [16][2]
| Describes all the different arrow key combinations the game allows when it is in scrolling mode.

## Detailed Description

Windowing system, widgets and events.

Definition in file window.cpp.

## Enumeration Type Documentation

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.

Definition at line 1821 of file window.cpp.

## Function Documentation

static void AssignWidgetToWindow | ( | Window * | w,
|  | const Widget * | widget |
| ) |  |  | `[static]`

Assign widgets to a new window by initialising its widget pointers, and by copying the widget array widget to `w->widget` to allow for resizable windows.

Parameters:

  | w | Window on which to attach the widget array
  | widget | pointer of widget array to fill the window with

Postcondition:
  `w->widget` points to allocated memory and contains the copied widget array except for the terminating widget, `w->widget_count` contains number of widgets in the allocated memory.

Definition at line 735 of file window.cpp.

References Widget::type, Window::widget, Window::widget_count, and WWT_LAST.

Referenced by Window::Initialize().

static void BringWindowToFront | ( | Window * | w | ) | `[static]`

On clicking on a window, make it the frontmost window of all.

However there are certain windows that always need to be on-top; these include

- Toolbar, Statusbar (always on)
- New window, Chatbar (only if open) The window is marked dirty for a repaint if the window is actually moved
  Parameters:

    | w | window that is put into the foreground

  Returns:
    pointer to the window, the same as the input pointer

Definition at line 693 of file window.cpp.

References Window::SetDirty(), Window::z_back, and Window::z_front.

Referenced by BringWindowToFrontById(), MaybeBringWindowToFront(), StartWindowDrag(), and StartWindowSizing().

Window* BringWindowToFrontById | ( | WindowClass | cls,
|  | WindowNumber | number |
| ) |  |  |

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

The window gets a white border for a brief period of time to visualize its "activation"

Parameters:

  | cls | WindowClass of the window to activate
  | number | WindowNumber of the window to activate

Returns:
  a pointer to the window thus activated

Definition at line 658 of file window.cpp.

References BringWindowToFront(), FindWindowById(), Window::flags4, and Window::SetDirty().

Referenced by AllocateWindowDescFront(), DoSelectCompanyManagerFace(), DoShowCompanyFinances(), CompanyWindow::OnClick(), ShowDepotWindow(), ShowGenerateWorldProgress(), and ShowSelectStationIfNeeded().

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_owner | original owner of the window
  | new_owner | the new owner of the window

Definition at line 626 of file window.cpp.

References Window::owner, and Window::window_class.

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

References DeleteNonVitalWindows(), Window::flags4, and WF_STICKY.

Referenced by GenerateWorld().

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:

  | id | company identifier

Definition at line 602 of file window.cpp.

References DeleteWindowById(), and Window::owner.

Referenced by CmdCompanyCtrl().

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

References Window::desc_flags, Window::SetDirty(), and WDF_CONSTRUCTION.

Referenced by SetLocalCompany().

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

References Window::flags4, WF_STICKY, and Window::window_class.

Referenced by DeleteAllNonVitalWindows().

void DeleteWindowByClass | ( | WindowClass | cls | ) |

Delete all windows of a given class.

Parameters:

  | cls | Window class of windows to delete

Definition at line 582 of file window.cpp.

References Window::window_class.

Referenced by NewGRFWindow::OnClick(), NewGRFAddWindow::OnClick(), ShowBuildRailToolbar(), ShowEndGameChart(), ShowHighscoreTable(), and ShowNewGRFSettings().

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

Delete a window by its class and window number (if it is open).

Parameters:

  | cls | Window class
  | number | Number of the window within the window class
  | force | force deletion; if false don't delete when stickied

Definition at line 568 of file window.cpp.

References Window::desc_flags, FindWindowById(), Window::flags4, WDF_STICKY_BUTTON, and WF_STICKY.

Referenced by _GenerateWorld(), CmdCompanyCtrl(), CmdDeleteGroup(), CmdMoveRailVehicle(), CmdSellRailWagon(), DeleteCompanyWindows(), DispatchLeftClickEvent(), GuiShowTooltips(), HandleGeneratingWorldAbortion(), HideVitalWindows(), MoveToNextItem(), BuildRailToolbarWindow::OnPlaceObjectAbort(), ShowBuildBridgeWindow(), ShowDropDownList(), ShowMessageHistory(), ShowNewsMessage(), ShowOnScreenKeyboard(), ShowQueryString(), ShowVehicleDetailsWindow(), ShowVehicleRefitWindow(), StartWindowDrag(), StartWindowSizing(), ToggleRailButton_Remove(), and Station::~Station().

static void DispatchLeftClickEvent | ( | Window * | w,
|  | int | x,
|  | int | y,
|  | bool | double_click |
| ) |  |  | `[static]`

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

Parameters:

  | w | Window to dispatch event in
  | x | X coordinate of the click
  | y | Y coordinate of the click
  | double_click | Was it a double click?

Definition at line 223 of file window.cpp.

References DeleteWindowById(), Window::desc_flags, Window::flags4, Window::focused_widget, GetWidgetFromPos(), Window::HandleButtonClick(), HideDropDownMenu(), Window::InvalidateWidget(), Window::IsWidgetDisabled(), Window::OnClick(), Window::OnDoubleClick(), Window::OnFocus(), Window::OnFocusLost(), ScrollbarClickHandler(), SetFocusedWindow(), StartWindowDrag(), StartWindowSizing(), Widget::type, WDF_DEF_WIDGET, WDF_NO_FOCUS, WDF_RESIZABLE, WDF_STD_BTN, WDF_STICKY_BUTTON, WF_STICKY, Window::widget, Window::window_class, WWT_CAPTION, WWT_EDITBOX, WWT_HSCROLLBAR, WWT_IMGBTN, WWT_PANEL, WWT_RESIZEBOX, WWT_SCROLL2BAR, WWT_SCROLLBAR, WWT_STICKYBOX, and WWT_TEXTBTN.

static void DispatchMouseWheelEvent | ( | Window * | w,
|  | int | widget,
|  | 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:

  | w | Window
  | widget | the widget where the scrollwheel was used
  | wheel | scroll up or down

Definition at line 361 of file window.cpp.

References Scrollbar::cap, Clamp(), Scrollbar::count, Scrollbar::pos, Window::SetDirty(), Widget::type, Window::vscroll, Window::vscroll2, Window::widget, WWT_SCROLL2BAR, and WWT_SCROLLBAR.

static void DispatchRightClickEvent | ( | Window * | w,
|  | int | x,
|  | int | y |
| ) |  |  | `[static]`

Dispatch right mouse-button click in window.

Parameters:

  | w | Window to dispatch event in
  | x | X coordinate of the click
  | y | Y coordinate of the click

Definition at line 335 of file window.cpp.

References Window::desc_flags, GetWidgetFromPos(), GuiShowTooltips(), Window::OnRightClick(), Widget::tooltips, WDF_STD_TOOLTIPS, and Window::widget.

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:

  | w | Window that needs to be repainted
  | left | Left edge of the rectangle that should be repainted
  | top | Top edge of the rectangle that should be repainted
  | right | Right edge of the rectangle that should be repainted
  | bottom | Bottom edge of the rectangle that should be repainted

Definition at line 398 of file window.cpp.

References FOR_ALL_WINDOWS_FROM_BACK_FROM, BlitterFactoryBase::GetCurrentBlitter(), Window::height, Window::left, Blitter::MoveTo(), Window::OnPaint(), Window::top, Window::width, and Window::z_front.

Referenced by 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:

  | left | Left edge of the rectangle that should be repainted
  | top | Top edge of the rectangle that should be repainted
  | right | Right edge of the rectangle that should be repainted
  | bottom | Bottom edge of the rectangle that should be repainted

Definition at line 457 of file window.cpp.

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

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

References GetGloballyFocusedWidget(), Widget::type, Window::window_class, and WWT_EDITBOX.

Referenced by HandleKeypress(), and Window::Initialize().

static Window* FindChildWindow | ( | const Window * | w | ) | `[static]`

Find the Window whose parent pointer points to this window.

Parameters:

  | w | parent Window to find child of

Returns:
  a Window pointer that is the child of w, or NULL otherwise

Definition at line 496 of file window.cpp.

References Window::parent.

Referenced by Window::DeleteChildWindows().

Window* FindWindowById | ( | WindowClass | cls,
|  | WindowNumber | number |
| ) |  |  |

Find a window by its class and window number.

Parameters:

  | cls | Window class
  | number | Number of the window within the window class

Returns:
  Pointer to the found window, or `NULL` if not available

Definition at line 552 of file window.cpp.

References Window::window_class, and Window::window_number.

Referenced by BringWindowToFrontById(), ChangeVehicleWindow(), ClickChangeDateCheat(), DeleteDepotHighlightOfVehicle(), DeleteGroupHighlightOfVehicle(), DeleteWindowById(), Window::FindWindowPlacementAndResize(), GenerateWorld(), GenericPlaceSignals(), HandleAutoSignalPlacement(), HandleKeypress(), IConsoleGUIPrint(), Window::Initialize(), IsNewsTickerShown(), LocalGetWindowPlacement(), BuildRailToolbarWindow::OnPlaceDrag(), PositionMainToolbar(), ReadyForNextItem(), ReinitGuiAfterToggleElrail(), RelocateAllWindows(), ResetSignalVariant(), SetDefaultRailGui(), ShowBuildRailToolbar(), ShowDropDownList(), ShowLastNewsMessage(), StationJoinerNeeded(), and VpHandlePlaceSizingDrag().

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:

  | x | position x to query
  | y | position y to query

Returns:
  a pointer to the found window if any, NULL otherwise

Definition at line 1152 of file window.cpp.

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

Referenced by HandleAutoscroll().

static Point GetAutoPlacePosition | ( | int | width,
|  | int | height |
| ) |  |  | `[static]`

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

Parameters:

  | width | Width of the new window
  | height | Height of the new window

Returns:
  Top-left coordinate of the new window

Definition at line 1001 of file window.cpp.

References Window::height, IsGoodAutoPlace1(), IsGoodAutoPlace2(), Window::left, Window::top, Window::width, Window::window_class, Point::x, and Point::y.

Referenced by LocalGetWindowPlacement().

const Widget* GetGloballyFocusedWidget | ( |  | ) |

Gets the globally focused widget.

Which is the focused widget of the focused window.

Returns:
  A pointer to the globally focused Widget, or NULL if there is no globally focused widget.

Definition at line 82 of file window.cpp.

References Window::focused_widget.

Referenced by EditBoxInGlobalFocus().

void HandleKeypress | ( | uint32 | raw_key | ) |

Handle keyboard input.

Parameters:

  | raw_key | Lower 8 bits contain the ASCII character, the higher 16 bits the keycode

Definition at line 1719 of file window.cpp.

References EditBoxInGlobalFocus(), Window::ES_HANDLED, FindWindowById(), GB(), IsGeneratingWorld(), and Window::OnKeyPress().

void InvalidateThisWindowData | ( | Window * | w,
|  | int | data |
| ) |  |  |

Mark window data as invalid (in need of re-computing).

Parameters:

  | w | Window with invalid data

Definition at line 2177 of file window.cpp.

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

Referenced by ChangeVehicleWindow(), InvalidateWindowClassesData(), and InvalidateWindowData().

void InvalidateWindow | ( | WindowClass | cls,
|  | WindowNumber | number |
| ) |  |  |

Mark window as dirty (in need of repainting).

Parameters:

  | cls | Window class
  | number | Window number in that class

Definition at line 2137 of file window.cpp.

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

Referenced by AddNewsItem(), AircraftEventHandler_AtTerminal(), ChangePopulation(), ChangeTownRating(), CmdAddVehicleGroup(), CmdAutofillTimetable(), CmdBuildAircraft(), CmdBuildAirport(), CmdBuildCompanyHQ(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRoadVeh(), CmdBuildShip(), CmdBuyShareInCompany(), CmdChangeServiceInt(), CmdChangeSetting(), CmdDoTownAction(), CmdMoveRailVehicle(), CmdPause(), CmdRefitAircraft(), CmdRefitRailVehicle(), CmdRefitRoadVeh(), CmdRefitShip(), CmdReverseTrainDirection(), CmdSellRailWagon(), CmdSellShareInCompany(), CmdSetAutoReplace(), CmdStartStopVehicle(), DeleteLastWagon(), DeleteNewsItem(), DeliverGoodsToIndustry(), DestroyCompanyHQ(), DoStartupNewCompany(), IndustryProductionCallback(), InvalidateVehicleOrder(), LoadUnloadVehicle(), RemoveOrderFromAllVehicles(), SetLocalCompany(), SetSettingValue(), SetTrainGroupID(), TrainConsistChanged(), TrainPowerChanged(), TriggerIndustryProduction(), UpdateCompanyRatingAndValue(), UpdateTownGrowRate(), and UpdateTrainGroupID().

void InvalidateWindowClasses | ( | WindowClass | cls | ) |

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

Parameters:

  | cls | Window class

Definition at line 2165 of file window.cpp.

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

Referenced by CmdSkipToOrder(), CmdStartStopVehicle(), and ProcessOrders().

void InvalidateWindowClassesData | ( | WindowClass | cls,
|  | int | data |
| ) |  |  |

Mark window data of all windows of a given class as invalid (in need of re-computing).

Parameters:

  | cls | Window class

Definition at line 2200 of file window.cpp.

References InvalidateThisWindowData(), and Window::window_class.

Referenced by AddRemoveEngineFromAutoreplaceAndBuildWindows(), CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRoadVeh(), CmdBuildShip(), CmdCloneOrder(), CmdDeleteOrder(), CmdInsertOrder(), CmdMoveOrder(), CmdMoveRailVehicle(), CmdRefitAircraft(), CmdRefitRailVehicle(), CmdRefitRoadVeh(), CmdRefitShip(), CmdRenameVehicle(), CmdSellRailWagon(), and DecloneOrder().

void InvalidateWindowData | ( | WindowClass | cls,
|  | WindowNumber | number,
|  | int | data |
| ) |  |  |

Mark window data of the window of a given class and specific window number as invalid (in need of re-computing).

Parameters:

  | cls | Window class
  | number | Window number within the class

Definition at line 2188 of file window.cpp.

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

Referenced by AddRemoveEngineFromAutoreplaceAndBuildWindows(), ChangePopulation(), CmdAddSharedVehicleGroup(), CmdAddVehicleGroup(), CmdBuildAircraft(), CmdBuildAirport(), CmdBuildBuoy(), CmdBuildDock(), CmdBuildRailroadStation(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRoadStop(), CmdBuildRoadVeh(), CmdBuildShip(), CmdBuildTrainWaypoint(), CmdCompanyCtrl(), CmdConvertRail(), CmdCreateGroup(), CmdDeleteGroup(), CmdMoveRailVehicle(), CmdPlaceSign(), CmdRemoveAllVehiclesGroup(), CmdRenameGroup(), CmdRenameSign(), CmdRenameStation(), CmdRenameTown(), CmdSetGroupReplaceProtection(), DeleteStationIfEmpty(), DoCreateTown(), IndustryDailyLoop(), InvalidateAutoreplaceWindow(), InvalidateVehicleOrder(), AILog::Log(), MoveToNextItem(), NewGRFAddWindow::OnClick(), ReloadNewGRFData(), SaveFileDone(), SaveFileStart(), ShowTicker(), VehicleEnter_Track(), and Station::~Station().

void InvalidateWindowWidget | ( | WindowClass | cls,
|  | WindowNumber | number,
|  | byte | widget_index |
| ) |  |  |

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

Parameters:

  | cls | Window class
  | number | Window number in that class
  | widget_index | Index number of the widget that needs repainting

Definition at line 2151 of file window.cpp.

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

Referenced by CmdBuildAirport(), CmdBuildBuoy(), CmdBuildDock(), CmdBuildRailroadStation(), CmdBuildRoadStop(), CmdMoveRailVehicle(), CmdRemoveFromRailroadStation(), CmdStartStopVehicle(), Station::MarkDirty(), MarkTrainAsStuck(), RemoveRoadStop(), TrainPowerChanged(), TryPathReserve(), UpdateAircraftSpeed(), and UpdateStationAcceptance().

static bool IsGoodAutoPlace1 | ( | int | left,
|  | int | top,
|  | int | width,
|  | int | height,
|  | 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:

  | left | Left edge of the rectangle
  | top | Top edge of the rectangle
  | width | Width of the rectangle
  | height | Height of the rectangle
  | pos | If 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 932 of file window.cpp.

References Window::height, Window::left, Window::top, Window::width, Window::window_class, Point::x, and Point::y.

Referenced by GetAutoPlacePosition().

static bool IsGoodAutoPlace2 | ( | int | left,
|  | int | top,
|  | int | width,
|  | int | height,
|  | 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:

  | left | Left edge of the rectangle
  | top | Top edge of the rectangle
  | width | Width of the rectangle
  | height | Height of the rectangle
  | pos | If 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 968 of file window.cpp.

References Window::height, Window::left, Window::top, Window::width, Window::window_class, Point::x, and Point::y.

Referenced by GetAutoPlacePosition().

static Point LocalGetWindowPlacement | ( | const WindowDesc * | desc,
|  | 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/36 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:

  | *desc | The pointer to the WindowDesc to be created
  | window_number | the window number of the new window

Returns:
  Coordinate of the top-left corner of the new window

Definition at line 1073 of file window.cpp.

References WindowDesc::default_height, WindowDesc::default_width, FindWindowById(), GetAutoPlacePosition(), WindowDesc::left, Window::left, WindowDesc::parent_cls, WindowDesc::top, Window::top, WDP_ALIGN_TBL, WDP_ALIGN_TBR, WDP_AUTO, WDP_CENTER, Window::width, Point::x, and Point::y.

Referenced by Window::Window().

static bool MaybeBringWindowToFront | ( | Window * | w | ) | `[static]`

Check if a window can be made 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:

  | w | Window to bring on-top

Returns:
  false if the window has an active modal child, true otherwise

Definition at line 1674 of file window.cpp.

References BringWindowToFront(), Window::desc_flags, Window::flags4, FOR_ALL_WINDOWS_FROM_BACK_FROM, Window::height, Window::left, Window::parent, Window::SetDirty(), Window::top, WDF_MODAL, Window::width, Window::window_class, and Window::z_front.

int PositionMainToolbar | ( | Window * | w | ) |

(Re)position main toolbar window at the screen

Parameters:

  | w | Window structure of the main toolbar window, may also be `NULL`

Returns:
  X coordinate of left edge of the repositioned toolbar window

Definition at line 2314 of file window.cpp.

References _settings_client, FindWindowById(), ClientSettings::gui, Window::height, Window::left, SetDirtyBlocks(), GUISettings::toolbar_pos, Window::width, and Window::window_class.

Referenced by RelocateAllWindows().

void RelocateAllWindows | ( | int | neww,
|  | int | newh |
| ) |  |  |

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

Parameters:

  | neww | New width of the game application screen
  | newh | New height of the game appliction screen

Definition at line 2381 of file window.cpp.

References Clamp(), FindWindowById(), Window::height, ViewPort::height, ViewPort::left, Window::left, min(), Window::OnResize(), PositionMainToolbar(), ResizeWindow(), ScaleByZoom(), ViewPort::top, Window::top, Window::viewport, ViewPort::virtual_height, ViewPort::virtual_width, Window::width, ViewPort::width, Window::window_class, Point::x, Point::y, and ViewPort::zoom.

Referenced by GameSizeChanged().

void ResizeWindow | ( | Window * | w,
|  | int | x,
|  | int | y |
| ) |  |  |

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:

  | w | Window to resize
  | x | delta x-size of changed window (positive if larger, etc.)
  | y | delta y-size of changed window

Definition at line 1307 of file window.cpp.

References GB(), Window::height, RESIZE_BOTTOM, RESIZE_LEFT, RESIZE_NONE, RESIZE_RIGHT, RESIZE_TOP, Window::SetDirty(), Widget::type, Window::widget, Window::width, and WWT_LAST.

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

void SetFocusedWindow | ( | Window * | w | ) |

Set the window that has the focus.

Parameters:

  | w | The window to set the focus on

Definition at line 59 of file window.cpp.

References Window::focused_widget, Window::InvalidateWidget(), Window::OnFocus(), Window::OnFocusLost(), and Window::widget.

Referenced by DispatchLeftClickEvent(), and Window::Initialize().

void SetHScrollCount | ( | Window * | w,
|  | int | num |
| ) |  |  |

Set the number of items of the horizontal scrollbar.

Function also updates the position of the scrollbar if necessary.

Parameters:

  | w | Window containing the horizontal scrollbar
  | num | New number of items

Definition at line 2368 of file window.cpp.

References Scrollbar::cap, Scrollbar::count, Window::hscroll, and Scrollbar::pos.

void SetVScroll2Count | ( | Window * | w,
|  | int | num |
| ) |  |  |

Set the number of items of the second vertical scrollbar.

Function also updates the position of the scrollbar if necessary.

Parameters:

  | w | Window containing the second vertical scrollbar
  | num | New number of items

Definition at line 2353 of file window.cpp.

References Scrollbar::cap, Scrollbar::count, Scrollbar::pos, and Window::vscroll2.

Referenced by ReplaceVehicleWindow::GenerateLists().

void SetVScrollCount | ( | Window * | w,
|  | int | num |
| ) |  |  |

Set the number of items of the vertical scrollbar.

Function also updates the position of the scrollbar if necessary.

Parameters:

  | w | Window containing the vertical scrollbar
  | num | New number of items

Definition at line 2338 of file window.cpp.

References Scrollbar::cap, Scrollbar::count, Scrollbar::pos, and Window::vscroll.

Referenced by ReplaceVehicleWindow::GenerateLists(), VehicleListWindow::OnPaint(), StationViewWindow::OnPaint(), CompanyStationsWindow::OnPaint(), NewGRFAddWindow::OnPaint(), and IndustryDirectoryWindow::OnPaint().

static void StartWindowDrag | ( | Window * | w | ) | `[static]`

Start window dragging.

Parameters:

  | w | Window to start dragging

Definition at line 1546 of file window.cpp.

References BringWindowToFront(), DeleteWindowById(), Window::flags4, Window::left, CursorVars::pos, Window::top, WF_DRAGGING, Point::x, and Point::y.

Referenced by DispatchLeftClickEvent().

static void StartWindowSizing | ( | Window * | w | ) | `[static]`

Start resizing a window.

Parameters:

  | w | Window to start resizing

Definition at line 1562 of file window.cpp.

References BringWindowToFront(), DeleteWindowById(), Window::flags4, CursorVars::pos, Point::x, and Point::y.

Referenced by DispatchLeftClickEvent().

bool VpHandlePlaceSizingDrag | ( |  | ) |

Handle the mouse while dragging for placement/resizing.

Returns:
  Boolean whether search for a handler should continue

Definition at line 2684 of file viewport.cpp.

References _left_button_down, FindWindowById(), HT_LINE, HT_RAIL, Window::OnPlaceDrag(), Window::OnPlaceMouseUp(), VHM_POINT, VHM_RAIL, VHM_RECT, and VPM_SIGNALDIRS.

## Variable Documentation

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

Window* _z_back_window = NULL

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

Definition at line 35 of file window.cpp.

Window* _z_front_window = NULL

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

Definition at line 33 of file window.cpp.

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