OpenTTD Source: Rect Struct Reference

OpenTTD Source 15.0-RC2

Public Member Functions | Data Fields
Rect Struct Reference

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

`#include <geometry_type.hpp>`

Inheritance diagram for Rect:

## 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

  height | The 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

  pt | the 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

  other | RectPadding 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

  s | number 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()

int Rect::Height | ( |  | ) | const
| inline

Get height of Rect.

Returns
  height of Rect.

Definition at line 117 of file geometry_type.hpp.

Referenced by DrawAircraftImage(), DrawEngineList(), DrawHorizontalScrollbar(), DrawMatrix(), DrawRoadVehImage(), DrawShipImage(), BuildSignalWindow::DrawSignalSprite(), DrawTrainDetails(), DrawTrainImage(), SelectCompanyLiveryWindow::DrawWidget(), BuildDocksDepotWindow::DrawWidget(), DropdownWindow::DrawWidget(), ErrmsgWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), PickerWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), BuildRailDepotWindow::DrawWidget(), BuildRoadDepotWindow::DrawWidget(), BuildRoadStationWindow::DrawWidget(), GameOptionsWindow::DrawWidget(), ScenarioEditorToolbarWindow::DrawWidget(), EnsureVisibleCaption(), GetAircraftSpriteSize(), DropdownWindow::GetDropDownItem(), GetRoadVehSpriteSize(), GetShipSpriteSize(), GetTrainSpriteSize(), BitmapTileArea::Initialize(), and PreventHiding().

## ◆ Indent()

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

Copy Rect and indent it from its position.

Parameters

  indent | offset in pixels for new Rect.
  end | if 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(), DrawBadgeColumn(), 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(), IndustryViewWindow::OnClick(), and VehicleGroupWindow::UpdateColumnRects().

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

  horz | RectPadding to remove from left and right of Rect.
  vert | RectPadding 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

  other | RectPadding 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

  h | number of pixels to remove from left and right sides.
  v | number 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

  left | number of pixels to remove from left side.
  top | number of pixels to remove from top side.
  right | number of pixels to remove from right side.
  bottom | number 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

  s | number 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(), NetworkClientListWindow::OnTooltip(), and VehicleGroupWindow::UpdateColumnRects().

## ◆ Translate()

Rect Rect::Translate | ( | int | x,
|  | int | y
| ) |  | const
| inline

Copy and translate Rect by x,y pixels.

Parameters

  x | number of pixels to move horizontally.
  y | number of pixels to move vertically.

Returns
  the new translated Rect.

Definition at line 200 of file geometry_type.hpp.

Referenced by DrawEngineList(), VehicleGroupWindow::DrawGroupInfo(), IndustryViewWindow::DrawInfo(), NetworkContentListWindow::DrawMatrix(), DrawRoadVehImage(), DrawTrainImage(), DepotWindow::DrawVehicleInDepot(), BaseVehicleListWindow::DrawVehicleListItems(), BuildAirportWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), SelectCompanyManagerFaceWindow::DrawWidget(), CompanyInfrastructureWindow::DrawWidget(), DepotWindow::DrawWidget(), DropdownWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), BaseGraphWindow::DrawWidget(), BaseCargoGraphWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), NetworkClientListWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), SmallMapWindow::DrawWidget(), StoryBookWindow::DrawWidget(), TextfileWindow::DrawWidget(), ScrollEditBoxTextRect(), and DropdownWindow::UpdateSizeAndPosition().

## ◆ Width()

int Rect::Width | ( |  | ) | const
| inline

Get width of Rect.

Returns
  width of Rect.

Definition at line 111 of file geometry_type.hpp.

Referenced by DrawAircraftImage(), StationViewWindow::DrawCargoIcons(), DrawMatrix(), DrawRoadVehImage(), DrawShipImage(), DrawTrainImage(), NewGRFInspectWindow::DrawVehicleChainWidget(), BaseVehicleListWindow::DrawVehicleListItems(), DrawVerticalScrollbar(), BuildDocksDepotWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), PickerWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), BuildRailDepotWindow::DrawWidget(), BuildRoadDepotWindow::DrawWidget(), BuildRoadStationWindow::DrawWidget(), GameOptionsWindow::DrawWidget(), SmallMapWindow::DrawWidget(), TextfileWindow::DrawWidget(), RefitWindow::DrawWidget(), GetAircraftSpriteSize(), GetRoadVehSpriteSize(), GetShipSpriteSize(), GetSingleVehicleWidth(), GetTrainSpriteSize(), BitmapTileArea::Initialize(), GSConfigWindow::OnClick(), NewGRFParametersWindow::OnClick(), ScriptSettingsWindow::OnClick(), GameOptionsWindow::OnPaint(), ScrollEditBoxTextRect(), and DropdownWindow::UpdateSizeAndPosition().

## ◆ WithHeight()

Rect Rect::WithHeight | ( | int | height,
|  | bool | end = `false`
| ) |  | const
| inline

Copy Rect and set its height.

Parameters

  height | height in pixels for new Rect.
  end | if set, set height at end of Rect, i.e. at bottom.

Returns
  the new resized Rect.

Definition at line 237 of file geometry_type.hpp.

References WithY().

Referenced by NetworkContentListWindow::DrawDetails(), DrawEngineList(), NetworkContentListWindow::DrawMatrix(), DepotWindow::DrawVehicleInDepot(), BaseVehicleListWindow::DrawVehicleListItems(), DrawVerticalScrollbar(), BuildAirportWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), SelectCompanyManagerFaceWindow::DrawWidget(), CompanyInfrastructureWindow::DrawWidget(), DepotWindow::DrawWidget(), DropdownWindow::DrawWidget(), ErrmsgWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), BaseGraphWindow::DrawWidget(), BaseCargoGraphWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), NetworkClientListWindow::DrawWidget(), SmallMapWindow::DrawWidget(), TextfileWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), and GameOptionsWindow::OnPaint().

## ◆ WithWidth()

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

Copy Rect and set its width.

Parameters

  width | width in pixels for new Rect.
  end | if 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(), DrawBadgeColumn(), DrawBoolButton(), DrawButtonDropdown(), ButtonLine::DrawButtons(), DrawEngineList(), StationViewWindow::DrawEntries(), 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(), ScrollEditBoxTextRect(), and VehicleGroupWindow::UpdateColumnRects().

## ◆ WithX() [1/2]

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

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

Parameters

  other | Rect 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_left | New left coordinate.
  new_right | New right coordinate.

Returns
  The new Rect.

Definition at line 272 of file geometry_type.hpp.

Referenced by VehicleGroupWindow::DrawGroupInfo(), 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

  other | Rect 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_top | New top coordinate.
  new_bottom | New bottom coordinate.

Returns
  The new Rect.

Definition at line 280 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 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:

- src/core/geometry_type.hpp