Functions

window_func.h File Reference

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

#include "window_type.h"
#include "company_type.h"

Go to the source code of this file.

Functions

WindowFindWindowById (WindowClass cls, WindowNumber number)
 Find a window by its class and window number.
WindowFindWindowByClass (WindowClass cls)
 Find any window by its class.
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.
void ResizeWindow (Window *w, int x, int y, bool clamp_to_screen=true)
 Resize the window.
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.
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.
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).
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.
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 ShowVitalWindows ()
 Show the vital in-game windows.
void ReInitAllWindows ()
 Re-initialize all windows.
void SetWindowWidgetDirty (WindowClass cls, WindowNumber number, byte widget_index)
 Mark a particular widget in a particular window as dirty (in need of repainting).
void SetWindowDirty (WindowClass cls, WindowNumber number)
 Mark 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 DeleteWindowById (WindowClass cls, WindowNumber number, bool force=true)
 Delete a window by its class and window number (if it is open).
void DeleteWindowByClass (WindowClass cls)
 Delete all windows of a given class.

Detailed Description

Window functions not directly related to making/drawing windows.

Definition in file window_func.h.


Function Documentation

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

References Window::owner, WC_AIRCRAFT_LIST, WC_BUY_COMPANY, WC_COMPANY, WC_COMPANY_COLOUR, WC_COMPANY_INFRASTRUCTURE, WC_FINANCES, WC_ROADVEH_LIST, WC_SHIPS_LIST, WC_STATION_LIST, WC_TRAINS_LIST, and 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 2810 of file window.cpp.

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

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

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

References Window::flags, WC_MAIN_TOOLBAR, WC_MAIN_WINDOW, WC_SELECT_GAME, WC_STATUS_BAR, WC_TOOLTIPS, 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 827 of file window.cpp.

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

Referenced by ClientNetworkContentSocketHandler::BeforeDownload(), ClientNetworkGameSocketHandler::ClientError(), CmdCompanyCtrl(), CmdDeleteGroup(), CmdGoalQuestionAnswer(), 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(), ShowCheatWindow(), ShowCustCurrency(), ShowDropDownList(), ShowLandInfo(), ShowMessageHistory(), ShowNetworkContentListWindow(), ShowNetworkLobbyWindow(), ShowNewsMessage(), ShowOnScreenKeyboard(), ShowReplaceGroupVehicleWindow(), ShowSaveLoadDialog(), ShowTerraformToolbar(), ShowTimetableWindow(), ShowVehicleDetailsWindow(), ShowVehicleRefitWindow(), StartWindowDrag(), StartWindowSizing(), AI::Stop(), ToggleRailButton_Remove(), Depot::~Depot(), Station::~Station(), and Town::~Town().

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

References Window::window_class.

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

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

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

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

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

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

Referenced by TooltipsWindow::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 1794 of file window.cpp.

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

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

void InvalidateWindowClassesData ( WindowClass  cls,
int  data,
bool  gui_scope 
)
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 2735 of file window.cpp.

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

Referenced by AcceptEnginePreview(), AddRemoveEngineFromAutoreplaceAndBuildWindows(), AircraftLeaveHangar(), Subsidy::AwardTo(), AIListWindow::ChangeAI(), ChangePopulation(), CheckTrainStayInDepot(), CmdAddSharedVehicleGroup(), CmdAddVehicleGroup(), CmdBuildAirport(), CmdBuildBuoy(), CmdBuildDock(), CmdBuildRailStation(), CmdBuildRailWagon(), CmdBuildRoadStop(), CmdBuildVehicle(), CmdCompanyCtrl(), CmdConvertRail(), CmdCreateGoal(), CmdCreateGroup(), CmdDeleteGroup(), CmdMoveRailVehicle(), CmdPlaceSign(), CmdRefitVehicle(), CmdRemoveAllVehiclesGroup(), CmdRemoveGoal(), CmdRenameGroup(), CmdRenameSign(), CmdRenameStation(), CmdRenameTown(), CmdSellRailWagon(), CmdSetCompanyColour(), CmdSetGroupReplaceProtection(), CmdTownCargoGoal(), CmdTownGrowthRate(), CmdTownSetText(), Company::Company(), Train::ConsistChanged(), CreateSubsidy(), DeleteNewGRFInspectWindow(), DeleteStationIfEmpty(), DeleteSubsidyWith(), DoCreateNewIndustry(), DoCreateTown(), DoScanNewGRFFiles(), DoStartupNewCompany(), StatusBarWindow::DrawWidget(), HandleMouseEvents(), IndustryDailyLoop(), InvalidateAutoreplaceWindow(), InvalidateVehicleOrder(), LinkGraph::Join(), LoadUnloadVehicle(), MoveToNextItem(), NetworkChatWindow::NetworkChatWindow(), NewVehicleAvailable(), NormaliseTrainHead(), GraphLegendWindow::OnClick(), MainWindow::OnInvalidateData(), Town::PostDestructor(), BaseStation::PostDestructor(), Industry::PostDestructor(), Company::PostDestructor(), Vehicle::PreDestructor(), RecomputePrices(), ReloadNewGRFData(), RemoveAirport(), RemoveBuoy(), Vehicle::RemoveFromShared(), AI::Rescan(), ReverseTrainDirection(), SaveFileDone(), SaveFileStart(), SetLocalCompany(), ShowTicker(), Game::StartNew(), AI::StartNew(), AI::Stop(), SubsidyMonthlyLoop(), UpdateNetworkGameWindow(), Waypoint::UpdateVirtCoord(), VehicleEnter_Track(), VehicleEnterDepot(), NetworkClientInfo::~NetworkClientInfo(), NetworkContentDownloadStatusWindow::~NetworkContentDownloadStatusWindow(), and Station::~Station().

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

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

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

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

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

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

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

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

Referenced by RelocateAllWindows(), and v_PositionStatusbar().

void ReInitAllWindows (  ) 
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:
w Window to resize
delta_x Delta x-size of changed window (positive if larger, etc.)
delta_y Delta y-size of changed window
clamp_to_screen Whether to make sure the whole window stays visible

Definition at line 1758 of file window.cpp.

References _cur_resolution, _current_text_dir, NWidgetBase::AssignSizePosition(), Ceil(), 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 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 2635 of file window.cpp.

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

Referenced by ServerNetworkGameSocketHandler::AcceptConnection(), AddNewsItem(), AgeVehicle(), AircraftEventHandler_AtTerminal(), Vehicle::BeginLoading(), ChangeTimetable(), ChangeTownRating(), CheckTrainStayInDepot(), ClickChangeDateCheat(), CmdAddVehicleGroup(), CmdAutofillTimetable(), CmdBuildAirport(), CmdBuildObject(), CmdBuildVehicle(), CmdBuyShareInCompany(), CmdChangeServiceInt(), CmdDoTownAction(), CmdForceTrainProceed(), CmdMoveRailVehicle(), CmdPause(), CmdRefitVehicle(), CmdRenameDepot(), CmdRenameGroup(), CmdReverseTrainDirection(), CmdSellShareInCompany(), CmdSetTimetableStart(), CmdSetVehicleOnTime(), CmdStartStopVehicle(), CompaniesGenStatistics(), CompaniesYearlyLoop(), Train::ConsistChanged(), Vehicle::Crash(), DecreaseVehicleValue(), DeleteLastWagon(), DeleteNewsItem(), DirtyCompanyInfrastructureWindows(), DoStartupNewCompany(), Vehicle::HandleBreakdown(), IConsoleGUIPrint(), IndustryDailyLoop(), IndustryProductionCallback(), InvalidateCompanyWindows(), InvalidateVehicleOrder(), LoadUnloadVehicle(), BuildSignalWindow::OnClick(), NewGRFParametersWindow::OnClick(), GameOptionsWindow::OnDropdownSelect(), Train::OnNewDay(), Ship::OnNewDay(), RoadVehicle::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(), ClientNetworkGameSocketHandler::SendCompanyInformationQuery(), ClientNetworkGameSocketHandler::SendJoin(), SetTrainGroupID(), GRFParameterInfo::SetValue(), TrainController(), TrainEnterStation(), TriggerIndustryProduction(), UpdateCompanyRatingAndValue(), UpdateTownGrowRate(), UpdateTrainGroupID(), UpdateVehicleTimetable(), Town::UpdateVirtCoord(), Station::UpdateVirtCoord(), VehicleEnterDepot(), and NetworkContentDownloadStatusWindow::~NetworkContentDownloadStatusWindow().

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