OpenTTD Source 20261112-master-gbcbec5e63f
Rect Struct Reference

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

#include <geometry_type.hpp>

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 CentreToWidth (int width) const
 Centre a horizontal dimension within 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 coordinates.
Rect WithY (int new_top, int new_bottom) const
 Create a new Rect, replacing the top and bottom coordinates.
Rect WithX (const Rect &other) const
 Create a new Rect, replacing the left and right coordinates.
Rect WithY (const Rect &other) const
 Create a new Rect, replacing the top and bottom coordinates.

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 152 of file geometry_type.hpp.

Member Function Documentation

◆ CentreToHeight()

◆ CentreToWidth()

Rect Rect::CentreToWidth ( int width) const
inlinenodiscard

Centre a horizontal dimension within this Rect.

Parameters
widthThe horizontal dimension.
Returns
the new resized Rect.

Definition at line 311 of file geometry_type.hpp.

References CentreBounds().

Referenced by ConnectionChainField::ClickedAt(), ConnectionChainField::Draw(), IndustryChainField::Draw(), and IndustryCargoesWindow::GetRowRect().

◆ Contains()

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

◆ Expand() [1/2]

Rect Rect::Expand ( const RectPadding & other) const
inlinenodiscard

Copy and expand Rect by a RectPadding.

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

Definition at line 240 of file geometry_type.hpp.

◆ Expand() [2/2]

Rect Rect::Expand ( int s) const
inlinenodiscard

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 230 of file geometry_type.hpp.

References Shrink().

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

◆ Height()

◆ Indent()

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

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 275 of file geometry_type.hpp.

References WithX().

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

◆ Shrink() [1/5]

Rect Rect::Shrink ( const RectPadding & horz,
const RectPadding & vert ) const
inlinenodiscard

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 220 of file geometry_type.hpp.

◆ Shrink() [2/5]

Rect Rect::Shrink ( const RectPadding & other) const
inlinenodiscard

Copy and shrink Rect by a RectPadding.

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

Definition at line 209 of file geometry_type.hpp.

◆ Shrink() [3/5]

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

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 186 of file geometry_type.hpp.

◆ Shrink() [4/5]

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

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 199 of file geometry_type.hpp.

◆ Shrink() [5/5]

Rect Rect::Shrink ( int s) const
inlinenodiscard

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 175 of file geometry_type.hpp.

Referenced by AcceptsProducesChainField::Draw(), CargoChainField::Draw(), ConnectionChainField::Draw(), HouseChainField::Draw(), IndustryChainField::Draw(), NWidgetBackground::Draw(), NWidgetLeaf::Draw(), NWidgetScrollbar::Draw(), StationViewWindow::DrawAcceptedCargo(), TownAuthorityWindow::DrawActions(), TimetableWindow::DrawArrivalDeparturePanel(), DrawArrowButtons(), DrawBoolButton(), DrawButtonDropdown(), ButtonLine::DrawButtons(), DrawCaption(), StationViewWindow::DrawCargoRatings(), NetworkContentListWindow::DrawDetails(), NetworkGameWindow::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(), BaseCargoGraphWindow::DrawWidget(), BaseGraphWindow::DrawWidget(), BaseNetworkContentDownloadStatusWindow::DrawWidget(), BootstrapAskForDownloadWindow::DrawWidget(), BootstrapErrorWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), BuildDocksDepotWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), BuildRailDepotWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), BuildRoadDepotWindow::DrawWidget(), BuildRoadStationWindow::DrawWidget(), CompanyInfrastructureWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), DepotWindow::DrawWidget(), DropdownWindow::DrawWidget(), GameOptionsWindow::DrawWidget(), GenerateProgressWindow::DrawWidget(), GraphLegendWindow::DrawWidget(), GSConfigWindow::DrawWidget(), IndustryCargoesWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), LandInfoWindow::DrawWidget(), LinkGraphLegendWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), MusicTrackSelectionWindow::DrawWidget(), MusicWindow::DrawWidget(), NetworkClientListWindow::DrawWidget(), NetworkJoinStatusWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), NewGRFWindow::DrawWidget(), OrdersWindow::DrawWidget(), PerformanceLeagueWindow::DrawWidget(), PickerWindow::DrawWidget(), RefitWindow::DrawWidget(), ReplaceVehicleWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), SavePresetWindow::DrawWidget(), ScanProgressWindow::DrawWidget(), ScriptLeagueWindow::DrawWidget(), ScriptListWindow::DrawWidget(), ScriptSettingsWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), SelectCompanyManagerFaceWindow::DrawWidget(), SelectStationWindow< T >::DrawWidget(), SignListWindow::DrawWidget(), SmallMapWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), StatusBarWindow::DrawWidget(), StoryBookWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), TextfileWindow::DrawWidget(), TooltipsWindow::DrawWidget(), TownAuthorityWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), TownViewWindow::DrawWidget(), TransparenciesWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), VehicleViewWindow::DrawWidget(), ScriptDebugWindow::DrawWidgetLog(), Window::DrawWidgets(), Expand(), QueryString::GetBoundingRect(), QueryString::GetCaretPosition(), QueryString::GetCharAtPosition(), DropdownWindow::GetDropDownItem(), IndustryCargoesWindow::GetRowRect(), HighlightDragPosition(), BuildVehicleWindow::OnClick(), GSConfigWindow::OnClick(), IndustryViewWindow::OnClick(), NetworkClientListWindow::OnClick(), NewGRFParametersWindow::OnClick(), ReplaceVehicleWindow::OnClick(), ScriptSettingsWindow::OnClick(), SelectCompanyManagerFaceWindow::OnClick(), VehicleGroupWindow::OnClick(), BuildVehicleWindow::OnPaint(), GameOptionsWindow::OnPaint(), ReplaceVehicleWindow::OnPaint(), StationViewWindow::OnPaint(), NetworkClientListWindow::OnTooltip(), and VehicleGroupWindow::UpdateColumnRects().

◆ Translate()

◆ Width()

◆ WithHeight()

◆ WithWidth()

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

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 262 of file geometry_type.hpp.

References WithX().

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

◆ WithX() [1/2]

Rect Rect::WithX ( const Rect & other) const
inlinenodiscard

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

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

Definition at line 349 of file geometry_type.hpp.

References WithX().

Referenced by WithX().

◆ WithX() [2/2]

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

◆ WithY() [1/2]

Rect Rect::WithY ( const Rect & other) const
inlinenodiscard

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

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

Definition at line 356 of file geometry_type.hpp.

References WithY().

Referenced by WithY().

◆ WithY() [2/2]

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

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

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

Definition at line 342 of file geometry_type.hpp.

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

Field Documentation

◆ bottom

int Rect::bottom = 0

Definition at line 156 of file geometry_type.hpp.

◆ left

int Rect::left = 0

Definition at line 153 of file geometry_type.hpp.

◆ right

int Rect::right = 0

Definition at line 155 of file geometry_type.hpp.

◆ top

int Rect::top = 0

Definition at line 154 of file geometry_type.hpp.


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