Castle Game Engine: CastleRectangles: Object TRectangle

# Object TRectangle
Description | Hierarchy | Fields | Methods | Properties
## Unit CastleRectangles ## Declaration `type TRectangle = object(TObject)` ## Description 2D rectangle with integer coordinates. Useful for various 2D GUI operations. The area covered by the rectangle starts in (Left,Bottom) pixel and spans (Width,Height) pixels. This means that the right-top pixel covered by the rectangle is (Left + Width - 1,Bottom + Height - 1). The rectangle is empty (Contains will always answer `False`) when either Width or Height are zero. ## Hierarchy TObject TRectangle ## Overview ### Fields
| `Left: Integer;`
| `Bottom: Integer;`
| `Width: Cardinal;`
| `Height: Cardinal;`
| `internal const Empty: TRectangle = (Left: 0; Bottom: 0; Width: 0; Height: 0);`
### Methods
| `function Contains(const X, Y: Integer): boolean;`
| `function Contains(const Point: TVector2Single): boolean;`
| `function Contains(const Point: TVector2Integer): boolean;`
| `function Center(const W, H: Cardinal): TRectangle;`
| `function Grow(const Delta: Integer): TRectangle;`
| `function Grow(const DeltaX, DeltaY: Integer): TRectangle;`
| `function RemoveLeft(W: Cardinal): TRectangle;`
| `function RemoveBottom(H: Cardinal): TRectangle;`
| `function RemoveRight(W: Cardinal): TRectangle;`
| `function RemoveTop(H: Cardinal): TRectangle;`
| `function GrowLeft(const W: Cardinal): TRectangle;`
| `function GrowBottom(const H: Cardinal): TRectangle;`
| `function GrowRight(const W: Cardinal): TRectangle;`
| `function GrowTop(const H: Cardinal): TRectangle;`
| `function LeftPart(W: Cardinal): TRectangle;`
| `function BottomPart(H: Cardinal): TRectangle;`
| `function RightPart(W: Cardinal): TRectangle;`
| `function TopPart(H: Cardinal): TRectangle;`
| `function Middle: TVector2Integer;`
| `function ClampX(const X: Integer): Integer;`
| `function ClampY(const Y: Integer): Integer;`
| `function ScaleToWidth(const NewWidth: Cardinal): TRectangle;`
| `function ScaleToHeight(const NewHeight: Cardinal): TRectangle;`
| `function AlignCore( const ThisPosition: THorizontalPosition; const OtherRect: TRectangle; const OtherPosition: THorizontalPosition; const X: Integer = 0): Integer;`
| `function Align( const ThisPosition: THorizontalPosition; const OtherRect: TRectangle; const OtherPosition: THorizontalPosition; const X: Integer = 0): TRectangle;`
| `function AlignCore( const ThisPosition: TVerticalPosition; const OtherRect: TRectangle; const OtherPosition: TVerticalPosition; const Y: Integer = 0): Integer;`
| `function Align( const ThisPosition: TVerticalPosition; const OtherRect: TRectangle; const OtherPosition: TVerticalPosition; const Y: Integer = 0): TRectangle;`
| `function ToString: string;`
### Properties
| `property Right: Integer read GetRight;`
| `property Top: Integer read GetTop;`
| `property LeftBottom: TVector2Integer read GetLeftBottom write SetLeftBottom;`
## Description ### Fields
| `Left: Integer;`
| `Bottom: Integer;`
| `Width: Cardinal;`
| `Height: Cardinal;`
| `internal const Empty: TRectangle = (Left: 0; Bottom: 0; Width: 0; Height: 0);`
### Methods
| `function Contains(const X, Y: Integer): boolean;`
| `function Contains(const Point: TVector2Single): boolean;`
| `function Contains(const Point: TVector2Integer): boolean;`
| `function Center(const W, H: Cardinal): TRectangle;`
Return rectangle with given width and height centered in the middle of this rectangle. The given W, H may be smaller or larger than this rectangle sizes.
| `function Grow(const Delta: Integer): TRectangle;`
Grow (when Delta > 0) or shrink (when Delta < 0) the rectangle, returning new value. This adds a margin of Delta pixels around all sides of the rectangle, so in total width grows by 2 * Delta, and the same for height. In case of shrinking, we protect from shrinking too much: the resulting width or height is set to zero (which makes a valid and empty rectangle) if shrinking too much.
| `function Grow(const DeltaX, DeltaY: Integer): TRectangle;`
| `function RemoveLeft(W: Cardinal): TRectangle;`
Returns the rectangle with a number of pixels from given side removed. Returns an empty rectangle if you try to remove too much.
| `function RemoveBottom(H: Cardinal): TRectangle;`
| `function RemoveRight(W: Cardinal): TRectangle;`
| `function RemoveTop(H: Cardinal): TRectangle;`
| `function GrowLeft(const W: Cardinal): TRectangle;`
Returns the rectangle with a number of pixels on given side added.
| `function GrowBottom(const H: Cardinal): TRectangle;`
| `function GrowRight(const W: Cardinal): TRectangle;`
| `function GrowTop(const H: Cardinal): TRectangle;`
| `function LeftPart(W: Cardinal): TRectangle;`
Returns the given side of the rectangle, cut down to given number of pixels from given side. This is similar to RemoveXxx methods, but here you specify which side to keep, as opposed to RemoveXxx methods where you specify which side you remove. If the requested size is larger than current size (for example, W > Width for `LeftPart`) then the unmodified rectangle is returned.
| `function BottomPart(H: Cardinal): TRectangle;`
| `function RightPart(W: Cardinal): TRectangle;`
| `function TopPart(H: Cardinal): TRectangle;`
| `function Middle: TVector2Integer;`
| `function ClampX(const X: Integer): Integer;`
Clamp value to be within allowed horizontal range. That is, clamp to `[Left, Right - 1]`.
| `function ClampY(const Y: Integer): Integer;`
Clamp value to be within allowed vertical range. That is, clamp to `[Bottom, Top - 1]`.
| `function ScaleToWidth(const NewWidth: Cardinal): TRectangle;`
| `function ScaleToHeight(const NewHeight: Cardinal): TRectangle;`
| `function AlignCore( const ThisPosition: THorizontalPosition; const OtherRect: TRectangle; const OtherPosition: THorizontalPosition; const X: Integer = 0): Integer;`
Align this rectangle within other rectangle by calculating new value for Left.
| `function Align( const ThisPosition: THorizontalPosition; const OtherRect: TRectangle; const OtherPosition: THorizontalPosition; const X: Integer = 0): TRectangle;`
| `function AlignCore( const ThisPosition: TVerticalPosition; const OtherRect: TRectangle; const OtherPosition: TVerticalPosition; const Y: Integer = 0): Integer;`
Align this rectangle within other rectangle by calculating new value for Bottom.
| `function Align( const ThisPosition: TVerticalPosition; const OtherRect: TRectangle; const OtherPosition: TVerticalPosition; const Y: Integer = 0): TRectangle;`
| `function ToString: string;`
### Properties
| `property Right: Integer read GetRight;`
`Right` and Top pixels are 1 pixel *outside* of the rectangle.
| `property Top: Integer read GetTop;`
| `property LeftBottom: TVector2Integer read GetLeftBottom write SetLeftBottom;`
Generated by PasDoc 0.13.0 on 2015-06-15 04:43:11