1use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9use objc2_core_foundation::*;
10
11use crate::*;
12
13#[repr(C)]
15pub struct CGMutablePath {
16 inner: [u8; 0],
17 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
18}
19
20cf_type!(
21 #[encoding_name = "CGPath"]
22 unsafe impl CGMutablePath: CGPath {}
23);
24
25#[repr(C)]
27pub struct CGPath {
28 inner: [u8; 0],
29 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
30}
31
32cf_type!(
33 #[encoding_name = "CGPath"]
34 unsafe impl CGPath {}
35);
36
37#[repr(transparent)]
40#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
41pub struct CGLineJoin(pub i32);
42impl CGLineJoin {
43 #[doc(alias = "kCGLineJoinMiter")]
44 pub const Miter: Self = Self(0);
45 #[doc(alias = "kCGLineJoinRound")]
46 pub const Round: Self = Self(1);
47 #[doc(alias = "kCGLineJoinBevel")]
48 pub const Bevel: Self = Self(2);
49}
50
51#[cfg(feature = "objc2")]
52unsafe impl Encode for CGLineJoin {
53 const ENCODING: Encoding = i32::ENCODING;
54}
55
56#[cfg(feature = "objc2")]
57unsafe impl RefEncode for CGLineJoin {
58 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
59}
60
61#[repr(transparent)]
64#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
65pub struct CGLineCap(pub i32);
66impl CGLineCap {
67 #[doc(alias = "kCGLineCapButt")]
68 pub const Butt: Self = Self(0);
69 #[doc(alias = "kCGLineCapRound")]
70 pub const Round: Self = Self(1);
71 #[doc(alias = "kCGLineCapSquare")]
72 pub const Square: Self = Self(2);
73}
74
75#[cfg(feature = "objc2")]
76unsafe impl Encode for CGLineCap {
77 const ENCODING: Encoding = i32::ENCODING;
78}
79
80#[cfg(feature = "objc2")]
81unsafe impl RefEncode for CGLineCap {
82 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
83}
84
85unsafe impl ConcreteType for CGPath {
86 #[doc(alias = "CGPathGetTypeID")]
87 #[inline]
88 fn type_id() -> CFTypeID {
89 extern "C-unwind" {
90 fn CGPathGetTypeID() -> CFTypeID;
91 }
92 unsafe { CGPathGetTypeID() }
93 }
94}
95
96#[inline]
97pub unsafe extern "C-unwind" fn CGPathCreateMutable() -> CFRetained<CGMutablePath> {
98 extern "C-unwind" {
99 fn CGPathCreateMutable() -> Option<NonNull<CGMutablePath>>;
100 }
101 let ret = unsafe { CGPathCreateMutable() };
102 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
103 unsafe { CFRetained::from_raw(ret) }
104}
105
106#[inline]
107pub unsafe extern "C-unwind" fn CGPathCreateCopy(
108 path: Option<&CGPath>,
109) -> Option<CFRetained<CGPath>> {
110 extern "C-unwind" {
111 fn CGPathCreateCopy(path: Option<&CGPath>) -> Option<NonNull<CGPath>>;
112 }
113 let ret = unsafe { CGPathCreateCopy(path) };
114 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
115}
116
117#[inline]
118pub unsafe extern "C-unwind" fn CGPathCreateCopyByTransformingPath(
119 path: Option<&CGPath>,
120 transform: *const CGAffineTransform,
121) -> Option<CFRetained<CGPath>> {
122 extern "C-unwind" {
123 fn CGPathCreateCopyByTransformingPath(
124 path: Option<&CGPath>,
125 transform: *const CGAffineTransform,
126 ) -> Option<NonNull<CGPath>>;
127 }
128 let ret = unsafe { CGPathCreateCopyByTransformingPath(path, transform) };
129 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
130}
131
132#[inline]
133pub unsafe extern "C-unwind" fn CGPathCreateMutableCopy(
134 path: Option<&CGPath>,
135) -> Option<CFRetained<CGMutablePath>> {
136 extern "C-unwind" {
137 fn CGPathCreateMutableCopy(path: Option<&CGPath>) -> Option<NonNull<CGMutablePath>>;
138 }
139 let ret = unsafe { CGPathCreateMutableCopy(path) };
140 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
141}
142
143#[inline]
144pub unsafe extern "C-unwind" fn CGPathCreateMutableCopyByTransformingPath(
145 path: Option<&CGPath>,
146 transform: *const CGAffineTransform,
147) -> Option<CFRetained<CGMutablePath>> {
148 extern "C-unwind" {
149 fn CGPathCreateMutableCopyByTransformingPath(
150 path: Option<&CGPath>,
151 transform: *const CGAffineTransform,
152 ) -> Option<NonNull<CGMutablePath>>;
153 }
154 let ret = unsafe { CGPathCreateMutableCopyByTransformingPath(path, transform) };
155 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
156}
157
158#[inline]
159pub unsafe extern "C-unwind" fn CGPathCreateWithRect(
160 rect: CGRect,
161 transform: *const CGAffineTransform,
162) -> CFRetained<CGPath> {
163 extern "C-unwind" {
164 fn CGPathCreateWithRect(
165 rect: CGRect,
166 transform: *const CGAffineTransform,
167 ) -> Option<NonNull<CGPath>>;
168 }
169 let ret = unsafe { CGPathCreateWithRect(rect, transform) };
170 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
171 unsafe { CFRetained::from_raw(ret) }
172}
173
174#[inline]
175pub unsafe extern "C-unwind" fn CGPathCreateWithEllipseInRect(
176 rect: CGRect,
177 transform: *const CGAffineTransform,
178) -> CFRetained<CGPath> {
179 extern "C-unwind" {
180 fn CGPathCreateWithEllipseInRect(
181 rect: CGRect,
182 transform: *const CGAffineTransform,
183 ) -> Option<NonNull<CGPath>>;
184 }
185 let ret = unsafe { CGPathCreateWithEllipseInRect(rect, transform) };
186 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
187 unsafe { CFRetained::from_raw(ret) }
188}
189
190#[inline]
191pub unsafe extern "C-unwind" fn CGPathCreateWithRoundedRect(
192 rect: CGRect,
193 corner_width: CGFloat,
194 corner_height: CGFloat,
195 transform: *const CGAffineTransform,
196) -> CFRetained<CGPath> {
197 extern "C-unwind" {
198 fn CGPathCreateWithRoundedRect(
199 rect: CGRect,
200 corner_width: CGFloat,
201 corner_height: CGFloat,
202 transform: *const CGAffineTransform,
203 ) -> Option<NonNull<CGPath>>;
204 }
205 let ret = unsafe { CGPathCreateWithRoundedRect(rect, corner_width, corner_height, transform) };
206 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
207 unsafe { CFRetained::from_raw(ret) }
208}
209
210extern "C-unwind" {
211 pub fn CGPathAddRoundedRect(
212 path: Option<&CGMutablePath>,
213 transform: *const CGAffineTransform,
214 rect: CGRect,
215 corner_width: CGFloat,
216 corner_height: CGFloat,
217 );
218}
219
220#[inline]
221pub unsafe extern "C-unwind" fn CGPathCreateCopyByDashingPath(
222 path: Option<&CGPath>,
223 transform: *const CGAffineTransform,
224 phase: CGFloat,
225 lengths: *const CGFloat,
226 count: usize,
227) -> Option<CFRetained<CGPath>> {
228 extern "C-unwind" {
229 fn CGPathCreateCopyByDashingPath(
230 path: Option<&CGPath>,
231 transform: *const CGAffineTransform,
232 phase: CGFloat,
233 lengths: *const CGFloat,
234 count: usize,
235 ) -> Option<NonNull<CGPath>>;
236 }
237 let ret = unsafe { CGPathCreateCopyByDashingPath(path, transform, phase, lengths, count) };
238 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
239}
240
241#[inline]
242pub unsafe extern "C-unwind" fn CGPathCreateCopyByStrokingPath(
243 path: Option<&CGPath>,
244 transform: *const CGAffineTransform,
245 line_width: CGFloat,
246 line_cap: CGLineCap,
247 line_join: CGLineJoin,
248 miter_limit: CGFloat,
249) -> Option<CFRetained<CGPath>> {
250 extern "C-unwind" {
251 fn CGPathCreateCopyByStrokingPath(
252 path: Option<&CGPath>,
253 transform: *const CGAffineTransform,
254 line_width: CGFloat,
255 line_cap: CGLineCap,
256 line_join: CGLineJoin,
257 miter_limit: CGFloat,
258 ) -> Option<NonNull<CGPath>>;
259 }
260 let ret = unsafe {
261 CGPathCreateCopyByStrokingPath(
262 path,
263 transform,
264 line_width,
265 line_cap,
266 line_join,
267 miter_limit,
268 )
269 };
270 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
271}
272
273extern "C-unwind" {
274 pub fn CGPathEqualToPath(path1: Option<&CGPath>, path2: Option<&CGPath>) -> bool;
275}
276
277extern "C-unwind" {
278 pub fn CGPathMoveToPoint(
280 path: Option<&CGMutablePath>,
281 m: *const CGAffineTransform,
282 x: CGFloat,
283 y: CGFloat,
284 );
285}
286
287extern "C-unwind" {
288 pub fn CGPathAddLineToPoint(
289 path: Option<&CGMutablePath>,
290 m: *const CGAffineTransform,
291 x: CGFloat,
292 y: CGFloat,
293 );
294}
295
296extern "C-unwind" {
297 pub fn CGPathAddQuadCurveToPoint(
298 path: Option<&CGMutablePath>,
299 m: *const CGAffineTransform,
300 cpx: CGFloat,
301 cpy: CGFloat,
302 x: CGFloat,
303 y: CGFloat,
304 );
305}
306
307extern "C-unwind" {
308 pub fn CGPathAddCurveToPoint(
309 path: Option<&CGMutablePath>,
310 m: *const CGAffineTransform,
311 cp1x: CGFloat,
312 cp1y: CGFloat,
313 cp2x: CGFloat,
314 cp2y: CGFloat,
315 x: CGFloat,
316 y: CGFloat,
317 );
318}
319
320extern "C-unwind" {
321 pub fn CGPathCloseSubpath(path: Option<&CGMutablePath>);
322}
323
324extern "C-unwind" {
325 pub fn CGPathAddRect(path: Option<&CGMutablePath>, m: *const CGAffineTransform, rect: CGRect);
327}
328
329extern "C-unwind" {
330 pub fn CGPathAddRects(
331 path: Option<&CGMutablePath>,
332 m: *const CGAffineTransform,
333 rects: *const CGRect,
334 count: usize,
335 );
336}
337
338extern "C-unwind" {
339 pub fn CGPathAddLines(
340 path: Option<&CGMutablePath>,
341 m: *const CGAffineTransform,
342 points: *const CGPoint,
343 count: usize,
344 );
345}
346
347extern "C-unwind" {
348 pub fn CGPathAddEllipseInRect(
349 path: Option<&CGMutablePath>,
350 m: *const CGAffineTransform,
351 rect: CGRect,
352 );
353}
354
355extern "C-unwind" {
356 pub fn CGPathAddRelativeArc(
357 path: Option<&CGMutablePath>,
358 matrix: *const CGAffineTransform,
359 x: CGFloat,
360 y: CGFloat,
361 radius: CGFloat,
362 start_angle: CGFloat,
363 delta: CGFloat,
364 );
365}
366
367extern "C-unwind" {
368 pub fn CGPathAddArc(
369 path: Option<&CGMutablePath>,
370 m: *const CGAffineTransform,
371 x: CGFloat,
372 y: CGFloat,
373 radius: CGFloat,
374 start_angle: CGFloat,
375 end_angle: CGFloat,
376 clockwise: bool,
377 );
378}
379
380extern "C-unwind" {
381 pub fn CGPathAddArcToPoint(
382 path: Option<&CGMutablePath>,
383 m: *const CGAffineTransform,
384 x1: CGFloat,
385 y1: CGFloat,
386 x2: CGFloat,
387 y2: CGFloat,
388 radius: CGFloat,
389 );
390}
391
392extern "C-unwind" {
393 pub fn CGPathAddPath(
394 path1: Option<&CGMutablePath>,
395 m: *const CGAffineTransform,
396 path2: Option<&CGPath>,
397 );
398}
399
400extern "C-unwind" {
401 pub fn CGPathIsEmpty(path: Option<&CGPath>) -> bool;
403}
404
405extern "C-unwind" {
406 pub fn CGPathIsRect(path: Option<&CGPath>, rect: *mut CGRect) -> bool;
407}
408
409extern "C-unwind" {
410 pub fn CGPathGetCurrentPoint(path: Option<&CGPath>) -> CGPoint;
411}
412
413extern "C-unwind" {
414 pub fn CGPathGetBoundingBox(path: Option<&CGPath>) -> CGRect;
415}
416
417extern "C-unwind" {
418 pub fn CGPathGetPathBoundingBox(path: Option<&CGPath>) -> CGRect;
419}
420
421extern "C-unwind" {
422 pub fn CGPathContainsPoint(
423 path: Option<&CGPath>,
424 m: *const CGAffineTransform,
425 point: CGPoint,
426 eo_fill: bool,
427 ) -> bool;
428}
429
430#[repr(transparent)]
433#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
434pub struct CGPathElementType(pub i32);
435impl CGPathElementType {
436 #[doc(alias = "kCGPathElementMoveToPoint")]
437 pub const MoveToPoint: Self = Self(0);
438 #[doc(alias = "kCGPathElementAddLineToPoint")]
439 pub const AddLineToPoint: Self = Self(1);
440 #[doc(alias = "kCGPathElementAddQuadCurveToPoint")]
441 pub const AddQuadCurveToPoint: Self = Self(2);
442 #[doc(alias = "kCGPathElementAddCurveToPoint")]
443 pub const AddCurveToPoint: Self = Self(3);
444 #[doc(alias = "kCGPathElementCloseSubpath")]
445 pub const CloseSubpath: Self = Self(4);
446}
447
448#[cfg(feature = "objc2")]
449unsafe impl Encode for CGPathElementType {
450 const ENCODING: Encoding = i32::ENCODING;
451}
452
453#[cfg(feature = "objc2")]
454unsafe impl RefEncode for CGPathElementType {
455 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
456}
457
458#[repr(C)]
460#[derive(Clone, Copy, Debug, PartialEq)]
461pub struct CGPathElement {
462 pub r#type: CGPathElementType,
463 pub points: NonNull<CGPoint>,
464}
465
466#[cfg(feature = "objc2")]
467unsafe impl Encode for CGPathElement {
468 const ENCODING: Encoding = Encoding::Struct(
469 "CGPathElement",
470 &[<CGPathElementType>::ENCODING, <NonNull<CGPoint>>::ENCODING],
471 );
472}
473
474#[cfg(feature = "objc2")]
475unsafe impl RefEncode for CGPathElement {
476 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
477}
478
479pub type CGPathApplierFunction =
481 Option<unsafe extern "C-unwind" fn(*mut c_void, NonNull<CGPathElement>)>;
482
483extern "C-unwind" {
484 pub fn CGPathApply(path: Option<&CGPath>, info: *mut c_void, function: CGPathApplierFunction);
485}
486
487#[cfg(feature = "block2")]
489pub type CGPathApplyBlock = *mut block2::Block<dyn Fn(NonNull<CGPathElement>)>;
490
491extern "C-unwind" {
492 #[cfg(feature = "block2")]
493 pub fn CGPathApplyWithBlock(path: &CGPath, block: CGPathApplyBlock);
494}
495
496#[inline]
497pub unsafe extern "C-unwind" fn CGPathCreateCopyByNormalizing(
498 path: Option<&CGPath>,
499 even_odd_fill_rule: bool,
500) -> Option<CFRetained<CGPath>> {
501 extern "C-unwind" {
502 fn CGPathCreateCopyByNormalizing(
503 path: Option<&CGPath>,
504 even_odd_fill_rule: bool,
505 ) -> Option<NonNull<CGPath>>;
506 }
507 let ret = unsafe { CGPathCreateCopyByNormalizing(path, even_odd_fill_rule) };
508 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
509}
510
511#[inline]
512pub unsafe extern "C-unwind" fn CGPathCreateCopyByUnioningPath(
513 path: Option<&CGPath>,
514 mask_path: Option<&CGPath>,
515 even_odd_fill_rule: bool,
516) -> Option<CFRetained<CGPath>> {
517 extern "C-unwind" {
518 fn CGPathCreateCopyByUnioningPath(
519 path: Option<&CGPath>,
520 mask_path: Option<&CGPath>,
521 even_odd_fill_rule: bool,
522 ) -> Option<NonNull<CGPath>>;
523 }
524 let ret = unsafe { CGPathCreateCopyByUnioningPath(path, mask_path, even_odd_fill_rule) };
525 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
526}
527
528#[inline]
529pub unsafe extern "C-unwind" fn CGPathCreateCopyByIntersectingPath(
530 path: Option<&CGPath>,
531 mask_path: Option<&CGPath>,
532 even_odd_fill_rule: bool,
533) -> Option<CFRetained<CGPath>> {
534 extern "C-unwind" {
535 fn CGPathCreateCopyByIntersectingPath(
536 path: Option<&CGPath>,
537 mask_path: Option<&CGPath>,
538 even_odd_fill_rule: bool,
539 ) -> Option<NonNull<CGPath>>;
540 }
541 let ret = unsafe { CGPathCreateCopyByIntersectingPath(path, mask_path, even_odd_fill_rule) };
542 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
543}
544
545#[inline]
546pub unsafe extern "C-unwind" fn CGPathCreateCopyBySubtractingPath(
547 path: Option<&CGPath>,
548 mask_path: Option<&CGPath>,
549 even_odd_fill_rule: bool,
550) -> Option<CFRetained<CGPath>> {
551 extern "C-unwind" {
552 fn CGPathCreateCopyBySubtractingPath(
553 path: Option<&CGPath>,
554 mask_path: Option<&CGPath>,
555 even_odd_fill_rule: bool,
556 ) -> Option<NonNull<CGPath>>;
557 }
558 let ret = unsafe { CGPathCreateCopyBySubtractingPath(path, mask_path, even_odd_fill_rule) };
559 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
560}
561
562#[inline]
563pub unsafe extern "C-unwind" fn CGPathCreateCopyBySymmetricDifferenceOfPath(
564 path: Option<&CGPath>,
565 mask_path: Option<&CGPath>,
566 even_odd_fill_rule: bool,
567) -> Option<CFRetained<CGPath>> {
568 extern "C-unwind" {
569 fn CGPathCreateCopyBySymmetricDifferenceOfPath(
570 path: Option<&CGPath>,
571 mask_path: Option<&CGPath>,
572 even_odd_fill_rule: bool,
573 ) -> Option<NonNull<CGPath>>;
574 }
575 let ret =
576 unsafe { CGPathCreateCopyBySymmetricDifferenceOfPath(path, mask_path, even_odd_fill_rule) };
577 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
578}
579
580#[inline]
581pub unsafe extern "C-unwind" fn CGPathCreateCopyOfLineBySubtractingPath(
582 path: Option<&CGPath>,
583 mask_path: Option<&CGPath>,
584 even_odd_fill_rule: bool,
585) -> Option<CFRetained<CGPath>> {
586 extern "C-unwind" {
587 fn CGPathCreateCopyOfLineBySubtractingPath(
588 path: Option<&CGPath>,
589 mask_path: Option<&CGPath>,
590 even_odd_fill_rule: bool,
591 ) -> Option<NonNull<CGPath>>;
592 }
593 let ret =
594 unsafe { CGPathCreateCopyOfLineBySubtractingPath(path, mask_path, even_odd_fill_rule) };
595 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
596}
597
598#[inline]
599pub unsafe extern "C-unwind" fn CGPathCreateCopyOfLineByIntersectingPath(
600 path: Option<&CGPath>,
601 mask_path: Option<&CGPath>,
602 even_odd_fill_rule: bool,
603) -> Option<CFRetained<CGPath>> {
604 extern "C-unwind" {
605 fn CGPathCreateCopyOfLineByIntersectingPath(
606 path: Option<&CGPath>,
607 mask_path: Option<&CGPath>,
608 even_odd_fill_rule: bool,
609 ) -> Option<NonNull<CGPath>>;
610 }
611 let ret =
612 unsafe { CGPathCreateCopyOfLineByIntersectingPath(path, mask_path, even_odd_fill_rule) };
613 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
614}
615
616#[inline]
617pub unsafe extern "C-unwind" fn CGPathCreateSeparateComponents(
618 path: Option<&CGPath>,
619 even_odd_fill_rule: bool,
620) -> Option<CFRetained<CFArray>> {
621 extern "C-unwind" {
622 fn CGPathCreateSeparateComponents(
623 path: Option<&CGPath>,
624 even_odd_fill_rule: bool,
625 ) -> Option<NonNull<CFArray>>;
626 }
627 let ret = unsafe { CGPathCreateSeparateComponents(path, even_odd_fill_rule) };
628 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
629}
630
631#[inline]
632pub unsafe extern "C-unwind" fn CGPathCreateCopyByFlattening(
633 path: Option<&CGPath>,
634 flattening_threshold: CGFloat,
635) -> Option<CFRetained<CGPath>> {
636 extern "C-unwind" {
637 fn CGPathCreateCopyByFlattening(
638 path: Option<&CGPath>,
639 flattening_threshold: CGFloat,
640 ) -> Option<NonNull<CGPath>>;
641 }
642 let ret = unsafe { CGPathCreateCopyByFlattening(path, flattening_threshold) };
643 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
644}
645
646extern "C-unwind" {
647 pub fn CGPathIntersectsPath(
648 path1: Option<&CGPath>,
649 path2: Option<&CGPath>,
650 even_odd_fill_rule: bool,
651 ) -> bool;
652}