CGGeometry.pas 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. { CoreGraphics - CGGeometry.h
  2. * Copyright (c) 1998-2003 Apple Computer, Inc.
  3. * All rights reserved.
  4. }
  5. { Pascal Translation Updated: Peter N Lewis, <[email protected]>, August 2005 }
  6. {
  7. Modified for use with Free Pascal
  8. Version 200
  9. Please report any bugs to <[email protected]>
  10. }
  11. {$mode macpas}
  12. {$packenum 1}
  13. {$macro on}
  14. {$inline on}
  15. {$CALLING MWPASCAL}
  16. unit CGGeometry;
  17. interface
  18. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  19. {$setc GAP_INTERFACES_VERSION := $0200}
  20. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  21. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  22. {$endc}
  23. {$ifc defined CPUPOWERPC and defined CPUI386}
  24. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  25. {$endc}
  26. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  27. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  28. {$endc}
  29. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  30. {$setc __ppc__ := 1}
  31. {$elsec}
  32. {$setc __ppc__ := 0}
  33. {$endc}
  34. {$ifc not defined __i386__ and defined CPUI386}
  35. {$setc __i386__ := 1}
  36. {$elsec}
  37. {$setc __i386__ := 0}
  38. {$endc}
  39. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  40. {$error Conflicting definitions for __ppc__ and __i386__}
  41. {$endc}
  42. {$ifc defined __ppc__ and __ppc__}
  43. {$setc TARGET_CPU_PPC := TRUE}
  44. {$setc TARGET_CPU_X86 := FALSE}
  45. {$elifc defined __i386__ and __i386__}
  46. {$setc TARGET_CPU_PPC := FALSE}
  47. {$setc TARGET_CPU_X86 := TRUE}
  48. {$elsec}
  49. {$error Neither __ppc__ nor __i386__ is defined.}
  50. {$endc}
  51. {$setc TARGET_CPU_PPC_64 := FALSE}
  52. {$ifc defined FPC_BIG_ENDIAN}
  53. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  54. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  55. {$elifc defined FPC_LITTLE_ENDIAN}
  56. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  57. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  58. {$elsec}
  59. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  60. {$endc}
  61. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  62. {$setc CALL_NOT_IN_CARBON := FALSE}
  63. {$setc OLDROUTINENAMES := FALSE}
  64. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  65. {$setc OPAQUE_UPP_TYPES := TRUE}
  66. {$setc OTCARBONAPPLICATION := TRUE}
  67. {$setc OTKERNEL := FALSE}
  68. {$setc PM_USE_SESSION_APIS := TRUE}
  69. {$setc TARGET_API_MAC_CARBON := TRUE}
  70. {$setc TARGET_API_MAC_OS8 := FALSE}
  71. {$setc TARGET_API_MAC_OSX := TRUE}
  72. {$setc TARGET_CARBON := TRUE}
  73. {$setc TARGET_CPU_68K := FALSE}
  74. {$setc TARGET_CPU_MIPS := FALSE}
  75. {$setc TARGET_CPU_SPARC := FALSE}
  76. {$setc TARGET_OS_MAC := TRUE}
  77. {$setc TARGET_OS_UNIX := FALSE}
  78. {$setc TARGET_OS_WIN32 := FALSE}
  79. {$setc TARGET_RT_MAC_68881 := FALSE}
  80. {$setc TARGET_RT_MAC_CFM := FALSE}
  81. {$setc TARGET_RT_MAC_MACHO := TRUE}
  82. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  83. {$setc TYPE_BOOL := FALSE}
  84. {$setc TYPE_EXTENDED := FALSE}
  85. {$setc TYPE_LONGLONG := TRUE}
  86. uses MacTypes,CFBase,CGBase;
  87. {$ALIGN POWER}
  88. { Points. }
  89. type
  90. CGPointPtr = ^CGPoint;
  91. CGPoint = record
  92. x: Float32;
  93. y: Float32;
  94. end;
  95. { Sizes. }
  96. type
  97. CGSizePtr = ^CGSize;
  98. CGSize = record
  99. width: Float32;
  100. height: Float32;
  101. end;
  102. { Rectangles. }
  103. type
  104. CGRectPtr = ^CGRect;
  105. CGRect = record
  106. origin: CGPoint;
  107. size: CGSize;
  108. end;
  109. { Rectangle edges. }
  110. type
  111. CGRectEdge = SInt32;
  112. const
  113. CGRectMinXEdge = 0;
  114. CGRectMinYEdge = 1;
  115. CGRectMaxXEdge = 2;
  116. CGRectMaxYEdge = 3;
  117. { The "zero" point -- equivalent to CGPointMake(0, 0). }
  118. var CGPointZero: CGPoint; external name '_CGPointZero'; (* attribute const *)
  119. { The "zero" size -- equivalent to CGSizeMake(0, 0). }
  120. var CGSizeZero: CGSize; external name '_CGSizeZero'; (* attribute const *)
  121. { The "zero" rectangle -- equivalent to CGRectMake(0, 0, 0, 0). }
  122. var CGRectZero: CGRect; external name '_CGRectZero'; (* attribute const *)
  123. { The "empty" rect. This is the rectangle returned when, for example, we
  124. * intersect two disjoint rectangles. Note that the null rect is not the
  125. * same as the zero rect. }
  126. var CGRectNull: CGRect; external name '_CGRectNull'; (* attribute const *)
  127. { The infinite rectangle. }
  128. var CGRectInfinite: CGRect; external name '_CGRectInfinite'; (* attribute const *) (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  129. { Make a point from `(x, y)'. }
  130. // CG_INLINE CGPoint CGPointMake(float x, float y);
  131. { Make a size from `(width, height)'. }
  132. // CG_INLINE CGSize CGSizeMake(float width, float height);
  133. { Make a rect from `(x, y; width, height)'. }
  134. // CG_INLINE CGRect CGRectMake(float x, float y, float width, float height);
  135. { Return the leftmost x-value of `rect'. }
  136. function CGRectGetMinX( rect: CGRect ): Float32; external name '_CGRectGetMinX';
  137. { Return the midpoint x-value of `rect'. }
  138. function CGRectGetMidX( rect: CGRect ): Float32; external name '_CGRectGetMidX';
  139. { Return the rightmost x-value of `rect'. }
  140. function CGRectGetMaxX( rect: CGRect ): Float32; external name '_CGRectGetMaxX';
  141. { Return the bottommost y-value of `rect'. }
  142. function CGRectGetMinY( rect: CGRect ): Float32; external name '_CGRectGetMinY';
  143. { Return the midpoint y-value of `rect'. }
  144. function CGRectGetMidY( rect: CGRect ): Float32; external name '_CGRectGetMidY';
  145. { Return the topmost y-value of `rect'. }
  146. function CGRectGetMaxY( rect: CGRect ): Float32; external name '_CGRectGetMaxY';
  147. { Return the width of `rect'. }
  148. function CGRectGetWidth( rect: CGRect ): Float32; external name '_CGRectGetWidth';
  149. { Return the height of `rect'. }
  150. function CGRectGetHeight( rect: CGRect ): Float32; external name '_CGRectGetHeight';
  151. { Return 1 if `point1' and `point2' are the same, 0 otherwise. }
  152. function CGPointEqualToPoint( point1: CGPoint; point2: CGPoint ): SInt32; external name '_CGPointEqualToPoint';
  153. { Return 1 if `size1' and `size2' are the same, 0 otherwise. }
  154. function CGSizeEqualToSize( size1: CGSize; size2: CGSize ): SInt32; external name '_CGSizeEqualToSize';
  155. { Return 1 if `rect1' and `rect2' are the same, 0 otherwise. }
  156. function CGRectEqualToRect( rect1: CGRect; rect2: CGRect ): SInt32; external name '_CGRectEqualToRect';
  157. { Standardize `rect' -- i.e., convert it to an equivalent rect which has
  158. * positive width and height. }
  159. function CGRectStandardize( rect: CGRect ): CGRect; external name '_CGRectStandardize';
  160. { Return 1 if `rect' is empty -- i.e., if it has zero width or height. A
  161. * null rect is defined to be empty. }
  162. function CGRectIsEmpty( rect: CGRect ): SInt32; external name '_CGRectIsEmpty';
  163. { Return 1 if `rect' is null -- e.g., the result of intersecting two
  164. * disjoint rectangles is a null rect. }
  165. function CGRectIsNull( rect: CGRect ): SInt32; external name '_CGRectIsNull';
  166. { Return true if `rect' is the infinite rectangle, false otherwise. }
  167. function CGRectIsInfinite( rect: CGRect ): CBool; external name '_CGRectIsInfinite'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  168. { Inset `rect' by `(dx, dy)' -- i.e., offset its origin by `(dx, dy)', and
  169. * decrease its size by `(2*dx, 2*dy)'. }
  170. function CGRectInset( rect: CGRect; dx: Float32; dy: Float32 ): CGRect; external name '_CGRectInset';
  171. { Expand `rect' to the smallest rect containing it with integral origin
  172. * and size. }
  173. function CGRectIntegral( rect: CGRect ): CGRect; external name '_CGRectIntegral';
  174. { Return the union of `r1' and `r2'. }
  175. function CGRectUnion( r1: CGRect; r2: CGRect ): CGRect; external name '_CGRectUnion';
  176. { Return the intersection of `r1' and `r2'. This may return a null
  177. * rect. }
  178. function CGRectIntersection( r1: CGRect; r2: CGRect ): CGRect; external name '_CGRectIntersection';
  179. { Offset `rect' by `(dx, dy)'. }
  180. function CGRectOffset( rect: CGRect; dx: Float32; dy: Float32 ): CGRect; external name '_CGRectOffset';
  181. { Make two new rectangles, `slice' and `remainder', by dividing `rect'
  182. * with a line that's parallel to one of its sides, specified by `edge' --
  183. * either `CGRectMinXEdge', `CGRectMinYEdge', `CGRectMaxXEdge', or
  184. * `CGRectMaxYEdge'. The size of `slice' is determined by `amount', which
  185. * measures the distance from the specified edge. }
  186. procedure CGRectDivide( rect: CGRect; var slice: CGRect; var remainder: CGRect; amount: Float32; edge: CGRectEdge ); external name '_CGRectDivide';
  187. { Return 1 if `point' is contained in `rect', 0 otherwise. }
  188. function CGRectContainsPoint( rect: CGRect; point: CGPoint ): SInt32; external name '_CGRectContainsPoint';
  189. { Return 1 if `rect2' is contained in `rect1', 0 otherwise. `rect2' is
  190. * contained in `rect1' if the union of `rect1' and `rect2' is equal to
  191. * `rect1'. }
  192. function CGRectContainsRect( rect1: CGRect; rect2: CGRect ): SInt32; external name '_CGRectContainsRect';
  193. { Return 1 if `rect1' intersects `rect2', 0 otherwise. `rect1' intersects
  194. * `rect2' if the intersection of `rect1' and `rect2' is not the null
  195. * rect. }
  196. function CGRectIntersectsRect( rect1: CGRect; rect2: CGRect ): SInt32; external name '_CGRectIntersectsRect';
  197. (*
  198. {** Definitions of inline functions. **}
  199. // CG_INLINE CGPoint CGPointMake(float x, float y)
  200. {
  201. CGPoint p; p.x = x; p.y = y; return p;
  202. }
  203. // CG_INLINE CGSize CGSizeMake(float width, float height)
  204. {
  205. CGSize size; size.width = width; size.height = height; return size;
  206. }
  207. // CG_INLINE CGRect CGRectMake(float x, float y, float width, float height)
  208. {
  209. CGRect rect;
  210. rect.origin.x = x; rect.origin.y = y;
  211. rect.size.width = width; rect.size.height = height;
  212. return rect;
  213. }
  214. *)
  215. end.