Ceci est une ancienne révision du document !


TRect, TPoint etc...

TRect

Création

pour créer un TRect :

// Avec les données Left, Top, Right, Bottom 
Rect:=Classes.Rect(ALeft, ATop, ARight, ABottom); //Retourne un TRect (unit Classes)
 
// Avec les données Left, Top, Width, Height 
Rect:=Bounds(ALeft, ATop, AWidth, AHeight); //Retourne un TRect  (unit Classes)

Utilitaires

// Savoir si RectA contient RectB (c'est a dire RectA entoure/englobe RectB)
Bool := RectA.Contains(RectB); 
 
// Savoir si RectA chevauche ou contient RectB (c'est a dire une partie RectA se trouve sur RectB)
Bool := RectA.IntersectsWith(RectB); 

Membres de TRect

  TRect =
{$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  packed
{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  record
     private
       function  getHeight: Longint; inline;
       function  getLocation: TPoint;
       function  getSize: TSize;
       function  getWidth : Longint; inline;
       procedure setHeight(AValue: Longint);
       procedure setSize(AValue: TSize);
       procedure setWidth (AValue: Longint);
     public
       constructor Create(Origin: TPoint); // empty rect at given origin
       constructor Create(Origin: TPoint; AWidth, AHeight: Longint);
       constructor Create(ALeft, ATop, ARight, ABottom: Longint);
       constructor Create(P1, P2: TPoint; Normalize: Boolean = False);
       constructor Create(R: TRect; Normalize: Boolean = False);
       class operator = (L, R: TRect): Boolean;
       class operator <> (L, R: TRect): Boolean;
       class operator + (L, R: TRect): TRect; // union
       class operator * (L, R: TRect): TRect; // intersection
       class function Empty: TRect; static;
       procedure NormalizeRect;
       function IsEmpty: Boolean;
       function Contains(Pt: TPoint): Boolean;
       function Contains(R: TRect): Boolean;
       function IntersectsWith(R: TRect): Boolean;
       class function Intersect(R1: TRect; R2: TRect): TRect; static;
       procedure Intersect(R: TRect);
       class function Union(R1, R2: TRect): TRect; static;
       procedure Union(R: TRect);
       class function Union(const Points: array of TPoint): TRect; static;
       procedure Offset(DX, DY: Longint);
       procedure Offset(DP: TPoint);
       procedure SetLocation(X, Y: Longint);
       procedure SetLocation(P: TPoint);
       procedure Inflate(DX, DY: Longint);
       procedure Inflate(DL, DT, DR, DB: Longint);
       function CenterPoint: TPoint;
       function SplitRect(SplitType: TSplitRectType; ASize: Longint): TRect;
       function SplitRect(SplitType: TSplitRectType; Percent: Double): TRect;
     public
       property Height: Longint read getHeight write setHeight;
       property Width : Longint read getWidth  write setWidth;
       property Size  : TSize   read getSize   write setSize;
       property Location  : TPoint read getLocation write setLocation;
       case Longint of
         0: (Left,Top,Right,Bottom : Longint);
         1: (TopLeft,BottomRight : TPoint);
         2: (Vector:TArray4IntegerType);
       end;
Vous pourriez laisser un commentaire si vous étiez connecté.