Browse Source

* part of advanced record patch

git-svn-id: trunk@32335 -
marco 9 years ago
parent
commit
1407995a37
3 changed files with 328 additions and 0 deletions
  1. 2 0
      .gitattributes
  2. 208 0
      rtl/inc/typshrd.inc
  3. 118 0
      rtl/inc/typshrdh.inc

+ 2 - 0
.gitattributes

@@ -8792,6 +8792,8 @@ rtl/inc/threadvr.inc svneol=native#text/plain
 rtl/inc/tinyheap.inc svneol=native#text/plain
 rtl/inc/tnyheaph.inc svneol=native#text/plain
 rtl/inc/typefile.inc svneol=native#text/plain
+rtl/inc/typshrd.inc svneol=native#text/plain
+rtl/inc/typshrdh.inc svneol=native#text/plain
 rtl/inc/ufloat128.pp svneol=native#text/plain
 rtl/inc/ustringh.inc svneol=native#text/plain
 rtl/inc/ustrings.inc svneol=native#text/plain

+ 208 - 0
rtl/inc/typshrd.inc

@@ -0,0 +1,208 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2015 by Marco van de Voort
+    member of the Free Pascal development team.
+
+    Types that are in unit types on all platforms but also in 
+    unit Windows on win<x> 
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+{ TSize }
+{$ifdef VER3}
+constructor TSize.Create(ax,ay:Longint);
+begin
+  cx:=ax; cy:=ay;
+end;
+
+constructor TSize.Create(asz :TSize);
+begin
+  cx:=asz.cx; cy:=asz.cy;
+  // vector:=TSize(asz.vector); ??
+end;
+{$endif}
+
+function TSize.IsZero : Boolean;
+begin
+  result:=(cx=0) and (cy=0);
+end;
+
+function TSize.Distance(const asz : TSize) : Double;
+begin
+  result:=sqrt(sqr(cx-asz.cx)+sqr(cy-asz.cy));
+end;
+
+function TSize.Add(const asz : TSize): TSize;
+begin
+  result.cx:=cx+asz.cx;
+  result.cy:=cy+asz.cy;
+end;
+
+function TSize.Subtract(const asz : TSize): TSize;
+begin
+  result.cx:=cx-asz.cx;
+  result.cy:=cy-asz.cy;
+end;
+
+class operator TSize.=(const asz1, asz2 : TSize) : Boolean;
+begin
+  result:=(asz1.cx=asz2.cx) and (asz1.cy=asz2.cy);
+end;
+
+class operator TSize.<> (const asz1, asz2 : TSize): Boolean;
+begin
+  result:=(asz1.cx<>asz2.cx) or (asz1.cy<>asz2.cy);
+end;
+
+class operator TSize.+(const asz1, asz2 : TSize): TSize;
+begin
+  result.cx:=asz1.cx+asz2.cx;
+  result.cy:=asz1.cy+asz2.cy;
+end;
+
+class operator TSize.-(const asz1, asz2 : TSize): TSize;
+begin
+  result.cx:=asz1.cx-asz2.cx;
+  result.cy:=asz1.cy-asz2.cy;
+end;
+
+{ TPoint }
+{$ifdef VER3}
+constructor TPoint.Create(ax,ay:Longint);
+begin
+  x:=ax; y:=ay;
+end;
+
+constructor TPoint.Create(apt :TPoint);
+begin
+  x:=apt.x; y:=apt.y;
+end;
+
+{$endif}
+function TPoint.Add(const apt: TPoint): TPoint;
+begin
+  result.x:=x+apt.x;
+end;
+
+function TPoint.Distance(const apt : TPoint) : Double;
+begin
+  result:=sqrt(sqr(apt.x-x)+sqr(apt.y-y));
+end;
+
+function TPoint.IsZero : Boolean;
+begin
+ result:=(x=0) and (y=0);
+end;
+
+function TPoint.Subtract(const apt : TPoint): TPoint;
+begin
+  result.x:=x-apt.x;
+end;
+
+procedure TPoint.SetLocation(const apt :TPoint);
+begin
+ x:=apt.x; y:=apt.y;
+end;
+procedure TPoint.SetLocation(ax,ay : Longint);
+begin
+  x:=ax; y:=ay;
+end;
+
+procedure TPoint.Offset(const apt :TPoint);
+begin
+ x:=x-apt.x;
+ y:=y-apt.y;
+end;
+
+procedure TPoint.Offset(dx,dy : Longint);
+begin
+  x:=x-dx;
+  y:=y-dy;
+end;
+
+class operator TPoint.= (const apt1, apt2 : TPoint) : Boolean;
+begin
+  result:=(apt1.x=apt2.x) and (apt1.y=apt2.y);
+end;
+
+class operator TPoint.<> (const apt1, apt2 : TPoint): Boolean;
+begin
+  result:=(apt1.x<>apt2.x) or (apt1.y<>apt2.y);
+end;
+
+class operator TPoint.+ (const apt1, apt2 : TPoint): TPoint;
+begin
+  result.x:=apt1.x+apt2.x;
+  result.y:=apt1.y+apt2.y;
+end;
+
+class operator TPoint.- (const apt1, apt2 : TPoint): TPoint;
+begin
+  result.x:=apt1.x-apt2.x;
+  result.y:=apt1.y-apt2.y;
+end;
+
+// warning suppression for the next ones?
+class operator TPoint.:= (const aspt : TSmallPoint): TPoint;
+begin
+  result.x:=aspt.x;
+  result.y:=aspt.y;
+end;
+
+class operator TPoint.Explicit (const apt: TPoint): TSmallPoint;
+begin
+  result.x:=apt.x;
+  result.y:=apt.y;
+end;
+
+{ TRect }
+
+function TRect.getHeight: Longint;
+begin
+  result:=bottom-top;
+end;
+
+function TRect.getLocation: TPoint;
+begin
+  result.x:=Left; result.y:=top;
+end;
+
+function TRect.getSize: TSize;
+begin
+  result.cx:=width; result.cy:=height;
+end;
+
+function TRect.getWidth: Longint;
+begin
+  result:=right-left;
+end;
+
+procedure TRect.setHeight(AValue: Longint);
+begin
+  right:=left+avalue;
+end;
+
+procedure TRect.setLocation(AValue: TPoint);
+begin
+  top:=avalue.x; left:=avalue.y;
+end;
+
+procedure TRect.setSize(AValue: TSize);
+begin
+  bottom:=top+avalue.cy;
+  right:=left+avalue.cx;
+end;
+
+procedure TRect.setWidth(AValue: Longint);
+begin
+  bottom:=top+avalue;
+end;
+
+

+ 118 - 0
rtl/inc/typshrdh.inc

@@ -0,0 +1,118 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2015 by Marco van de Voort
+    member of the Free Pascal development team.
+
+    Types that are in unit types on all platforms but also in 
+    unit Windows on win<x> 
+
+    Name is types shared, but 8.3'd to typshard
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+// the aliases without "T" remain unit Windows only, so are in unit Windows, not here.
+// note 2.6.x requires a space after the operator, 3.x.x seems to fix it.
+// tried to make all records unions with an array type as second form, but that
+// fails because of the properties. TRect doesn't suffer from this because it has
+// getters/setters in the properties instead of field references
+
+  TArray4IntegerType = array[0..3] of Longint;
+
+  PSmallPoint = ^TSmallPoint;
+  TSmallPoint =
+{$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
+  packed
+{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
+  record
+      X,
+      Y : SmallInt;
+      end;
+
+  TSize =
+{$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
+  packed
+{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
+  record
+      cx : Longint; cy : Longint;
+     public
+       {$ifdef VER3}
+       constructor Create(ax,ay:Longint); overload;
+       constructor Create(asz :TSize); overload;
+       {$endif}
+       function Add(const asz: TSize): TSize;
+       function Distance(const asz : TSize) : Double;
+       function IsZero : Boolean;
+       function Subtract(const asz : TSize): TSize;
+       class operator = (const asz1, asz2 : TSize) : Boolean;
+       class operator <> (const asz1, asz2 : TSize): Boolean;
+       class operator + (const asz1, asz2 : TSize): TSize;
+       class operator - (const asz1, asz2 : TSize): TSize;
+       property Width : Longint read cx write cx;
+       property Height: Longint read cy write cy;
+     end;
+  PSize =^TSize;
+
+  TPoint  =
+  {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
+   packed
+  {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
+  record
+       x : Longint; y : Longint;
+     public
+       {$ifdef VER3}
+       constructor Create(ax,ay:Longint); overload;
+       constructor Create(apt :TPoint); overload;
+       {$endif}
+       function Add(const apt: TPoint): TPoint;
+       function Distance(const apt : TPoint) : Double;
+       function IsZero : Boolean;
+       function Subtract(const apt : TPoint): TPoint;
+       procedure SetLocation(const apt :TPoint);
+       procedure SetLocation(ax,ay : Longint);
+       procedure Offset(const apt :TPoint);
+       procedure Offset(dx,dy : Longint);
+       class operator = (const apt1, apt2 : TPoint) : Boolean;
+       class operator <> (const apt1, apt2 : TPoint): Boolean;
+       class operator + (const apt1, apt2 : TPoint): TPoint;
+       class operator - (const apt1, apt2 : TPoint): TPoint;
+       class operator := (const aspt : TSmallPoint) : TPoint;
+       class operator Explicit (Const apt : TPoint) : TSmallPoint;
+     end;
+  PPoint = ^TPoint;
+
+  { 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 setLocation(AValue: TPoint);
+       procedure setSize(AValue: TSize);
+       procedure setWidth (AValue: Longint);
+     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;
+  PRect = ^TRect;
+
+