Defines | 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 "genworld.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 "newgrf_debug.h"
#include "hotkeys.h"
#include "toolbar_gui.h"
#include "statusbar_gui.h"

Go to the source code of this file.

Defines

#define scrollspeed   3

Enumerations

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

void SetFocusedWindow (Window *w)
 Set the window that has the focus.
static bool EditBoxInGlobalFocus ()
 Check if an edit box is in global focus.
static void StartWindowDrag (Window *w)
 Start window dragging.
static void StartWindowSizing (Window *w, bool to_left)
 Start resizing a window.
static void DispatchLeftClickEvent (Window *w, int x, int y, int click_count)
 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 DispatchHoverEvent (Window *w, int x, int y)
 Dispatch hover of the mouse over a window.
static void DispatchMouseWheelEvent (Window *w, NWidgetCore *nwid, 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.
static WindowFindChildWindow (const Window *w, WindowClass wc)
 Find the Window whose parent pointer points to this window.
WindowFindWindowById (WindowClass cls, WindowNumber number)
 Find a window by its class and window number.
WindowFindWindowByClass (WindowClass cls)
 Find any window by its class.
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.
WindowBringWindowToFrontById (WindowClass cls, WindowNumber number)
 Find a window and make it the top-window on the screen.
static bool IsVitalWindow (const Window *w)
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.
Point GetToolbarAlignedWindowPosition (int window_width)
 Computer the position of the top-left corner of a window to be opened right under the toolbar.
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.
WindowFindWindowFromPt (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 ()
static void HandlePlacePresize ()
static EventState HandleMouseDragDrop ()
 Handle dragging and dropping in mouse dragging mode (WSM_DRAGDROP).
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.
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.
void ResizeWindow (Window *w, int delta_x, int delta_y)
 Resize the window.
int GetMainViewTop ()
 Return the top of the main view available for general use.
int GetMainViewBottom ()
 Return the bottom of the main view available for general use.
static EventState HandleWindowDragging ()
 Handle dragging/resizing of a window.
static EventState HandleScrollbarScrolling ()
 handle scrollbar scrolling with the mouse.
static EventState HandleViewportScroll ()
 Handle viewport scrolling with the mouse.
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).
EventState VpHandlePlaceSizingDrag ()
 Handle the mouse while dragging for placement/resizing.
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).
void SetWindowWidgetDirty (WindowClass cls, WindowNumber number, byte widget_index)
 Mark a particular widget in a particular window as dirty (in need of repainting).
void SetWindowClassesDirty (WindowClass cls)
 Mark all windows of a particular class as dirty (in need of repainting).
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).
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.
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.
void ReInitAllWindows ()
 Re-initialize all windows.
static int PositionWindow (Window *w, WindowClass clss, int setting)
 (Re)position a window at the screen.
int PositionMainToolbar (Window *w)
 (Re)position main toolbar window at the screen.
int PositionStatusbar (Window *w)
 (Re)position statusbar window at the screen.
int PositionNewsMessage (Window *w)
 (Re)position news message window at the screen.
int PositionNetworkChatWindow (Window *w)
 (Re)position network chat window at the screen.
void ChangeVehicleViewports (VehicleID from_index, VehicleID to_index)
 Switches viewports following vehicles, which get autoreplaced.
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.
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.
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 = 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 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.
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.

MAX_OFFSET_HOVER 

Maximum mouse movement before stopping a hover event.

Definition at line 2094 of file window.cpp.

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


Function Documentation

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 861 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 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:
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 823 of file window.cpp.

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

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

void ChangeVehicleViewports ( VehicleID  from_index,
VehicleID  to_index 
)

Switches viewports following vehicles, which get autoreplaced.

Parameters:
from_index the old vehicle ID
to_index the new vehicle ID

Definition at line 2728 of file window.cpp.

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

Referenced by CopyHeadSpecificThings().

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

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

Referenced by ChangeOwnershipOfCompanyItems().

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

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

Referenced by GenerateWorld(), and MainWindow::OnKeyPress().

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

References DeleteWindowById(), and Window::owner.

Referenced by CmdCompanyCtrl(), and Company::~Company().

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

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

Referenced by DeleteAllNonVitalWindows(), and MainWindow::OnKeyPress().

void DeleteWindowByClass ( WindowClass  cls  ) 
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 727 of file window.cpp.

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

Referenced by ClientNetworkContentSocketHandler::BeforeDownload(), CleanupGeneration(), ClientNetworkGameSocketHandler::ClientError(), CmdCompanyCtrl(), CmdDeleteGroup(), CmdMoveRailVehicle(), DeleteCompanyWindows(), DeleteNewGRFInspectWindow(), DispatchLeftClickEvent(), EnginesDailyLoop(), GuiShowTooltips(), HideVitalWindows(), IConsoleSwitch(), MoveToNextItem(), NetworkDisconnect(), SelectStationWindow< T >::OnClick(), BuildRoadStationWindow::OnClick(), BuildRoadToolbarWindow::OnClick(), BuildRailStationWindow::OnClick(), ScenarioEditorLandscapeGenerationWindow::OnPlaceObjectAbort(), TerraformToolbarWindow::OnPlaceObjectAbort(), BuildRoadToolbarWindow::OnPlaceObjectAbort(), BuildRailToolbarWindow::OnPlaceObjectAbort(), BuildDocksToolbarWindow::OnPlaceObjectAbort(), BuildAirToolbarWindow::OnPlaceObjectAbort(), Vehicle::PreDestructor(), ClientNetworkGameSocketHandler::Receive_SERVER_BANNED(), ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(), ClientNetworkGameSocketHandler::Receive_SERVER_FULL(), ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(), RemoveAirport(), Vehicle::RemoveFromShared(), ShowAIConfigWindow(), ShowCheatWindow(), ShowCustCurrency(), ShowDropDownList(), ShowErrorMessage(), ShowGameDifficulty(), ShowGameOptions(), ShowGameSettings(), ShowLandInfo(), ShowMessageHistory(), ShowMessageOptions(), ShowNetworkContentListWindow(), ShowNetworkLobbyWindow(), ShowNewsMessage(), ShowOnScreenKeyboard(), ShowQueryString(), ShowRenameSignWindow(), ShowReplaceGroupVehicleWindow(), ShowSaveLoadDialog(), ShowTerraformToolbar(), ShowTimetableWindow(), ShowVehicleDetailsWindow(), ShowVehicleRefitWindow(), StartWindowDrag(), StartWindowSizing(), AI::Stop(), ToggleRailButton_Remove(), Depot::~Depot(), Station::~Station(), and Town::~Town().

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

Dispatch hover of the mouse over a window.

Parameters:
w Window to dispatch event in.
x X coordinate of the click.
y Y coordinate of the click.

Definition at line 415 of file window.cpp.

References NWidgetBase::GetWidgetFromPos(), GuiShowTooltips(), NWidgetCore::index, Window::nested_root, Window::OnHover(), and NWidgetCore::tool_tip.

static void DispatchLeftClickEvent ( Window w,
int  x,
int  y,
int  click_count 
) [static]
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:
w Window
nwid the widget where the scrollwheel was used
wheel scroll up or down

Definition at line 442 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.

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

References _settings_client, NWidgetBase::GetWidgetFromPos(), ClientSettings::gui, GuiShowTooltips(), GUISettings::hover_delay, NWidgetCore::index, Window::nested_root, Window::OnRightClick(), and NWidgetCore::tool_tip.

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

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

static bool EditBoxInGlobalFocus (  )  [static]

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

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

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

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:
w The window to check.
nx The proposed new x-location of the window.
ny The proposed new y-location of the window.

Definition at line 1536 of file window.cpp.

References Clamp(), NWidgetBase::current_x, NWidgetBase::current_y, FindWindowById(), NWidgetBase::GetWidgetOfType(), ViewPort::left, Window::left, Window::nested_root, PHD_DOWN, PHD_UP, NWidgetBase::pos_x, NWidgetBase::pos_y, PreventHiding(), Window::top, ViewPort::top, Window::viewport, and WWT_CAPTION.

Referenced by HandleWindowDragging(), RelocateAllWindows(), and ResizeWindow().

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

Find the Window whose parent pointer points to this window.

Parameters:
w parent Window to find child of
wc Window 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 635 of file window.cpp.

References Window::parent, and Window::window_class.

Referenced by Window::DeleteChildWindows().

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:
cls Window class
Returns:
Pointer to the found window, or NULL if not available

Definition at line 711 of file window.cpp.

References Window::window_class.

Referenced by GetAutoPlacePosition(), Window::InitializeData(), IsGoodAutoPlace1(), and IndustryCargoesWindow::OnClick().

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

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

Referenced by BringWindowToFrontById(), ChangeVehicleWindow(), DeleteDepotHighlightOfVehicle(), DeleteRenameSignWindow(), DeleteWindowById(), DoCommandPInternal(), SmallMapWindow::DrawMapIndicators(), StatusBarWindow::DrawWidget(), EnsureVisibleCaption(), FindVehicleGroupWindow(), Window::FindWindowPlacementAndResize(), GenerateWorld(), GenericPlaceSignals(), TileHighlightData::GetCallbackWnd(), GetLobbyCompanyInfo(), GetMainViewBottom(), GetMainViewTop(), GetToolbarAlignedWindowPosition(), HandleAutoSignalPlacement(), HandleKeypress(), HandleViewportScroll(), Window::InitializeData(), IsNewsTickerShown(), LinkGraph::Join(), LocalGetWindowPlacement(), MakeZoomedInScreenshot(), NetworkContentDownloadStatusWindow::NetworkContentDownloadStatusWindow(), WatchCompany::OnClick(), ExtraViewportWindow::OnClick(), VehicleViewWindow::OnClick(), SmallMapWindow::OnClick(), ErrmsgWindow::OnInitialPosition(), ScenarioEditorToolbarWindow::OnInvalidateData(), MainToolbarWindow::OnInvalidateData(), NetworkContentListWindow::OnInvalidateData(), DropdownWindow::OnMouseLoop(), BuildRailToolbarWindow::OnPlaceDrag(), PositionWindow(), ReadyForNextItem(), ReinitGuiAfterToggleElrail(), RelocateAllWindows(), ResetSignalVariant(), ScrollMainWindowTo(), SetDefaultRailGui(), ShowExtraViewPortWindow(), ShowLastNewsMessage(), ShowQuery(), StationJoinerNeeded(), UpdateOSKOriginalText(), and WatchCompany::WatchCompany().

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

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

Referenced by HandleAutoscroll(), HandleMouseOver(), and HandleViewportScroll().

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

References FindWindowByClass(), Window::height, IsGoodAutoPlace1(), IsGoodAutoPlace2(), Window::left, Window::top, Window::width, and Window::window_class.

Referenced by LocalGetWindowPlacement().

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

References FindWindowById(), and Window::top.

Referenced by TooltipsWindow::OnInitialPosition(), ErrmsgWindow::OnInitialPosition(), BuildBridgeWindow::OnInitialPosition(), and ShowDropDownList().

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

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

Referenced by TooltipsWindow::OnInitialPosition(), ErrmsgWindow::OnInitialPosition(), BuildBridgeWindow::OnInitialPosition(), and ShowDropDownList().

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_width the width of the window to get the position for
Returns:
Coordinate of the top-left corner of the new window.

Definition at line 1196 of file window.cpp.

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

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

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

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

static EventState HandleMouseDragDrop (  )  [static]

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

Returns:
State of handling the event.

Definition at line 1433 of file window.cpp.

References _left_button_down, _special_mouse_mode, CursorVars::delta, TileHighlightData::GetCallbackWnd(), GetWidgetFromPos(), Window::left, Window::OnDragDrop(), Window::OnMouseDrag(), Window::top, and WSM_DRAGDROP.

static void HandleMouseOver (  )  [static]

Report position of the mouse to the underlying window.

Definition at line 1457 of file window.cpp.

References FindWindowFromPt(), NWidgetBase::GetWidgetFromPos(), NWidgetCore::index, Window::left, Window::nested_root, Window::OnMouseOver(), and Window::top.

static EventState HandleScrollbarScrolling (  )  [static]
static EventState HandleViewportScroll (  )  [static]
static EventState HandleWindowDragging (  )  [static]
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:
cls Window class
data The data to invalidate with
gui_scope Whether the call is done from GUI scope

Definition at line 2529 of file window.cpp.

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

Referenced by AddRemoveEngineFromAutoreplaceAndBuildWindows(), CcBuildWagon(), ClickChangeDateCheat(), ClickSetProdCheat(), CmdBuildVehicle(), CmdCloneOrder(), CmdCompanyCtrl(), CmdMoveOrder(), CmdMoveRailVehicle(), CmdPause(), CmdRefitVehicle(), CmdRenameCompany(), CmdRenameVehicle(), CmdSellRailWagon(), Company::Company(), Vehicle::Crash(), DecloneOrder(), DeleteOrder(), GenerateDesertArea(), InsertOrder(), InvalidateCompanyInfrastructureWindow(), InvalidateNewGRFChangeWindows(), NetworkAfterNewGRFScan(), IndustryCargoesWindow::NotifySmallmap(), SmallMapWindow::OnClick(), OnNewYear(), Company::PostDestructor(), Vehicle::PreDestructor(), ReadLanguagePack(), ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(), ClientNetworkGameSocketHandler::Receive_SERVER_COMPANY_INFO(), ClientNetworkGameSocketHandler::Receive_SERVER_JOIN(), ClientNetworkGameSocketHandler::Receive_SERVER_MOVE(), ClientNetworkGameSocketHandler::Receive_SERVER_QUIT(), ReloadNewGRFData(), RoadVehAccelerationModelChanged(), SetNewLandscapeType(), StartupEngines(), and NetworkContentDownloadStatusWindow::~NetworkContentDownloadStatusWindow().

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:
cls Window class
number Window number within the class
data The data to invalidate with
gui_scope Whether the call is done from GUI scope

Definition at line 2511 of file window.cpp.

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

Referenced by AcceptEnginePreview(), AddRemoveEngineFromAutoreplaceAndBuildWindows(), Subsidy::AwardTo(), ChangePopulation(), CmdAddSharedVehicleGroup(), CmdAddVehicleGroup(), CmdBuildAirport(), CmdBuildBuoy(), CmdBuildDock(), CmdBuildRailStation(), CmdBuildRailWagon(), CmdBuildRoadStop(), CmdBuildVehicle(), CmdCompanyCtrl(), CmdConvertRail(), CmdCreateGroup(), CmdDeleteGroup(), CmdInsertSignalInstruction(), CmdModifySignalInstruction(), CmdMoveRailVehicle(), CmdPlaceSign(), CmdRefitVehicle(), CmdRemoveAllVehiclesGroup(), CmdRemoveSignalInstruction(), CmdRenameGroup(), CmdRenameSign(), CmdRenameStation(), CmdRenameTown(), CmdSellRailWagon(), CmdSetCompanyColour(), CmdSetGroupReplaceProtection(), CmdSetSignalSpeedLimit(), Company::Company(), Train::ConsistChanged(), DeleteNewGRFInspectWindow(), DeleteStationIfEmpty(), DoCreateNewIndustry(), DoCreateTown(), DoStartupNewCompany(), StatusBarWindow::DrawWidget(), HandleMouseEvents(), IndustryDailyLoop(), InvalidateAutoreplaceWindow(), InvalidateVehicleOrder(), LoadUnloadVehicle(), AILog::Log(), MoveToNextItem(), NetworkChatWindow::NetworkChatWindow(), NewVehicleAvailable(), NormaliseTrainHead(), GraphLegendWindow::OnClick(), MainWindow::OnInvalidateData(), Town::PostDestructor(), BaseStation::PostDestructor(), Industry::PostDestructor(), Company::PostDestructor(), Vehicle::PreDestructor(), RecomputePrices(), ReloadNewGRFData(), RemoveBuoy(), Vehicle::RemoveFromShared(), SaveFileDone(), SaveFileStart(), SetLocalCompany(), ShowTicker(), AI::StartNew(), AI::Stop(), UpdateNetworkGameWindow(), Waypoint::UpdateVirtCoord(), VehicleEnter_Track(), VehicleEnterDepot(), NetworkClientInfo::~NetworkClientInfo(), NetworkContentDownloadStatusWindow::~NetworkContentDownloadStatusWindow(), and Station::~Station().

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

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

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

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

Referenced by GetAutoPlacePosition().

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:
*desc The pointer to the WindowDesc to be created.
sm_width Smallest width of the window.
sm_height Smallest height of the window.
window_number The window number of the new window.
Returns:
Coordinate of the top-left corner of the new window.

Definition at line 1221 of file window.cpp.

References WindowDesc::default_height, WindowDesc::default_pos, WindowDesc::default_width, FindWindowById(), GetAutoPlacePosition(), GetToolbarAlignedWindowPosition(), Window::height, Window::left, max(), WindowDesc::parent_cls, Window::top, WDP_ALIGN_TOOLBAR, WDP_AUTO, WDP_CENTER, and WDP_MANUAL.

Referenced by Window::OnInitialPosition().

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

References BringWindowToFront(), Window::desc_flags, Window::flags4, FOR_ALL_WINDOWS_FROM_BACK_FROM, Window::height, Window::IsShaded(), Window::left, Window::parent, Window::SetDirty(), Window::top, Window::unshaded_size, 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 2683 of file window.cpp.

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

Referenced by RelocateAllWindows(), and v_PositionMainToolbar().

int PositionNetworkChatWindow ( Window w  ) 

(Re)position network chat window at the screen.

Parameters:
w Window structure of the network chat window, may also be NULL.
Returns:
X coordinate of left edge of the repositioned network chat winodw.

Definition at line 2716 of file window.cpp.

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

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

int PositionNewsMessage ( Window w  ) 

(Re)position news message window at the screen.

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

Definition at line 2705 of file window.cpp.

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

Referenced by RelocateAllWindows(), and v_PositionStatusbar().

int PositionStatusbar ( Window w  ) 

(Re)position statusbar window at the screen.

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

Definition at line 2694 of file window.cpp.

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

Referenced by RelocateAllWindows(), and v_PositionStatusbar().

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

(Re)position a window at the screen.

Parameters:
w Window structure of the window, may also be NULL.
clss The class of the window to position.
setting The actual setting used for the window's position.
Returns:
X coordinate of left edge of the repositioned window.

Definition at line 2660 of file window.cpp.

References FindWindowById(), Window::height, ViewPort::left, Window::left, SetDirtyBlocks(), Window::top, Window::viewport, Window::width, and Window::window_class.

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

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:
nx Base horizontal coordinate of the rectangle.
ny Base vertical coordinate of the rectangle.
rect Rectangle that must stay visible for MIN_VISIBLE_TITLE_BAR pixels (horizontally, vertically, or both)
v Window lying in front of the rectangle.
px Previous horizontal base coordinate.
dir If no room horizontally, move the rectangle to the indicated position.

Definition at line 1498 of file window.cpp.

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

Referenced by EnsureVisibleCaption().

void ReInitAllWindows (  ) 
void RelocateAllWindows ( int  neww,
int  newh 
)
void ResizeWindow ( Window w,
int  delta_x,
int  delta_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
delta_x Delta x-size of changed window (positive if larger, etc.)
delta_y Delta y-size of changed window

Definition at line 1574 of file window.cpp.

References _current_text_dir, NWidgetBase::AssignSizePosition(), NWidgetBase::current_x, NWidgetBase::current_y, EnsureVisibleCaption(), Window::height, Window::left, max(), Window::nested_root, Window::OnResize(), NWidgetBase::resize_x, NWidgetBase::resize_y, Window::SetDirty(), NWidgetBase::smallest_x, NWidgetBase::smallest_y, ST_RESIZE, TD_RTL, Window::top, and Window::width.

Referenced by NetworkClientListWindow::CheckClientListHeight(), TownAuthorityWindow::DrawRatings(), Window::FindWindowPlacementAndResize(), HandleWindowDragging(), BuildRoadStationWindow::OnPaint(), BuildDocksStationWindow::OnPaint(), BuildAirportWindow::OnPaint(), Window::ReInit(), 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 124 of file window.cpp.

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

Referenced by DispatchLeftClickEvent(), Window::InitializeData(), and OskWindow::OnClick().

void SetWindowClassesDirty ( WindowClass  cls  ) 
void SetWindowDirty ( 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 2449 of file window.cpp.

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

Referenced by ServerNetworkGameSocketHandler::AcceptConnection(), AddNewsItem(), AgeVehicle(), AircraftEventHandler_AtTerminal(), Vehicle::BeginLoading(), AIListWindow::ChangeAI(), ChangePopulation(), ChangeTimetable(), ChangeTownRating(), CheckVehicleBreakdown(), Vehicle::ClearSeparation(), ClickChangeDateCheat(), CmdAddVehicleGroup(), CmdAutofillTimetable(), CmdAutomateTimetable(), CmdBuildAirport(), CmdBuildObject(), CmdBuildVehicle(), CmdBuyShareInCompany(), CmdChangeCompanySetting(), CmdChangeServiceInt(), CmdChangeSetting(), CmdDoTownAction(), CmdForceTrainProceed(), CmdPause(), CmdRefitVehicle(), CmdRenameDepot(), CmdReverseTrainDirection(), CmdSellShareInCompany(), CmdSetTimetableStart(), CmdSetVehicleOnTime(), CmdStartStopVehicle(), CompaniesGenStatistics(), CompaniesYearlyLoop(), Train::ConsistChanged(), Vehicle::Crash(), DecreaseVehicleValue(), DeleteLastWagon(), DeleteNewsItem(), DirtyCompanyInfrastructureWindows(), DoStartupNewCompany(), Vehicle::HandleBreakdown(), HandleSharingCompanyDeletion(), IConsoleGUIPrint(), IndustryDailyLoop(), IndustryProductionCallback(), InvalidateCompanyWindows(), InvalidateVehicleOrder(), LoadUnloadVehicle(), BuildSignalWindow::OnClick(), GameOptionsWindow::OnDropdownSelect(), Train::OnNewDay(), Ship::OnNewDay(), RoadVehicle::OnNewDay(), OnNewDay(), Aircraft::OnNewDay(), OnNewMonth(), GroundVehicle< T, Type >::PowerChanged(), Vehicle::PreDestructor(), ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(), ClientNetworkGameSocketHandler::Receive_SERVER_COMPANY_INFO(), ClientNetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT(), ClientNetworkGameSocketHandler::Receive_SERVER_JOIN(), ClientNetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN(), ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DATA(), ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(), ClientNetworkGameSocketHandler::Receive_SERVER_MAP_SIZE(), ClientNetworkGameSocketHandler::Receive_SERVER_QUIT(), ClientNetworkGameSocketHandler::Receive_SERVER_WAIT(), RemoveAirport(), RemoveOrderFromAllVehicles(), CopyPaste::SaveLoadTemplate(), ClientNetworkGameSocketHandler::SendCompanyInformationQuery(), ClientNetworkGameSocketHandler::SendJoin(), SetSettingValue(), SetTrainGroupID(), TrainEnterStation(), TriggerIndustryProduction(), UpdateCompanyRatingAndValue(), UpdateTownGrowRate(), UpdateTrainGroupID(), UpdateVehicleTimetable(), Town::UpdateVirtCoord(), Station::UpdateVirtCoord(), VehicleEnterDepot(), and NetworkContentDownloadStatusWindow::~NetworkContentDownloadStatusWindow().

void SetWindowWidgetDirty ( WindowClass  cls,
WindowNumber  number,
byte  widget_index 
)
static void StartWindowDrag ( Window w  )  [static]

Start window dragging.

Parameters:
w Window to start dragging

Definition at line 1798 of file window.cpp.

References BringWindowToFront(), DeleteWindowById(), Window::flags4, Window::left, and Window::top.

Referenced by DispatchLeftClickEvent().

static void StartWindowSizing ( Window w,
bool  to_left 
) [static]

Start resizing a window.

Parameters:
w Window to start resizing.
to_left Whether to drag towards the left or not

Definition at line 1816 of file window.cpp.

References BringWindowToFront(), DeleteWindowById(), Window::flags4, and WF_SIZING_LEFT.

Referenced by DispatchLeftClickEvent().

EventState VpHandlePlaceSizingDrag (  ) 

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

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

Definition at line 43 of file window.cpp.

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

Definition at line 41 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 2127 of file window.cpp.