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        #[unsafe(method(initWithCoder:))]
199        #[unsafe(method_family = init)]
200        pub unsafe fn initWithCoder(
201            this: Allocated<Self>,
202            a_decoder: &NSCoder,
203        ) -> Option<Retained<Self>>;
204
205        #[cfg(feature = "SKTexture")]
206        /// Texture to be drawn (is stretched to fill the sprite)
207        #[unsafe(method(texture))]
208        #[unsafe(method_family = none)]
209        pub unsafe fn texture(&self) -> Option<Retained<SKTexture>>;
210
211        #[cfg(feature = "SKTexture")]
212        /// Setter for [`texture`][Self::texture].
213        #[unsafe(method(setTexture:))]
214        #[unsafe(method_family = none)]
215        pub unsafe fn setTexture(&self, texture: Option<&SKTexture>);
216
217        #[cfg(feature = "SKTexture")]
218        /// Texture to use for generating normals that lights use to light this sprite.
219        ///
220        /// This will only be used if the sprite is lit by at least one light.
221        ///
222        ///
223        /// See: SKLightNode
224        ///
225        /// See: lightingBitMask
226        #[unsafe(method(normalTexture))]
227        #[unsafe(method_family = none)]
228        pub unsafe fn normalTexture(&self) -> Option<Retained<SKTexture>>;
229
230        #[cfg(feature = "SKTexture")]
231        /// Setter for [`normalTexture`][Self::normalTexture].
232        #[unsafe(method(setNormalTexture:))]
233        #[unsafe(method_family = none)]
234        pub unsafe fn setNormalTexture(&self, normal_texture: Option<&SKTexture>);
235
236        /// Bitmask to indicate being lit by a set of lights using overlapping lighting categories.
237        ///
238        /// A light whose category is set to a value that masks to non-zero using this mask will
239        /// apply light to this sprite.
240        ///
241        /// When used together with a normal texture, complex lighting effects can be used.
242        #[unsafe(method(lightingBitMask))]
243        #[unsafe(method_family = none)]
244        pub unsafe fn lightingBitMask(&self) -> u32;
245
246        /// Setter for [`lightingBitMask`][Self::lightingBitMask].
247        #[unsafe(method(setLightingBitMask:))]
248        #[unsafe(method_family = none)]
249        pub unsafe fn setLightingBitMask(&self, lighting_bit_mask: u32);
250
251        #[unsafe(method(shadowCastBitMask))]
252        #[unsafe(method_family = none)]
253        pub unsafe fn shadowCastBitMask(&self) -> u32;
254
255        /// Setter for [`shadowCastBitMask`][Self::shadowCastBitMask].
256        #[unsafe(method(setShadowCastBitMask:))]
257        #[unsafe(method_family = none)]
258        pub unsafe fn setShadowCastBitMask(&self, shadow_cast_bit_mask: u32);
259
260        #[unsafe(method(shadowedBitMask))]
261        #[unsafe(method_family = none)]
262        pub unsafe fn shadowedBitMask(&self) -> u32;
263
264        /// Setter for [`shadowedBitMask`][Self::shadowedBitMask].
265        #[unsafe(method(setShadowedBitMask:))]
266        #[unsafe(method_family = none)]
267        pub unsafe fn setShadowedBitMask(&self, shadowed_bit_mask: u32);
268
269        #[cfg(feature = "objc2-core-foundation")]
270        /// Controls how the texture is stretched to fill the SKSpriteNode. Stretching is performed via a 9-part algorithm where the upper
271        /// &
272        /// 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).
273        #[unsafe(method(centerRect))]
274        #[unsafe(method_family = none)]
275        pub unsafe fn centerRect(&self) -> CGRect;
276
277        #[cfg(feature = "objc2-core-foundation")]
278        /// Setter for [`centerRect`][Self::centerRect].
279        #[unsafe(method(setCenterRect:))]
280        #[unsafe(method_family = none)]
281        pub unsafe fn setCenterRect(&self, center_rect: CGRect);
282
283        #[cfg(feature = "objc2-core-foundation")]
284        /// 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.
285        #[unsafe(method(colorBlendFactor))]
286        #[unsafe(method_family = none)]
287        pub unsafe fn colorBlendFactor(&self) -> CGFloat;
288
289        #[cfg(feature = "objc2-core-foundation")]
290        /// Setter for [`colorBlendFactor`][Self::colorBlendFactor].
291        #[unsafe(method(setColorBlendFactor:))]
292        #[unsafe(method_family = none)]
293        pub unsafe fn setColorBlendFactor(&self, color_blend_factor: CGFloat);
294
295        /// Base color for the sprite (If no texture is present, the color still is drawn)
296        #[unsafe(method(color))]
297        #[unsafe(method_family = none)]
298        pub unsafe fn color(&self) -> Retained<NSColor>;
299
300        /// Setter for [`color`][Self::color].
301        #[unsafe(method(setColor:))]
302        #[unsafe(method_family = none)]
303        pub unsafe fn setColor(&self, color: &NSColor);
304
305        /// Sets the blend mode to use when composing the sprite with the final framebuffer.
306        ///
307        /// See: SKNode.SKBlendMode
308        #[unsafe(method(blendMode))]
309        #[unsafe(method_family = none)]
310        pub unsafe fn blendMode(&self) -> SKBlendMode;
311
312        /// Setter for [`blendMode`][Self::blendMode].
313        #[unsafe(method(setBlendMode:))]
314        #[unsafe(method_family = none)]
315        pub unsafe fn setBlendMode(&self, blend_mode: SKBlendMode);
316
317        #[cfg(feature = "objc2-core-foundation")]
318        /// 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.
319        #[unsafe(method(anchorPoint))]
320        #[unsafe(method_family = none)]
321        pub unsafe fn anchorPoint(&self) -> CGPoint;
322
323        #[cfg(feature = "objc2-core-foundation")]
324        /// Setter for [`anchorPoint`][Self::anchorPoint].
325        #[unsafe(method(setAnchorPoint:))]
326        #[unsafe(method_family = none)]
327        pub unsafe fn setAnchorPoint(&self, anchor_point: CGPoint);
328
329        #[cfg(feature = "objc2-core-foundation")]
330        /// Set the size of the sprite (in parent's coordinate space)
331        #[unsafe(method(size))]
332        #[unsafe(method_family = none)]
333        pub unsafe fn size(&self) -> CGSize;
334
335        #[cfg(feature = "objc2-core-foundation")]
336        /// Setter for [`size`][Self::size].
337        #[unsafe(method(setSize:))]
338        #[unsafe(method_family = none)]
339        pub unsafe fn setSize(&self, size: CGSize);
340
341        #[cfg(feature = "objc2-core-foundation")]
342        /// Adjust the sprite's xScale
343        /// &
344        /// yScale to achieve the desired size (in parent's coordinate space)
345        #[unsafe(method(scaleToSize:))]
346        #[unsafe(method_family = none)]
347        pub unsafe fn scaleToSize(&self, size: CGSize);
348
349        #[cfg(feature = "SKShader")]
350        #[unsafe(method(shader))]
351        #[unsafe(method_family = none)]
352        pub unsafe fn shader(&self) -> Option<Retained<SKShader>>;
353
354        #[cfg(feature = "SKShader")]
355        /// Setter for [`shader`][Self::shader].
356        #[unsafe(method(setShader:))]
357        #[unsafe(method_family = none)]
358        pub unsafe fn setShader(&self, shader: Option<&SKShader>);
359
360        #[cfg(feature = "SKAttribute")]
361        /// Optional dictionary of SKAttributeValues
362        /// Attributes can be used with custom SKShaders.
363        #[unsafe(method(attributeValues))]
364        #[unsafe(method_family = none)]
365        pub unsafe fn attributeValues(&self) -> Retained<NSDictionary<NSString, SKAttributeValue>>;
366
367        #[cfg(feature = "SKAttribute")]
368        /// Setter for [`attributeValues`][Self::attributeValues].
369        #[unsafe(method(setAttributeValues:))]
370        #[unsafe(method_family = none)]
371        pub unsafe fn setAttributeValues(
372            &self,
373            attribute_values: &NSDictionary<NSString, SKAttributeValue>,
374        );
375
376        #[cfg(feature = "SKAttribute")]
377        #[unsafe(method(valueForAttributeNamed:))]
378        #[unsafe(method_family = none)]
379        pub unsafe fn valueForAttributeNamed(
380            &self,
381            key: &NSString,
382        ) -> Option<Retained<SKAttributeValue>>;
383
384        #[cfg(feature = "SKAttribute")]
385        #[unsafe(method(setValue:forAttributeNamed:))]
386        #[unsafe(method_family = none)]
387        pub unsafe fn setValue_forAttributeNamed(&self, value: &SKAttributeValue, key: &NSString);
388    );
389}
390
391/// Methods declared on superclass `SKNode`.
392#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
393#[cfg(target_os = "macos")]
394impl SKSpriteNode {
395    extern_methods!(
396        #[unsafe(method(init))]
397        #[unsafe(method_family = init)]
398        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
399
400        #[unsafe(method(node))]
401        #[unsafe(method_family = none)]
402        pub unsafe fn node(mtm: MainThreadMarker) -> Retained<Self>;
403
404        #[unsafe(method(nodeWithFileNamed:))]
405        #[unsafe(method_family = none)]
406        pub unsafe fn nodeWithFileNamed(
407            filename: &NSString,
408            mtm: MainThreadMarker,
409        ) -> Option<Retained<Self>>;
410
411        #[unsafe(method(nodeWithFileNamed:securelyWithClasses:andError:_))]
412        #[unsafe(method_family = none)]
413        pub unsafe fn nodeWithFileNamed_securelyWithClasses_andError(
414            filename: &NSString,
415            classes: &NSSet<AnyClass>,
416            mtm: MainThreadMarker,
417        ) -> Result<Retained<Self>, Retained<NSError>>;
418    );
419}
420
421/// Methods declared on superclass `NSObject`.
422#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
423#[cfg(target_os = "macos")]
424impl SKSpriteNode {
425    extern_methods!(
426        #[unsafe(method(new))]
427        #[unsafe(method_family = new)]
428        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
429    );
430}