Browse Source

* Forgot CenterAt

Michaël Van Canneyt 1 year ago
parent
commit
bc00d5ae06
1 changed files with 44 additions and 1 deletions
  1. 44 1
      rtl/objpas/types.pp

+ 44 - 1
rtl/objpas/types.pp

@@ -474,9 +474,12 @@ function Point(x,y : Integer) : TPoint; inline;
 function PointF(x,y: Single) : TPointF; inline;
 function PointF(x,y: Single) : TPointF; inline;
 function PtInRect(const Rect : TRect; const p : TPoint) : Boolean;
 function PtInRect(const Rect : TRect; const p : TPoint) : Boolean;
 function IntersectRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
 function IntersectRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
+function RectCenter(var R: TRect; const Bounds: TRect): TRect;
+function RectCenter(var R: TRectF; const Bounds: TRectF): TRectF;
 function UnionRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
 function UnionRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
 function IsRectEmpty(const Rect : TRect) : Boolean;
 function IsRectEmpty(const Rect : TRect) : Boolean;
 function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
 function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
+function OffsetRect(var Rect : TRectF;DX : Single;DY : Single) : Boolean;
 function CenterPoint(const Rect: TRect): TPoint;
 function CenterPoint(const Rect: TRect): TPoint;
 function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
 function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
 function Size(AWidth, AHeight: Integer): TSize; inline;
 function Size(AWidth, AHeight: Integer): TSize; inline;
@@ -584,6 +587,32 @@ begin
     FillChar(Rect,SizeOf(Rect),0);
     FillChar(Rect,SizeOf(Rect),0);
 end;
 end;
 
 
+function RectCenter(var R: TRect; const Bounds: TRect): TRect;
+
+var
+  C : TPoint;
+  CS : TPoint;
+
+begin
+  C:=Bounds.CenterPoint;
+  CS:=R.CenterPoint;
+  OffsetRect(R,C.X-CS.X,C.Y-CS.Y);
+  Result:=R;
+end;
+
+function RectCenter(var R: TRectF; const Bounds: TRectF): TRectF;
+
+Var
+  C,CS : TPointF;
+
+begin
+  C:=Bounds.CenterPoint;
+  CS:=R.CenterPoint;
+  OffsetRect(R,C.X-CS.X,C.Y-CS.Y);
+  Result:=R;
+end;
+
+
 function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
 function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
 var
 var
   lRect: TRect;
   lRect: TRect;
@@ -631,6 +660,19 @@ begin
     Result := b + ((a - b) shr 1);
     Result := b + ((a - b) shr 1);
 end;
 end;
 
 
+function OffsetRect(var Rect: TRectF; DX: Single; DY: Single): Boolean;
+begin
+  Result:=assigned(@Rect);
+  if Result then
+    with Rect do
+      begin
+        Left:=Left+dx;
+        Right:=Right+dx;
+        Top:=Top+dy;
+        Bottom:=Bottom+dy;
+      end;
+end;
+
 function CenterPoint(const Rect: TRect): TPoint;
 function CenterPoint(const Rect: TRect): TPoint;
 begin
 begin
   with Rect do
   with Rect do
@@ -1133,7 +1175,8 @@ end;
 
 
 function TRectF.CenterAt(const Dest: TRectF): TRectF;
 function TRectF.CenterAt(const Dest: TRectF): TRectF;
 begin
 begin
-
+  Result:=Self;
+  RectCenter(Result,Dest);
 end;
 end;
 
 
 function TRectF.Fit(const Dest: TRectF): Single;
 function TRectF.Fit(const Dest: TRectF): Single;