OpenTTD Source 20251019-master-g9f7f314f81
Rect Struct Reference

Specification of a rectangle with absolute coordinates of all edges. More...

#include <geometry_type.hpp>

Inheritance diagram for Rect:
StationRect

Public Member Functions

int Width () const
 Get width of Rect.
 
int Height () const
 Get height of Rect.
 
Rect Shrink (int s) const
 Copy and shrink Rect by s pixels.
 
Rect Shrink (int h, int v) const
 Copy and shrink Rect by h horizontal and v vertical pixels.
 
Rect Shrink (int left, int top, int right, int bottom) const
 Copy and shrink Rect by pixels.
 
Rect Shrink (const RectPadding &other) const
 Copy and shrink Rect by a RectPadding.
 
Rect Shrink (const RectPadding &horz, const RectPadding &vert) const
 Copy and shrink Rect by a different horizontal and vertical RectPadding.
 
Rect Expand (int s) const
 Copy and expand Rect by s pixels.
 
Rect Expand (const RectPadding &other) const
 Copy and expand Rect by a RectPadding.
 
Rect Translate (int x, int y) const
 Copy and translate Rect by x,y pixels.
 
Rect WithWidth (int width, bool end) const
 Copy Rect and set its width.
 
Rect Indent (int indent, bool end) const
 Copy Rect and indent it from its position.
 
Rect WithHeight (int height, bool end=false) const
 Copy Rect and set its height.
 
bool Contains (const Point &pt) const
 Test if a point falls inside this Rect.
 
Rect CentreToHeight (int height) const
 Centre a vertical dimension within this Rect.
 
Rect WithX (int new_left, int new_right) const
 Create a new Rect, replacing the left and right coordiates.
 
Rect WithY (int new_top, int new_bottom) const
 Create a new Rect, replacing the top and bottom coordiates.
 
Rect WithX (const Rect &other) const
 Create a new Rect, replacing the left and right coordiates.
 
Rect WithY (const Rect &other) const
 Create a new Rect, replacing the top and bottom coordiates.
 

Data Fields

int left = 0
 
int top = 0
 
int right = 0
 
int bottom = 0
 

Detailed Description

Specification of a rectangle with absolute coordinates of all edges.

Definition at line 101 of file geometry_type.hpp.

Member Function Documentation

◆ CentreToHeight()

Rect Rect::CentreToHeight ( int  height) const
inline

Centre a vertical dimension within this Rect.

Parameters
heightThe vertical dimension.
Returns
the new resized Rect.

Definition at line 260 of file geometry_type.hpp.

References CentreBounds().

Referenced by CompanyButtonLine::Draw(), ClientButtonLine::Draw(), DrawButtonDropdown(), ButtonLine::DrawButtons(), VehicleGroupWindow::DrawGroupInfo(), and SelectCompanyManagerFaceWindow::DrawWidget().

◆ Contains()

bool Rect::Contains ( const Point pt) const
inline

Test if a point falls inside this Rect.

Parameters
ptthe point to test.
Returns
true iff the point falls inside the Rect.

Definition at line 249 of file geometry_type.hpp.

References Coord2D< T >::x, and Coord2D< T >::y.

Referenced by ButtonLine::GetButton(), ClientButtonLine::GetTooltip(), VehicleGroupWindow::OnClick(), and IndustryViewWindow::OnClick().

◆ Expand() [1/2]

Rect Rect::Expand ( const RectPadding other) const
inline

Copy and expand Rect by a RectPadding.

Parameters
otherRectPadding to add to each side of Rect.
Returns
the new larger Rect.

Definition at line 189 of file geometry_type.hpp.

◆ Expand() [2/2]

Rect Rect::Expand ( int  s) const
inline

Copy and expand Rect by s pixels.

Parameters
snumber of pixels to add to each side of Rect.
Returns
the new larger Rect.

Definition at line 179 of file geometry_type.hpp.

References Shrink().

Referenced by DrawAircraftImage(), DrawFrame(), DrawRoadVehImage(), DrawShipImage(), DrawTrainImage(), SpriteAlignerWindow::DrawWidget(), RefitWindow::DrawWidget(), and Window::DrawWidgets().

◆ Height()

◆ Indent()

Rect Rect::Indent ( int  indent,
bool  end 
) const
inline

Copy Rect and indent it from its position.

Parameters
indentoffset in pixels for new Rect.
endif set, set indent at end of Rect, i.e. on right.
Returns
the new resized Rect.

Definition at line 224 of file geometry_type.hpp.

References WithX().

Referenced by CompanyButtonLine::Draw(), ClientButtonLine::Draw(), DrawButtonDropdown(), ButtonLine::DrawButtons(), StationViewWindow::DrawCargoRatings(), DrawCategory(), DrawEngineList(), StationViewWindow::DrawEntries(), VehicleGroupWindow::DrawGroupInfo(), DrawImageTextButtons(), IndustryViewWindow::DrawInfo(), GoalListWindow::DrawListColumn(), TownAuthorityWindow::DrawRatings(), DrawTrainDetails(), DepotWindow::DrawVehicleInDepot(), BaseVehicleListWindow::DrawVehicleListItems(), DrawVehicleRefitWindow(), BuildBridgeWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), SelectCompanyManagerFaceWindow::DrawWidget(), CompanyInfrastructureWindow::DrawWidget(), DepotWindow::DrawWidget(), GSConfigWindow::DrawWidget(), GraphLegendWindow::DrawWidget(), BaseCargoGraphWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), PerformanceLeagueWindow::DrawWidget(), ScriptLeagueWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), ScriptSettingsWindow::DrawWidget(), SignListWindow::DrawWidget(), SmallMapWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), TownViewWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), QueryString::GetBoundingRect(), ButtonLine::GetButton(), QueryString::GetCaretPosition(), QueryString::GetCharAtPosition(), VehicleGroupWindow::OnClick(), and IndustryViewWindow::OnClick().

◆ Shrink() [1/5]

Rect Rect::Shrink ( const RectPadding horz,
const RectPadding vert 
) const
inline

Copy and shrink Rect by a different horizontal and vertical RectPadding.

Parameters
horzRectPadding to remove from left and right of Rect.
vertRectPadding to remove from top and bottom of Rect.
Returns
the new smaller Rect.

Definition at line 169 of file geometry_type.hpp.

◆ Shrink() [2/5]

Rect Rect::Shrink ( const RectPadding other) const
inline

Copy and shrink Rect by a RectPadding.

Parameters
otherRectPadding to remove from each side of Rect.
Returns
the new smaller Rect.

Definition at line 158 of file geometry_type.hpp.

◆ Shrink() [3/5]

Rect Rect::Shrink ( int  h,
int  v 
) const
inline

Copy and shrink Rect by h horizontal and v vertical pixels.

Parameters
hnumber of pixels to remove from left and right sides.
vnumber of pixels to remove from top and bottom sides.
Returns
the new smaller Rect.

Definition at line 135 of file geometry_type.hpp.

◆ Shrink() [4/5]

Rect Rect::Shrink ( int  left,
int  top,
int  right,
int  bottom 
) const
inline

Copy and shrink Rect by pixels.

Parameters
leftnumber of pixels to remove from left side.
topnumber of pixels to remove from top side.
rightnumber of pixels to remove from right side.
bottomnumber of pixels to remove from bottom side.
Returns
the new smaller Rect.

Definition at line 148 of file geometry_type.hpp.

◆ Shrink() [5/5]

Rect Rect::Shrink ( int  s) const
inline

Copy and shrink Rect by s pixels.

Parameters
snumber of pixels to remove from each side of Rect.
Returns
the new smaller Rect.

Definition at line 124 of file geometry_type.hpp.

Referenced by NWidgetBackground::Draw(), NWidgetScrollbar::Draw(), NWidgetLeaf::Draw(), StationViewWindow::DrawAcceptedCargo(), TownAuthorityWindow::DrawActions(), TimetableWindow::DrawArrivalDeparturePanel(), DrawArrowButtons(), DrawBoolButton(), ButtonLine::DrawButtons(), DrawCaption(), StationViewWindow::DrawCargoRatings(), NetworkContentListWindow::DrawDetails(), DrawDropDownButton(), DrawEngineList(), DrawFrame(), DrawFrameRect(), VehicleGroupWindow::DrawGroupInfo(), DrawHorizontalScrollbar(), DrawImageTextButtons(), IndustryViewWindow::DrawInfo(), DrawInset(), GoalListWindow::DrawListColumn(), NetworkContentListWindow::DrawMatrix(), TownAuthorityWindow::DrawRatings(), DrawResizeBox(), NetworkGameWindow::DrawServerLine(), BuildSignalWindow::DrawSignalSprite(), NewGRFInspectWindow::DrawString(), TimetableWindow::DrawSummaryPanel(), TimetableWindow::DrawTimetablePanel(), DrawUpDownButtons(), NewGRFInspectWindow::DrawVehicleChainWidget(), DepotWindow::DrawVehicleInDepot(), BaseVehicleListWindow::DrawVehicleListItems(), DrawVehicleRefitWindow(), DrawVerticalScrollbar(), AIConfigWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), ReplaceVehicleWindow::DrawWidget(), BootstrapErrorWindow::DrawWidget(), BootstrapAskForDownloadWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), SelectCompanyManagerFaceWindow::DrawWidget(), CompanyInfrastructureWindow::DrawWidget(), DepotWindow::DrawWidget(), BuildDocksDepotWindow::DrawWidget(), DropdownWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), GSConfigWindow::DrawWidget(), GenerateProgressWindow::DrawWidget(), GraphLegendWindow::DrawWidget(), BaseGraphWindow::DrawWidget(), BaseCargoGraphWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), IndustryCargoesWindow::DrawWidget(), PerformanceLeagueWindow::DrawWidget(), ScriptLeagueWindow::DrawWidget(), LinkGraphLegendWindow::DrawWidget(), LandInfoWindow::DrawWidget(), TooltipsWindow::DrawWidget(), MusicTrackSelectionWindow::DrawWidget(), MusicWindow::DrawWidget(), BaseNetworkContentDownloadStatusWindow::DrawWidget(), NetworkClientListWindow::DrawWidget(), NetworkJoinStatusWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), NewGRFWindow::DrawWidget(), SavePresetWindow::DrawWidget(), ScanProgressWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), OrdersWindow::DrawWidget(), PickerWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), BuildRailDepotWindow::DrawWidget(), BuildRoadDepotWindow::DrawWidget(), BuildRoadStationWindow::DrawWidget(), ScriptListWindow::DrawWidget(), ScriptSettingsWindow::DrawWidget(), GameOptionsWindow::DrawWidget(), SignListWindow::DrawWidget(), SmallMapWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), SelectStationWindow< T >::DrawWidget(), StatusBarWindow::DrawWidget(), StoryBookWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), TextfileWindow::DrawWidget(), TownAuthorityWindow::DrawWidget(), TownViewWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), TransparenciesWindow::DrawWidget(), RefitWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), VehicleViewWindow::DrawWidget(), ScriptDebugWindow::DrawWidgetLog(), Window::DrawWidgets(), Expand(), QueryString::GetBoundingRect(), QueryString::GetCaretPosition(), QueryString::GetCharAtPosition(), DropdownWindow::GetDropDownItem(), HighlightDragPosition(), ReplaceVehicleWindow::OnClick(), BuildVehicleWindow::OnClick(), SelectCompanyManagerFaceWindow::OnClick(), GSConfigWindow::OnClick(), VehicleGroupWindow::OnClick(), IndustryViewWindow::OnClick(), NetworkClientListWindow::OnClick(), NewGRFParametersWindow::OnClick(), ScriptSettingsWindow::OnClick(), ReplaceVehicleWindow::OnPaint(), BuildVehicleWindow::OnPaint(), GameOptionsWindow::OnPaint(), StationViewWindow::OnPaint(), and NetworkClientListWindow::OnTooltip().

◆ Translate()

◆ Width()

◆ WithHeight()

◆ WithWidth()

Rect Rect::WithWidth ( int  width,
bool  end 
) const
inline

Copy Rect and set its width.

Parameters
widthwidth in pixels for new Rect.
endif set, set width at end of Rect, i.e. on right.
Returns
the new resized Rect.

Definition at line 211 of file geometry_type.hpp.

References WithX().

Referenced by CompanyButtonLine::Draw(), ClientButtonLine::Draw(), DrawBoolButton(), DrawButtonDropdown(), ButtonLine::DrawButtons(), DrawEngineList(), StationViewWindow::DrawEntries(), VehicleGroupWindow::DrawGroupInfo(), DrawHorizontalScrollbar(), DrawImageTextButtons(), IndustryViewWindow::DrawInfo(), GoalListWindow::DrawListColumn(), TownAuthorityWindow::DrawRatings(), NetworkGameWindow::DrawServerLine(), Window::DrawSortButtonState(), DrawUpDownButtons(), DepotWindow::DrawVehicleInDepot(), BuildBridgeWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), SelectCompanyManagerFaceWindow::DrawWidget(), CompanyInfrastructureWindow::DrawWidget(), DepotWindow::DrawWidget(), GSConfigWindow::DrawWidget(), BaseCargoGraphWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), PerformanceLeagueWindow::DrawWidget(), ScriptLeagueWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), ScriptSettingsWindow::DrawWidget(), SmallMapWindow::DrawWidget(), TextfileWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), ButtonLine::GetButton(), ClientButtonLine::GetTooltip(), ReplaceVehicleWindow::OnClick(), BuildVehicleWindow::OnClick(), SelectCompanyManagerFaceWindow::OnClick(), VehicleGroupWindow::OnClick(), IndustryViewWindow::OnClick(), and ScrollEditBoxTextRect().

◆ WithX() [1/2]

Rect Rect::WithX ( const Rect other) const
inline

Create a new Rect, replacing the left and right coordiates.

Parameters
otherRect containing the new left and right coordinates.
Returns
The new Rect.

Definition at line 287 of file geometry_type.hpp.

References WithX().

Referenced by WithX().

◆ WithX() [2/2]

Rect Rect::WithX ( int  new_left,
int  new_right 
) const
inline

Create a new Rect, replacing the left and right coordiates.

Parameters
new_leftNew left coordinate.
new_rightNew right coordinate.
Returns
The new Rect.

Definition at line 272 of file geometry_type.hpp.

Referenced by BaseVehicleListWindow::DrawVehicleListItems(), DrawVerticalScrollbar(), RefitWindow::DrawWidget(), QueryString::GetBoundingRect(), Indent(), and WithWidth().

◆ WithY() [1/2]

Rect Rect::WithY ( const Rect other) const
inline

Create a new Rect, replacing the top and bottom coordiates.

Parameters
otherRect containing the new top and bottom coordinates.
Returns
The new Rect.

Definition at line 294 of file geometry_type.hpp.

References WithY().

Referenced by WithY().

◆ WithY() [2/2]

Rect Rect::WithY ( int  new_top,
int  new_bottom 
) const
inline

Create a new Rect, replacing the top and bottom coordiates.

Parameters
new_topNew top coordinate.
new_bottomNew bottom coordinate.
Returns
The new Rect.

Definition at line 280 of file geometry_type.hpp.

Referenced by DrawEngineList(), DrawHorizontalScrollbar(), NetworkContentListWindow::DrawMatrix(), DrawTrainDetails(), DropdownWindow::DrawWidget(), ErrmsgWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), TransparenciesWindow::DrawWidget(), DropdownWindow::GetDropDownItem(), and WithHeight().

Field Documentation

◆ bottom

int Rect::bottom = 0

Definition at line 105 of file geometry_type.hpp.

◆ left

int Rect::left = 0

Definition at line 102 of file geometry_type.hpp.

◆ right

int Rect::right = 0

Definition at line 104 of file geometry_type.hpp.

◆ top

int Rect::top = 0

Definition at line 103 of file geometry_type.hpp.


The documentation for this struct was generated from the following file: