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#[doc(alias = "CGShadingRef")]
15#[repr(C)]
16pub struct CGShading {
17 inner: [u8; 0],
18 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
19}
20
21cf_type!(
22 unsafe impl CGShading {}
23);
24#[cfg(feature = "objc2")]
25cf_objc2_type!(
26 unsafe impl RefEncode<"CGShading"> for CGShading {}
27);
28
29unsafe impl ConcreteType for CGShading {
30 #[doc(alias = "CGShadingGetTypeID")]
31 #[inline]
32 fn type_id() -> CFTypeID {
33 extern "C-unwind" {
34 fn CGShadingGetTypeID() -> CFTypeID;
35 }
36 unsafe { CGShadingGetTypeID() }
37 }
38}
39
40impl CGShading {
41 #[doc(alias = "CGShadingCreateAxial")]
42 #[cfg(all(feature = "CGColorSpace", feature = "CGFunction"))]
43 #[inline]
44 pub fn new_axial(
45 space: Option<&CGColorSpace>,
46 start: CGPoint,
47 end: CGPoint,
48 function: Option<&CGFunction>,
49 extend_start: bool,
50 extend_end: bool,
51 ) -> Option<CFRetained<CGShading>> {
52 extern "C-unwind" {
53 fn CGShadingCreateAxial(
54 space: Option<&CGColorSpace>,
55 start: CGPoint,
56 end: CGPoint,
57 function: Option<&CGFunction>,
58 extend_start: bool,
59 extend_end: bool,
60 ) -> Option<NonNull<CGShading>>;
61 }
62 let ret =
63 unsafe { CGShadingCreateAxial(space, start, end, function, extend_start, extend_end) };
64 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
65 }
66
67 #[doc(alias = "CGShadingCreateAxialWithContentHeadroom")]
68 #[cfg(all(feature = "CGColorSpace", feature = "CGFunction"))]
69 #[inline]
70 pub fn new_axial_with_content_headroom(
71 headroom: c_float,
72 space: Option<&CGColorSpace>,
73 start: CGPoint,
74 end: CGPoint,
75 function: Option<&CGFunction>,
76 extend_start: bool,
77 extend_end: bool,
78 ) -> Option<CFRetained<CGShading>> {
79 extern "C-unwind" {
80 fn CGShadingCreateAxialWithContentHeadroom(
81 headroom: c_float,
82 space: Option<&CGColorSpace>,
83 start: CGPoint,
84 end: CGPoint,
85 function: Option<&CGFunction>,
86 extend_start: bool,
87 extend_end: bool,
88 ) -> Option<NonNull<CGShading>>;
89 }
90 let ret = unsafe {
91 CGShadingCreateAxialWithContentHeadroom(
92 headroom,
93 space,
94 start,
95 end,
96 function,
97 extend_start,
98 extend_end,
99 )
100 };
101 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
102 }
103
104 #[doc(alias = "CGShadingCreateRadial")]
105 #[cfg(all(feature = "CGColorSpace", feature = "CGFunction"))]
106 #[inline]
107 pub fn new_radial(
108 space: Option<&CGColorSpace>,
109 start: CGPoint,
110 start_radius: CGFloat,
111 end: CGPoint,
112 end_radius: CGFloat,
113 function: Option<&CGFunction>,
114 extend_start: bool,
115 extend_end: bool,
116 ) -> Option<CFRetained<CGShading>> {
117 extern "C-unwind" {
118 fn CGShadingCreateRadial(
119 space: Option<&CGColorSpace>,
120 start: CGPoint,
121 start_radius: CGFloat,
122 end: CGPoint,
123 end_radius: CGFloat,
124 function: Option<&CGFunction>,
125 extend_start: bool,
126 extend_end: bool,
127 ) -> Option<NonNull<CGShading>>;
128 }
129 let ret = unsafe {
130 CGShadingCreateRadial(
131 space,
132 start,
133 start_radius,
134 end,
135 end_radius,
136 function,
137 extend_start,
138 extend_end,
139 )
140 };
141 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
142 }
143
144 #[doc(alias = "CGShadingCreateRadialWithContentHeadroom")]
145 #[cfg(all(feature = "CGColorSpace", feature = "CGFunction"))]
146 #[inline]
147 pub fn new_radial_with_content_headroom(
148 headroom: c_float,
149 space: Option<&CGColorSpace>,
150 start: CGPoint,
151 start_radius: CGFloat,
152 end: CGPoint,
153 end_radius: CGFloat,
154 function: Option<&CGFunction>,
155 extend_start: bool,
156 extend_end: bool,
157 ) -> Option<CFRetained<CGShading>> {
158 extern "C-unwind" {
159 fn CGShadingCreateRadialWithContentHeadroom(
160 headroom: c_float,
161 space: Option<&CGColorSpace>,
162 start: CGPoint,
163 start_radius: CGFloat,
164 end: CGPoint,
165 end_radius: CGFloat,
166 function: Option<&CGFunction>,
167 extend_start: bool,
168 extend_end: bool,
169 ) -> Option<NonNull<CGShading>>;
170 }
171 let ret = unsafe {
172 CGShadingCreateRadialWithContentHeadroom(
173 headroom,
174 space,
175 start,
176 start_radius,
177 end,
178 end_radius,
179 function,
180 extend_start,
181 extend_end,
182 )
183 };
184 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
185 }
186
187 #[doc(alias = "CGShadingGetContentHeadroom")]
188 #[inline]
189 pub fn content_headroom(shading: Option<&CGShading>) -> c_float {
190 extern "C-unwind" {
191 fn CGShadingGetContentHeadroom(shading: Option<&CGShading>) -> c_float;
192 }
193 unsafe { CGShadingGetContentHeadroom(shading) }
194 }
195}
196
197#[cfg(all(feature = "CGColorSpace", feature = "CGFunction"))]
198#[deprecated = "renamed to `CGShading::new_axial`"]
199#[inline]
200pub extern "C-unwind" fn CGShadingCreateAxial(
201 space: Option<&CGColorSpace>,
202 start: CGPoint,
203 end: CGPoint,
204 function: Option<&CGFunction>,
205 extend_start: bool,
206 extend_end: bool,
207) -> Option<CFRetained<CGShading>> {
208 extern "C-unwind" {
209 fn CGShadingCreateAxial(
210 space: Option<&CGColorSpace>,
211 start: CGPoint,
212 end: CGPoint,
213 function: Option<&CGFunction>,
214 extend_start: bool,
215 extend_end: bool,
216 ) -> Option<NonNull<CGShading>>;
217 }
218 let ret =
219 unsafe { CGShadingCreateAxial(space, start, end, function, extend_start, extend_end) };
220 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
221}
222
223#[cfg(all(feature = "CGColorSpace", feature = "CGFunction"))]
224#[deprecated = "renamed to `CGShading::new_axial_with_content_headroom`"]
225#[inline]
226pub extern "C-unwind" fn CGShadingCreateAxialWithContentHeadroom(
227 headroom: c_float,
228 space: Option<&CGColorSpace>,
229 start: CGPoint,
230 end: CGPoint,
231 function: Option<&CGFunction>,
232 extend_start: bool,
233 extend_end: bool,
234) -> Option<CFRetained<CGShading>> {
235 extern "C-unwind" {
236 fn CGShadingCreateAxialWithContentHeadroom(
237 headroom: c_float,
238 space: Option<&CGColorSpace>,
239 start: CGPoint,
240 end: CGPoint,
241 function: Option<&CGFunction>,
242 extend_start: bool,
243 extend_end: bool,
244 ) -> Option<NonNull<CGShading>>;
245 }
246 let ret = unsafe {
247 CGShadingCreateAxialWithContentHeadroom(
248 headroom,
249 space,
250 start,
251 end,
252 function,
253 extend_start,
254 extend_end,
255 )
256 };
257 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
258}
259
260#[cfg(all(feature = "CGColorSpace", feature = "CGFunction"))]
261#[deprecated = "renamed to `CGShading::new_radial`"]
262#[inline]
263pub extern "C-unwind" fn CGShadingCreateRadial(
264 space: Option<&CGColorSpace>,
265 start: CGPoint,
266 start_radius: CGFloat,
267 end: CGPoint,
268 end_radius: CGFloat,
269 function: Option<&CGFunction>,
270 extend_start: bool,
271 extend_end: bool,
272) -> Option<CFRetained<CGShading>> {
273 extern "C-unwind" {
274 fn CGShadingCreateRadial(
275 space: Option<&CGColorSpace>,
276 start: CGPoint,
277 start_radius: CGFloat,
278 end: CGPoint,
279 end_radius: CGFloat,
280 function: Option<&CGFunction>,
281 extend_start: bool,
282 extend_end: bool,
283 ) -> Option<NonNull<CGShading>>;
284 }
285 let ret = unsafe {
286 CGShadingCreateRadial(
287 space,
288 start,
289 start_radius,
290 end,
291 end_radius,
292 function,
293 extend_start,
294 extend_end,
295 )
296 };
297 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
298}
299
300#[cfg(all(feature = "CGColorSpace", feature = "CGFunction"))]
301#[deprecated = "renamed to `CGShading::new_radial_with_content_headroom`"]
302#[inline]
303pub extern "C-unwind" fn CGShadingCreateRadialWithContentHeadroom(
304 headroom: c_float,
305 space: Option<&CGColorSpace>,
306 start: CGPoint,
307 start_radius: CGFloat,
308 end: CGPoint,
309 end_radius: CGFloat,
310 function: Option<&CGFunction>,
311 extend_start: bool,
312 extend_end: bool,
313) -> Option<CFRetained<CGShading>> {
314 extern "C-unwind" {
315 fn CGShadingCreateRadialWithContentHeadroom(
316 headroom: c_float,
317 space: Option<&CGColorSpace>,
318 start: CGPoint,
319 start_radius: CGFloat,
320 end: CGPoint,
321 end_radius: CGFloat,
322 function: Option<&CGFunction>,
323 extend_start: bool,
324 extend_end: bool,
325 ) -> Option<NonNull<CGShading>>;
326 }
327 let ret = unsafe {
328 CGShadingCreateRadialWithContentHeadroom(
329 headroom,
330 space,
331 start,
332 start_radius,
333 end,
334 end_radius,
335 function,
336 extend_start,
337 extend_end,
338 )
339 };
340 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
341}
342
343#[deprecated = "renamed to `CGShading::content_headroom`"]
344#[inline]
345pub extern "C-unwind" fn CGShadingGetContentHeadroom(shading: Option<&CGShading>) -> c_float {
346 extern "C-unwind" {
347 fn CGShadingGetContentHeadroom(shading: Option<&CGShading>) -> c_float;
348 }
349 unsafe { CGShadingGetContentHeadroom(shading) }
350}