OpenTTD
Functions
window_func.h File Reference

Window functions not directly related to making/drawing windows. More...

#include "window_type.h"
#include "company_type.h"
#include "core/geometry_type.hpp"

Go to the source code of this file.

Functions

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 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...
 
void ResizeWindow (Window *w, int x, int y, bool clamp_to_screen=true)
 Resize the window. 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...
 
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...
 
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.
 
void SetupColoursAndInitialWindow ()
 Initialise the default colours (remaps and the likes), and load the main windows.
 
void InputLoop ()
 Regular call from the global game loop.
 
void InvalidateWindowData (WindowClass cls, WindowNumber number, int data=0, bool gui_scope=false)
 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=0, bool gui_scope=false)
 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 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 ShowVitalWindows ()
 Show the vital in-game windows.
 
void ReInitAllWindows ()
 Re-initialize all windows. 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 SetWindowDirty (WindowClass cls, WindowNumber number)
 Mark 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 DeleteWindowById (WindowClass cls, WindowNumber number, bool force=true)
 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...
 
bool EditBoxInGlobalFocus ()
 Check if an edit box is in global focus. More...
 
Point GetCaretPosition ()
 

Detailed Description

Window functions not directly related to making/drawing windows.

Definition in file window_func.h.

Function Documentation

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

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

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

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

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

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

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

◆ ReInitAllWindows()

void ReInitAllWindows ( )

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

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