typshrdh.inc 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2015 by Marco van de Voort
  4. member of the Free Pascal development team.
  5. Types that are in unit types on all platforms but also in
  6. unit Windows on win<x>
  7. Name is types shared, but 8.3'd to typshard
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************}
  14. // the aliases without "T" remain unit Windows only, so are in unit Windows, not here.
  15. // note 2.6.x requires a space after the operator, 3.x.x seems to fix it.
  16. // tried to make all records unions with an array type as second form, but that
  17. // fails because of the properties. TRect doesn't suffer from this because it has
  18. // getters/setters in the properties instead of field references
  19. TArray4IntegerType = array[0..3] of Longint;
  20. PSmallPoint = ^TSmallPoint;
  21. TSmallPoint =
  22. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  23. packed
  24. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  25. record
  26. X,
  27. Y : SmallInt;
  28. end;
  29. TSize =
  30. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  31. packed
  32. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  33. record
  34. cx : Longint; cy : Longint;
  35. public
  36. {$ifdef VER3}
  37. constructor Create(ax,ay:Longint); overload;
  38. constructor Create(asz :TSize); overload;
  39. {$endif}
  40. function Add(const asz: TSize): TSize;
  41. function Distance(const asz : TSize) : Double;
  42. function IsZero : Boolean;
  43. function Subtract(const asz : TSize): TSize;
  44. class operator = (const asz1, asz2 : TSize) : Boolean;
  45. class operator <> (const asz1, asz2 : TSize): Boolean;
  46. class operator + (const asz1, asz2 : TSize): TSize;
  47. class operator - (const asz1, asz2 : TSize): TSize;
  48. property Width : Longint read cx write cx;
  49. property Height: Longint read cy write cy;
  50. end;
  51. PSize =^TSize;
  52. TPoint =
  53. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  54. packed
  55. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  56. record
  57. X : Longint; Y : Longint;
  58. public
  59. {$ifdef VER3}
  60. constructor Create(ax,ay:Longint); overload;
  61. constructor Create(apt :TPoint); overload;
  62. {$endif}
  63. class function Zero: TPoint; static; inline;
  64. function Add(const apt: TPoint): TPoint;
  65. function Distance(const apt: TPoint) : ValReal;
  66. function IsZero : Boolean;
  67. function Subtract(const apt : TPoint): TPoint;
  68. procedure SetLocation(const apt :TPoint);
  69. procedure SetLocation(ax,ay : Longint);
  70. procedure Offset(const apt :TPoint);
  71. procedure Offset(dx,dy : Longint);
  72. class function PointInCircle(const apt, acenter: TPoint; const aradius: Integer): Boolean; static; inline;
  73. class operator = (const apt1, apt2 : TPoint) : Boolean;
  74. class operator <> (const apt1, apt2 : TPoint): Boolean;
  75. class operator + (const apt1, apt2 : TPoint): TPoint;
  76. class operator - (const apt1, apt2 : TPoint): TPoint;
  77. class operator := (const aspt : TSmallPoint) : TPoint;
  78. class operator Explicit (Const apt : TPoint) : TSmallPoint;
  79. end;
  80. PPoint = ^TPoint;
  81. TSplitRectType = (
  82. srLeft,
  83. srRight,
  84. srTop,
  85. srBottom
  86. );
  87. { TRect }
  88. TRect =
  89. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  90. packed
  91. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  92. record
  93. private
  94. function getHeight: Longint; inline;
  95. function getLocation: TPoint;
  96. function getSize: TSize;
  97. function getWidth : Longint; inline;
  98. procedure setHeight(AValue: Longint);
  99. procedure setSize(AValue: TSize);
  100. procedure setWidth (AValue: Longint);
  101. public
  102. constructor Create(Origin: TPoint); // empty rect at given origin
  103. constructor Create(Origin: TPoint; AWidth, AHeight: Longint);
  104. constructor Create(ALeft, ATop, ARight, ABottom: Longint);
  105. constructor Create(P1, P2: TPoint; Normalize: Boolean = False);
  106. constructor Create(R: TRect; Normalize: Boolean = False);
  107. class operator = (L, R: TRect): Boolean;
  108. class operator <> (L, R: TRect): Boolean;
  109. class operator + (L, R: TRect): TRect; // union
  110. class operator * (L, R: TRect): TRect; // intersection
  111. class function Empty: TRect; static;
  112. procedure NormalizeRect;
  113. function IsEmpty: Boolean;
  114. function Contains(Pt: TPoint): Boolean;
  115. function Contains(R: TRect): Boolean;
  116. function IntersectsWith(R: TRect): Boolean;
  117. class function Intersect(R1: TRect; R2: TRect): TRect; static;
  118. procedure Intersect(R: TRect);
  119. class function Union(R1, R2: TRect): TRect; static;
  120. procedure Union(R: TRect);
  121. class function Union(const Points: array of TPoint): TRect; static;
  122. procedure Offset(DX, DY: Longint);
  123. procedure Offset(DP: TPoint);
  124. procedure SetLocation(X, Y: Longint);
  125. procedure SetLocation(P: TPoint);
  126. procedure Inflate(DX, DY: Longint);
  127. procedure Inflate(DL, DT, DR, DB: Longint);
  128. function CenterPoint: TPoint;
  129. function SplitRect(SplitType: TSplitRectType; ASize: Longint): TRect;
  130. function SplitRect(SplitType: TSplitRectType; Percent: Double): TRect;
  131. public
  132. property Height: Longint read getHeight write setHeight;
  133. property Width : Longint read getWidth write setWidth;
  134. property Size : TSize read getSize write setSize;
  135. property Location : TPoint read getLocation write setLocation;
  136. case Longint of
  137. 0: (Left,Top,Right,Bottom : Longint);
  138. 1: (TopLeft,BottomRight : TPoint);
  139. 2: (Vector:TArray4IntegerType);
  140. end;
  141. PRect = ^TRect;