Castle Game EngineIntroduction Units Class Hierarchy Classes, Interfaces, Objects and Records Types Variables Constants Functions and Procedures Identifiers
|
Record TRectangle
Unit
CastleRectangles
Declaration
type TRectangle = record
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. Neither Width nor Height can ever be negative.
Overview
Fields
Methods
Properties
Description
Fields
Methods
function IsEmpty: boolean; |
|
function Contains(const X, Y: Integer): boolean; overload; |
|
function Contains(const Point: TVector2): boolean; overload; |
|
function CenterInside(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; overload; |
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; overload; |
|
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 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 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 Middle: TVector2Integer; deprecated 'use Center'; |
Warning: this symbol is deprecated: use Center |
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 ScaleAroundCenter(const Factor: Single): TRectangle; |
Scale rectangle position and size around it's own Center point.
Since the scaling is independent in each axis, this handles "carefully" a half-empty rectangles (when one size is <= 0, but other is > 0). It scales correctly the positive dimension (not just returns Empty constant), leaving the other dimension (it's position and size) untouched.
|
function ScaleAroundMiddle(const Factor: Single): TRectangle; deprecated 'use ScaleAroundCenter'; |
Warning: this symbol is deprecated: use ScaleAroundCenter |
function ScaleAround0(const Factor: Single): TRectangle; |
Scale rectangle position and size around the (0,0) point.
Since the scaling is independent in each axis, this handles "carefully" a half-empty rectangles (when one size is <= 0, but other is > 0). It scales correctly the positive dimension (not just returns Empty constant), leaving the other dimension (it's position and size) untouched.
These details matter, e.g. when you set TUIControlSizeable.Width, but not TUIControlSizeable.Height, and then you expect the TUIControl.CalculatedWidth to work.
|
function ScaleWidthAround0(const Factor: Single): Cardinal; |
Scale Width, in the same manner as ScaleAround0 would do.
|
function ScaleHeightAround0(const Factor: Single): Cardinal; |
Scale Height, in the same manner as ScaleAround0 would do.
|
function AlignCore( const ThisPosition: TVerticalPosition; const OtherRect: TRectangle; const OtherPosition: TVerticalPosition; const Y: Integer = 0): Integer; overload; |
Align this rectangle within other rectangle by calculating new value for Bottom.
|
function ToString: string; |
|
function Translate(const V: TVector2Integer): TRectangle; |
Move the rectangle. Empty rectangle after moving is still an empty rectangle.
|
function Collides(const R: TRectangle): boolean; |
Does it have any common part with another rectangle.
|
class operator + (const R1, R2: TRectangle): TRectangle; |
Sum of the two rectangles is a bounding rectangle - a smallest rectangle that contains them both.
|
Properties
property Right: Integer read GetRight ; |
Right and top coordinates of the rectangle. Right is simply the Left + Width , Top is simply the Bottom + Height .
If you use this for drawing, note that the pixel with coordinates (Right , Top) is actually *outside* of the rectangle (by 1 pixel). That's because the rectangle starts at pixel (Left, Bottom) and spans the (Width, Height) pixels.
|
property Top: Integer read GetTop ; |
|
property LeftBottom: TVector2Integer read GetLeftBottom write SetLeftBottom; |
|
Generated by PasDoc 0.15.0.
|