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")]
35unsafe impl NSCoding for SKSpriteNode {}
36
37#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
38#[cfg(target_os = "macos")]
39unsafe impl NSCopying for SKSpriteNode {}
40
41#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
42#[cfg(target_os = "macos")]
43unsafe impl CopyingHelper for SKSpriteNode {
44    type Result = Self;
45}
46
47#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
48#[cfg(target_os = "macos")]
49unsafe impl NSObjectProtocol for SKSpriteNode {}
50
51#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
52#[cfg(target_os = "macos")]
53unsafe impl NSSecureCoding for SKSpriteNode {}
54
55#[cfg(all(
56    feature = "SKNode",
57    feature = "SKWarpGeometry",
58    feature = "objc2-app-kit"
59))]
60#[cfg(target_os = "macos")]
61unsafe impl SKWarpable for SKSpriteNode {}
62
63#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
64#[cfg(target_os = "macos")]
65impl SKSpriteNode {
66    extern_methods!(
67        #[cfg(all(feature = "SKTexture", feature = "objc2-core-foundation"))]
68        /// Create a sprite with an SKTexture and the specified size.
69        ///
70        /// Parameter `texture`: the texture to reference for size and content
71        ///
72        /// Parameter `size`: the size of the sprite in points
73        #[unsafe(method(spriteNodeWithTexture:size:))]
74        #[unsafe(method_family = none)]
75        pub unsafe fn spriteNodeWithTexture_size(
76            texture: Option<&SKTexture>,
77            size: CGSize,
78            mtm: MainThreadMarker,
79        ) -> Retained<Self>;
80
81        #[cfg(feature = "SKTexture")]
82        /// Create a sprite with an SKTexture and set its size to the SKTexture's pixel width/height.
83        ///
84        /// Parameter `texture`: the texture to reference for size and content
85        #[unsafe(method(spriteNodeWithTexture:))]
86        #[unsafe(method_family = none)]
87        pub unsafe fn spriteNodeWithTexture(
88            texture: Option<&SKTexture>,
89            mtm: MainThreadMarker,
90        ) -> Retained<Self>;
91
92        #[cfg(feature = "SKTexture")]
93        #[unsafe(method(spriteNodeWithTexture:normalMap:))]
94        #[unsafe(method_family = none)]
95        pub unsafe fn spriteNodeWithTexture_normalMap(
96            texture: Option<&SKTexture>,
97            normal_map: Option<&SKTexture>,
98            mtm: MainThreadMarker,
99        ) -> Retained<Self>;
100
101        /// 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)
102        /// 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.
103        /// 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.
104        ///
105        /// Parameter `name`: is the name of an image file stored in the app bundle.
106        #[unsafe(method(spriteNodeWithImageNamed:))]
107        #[unsafe(method_family = none)]
108        pub unsafe fn spriteNodeWithImageNamed(
109            name: &NSString,
110            mtm: MainThreadMarker,
111        ) -> Retained<Self>;
112
113        #[unsafe(method(spriteNodeWithImageNamed:normalMapped:))]
114        #[unsafe(method_family = none)]
115        pub unsafe fn spriteNodeWithImageNamed_normalMapped(
116            name: &NSString,
117            generate_normal_map: bool,
118            mtm: MainThreadMarker,
119        ) -> Retained<Self>;
120
121        #[cfg(feature = "objc2-core-foundation")]
122        /// Create a sprite with a color and the specified bounds.
123        ///
124        /// Parameter `color`: the color to use for tinting the sprite.
125        ///
126        /// Parameter `size`: the size of the sprite in points
127        #[unsafe(method(spriteNodeWithColor:size:))]
128        #[unsafe(method_family = none)]
129        pub unsafe fn spriteNodeWithColor_size(
130            color: &NSColor,
131            size: CGSize,
132            mtm: MainThreadMarker,
133        ) -> Retained<Self>;
134
135        #[cfg(all(feature = "SKTexture", feature = "objc2-core-foundation"))]
136        /// Designated Initializer
137        /// Initialize a sprite with a color and the specified bounds.
138        ///
139        /// Parameter `texture`: the texture to use (can be nil for colored sprite)
140        ///
141        /// Parameter `color`: the color to use for tinting the sprite.
142        ///
143        /// Parameter `size`: the size of the sprite in points
144        #[unsafe(method(initWithTexture:color:size:))]
145        #[unsafe(method_family = init)]
146        pub unsafe fn initWithTexture_color_size(
147            this: Allocated<Self>,
148            texture: Option<&SKTexture>,
149            color: &NSColor,
150            size: CGSize,
151        ) -> Retained<Self>;
152
153        #[cfg(feature = "SKTexture")]
154        /// Initialize a sprite with an SKTexture and set its size to the SKTexture's width/height.
155        ///
156        /// Parameter `texture`: the texture to reference for size and content
157        #[unsafe(method(initWithTexture:))]
158        #[unsafe(method_family = init)]
159        pub unsafe fn initWithTexture(
160            this: Allocated<Self>,
161            texture: Option<&SKTexture>,
162        ) -> Retained<Self>;
163
164        /// 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)
165        /// 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.
166        /// 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.
167        ///
168        /// Parameter `name`: the name or path of the image to load.
169        #[unsafe(method(initWithImageNamed:))]
170        #[unsafe(method_family = init)]
171        pub unsafe fn initWithImageNamed(this: Allocated<Self>, name: &NSString) -> Retained<Self>;
172
173        #[cfg(feature = "objc2-core-foundation")]
174        /// Initialize a sprite with a color and the specified bounds.
175        ///
176        /// Parameter `color`: the color to use for tinting the sprite.
177        ///
178        /// Parameter `size`: the size of the sprite in points
179        #[unsafe(method(initWithColor:size:))]
180        #[unsafe(method_family = init)]
181        pub unsafe fn initWithColor_size(
182            this: Allocated<Self>,
183            color: &NSColor,
184            size: CGSize,
185        ) -> Retained<Self>;
186
187        /// Support coding and decoding via NSKeyedArchiver.
188        #[unsafe(method(initWithCoder:))]
189        #[unsafe(method_family = init)]
190        pub unsafe fn initWithCoder(
191            this: Allocated<Self>,
192            a_decoder: &NSCoder,
193        ) -> Option<Retained<Self>>;
194
195        #[cfg(feature = "SKTexture")]
196        /// Texture to be drawn (is stretched to fill the sprite)
197        #[unsafe(method(texture))]
198        #[unsafe(method_family = none)]
199        pub unsafe fn texture(&self) -> Option<Retained<SKTexture>>;
200
201        #[cfg(feature = "SKTexture")]
202        /// Setter for [`texture`][Self::texture].
203        #[unsafe(method(setTexture:))]
204        #[unsafe(method_family = none)]
205        pub unsafe fn setTexture(&self, texture: Option<&SKTexture>);
206
207        #[cfg(feature = "SKTexture")]
208        /// Texture to use for generating normals that lights use to light this sprite.
209        ///
210        /// This will only be used if the sprite is lit by at least one light.
211        ///
212        ///
213        /// See: SKLightNode
214        ///
215        /// See: lightingBitMask
216        #[unsafe(method(normalTexture))]
217        #[unsafe(method_family = none)]
218        pub unsafe fn normalTexture(&self) -> Option<Retained<SKTexture>>;
219
220        #[cfg(feature = "SKTexture")]
221        /// Setter for [`normalTexture`][Self::normalTexture].
222        #[unsafe(method(setNormalTexture:))]
223        #[unsafe(method_family = none)]
224        pub unsafe fn setNormalTexture(&self, normal_texture: Option<&SKTexture>);
225
226        /// Bitmask to indicate being lit by a set of lights using overlapping lighting categories.
227        ///
228        /// A light whose category is set to a value that masks to non-zero using this mask will
229        /// apply light to this sprite.
230        ///
231        /// When used together with a normal texture, complex lighting effects can be used.
232        #[unsafe(method(lightingBitMask))]
233        #[unsafe(method_family = none)]
234        pub unsafe fn lightingBitMask(&self) -> u32;
235
236        /// Setter for [`lightingBitMask`][Self::lightingBitMask].
237        #[unsafe(method(setLightingBitMask:))]
238        #[unsafe(method_family = none)]
239        pub unsafe fn setLightingBitMask(&self, lighting_bit_mask: u32);
240
241        #[unsafe(method(shadowCastBitMask))]
242        #[unsafe(method_family = none)]
243        pub unsafe fn shadowCastBitMask(&self) -> u32;
244
245        /// Setter for [`shadowCastBitMask`][Self::shadowCastBitMask].
246        #[unsafe(method(setShadowCastBitMask:))]
247        #[unsafe(method_family = none)]
248        pub unsafe fn setShadowCastBitMask(&self, shadow_cast_bit_mask: u32);
249
250        #[unsafe(method(shadowedBitMask))]
251        #[unsafe(method_family = none)]
252        pub unsafe fn shadowedBitMask(&self) -> u32;
253
254        /// Setter for [`shadowedBitMask`][Self::shadowedBitMask].
255        #[unsafe(method(setShadowedBitMask:))]
256        #[unsafe(method_family = none)]
257        pub unsafe fn setShadowedBitMask(&self, shadowed_bit_mask: u32);
258
259        #[cfg(feature = "objc2-core-foundation")]
260        /// Controls how the texture is stretched to fill the SKSpriteNode. Stretching is performed via a 9-part algorithm where the upper
261        /// &
262        /// 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).
263        #[unsafe(method(centerRect))]
264        #[unsafe(method_family = none)]
265        pub unsafe fn centerRect(&self) -> CGRect;
266
267        #[cfg(feature = "objc2-core-foundation")]
268        /// Setter for [`centerRect`][Self::centerRect].
269        #[unsafe(method(setCenterRect:))]
270        #[unsafe(method_family = none)]
271        pub unsafe fn setCenterRect(&self, center_rect: CGRect);
272
273        #[cfg(feature = "objc2-core-foundation")]
274        /// 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.
275        #[unsafe(method(colorBlendFactor))]
276        #[unsafe(method_family = none)]
277        pub unsafe fn colorBlendFactor(&self) -> CGFloat;
278
279        #[cfg(feature = "objc2-core-foundation")]
280        /// Setter for [`colorBlendFactor`][Self::colorBlendFactor].
281        #[unsafe(method(setColorBlendFactor:))]
282        #[unsafe(method_family = none)]
283        pub unsafe fn setColorBlendFactor(&self, color_blend_factor: CGFloat);
284
285        /// Base color for the sprite (If no texture is present, the color still is drawn)
286        #[unsafe(method(color))]
287        #[unsafe(method_family = none)]
288        pub unsafe fn color(&self) -> Retained<NSColor>;
289
290        /// Setter for [`color`][Self::color].
291        #[unsafe(method(setColor:))]
292        #[unsafe(method_family = none)]
293        pub unsafe fn setColor(&self, color: &NSColor);
294
295        /// Sets the blend mode to use when composing the sprite with the final framebuffer.
296        ///
297        /// See: SKNode.SKBlendMode
298        #[unsafe(method(blendMode))]
299        #[unsafe(method_family = none)]
300        pub unsafe fn blendMode(&self) -> SKBlendMode;
301
302        /// Setter for [`blendMode`][Self::blendMode].
303        #[unsafe(method(setBlendMode:))]
304        #[unsafe(method_family = none)]
305        pub unsafe fn setBlendMode(&self, blend_mode: SKBlendMode);
306
307        #[cfg(feature = "objc2-core-foundation")]
308        /// 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.
309        #[unsafe(method(anchorPoint))]
310        #[unsafe(method_family = none)]
311        pub unsafe fn anchorPoint(&self) -> CGPoint;
312
313        #[cfg(feature = "objc2-core-foundation")]
314        /// Setter for [`anchorPoint`][Self::anchorPoint].
315        #[unsafe(method(setAnchorPoint:))]
316        #[unsafe(method_family = none)]
317        pub unsafe fn setAnchorPoint(&self, anchor_point: CGPoint);
318
319        #[cfg(feature = "objc2-core-foundation")]
320        /// Set the size of the sprite (in parent's coordinate space)
321        #[unsafe(method(size))]
322        #[unsafe(method_family = none)]
323        pub unsafe fn size(&self) -> CGSize;
324
325        #[cfg(feature = "objc2-core-foundation")]
326        /// Setter for [`size`][Self::size].
327        #[unsafe(method(setSize:))]
328        #[unsafe(method_family = none)]
329        pub unsafe fn setSize(&self, size: CGSize);
330
331        #[cfg(feature = "objc2-core-foundation")]
332        /// Adjust the sprite's xScale
333        /// &
334        /// yScale to achieve the desired size (in parent's coordinate space)
335        #[unsafe(method(scaleToSize:))]
336        #[unsafe(method_family = none)]
337        pub unsafe fn scaleToSize(&self, size: CGSize);
338
339        #[cfg(feature = "SKShader")]
340        #[unsafe(method(shader))]
341        #[unsafe(method_family = none)]
342        pub unsafe fn shader(&self) -> Option<Retained<SKShader>>;
343
344        #[cfg(feature = "SKShader")]
345        /// Setter for [`shader`][Self::shader].
346        #[unsafe(method(setShader:))]
347        #[unsafe(method_family = none)]
348        pub unsafe fn setShader(&self, shader: Option<&SKShader>);
349
350        #[cfg(feature = "SKAttribute")]
351        /// Optional dictionary of SKAttributeValues
352        /// Attributes can be used with custom SKShaders.
353        #[unsafe(method(attributeValues))]
354        #[unsafe(method_family = none)]
355        pub unsafe fn attributeValues(&self) -> Retained<NSDictionary<NSString, SKAttributeValue>>;
356
357        #[cfg(feature = "SKAttribute")]
358        /// Setter for [`attributeValues`][Self::attributeValues].
359        #[unsafe(method(setAttributeValues:))]
360        #[unsafe(method_family = none)]
361        pub unsafe fn setAttributeValues(
362            &self,
363            attribute_values: &NSDictionary<NSString, SKAttributeValue>,
364        );
365
366        #[cfg(feature = "SKAttribute")]
367        #[unsafe(method(valueForAttributeNamed:))]
368        #[unsafe(method_family = none)]
369        pub unsafe fn valueForAttributeNamed(
370            &self,
371            key: &NSString,
372        ) -> Option<Retained<SKAttributeValue>>;
373
374        #[cfg(feature = "SKAttribute")]
375        #[unsafe(method(setValue:forAttributeNamed:))]
376        #[unsafe(method_family = none)]
377        pub unsafe fn setValue_forAttributeNamed(&self, value: &SKAttributeValue, key: &NSString);
378    );
379}
380
381/// Methods declared on superclass `SKNode`.
382#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
383#[cfg(target_os = "macos")]
384impl SKSpriteNode {
385    extern_methods!(
386        #[unsafe(method(init))]
387        #[unsafe(method_family = init)]
388        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
389
390        #[unsafe(method(node))]
391        #[unsafe(method_family = none)]
392        pub unsafe fn node(mtm: MainThreadMarker) -> Retained<Self>;
393
394        #[unsafe(method(nodeWithFileNamed:))]
395        #[unsafe(method_family = none)]
396        pub unsafe fn nodeWithFileNamed(
397            filename: &NSString,
398            mtm: MainThreadMarker,
399        ) -> Option<Retained<Self>>;
400
401        #[unsafe(method(nodeWithFileNamed:securelyWithClasses:andError:_))]
402        #[unsafe(method_family = none)]
403        pub unsafe fn nodeWithFileNamed_securelyWithClasses_andError(
404            filename: &NSString,
405            classes: &NSSet<AnyClass>,
406            mtm: MainThreadMarker,
407        ) -> Result<Retained<Self>, Retained<NSError>>;
408    );
409}
410
411/// Methods declared on superclass `NSObject`.
412#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
413#[cfg(target_os = "macos")]
414impl SKSpriteNode {
415    extern_methods!(
416        #[unsafe(method(new))]
417        #[unsafe(method_family = new)]
418        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
419    );
420}