CGPath.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. { CoreGraphics - CGPath.h
  2. * Copyright (c) 2001-2002 Apple Computer, Inc.
  3. * All rights reserved.
  4. }
  5. { Pascal Translation: 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 CGPath;
  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,CGBase,CGAffineTransforms,CFBase,CGGeometry;
  87. {$ALIGN POWER}
  88. type
  89. CGMutablePathRef = ^SInt32; { an opaque 32-bit type }
  90. type
  91. CGPathRef = ^SInt32; { an opaque 32-bit type }
  92. { Return the CFTypeID for CGPathRefs. }
  93. function CGPathGetTypeID: CFTypeID; external name '_CGPathGetTypeID'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  94. { Create a mutable path. }
  95. function CGPathCreateMutable: CGMutablePathRef; external name '_CGPathCreateMutable'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  96. { Create a copy of `path'. }
  97. function CGPathCreateCopy( path: CGPathRef ): CGPathRef; external name '_CGPathCreateCopy'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  98. { Create a mutable copy of `path'. }
  99. function CGPathCreateMutableCopy( path: CGPathRef ): CGMutablePathRef; external name '_CGPathCreateMutableCopy'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  100. { Equivalent to `CFRetain(path)', except it doesn't crash (as CFRetain
  101. * does) if `path' is NULL. }
  102. function CGPathRetain( path: CGPathRef ): CGPathRef; external name '_CGPathRetain'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  103. { Equivalent to `CFRelease(path)', except it doesn't crash (as CFRelease
  104. * does) if `path' is NULL. }
  105. procedure CGPathRelease( path: CGPathRef ); external name '_CGPathRelease'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  106. { Return true if `path1' is equal to `path2'; false otherwise. }
  107. function CGPathEqualToPath( path1: CGPathRef; path2: CGPathRef ): CBool; external name '_CGPathEqualToPath'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  108. {** Path construction functions. **}
  109. { Move the current point to `(x, y)' in `path' and begin a new subpath.
  110. * If `m' is non-NULL, then transform `(x, y)' by `m' first. }
  111. procedure CGPathMoveToPoint( path: CGMutablePathRef; const (*var*) m: CGAffineTransform; x: Float32; y: Float32 ); external name '_CGPathMoveToPoint'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  112. { Append a straight line segment from the current point to `(x, y)' in
  113. * `path' and move the current point to `(x, y)'. If `m' is non-NULL, then
  114. * transform `(x, y)' by `m' first. }
  115. procedure CGPathAddLineToPoint( path: CGMutablePathRef; const (*var*) m: CGAffineTransform; x: Float32; y: Float32 ); external name '_CGPathAddLineToPoint'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  116. { Append a quadratic curve from the current point to `(x, y)' with control
  117. * point `(cpx, cpy)' in `path' and move the current point to `(x, y)'. If
  118. * `m' is non-NULL, then transform all points by `m' first. }
  119. procedure CGPathAddQuadCurveToPoint( path: CGMutablePathRef; const (*var*) m: CGAffineTransform; cpx: Float32; cpy: Float32; x: Float32; y: Float32 ); external name '_CGPathAddQuadCurveToPoint'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  120. { Append a cubic Bezier curve from the current point to `(x,y)' with
  121. * control points `(cp1x, cp1y)' and `(cp2x, cp2y)' in `path' and move the
  122. * current point to `(x, y)'. If `m' is non-NULL, then transform all points
  123. * by `m' first. }
  124. procedure CGPathAddCurveToPoint( path: CGMutablePathRef; const (*var*) m: CGAffineTransform; cp1x: Float32; cp1y: Float32; cp2x: Float32; cp2y: Float32; x: Float32; y: Float32 ); external name '_CGPathAddCurveToPoint'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  125. { Append a line from the current point to the starting point of the
  126. * current subpath of `path' and end the subpath. }
  127. procedure CGPathCloseSubpath( path: CGMutablePathRef ); external name '_CGPathCloseSubpath'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  128. {** Path construction convenience functions. **}
  129. { Add `rect' to `path'. If `m' is non-NULL, then first transform `rect' by
  130. * `m' before adding it to `path'. }
  131. procedure CGPathAddRect( path: CGMutablePathRef; const (*var*) m: CGAffineTransform; rect: CGRect ); external name '_CGPathAddRect'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  132. { Add each rectangle specified by `rects', an array of `count' CGRects, to
  133. * `path'. If `m' is non-NULL, then first transform each rectangle by `m'
  134. * before adding it to `path'. }
  135. procedure CGPathAddRects( path: CGMutablePathRef; const (*var*) m: CGAffineTransform; {const} rects: {variable-size-array} CGRectPtr; count: size_t ); external name '_CGPathAddRects'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  136. { Move to the first element of `points', an array of `count' CGPoints, and
  137. * append a line from each point to the next point in `points'. If `m' is
  138. * non-NULL, then first transform each point by `m'. }
  139. procedure CGPathAddLines( path: CGMutablePathRef; const (*var*) m: CGAffineTransform; {const} points: {variable-size-array} CGPointPtr; count: size_t ); external name '_CGPathAddLines'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  140. { Add an ellipse (an oval) inside `rect' to `path'. The ellipse is
  141. * approximated by a sequence of Bezier curves. The center of the ellipse
  142. * is the midpoint of `rect'. If `rect' is square, then the ellipse will
  143. * be circular with radius equal to one-half the width (equivalently,
  144. * one-half the height) of `rect'. If `rect' is rectangular, then the
  145. * major- and minor-axes will be the `width' and `height' of rect. The
  146. * ellipse forms a complete subpath of `path' --- that is, it begins with a
  147. * "move to" and ends with a "close subpath" --- oriented in the clockwise
  148. * direction. If `m' is non-NULL, then the constructed Bezier curves
  149. * representing the ellipse will be transformed by `m' before they are
  150. * added to `path'. }
  151. procedure CGPathAddEllipseInRect( path: CGMutablePathRef; const (*var*) m: CGAffineTransform; rect: CGRect ); external name '_CGPathAddEllipseInRect'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  152. { Add an arc of a circle to `path', possibly preceded by a straight line
  153. * segment. The arc is approximated by a sequence of cubic Bezier
  154. * curves. `(x, y)' is the center of the arc; `radius' is its radius;
  155. * `startAngle' is the angle to the first endpoint of the arc; `endAngle'
  156. * is the angle to the second endpoint of the arc; and `clockwise' is true
  157. * if the arc is to be drawn clockwise, false otherwise. `startAngle' and
  158. * `endAngle' are measured in radians. If `m' is non-NULL, then the
  159. * constructed Bezier curves representing the arc will be transformed by
  160. * `m' before they are added to `path'. }
  161. procedure CGPathAddArc( path: CGMutablePathRef; const (*var*) m: CGAffineTransform; x: Float32; y: Float32; radius: Float32; startAngle: Float32; endAngle: Float32; clockwise: CBool ); external name '_CGPathAddArc'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  162. { Add an arc of a circle to `path', possibly preceded by a straight line
  163. * segment. The arc is approximated by a sequence of cubic Bezier curves.
  164. * `radius' is the radius of the arc. The resulting arc is tangent to the
  165. * line from the current point of `path' to `(x1, y1)', and the line from
  166. * `(x1, y1)' to `(x2, y2)'. If `m' is non-NULL, then the constructed
  167. * Bezier curves representing the arc will be transformed by `m' before
  168. * they are added to `path'. }
  169. procedure CGPathAddArcToPoint( path: CGMutablePathRef; const (*var*) m: CGAffineTransform; x1: Float32; y1: Float32; x2: Float32; y2: Float32; radius: Float32 ); external name '_CGPathAddArcToPoint'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  170. { Add `path2' to `path1'. If `m' is non-NULL, then the points in `path2'
  171. * will be transformed by `m' before they are added to `path1'.}
  172. procedure CGPathAddPath( path1: CGMutablePathRef; const (*var*) m: CGAffineTransform; path2: CGPathRef ); external name '_CGPathAddPath'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  173. {** Path information functions. **}
  174. { Return true if `path' contains no elements, false otherwise. }
  175. function CGPathIsEmpty( path: CGPathRef ): CBool; external name '_CGPathIsEmpty'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  176. { Return true if `path' represents a rectangle, false otherwise. }
  177. function CGPathIsRect( path: CGPathRef; var rect: CGRect ): CBool; external name '_CGPathIsRect'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  178. { Return the current point of the current subpath of `path'. If there is
  179. * no current point, then return CGPointZero. }
  180. function CGPathGetCurrentPoint( path: CGPathRef ): CGPoint; external name '_CGPathGetCurrentPoint'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  181. { Return the bounding box of `path'. The bounding box is the smallest
  182. * rectangle completely enclosing all points in the path, including control
  183. * points for Bezier and quadratic curves. If the path is empty, then
  184. * return CGRectNull. }
  185. function CGPathGetBoundingBox( path: CGPathRef ): CGRect; external name '_CGPathGetBoundingBox'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  186. { Return true if `point' is contained in `path'; false otherwise. A point
  187. * is contained in a path if it is inside the painted region when the path
  188. * is filled; if `eoFill' is true, then the even-odd fill rule is used to
  189. * evaluate the painted region of the path, otherwise, the winding-number
  190. * fill rule is used. If `m' is non-NULL, then the point is transformed by
  191. * `m' before determining whether the path contains it. }
  192. function CGPathContainsPoint( path: CGPathRef; const (*var*) m: CGAffineTransform; point: CGPoint; eoFill: CBool ): CBool; external name '_CGPathContainsPoint'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  193. type
  194. CGPathElementType = SInt32;
  195. const
  196. kCGPathElementMoveToPoint = 0;
  197. kCGPathElementAddLineToPoint = 1;
  198. kCGPathElementAddQuadCurveToPoint = 2;
  199. kCGPathElementAddCurveToPoint = 3;
  200. kCGPathElementCloseSubpath = 4;
  201. type
  202. CGPathElement = record
  203. typ: CGPathElementType;
  204. points: CGPointPtr;
  205. end;
  206. type
  207. CGPathApplierFunction = procedure( info: UnivPtr; const (*var*) element: CGPathElement );
  208. procedure CGPathApply( path: CGPathRef; info: UnivPtr; func: CGPathApplierFunction ); external name '_CGPathApply'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  209. end.