objc2_sprite_kit/generated/
SKSpriteNode.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-app-kit")]
7#[cfg(target_os = "macos")]
8use objc2_app_kit::*;
9#[cfg(feature = "objc2-core-foundation")]
10use objc2_core_foundation::*;
11use objc2_foundation::*;
12
13use crate::*;
14
15extern_class!(
16    /// A Sprite is a textured 2D node. It can be placed, rotated, scaled and animated like any other node except it draws a textured rectangle specified by the bounds and anchor point.
17    ///
18    /// Sprites are used to define quad primitives with color and/or textures applied to them.
19    /// See
20    /// <a href="http://en.wikipedia.org/wiki/Sprite_(computer_graphics)">
21    /// wiki
22    /// </a>
23    /// for a definition of a Sprite.
24    ///
25    /// See also [Apple's documentation](https://developer.apple.com/documentation/spritekit/skspritenode?language=objc)
26    #[unsafe(super(SKNode, NSResponder, NSObject))]
27    #[derive(Debug, PartialEq, Eq, Hash)]
28    #[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
29    #[cfg(target_os = "macos")]
30    pub struct SKSpriteNode;
31);
32
33#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
34#[cfg(target_os = "macos")]
35extern_conformance!(
36    unsafe impl NSCoding for SKSpriteNode {}
37);
38
39#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
40#[cfg(target_os = "macos")]
41extern_conformance!(
42    unsafe impl NSCopying for SKSpriteNode {}
43);
44
45#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
46#[cfg(target_os = "macos")]
47unsafe impl CopyingHelper for SKSpriteNode {
48    type Result = Self;
49}
50
51#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
52#[cfg(target_os = "macos")]
53extern_conformance!(
54    unsafe impl NSObjectProtocol for SKSpriteNode {}
55);
56
57#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
58#[cfg(target_os = "macos")]
59extern_conformance!(
60    unsafe impl NSSecureCoding for SKSpriteNode {}
61);
62
63#[cfg(all(
64    feature = "SKNode",
65    feature = "SKWarpGeometry",
66    feature = "objc2-app-kit"
67))]
68#[cfg(target_os = "macos")]
69extern_conformance!(
70    unsafe impl SKWarpable for SKSpriteNode {}
71);
72
73#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
74#[cfg(target_os = "macos")]
75impl SKSpriteNode {
76    extern_methods!(
77        #[cfg(all(feature = "SKTexture", feature = "objc2-core-foundation"))]
78        /// Create a sprite with an SKTexture and the specified size.
79        ///
80        /// Parameter `texture`: the texture to reference for size and content
81        ///
82        /// Parameter `size`: the size of the sprite in points
83        #[unsafe(method(spriteNodeWithTexture:size:))]
84        #[unsafe(method_family = none)]
85        pub unsafe fn spriteNodeWithTexture_size(
86            texture: Option<&SKTexture>,
87            size: CGSize,
88            mtm: MainThreadMarker,
89        ) -> Retained<Self>;
90
91        #[cfg(feature = "SKTexture")]
92        /// Create a sprite with an SKTexture and set its size to the SKTexture's pixel width/height.
93        ///
94        /// Parameter `texture`: the texture to reference for size and content
95        #[unsafe(method(spriteNodeWithTexture:))]
96        #[unsafe(method_family = none)]
97        pub unsafe fn spriteNodeWithTexture(
98            texture: Option<&SKTexture>,
99            mtm: MainThreadMarker,
100        ) -> Retained<Self>;
101
102        #[cfg(feature = "SKTexture")]
103        #[unsafe(method(spriteNodeWithTexture:normalMap:))]
104        #[unsafe(method_family = none)]
105        pub unsafe fn spriteNodeWithTexture_normalMap(
106            texture: Option<&SKTexture>,
107            normal_map: Option<&SKTexture>,
108            mtm: MainThreadMarker,
109        ) -> Retained<Self>;
110
111        /// Create a sprite with an image from your app bundle (An SKTexture is created for the image and set on the sprite. Its size is set to the SKTexture's pixel width/height)
112        /// The position of the sprite is (0, 0) and the texture anchored at (0.5, 0.5), so that it is offset by half the width and half the height.
113        /// Thus the sprite has the texture centered about the position. If you wish to have the texture anchored at a different offset set the anchorPoint to another pair of values in the interval from 0.0 up to and including 1.0.
114        ///
115        /// Parameter `name`: is the name of an image file stored in the app bundle.
116        #[unsafe(method(spriteNodeWithImageNamed:))]
117        #[unsafe(method_family = none)]
118        pub unsafe fn spriteNodeWithImageNamed(
119            name: &NSString,
120            mtm: MainThreadMarker,
121        ) -> Retained<Self>;
122
123        #[unsafe(method(spriteNodeWithImageNamed:normalMapped:))]
124        #[unsafe(method_family = none)]
125        pub unsafe fn spriteNodeWithImageNamed_normalMapped(
126            name: &NSString,
127            generate_normal_map: bool,
128            mtm: MainThreadMarker,
129        ) -> Retained<Self>;
130
131        #[cfg(feature = "objc2-core-foundation")]
132        /// Create a sprite with a color and the specified bounds.
133        ///
134        /// Parameter `color`: the color to use for tinting the sprite.
135        ///
136        /// Parameter `size`: the size of the sprite in points
137        #[unsafe(method(spriteNodeWithColor:size:))]
138        #[unsafe(method_family = none)]
139        pub unsafe fn spriteNodeWithColor_size(
140            color: &NSColor,
141            size: CGSize,
142            mtm: MainThreadMarker,
143        ) -> Retained<Self>;
144
145        #[cfg(all(feature = "SKTexture", feature = "objc2-core-foundation"))]
146        /// Designated Initializer
147        /// Initialize a sprite with a color and the specified bounds.
148        ///
149        /// Parameter `texture`: the texture to use (can be nil for colored sprite)
150        ///
151        /// Parameter `color`: the color to use for tinting the sprite.
152        ///
153        /// Parameter `size`: the size of the sprite in points
154        #[unsafe(method(initWithTexture:color:size:))]
155        #[unsafe(method_family = init)]
156        pub unsafe fn initWithTexture_color_size(
157            this: Allocated<Self>,
158            texture: Option<&SKTexture>,
159            color: &NSColor,
160            size: CGSize,
161        ) -> Retained<Self>;
162
163        #[cfg(feature = "SKTexture")]
164        /// Initialize a sprite with an SKTexture and set its size to the SKTexture's width/height.
165        ///
166        /// Parameter `texture`: the texture to reference for size and content
167        #[unsafe(method(initWithTexture:))]
168        #[unsafe(method_family = init)]
169        pub unsafe fn initWithTexture(
170            this: Allocated<Self>,
171            texture: Option<&SKTexture>,
172        ) -> Retained<Self>;
173
174        /// Initialize a sprite with an image from your app bundle (An SKTexture is created for the image and set on the sprite. Its size is set to the SKTexture's pixel width/height)
175        /// The position of the sprite is (0, 0) and the texture anchored at (0.5, 0.5), so that it is offset by half the width and half the height.
176        /// Thus the sprite has the texture centered about the position. If you wish to have the texture anchored at a different offset set the anchorPoint to another pair of values in the interval from 0.0 up to and including 1.0.
177        ///
178        /// Parameter `name`: the name or path of the image to load.
179        #[unsafe(method(initWithImageNamed:))]
180        #[unsafe(method_family = init)]
181        pub unsafe fn initWithImageNamed(this: Allocated<Self>, name: &NSString) -> Retained<Self>;
182
183        #[cfg(feature = "objc2-core-foundation")]
184        /// Initialize a sprite with a color and the specified bounds.
185        ///
186        /// Parameter `color`: the color to use for tinting the sprite.
187        ///
188        /// Parameter `size`: the size of the sprite in points
189        #[unsafe(method(initWithColor:size:))]
190        #[unsafe(method_family = init)]
191        pub unsafe fn initWithColor_size(
192            this: Allocated<Self>,
193            color: &NSColor,
194            size: CGSize,
195        ) -> Retained<Self>;
196
197        /// Support coding and decoding via NSKeyedArchiver.
198        ///
199        /// # Safety
200        ///
201        /// `a_decoder` possibly has further requirements.
202        #[unsafe(method(initWithCoder:))]
203        #[unsafe(method_family = init)]
204        pub unsafe fn initWithCoder(
205            this: Allocated<Self>,
206            a_decoder: &NSCoder,
207        ) -> Option<Retained<Self>>;
208
209        #[cfg(feature = "SKTexture")]
210        /// Texture to be drawn (is stretched to fill the sprite)
211        #[unsafe(method(texture))]
212        #[unsafe(method_family = none)]
213        pub unsafe fn texture(&self) -> Option<Retained<SKTexture>>;
214
215        #[cfg(feature = "SKTexture")]
216        /// Setter for [`texture`][Self::texture].
217        #[unsafe(method(setTexture:))]
218        #[unsafe(method_family = none)]
219        pub unsafe fn setTexture(&self, texture: Option<&SKTexture>);
220
221        #[cfg(feature = "SKTexture")]
222        /// Texture to use for generating normals that lights use to light this sprite.
223        ///
224        /// This will only be used if the sprite is lit by at least one light.
225        ///
226        ///
227        /// See: SKLightNode
228        ///
229        /// See: lightingBitMask
230        #[unsafe(method(normalTexture))]
231        #[unsafe(method_family = none)]
232        pub unsafe fn normalTexture(&self) -> Option<Retained<SKTexture>>;
233
234        #[cfg(feature = "SKTexture")]
235        /// Setter for [`normalTexture`][Self::normalTexture].
236        #[unsafe(method(setNormalTexture:))]
237        #[unsafe(method_family = none)]
238        pub unsafe fn setNormalTexture(&self, normal_texture: Option<&SKTexture>);
239
240        /// Bitmask to indicate being lit by a set of lights using overlapping lighting categories.
241        ///
242        /// A light whose category is set to a value that masks to non-zero using this mask will
243        /// apply light to this sprite.
244        ///
245        /// When used together with a normal texture, complex lighting effects can be used.
246        #[unsafe(method(lightingBitMask))]
247        #[unsafe(method_family = none)]
248        pub unsafe fn lightingBitMask(&self) -> u32;
249
250        /// Setter for [`lightingBitMask`][Self::lightingBitMask].
251        #[unsafe(method(setLightingBitMask:))]
252        #[unsafe(method_family = none)]
253        pub unsafe fn setLightingBitMask(&self, lighting_bit_mask: u32);
254
255        #[unsafe(method(shadowCastBitMask))]
256        #[unsafe(method_family = none)]
257        pub unsafe fn shadowCastBitMask(&self) -> u32;
258
259        /// Setter for [`shadowCastBitMask`][Self::shadowCastBitMask].
260        #[unsafe(method(setShadowCastBitMask:))]
261        #[unsafe(method_family = none)]
262        pub unsafe fn setShadowCastBitMask(&self, shadow_cast_bit_mask: u32);
263
264        #[unsafe(method(shadowedBitMask))]
265        #[unsafe(method_family = none)]
266        pub unsafe fn shadowedBitMask(&self) -> u32;
267
268        /// Setter for [`shadowedBitMask`][Self::shadowedBitMask].
269        #[unsafe(method(setShadowedBitMask:))]
270        #[unsafe(method_family = none)]
271        pub unsafe fn setShadowedBitMask(&self, shadowed_bit_mask: u32);
272
273        #[cfg(feature = "objc2-core-foundation")]
274        /// Controls how the texture is stretched to fill the SKSpriteNode. Stretching is performed via a 9-part algorithm where the upper
275        /// &
276        /// lower middle parts are scaled horizontally, the left and right middle parts are scaled vertically, the center is scaled in both directions, and the corners are preserved. The centerRect defines the center region in a (0.0 - 1.0) coordinate space. Defaults to {(0,0) (1,1)} (the entire texture is stretched).
277        #[unsafe(method(centerRect))]
278        #[unsafe(method_family = none)]
279        pub unsafe fn centerRect(&self) -> CGRect;
280
281        #[cfg(feature = "objc2-core-foundation")]
282        /// Setter for [`centerRect`][Self::centerRect].
283        #[unsafe(method(setCenterRect:))]
284        #[unsafe(method_family = none)]
285        pub unsafe fn setCenterRect(&self, center_rect: CGRect);
286
287        #[cfg(feature = "objc2-core-foundation")]
288        /// Controls the blending between the texture and the sprite's color. The valid interval of values is from 0.0 up to and including 1.0. A value above or below that interval is clamped to the minimum (0.0) if below or the maximum (1.0) if above.
289        #[unsafe(method(colorBlendFactor))]
290        #[unsafe(method_family = none)]
291        pub unsafe fn colorBlendFactor(&self) -> CGFloat;
292
293        #[cfg(feature = "objc2-core-foundation")]
294        /// Setter for [`colorBlendFactor`][Self::colorBlendFactor].
295        #[unsafe(method(setColorBlendFactor:))]
296        #[unsafe(method_family = none)]
297        pub unsafe fn setColorBlendFactor(&self, color_blend_factor: CGFloat);
298
299        /// Base color for the sprite (If no texture is present, the color still is drawn)
300        #[unsafe(method(color))]
301        #[unsafe(method_family = none)]
302        pub unsafe fn color(&self) -> Retained<NSColor>;
303
304        /// Setter for [`color`][Self::color].
305        #[unsafe(method(setColor:))]
306        #[unsafe(method_family = none)]
307        pub unsafe fn setColor(&self, color: &NSColor);
308
309        /// Sets the blend mode to use when composing the sprite with the final framebuffer.
310        ///
311        /// See: SKNode.SKBlendMode
312        #[unsafe(method(blendMode))]
313        #[unsafe(method_family = none)]
314        pub unsafe fn blendMode(&self) -> SKBlendMode;
315
316        /// Setter for [`blendMode`][Self::blendMode].
317        #[unsafe(method(setBlendMode:))]
318        #[unsafe(method_family = none)]
319        pub unsafe fn setBlendMode(&self, blend_mode: SKBlendMode);
320
321        #[cfg(feature = "objc2-core-foundation")]
322        /// Used to choose the location in the sprite that maps to its 'position' in the parent's coordinate space. The valid interval for each input is from 0.0 up to and including 1.0.
323        #[unsafe(method(anchorPoint))]
324        #[unsafe(method_family = none)]
325        pub unsafe fn anchorPoint(&self) -> CGPoint;
326
327        #[cfg(feature = "objc2-core-foundation")]
328        /// Setter for [`anchorPoint`][Self::anchorPoint].
329        #[unsafe(method(setAnchorPoint:))]
330        #[unsafe(method_family = none)]
331        pub unsafe fn setAnchorPoint(&self, anchor_point: CGPoint);
332
333        #[cfg(feature = "objc2-core-foundation")]
334        /// Set the size of the sprite (in parent's coordinate space)
335        #[unsafe(method(size))]
336        #[unsafe(method_family = none)]
337        pub unsafe fn size(&self) -> CGSize;
338
339        #[cfg(feature = "objc2-core-foundation")]
340        /// Setter for [`size`][Self::size].
341        #[unsafe(method(setSize:))]
342        #[unsafe(method_family = none)]
343        pub unsafe fn setSize(&self, size: CGSize);
344
345        #[cfg(feature = "objc2-core-foundation")]
346        /// Adjust the sprite's xScale
347        /// &
348        /// yScale to achieve the desired size (in parent's coordinate space)
349        #[unsafe(method(scaleToSize:))]
350        #[unsafe(method_family = none)]
351        pub unsafe fn scaleToSize(&self, size: CGSize);
352
353        #[cfg(feature = "SKShader")]
354        #[unsafe(method(shader))]
355        #[unsafe(method_family = none)]
356        pub unsafe fn shader(&self) -> Option<Retained<SKShader>>;
357
358        #[cfg(feature = "SKShader")]
359        /// Setter for [`shader`][Self::shader].
360        #[unsafe(method(setShader:))]
361        #[unsafe(method_family = none)]
362        pub unsafe fn setShader(&self, shader: Option<&SKShader>);
363
364        #[cfg(feature = "SKAttribute")]
365        /// Optional dictionary of SKAttributeValues
366        /// Attributes can be used with custom SKShaders.
367        #[unsafe(method(attributeValues))]
368        #[unsafe(method_family = none)]
369        pub unsafe fn attributeValues(&self) -> Retained<NSDictionary<NSString, SKAttributeValue>>;
370
371        #[cfg(feature = "SKAttribute")]
372        /// Setter for [`attributeValues`][Self::attributeValues].
373        ///
374        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
375        #[unsafe(method(setAttributeValues:))]
376        #[unsafe(method_family = none)]
377        pub unsafe fn setAttributeValues(
378            &self,
379            attribute_values: &NSDictionary<NSString, SKAttributeValue>,
380        );
381
382        #[cfg(feature = "SKAttribute")]
383        #[unsafe(method(valueForAttributeNamed:))]
384        #[unsafe(method_family = none)]
385        pub unsafe fn valueForAttributeNamed(
386            &self,
387            key: &NSString,
388        ) -> Option<Retained<SKAttributeValue>>;
389
390        #[cfg(feature = "SKAttribute")]
391        #[unsafe(method(setValue:forAttributeNamed:))]
392        #[unsafe(method_family = none)]
393        pub unsafe fn setValue_forAttributeNamed(&self, value: &SKAttributeValue, key: &NSString);
394    );
395}
396
397/// Methods declared on superclass `SKNode`.
398#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
399#[cfg(target_os = "macos")]
400impl SKSpriteNode {
401    extern_methods!(
402        #[unsafe(method(init))]
403        #[unsafe(method_family = init)]
404        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
405
406        #[unsafe(method(node))]
407        #[unsafe(method_family = none)]
408        pub unsafe fn node(mtm: MainThreadMarker) -> Retained<Self>;
409
410        #[unsafe(method(nodeWithFileNamed:))]
411        #[unsafe(method_family = none)]
412        pub unsafe fn nodeWithFileNamed(
413            filename: &NSString,
414            mtm: MainThreadMarker,
415        ) -> Option<Retained<Self>>;
416
417        /// # Safety
418        ///
419        /// `classes` generic probably has further requirements.
420        #[unsafe(method(nodeWithFileNamed:securelyWithClasses:andError:_))]
421        #[unsafe(method_family = none)]
422        pub unsafe fn nodeWithFileNamed_securelyWithClasses_andError(
423            filename: &NSString,
424            classes: &NSSet<AnyClass>,
425            mtm: MainThreadMarker,
426        ) -> Result<Retained<Self>, Retained<NSError>>;
427    );
428}
429
430/// Methods declared on superclass `NSObject`.
431#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
432#[cfg(target_os = "macos")]
433impl SKSpriteNode {
434    extern_methods!(
435        #[unsafe(method(new))]
436        #[unsafe(method_family = new)]
437        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
438    );
439}