objc2-sprite-kit 0.3.2

Bindings to the SpriteKit framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-app-kit")]
#[cfg(target_os = "macos")]
use objc2_app_kit::*;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;
use objc2_foundation::*;

use crate::*;

extern_class!(
    /// 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.
    ///
    /// Sprites are used to define quad primitives with color and/or textures applied to them.
    /// See
    /// <a href="http://en.wikipedia.org/wiki/Sprite_(computer_graphics)">
    /// wiki
    /// </a>
    /// for a definition of a Sprite.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/spritekit/skspritenode?language=objc)
    #[unsafe(super(SKNode, NSResponder, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
    #[cfg(target_os = "macos")]
    pub struct SKSpriteNode;
);

#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
#[cfg(target_os = "macos")]
extern_conformance!(
    unsafe impl NSCoding for SKSpriteNode {}
);

#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
#[cfg(target_os = "macos")]
extern_conformance!(
    unsafe impl NSCopying for SKSpriteNode {}
);

#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
#[cfg(target_os = "macos")]
unsafe impl CopyingHelper for SKSpriteNode {
    type Result = Self;
}

#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
#[cfg(target_os = "macos")]
extern_conformance!(
    unsafe impl NSObjectProtocol for SKSpriteNode {}
);

#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
#[cfg(target_os = "macos")]
extern_conformance!(
    unsafe impl NSSecureCoding for SKSpriteNode {}
);

#[cfg(all(
    feature = "SKNode",
    feature = "SKWarpGeometry",
    feature = "objc2-app-kit"
))]
#[cfg(target_os = "macos")]
extern_conformance!(
    unsafe impl SKWarpable for SKSpriteNode {}
);

#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
#[cfg(target_os = "macos")]
impl SKSpriteNode {
    extern_methods!(
        #[cfg(all(feature = "SKTexture", feature = "objc2-core-foundation"))]
        /// Create a sprite with an SKTexture and the specified size.
        ///
        /// Parameter `texture`: the texture to reference for size and content
        ///
        /// Parameter `size`: the size of the sprite in points
        #[unsafe(method(spriteNodeWithTexture:size:))]
        #[unsafe(method_family = none)]
        pub unsafe fn spriteNodeWithTexture_size(
            texture: Option<&SKTexture>,
            size: CGSize,
            mtm: MainThreadMarker,
        ) -> Retained<Self>;

        #[cfg(feature = "SKTexture")]
        /// Create a sprite with an SKTexture and set its size to the SKTexture's pixel width/height.
        ///
        /// Parameter `texture`: the texture to reference for size and content
        #[unsafe(method(spriteNodeWithTexture:))]
        #[unsafe(method_family = none)]
        pub unsafe fn spriteNodeWithTexture(
            texture: Option<&SKTexture>,
            mtm: MainThreadMarker,
        ) -> Retained<Self>;

        #[cfg(feature = "SKTexture")]
        #[unsafe(method(spriteNodeWithTexture:normalMap:))]
        #[unsafe(method_family = none)]
        pub unsafe fn spriteNodeWithTexture_normalMap(
            texture: Option<&SKTexture>,
            normal_map: Option<&SKTexture>,
            mtm: MainThreadMarker,
        ) -> Retained<Self>;

        /// 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)
        /// 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.
        /// 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.
        ///
        /// Parameter `name`: is the name of an image file stored in the app bundle.
        #[unsafe(method(spriteNodeWithImageNamed:))]
        #[unsafe(method_family = none)]
        pub unsafe fn spriteNodeWithImageNamed(
            name: &NSString,
            mtm: MainThreadMarker,
        ) -> Retained<Self>;

        #[unsafe(method(spriteNodeWithImageNamed:normalMapped:))]
        #[unsafe(method_family = none)]
        pub unsafe fn spriteNodeWithImageNamed_normalMapped(
            name: &NSString,
            generate_normal_map: bool,
            mtm: MainThreadMarker,
        ) -> Retained<Self>;

        #[cfg(feature = "objc2-core-foundation")]
        /// Create a sprite with a color and the specified bounds.
        ///
        /// Parameter `color`: the color to use for tinting the sprite.
        ///
        /// Parameter `size`: the size of the sprite in points
        #[unsafe(method(spriteNodeWithColor:size:))]
        #[unsafe(method_family = none)]
        pub unsafe fn spriteNodeWithColor_size(
            color: &NSColor,
            size: CGSize,
            mtm: MainThreadMarker,
        ) -> Retained<Self>;

        #[cfg(all(feature = "SKTexture", feature = "objc2-core-foundation"))]
        /// Designated Initializer
        /// Initialize a sprite with a color and the specified bounds.
        ///
        /// Parameter `texture`: the texture to use (can be nil for colored sprite)
        ///
        /// Parameter `color`: the color to use for tinting the sprite.
        ///
        /// Parameter `size`: the size of the sprite in points
        #[unsafe(method(initWithTexture:color:size:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithTexture_color_size(
            this: Allocated<Self>,
            texture: Option<&SKTexture>,
            color: &NSColor,
            size: CGSize,
        ) -> Retained<Self>;

        #[cfg(feature = "SKTexture")]
        /// Initialize a sprite with an SKTexture and set its size to the SKTexture's width/height.
        ///
        /// Parameter `texture`: the texture to reference for size and content
        #[unsafe(method(initWithTexture:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithTexture(
            this: Allocated<Self>,
            texture: Option<&SKTexture>,
        ) -> Retained<Self>;

        /// 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)
        /// 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.
        /// 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.
        ///
        /// Parameter `name`: the name or path of the image to load.
        #[unsafe(method(initWithImageNamed:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithImageNamed(this: Allocated<Self>, name: &NSString) -> Retained<Self>;

        #[cfg(feature = "objc2-core-foundation")]
        /// Initialize a sprite with a color and the specified bounds.
        ///
        /// Parameter `color`: the color to use for tinting the sprite.
        ///
        /// Parameter `size`: the size of the sprite in points
        #[unsafe(method(initWithColor:size:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithColor_size(
            this: Allocated<Self>,
            color: &NSColor,
            size: CGSize,
        ) -> Retained<Self>;

        /// Support coding and decoding via NSKeyedArchiver.
        ///
        /// # Safety
        ///
        /// `a_decoder` possibly has further requirements.
        #[unsafe(method(initWithCoder:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithCoder(
            this: Allocated<Self>,
            a_decoder: &NSCoder,
        ) -> Option<Retained<Self>>;

        #[cfg(feature = "SKTexture")]
        /// Texture to be drawn (is stretched to fill the sprite)
        #[unsafe(method(texture))]
        #[unsafe(method_family = none)]
        pub unsafe fn texture(&self) -> Option<Retained<SKTexture>>;

        #[cfg(feature = "SKTexture")]
        /// Setter for [`texture`][Self::texture].
        #[unsafe(method(setTexture:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTexture(&self, texture: Option<&SKTexture>);

        #[cfg(feature = "SKTexture")]
        /// Texture to use for generating normals that lights use to light this sprite.
        ///
        /// This will only be used if the sprite is lit by at least one light.
        ///
        ///
        /// See: SKLightNode
        ///
        /// See: lightingBitMask
        #[unsafe(method(normalTexture))]
        #[unsafe(method_family = none)]
        pub unsafe fn normalTexture(&self) -> Option<Retained<SKTexture>>;

        #[cfg(feature = "SKTexture")]
        /// Setter for [`normalTexture`][Self::normalTexture].
        #[unsafe(method(setNormalTexture:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setNormalTexture(&self, normal_texture: Option<&SKTexture>);

        /// Bitmask to indicate being lit by a set of lights using overlapping lighting categories.
        ///
        /// A light whose category is set to a value that masks to non-zero using this mask will
        /// apply light to this sprite.
        ///
        /// When used together with a normal texture, complex lighting effects can be used.
        #[unsafe(method(lightingBitMask))]
        #[unsafe(method_family = none)]
        pub unsafe fn lightingBitMask(&self) -> u32;

        /// Setter for [`lightingBitMask`][Self::lightingBitMask].
        #[unsafe(method(setLightingBitMask:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setLightingBitMask(&self, lighting_bit_mask: u32);

        #[unsafe(method(shadowCastBitMask))]
        #[unsafe(method_family = none)]
        pub unsafe fn shadowCastBitMask(&self) -> u32;

        /// Setter for [`shadowCastBitMask`][Self::shadowCastBitMask].
        #[unsafe(method(setShadowCastBitMask:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setShadowCastBitMask(&self, shadow_cast_bit_mask: u32);

        #[unsafe(method(shadowedBitMask))]
        #[unsafe(method_family = none)]
        pub unsafe fn shadowedBitMask(&self) -> u32;

        /// Setter for [`shadowedBitMask`][Self::shadowedBitMask].
        #[unsafe(method(setShadowedBitMask:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setShadowedBitMask(&self, shadowed_bit_mask: u32);

        #[cfg(feature = "objc2-core-foundation")]
        /// Controls how the texture is stretched to fill the SKSpriteNode. Stretching is performed via a 9-part algorithm where the upper
        /// &
        /// 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).
        #[unsafe(method(centerRect))]
        #[unsafe(method_family = none)]
        pub unsafe fn centerRect(&self) -> CGRect;

        #[cfg(feature = "objc2-core-foundation")]
        /// Setter for [`centerRect`][Self::centerRect].
        #[unsafe(method(setCenterRect:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setCenterRect(&self, center_rect: CGRect);

        #[cfg(feature = "objc2-core-foundation")]
        /// 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.
        #[unsafe(method(colorBlendFactor))]
        #[unsafe(method_family = none)]
        pub unsafe fn colorBlendFactor(&self) -> CGFloat;

        #[cfg(feature = "objc2-core-foundation")]
        /// Setter for [`colorBlendFactor`][Self::colorBlendFactor].
        #[unsafe(method(setColorBlendFactor:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setColorBlendFactor(&self, color_blend_factor: CGFloat);

        /// Base color for the sprite (If no texture is present, the color still is drawn)
        #[unsafe(method(color))]
        #[unsafe(method_family = none)]
        pub unsafe fn color(&self) -> Retained<NSColor>;

        /// Setter for [`color`][Self::color].
        #[unsafe(method(setColor:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setColor(&self, color: &NSColor);

        /// Sets the blend mode to use when composing the sprite with the final framebuffer.
        ///
        /// See: SKNode.SKBlendMode
        #[unsafe(method(blendMode))]
        #[unsafe(method_family = none)]
        pub unsafe fn blendMode(&self) -> SKBlendMode;

        /// Setter for [`blendMode`][Self::blendMode].
        #[unsafe(method(setBlendMode:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setBlendMode(&self, blend_mode: SKBlendMode);

        #[cfg(feature = "objc2-core-foundation")]
        /// 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.
        #[unsafe(method(anchorPoint))]
        #[unsafe(method_family = none)]
        pub unsafe fn anchorPoint(&self) -> CGPoint;

        #[cfg(feature = "objc2-core-foundation")]
        /// Setter for [`anchorPoint`][Self::anchorPoint].
        #[unsafe(method(setAnchorPoint:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAnchorPoint(&self, anchor_point: CGPoint);

        #[cfg(feature = "objc2-core-foundation")]
        /// Set the size of the sprite (in parent's coordinate space)
        #[unsafe(method(size))]
        #[unsafe(method_family = none)]
        pub unsafe fn size(&self) -> CGSize;

        #[cfg(feature = "objc2-core-foundation")]
        /// Setter for [`size`][Self::size].
        #[unsafe(method(setSize:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setSize(&self, size: CGSize);

        #[cfg(feature = "objc2-core-foundation")]
        /// Adjust the sprite's xScale
        /// &
        /// yScale to achieve the desired size (in parent's coordinate space)
        #[unsafe(method(scaleToSize:))]
        #[unsafe(method_family = none)]
        pub unsafe fn scaleToSize(&self, size: CGSize);

        #[cfg(feature = "SKShader")]
        #[unsafe(method(shader))]
        #[unsafe(method_family = none)]
        pub unsafe fn shader(&self) -> Option<Retained<SKShader>>;

        #[cfg(feature = "SKShader")]
        /// Setter for [`shader`][Self::shader].
        #[unsafe(method(setShader:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setShader(&self, shader: Option<&SKShader>);

        #[cfg(feature = "SKAttribute")]
        /// Optional dictionary of SKAttributeValues
        /// Attributes can be used with custom SKShaders.
        #[unsafe(method(attributeValues))]
        #[unsafe(method_family = none)]
        pub unsafe fn attributeValues(&self) -> Retained<NSDictionary<NSString, SKAttributeValue>>;

        #[cfg(feature = "SKAttribute")]
        /// Setter for [`attributeValues`][Self::attributeValues].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setAttributeValues:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAttributeValues(
            &self,
            attribute_values: &NSDictionary<NSString, SKAttributeValue>,
        );

        #[cfg(feature = "SKAttribute")]
        #[unsafe(method(valueForAttributeNamed:))]
        #[unsafe(method_family = none)]
        pub unsafe fn valueForAttributeNamed(
            &self,
            key: &NSString,
        ) -> Option<Retained<SKAttributeValue>>;

        #[cfg(feature = "SKAttribute")]
        #[unsafe(method(setValue:forAttributeNamed:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setValue_forAttributeNamed(&self, value: &SKAttributeValue, key: &NSString);
    );
}

/// Methods declared on superclass `SKNode`.
#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
#[cfg(target_os = "macos")]
impl SKSpriteNode {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(node))]
        #[unsafe(method_family = none)]
        pub unsafe fn node(mtm: MainThreadMarker) -> Retained<Self>;

        #[unsafe(method(nodeWithFileNamed:))]
        #[unsafe(method_family = none)]
        pub unsafe fn nodeWithFileNamed(
            filename: &NSString,
            mtm: MainThreadMarker,
        ) -> Option<Retained<Self>>;

        /// # Safety
        ///
        /// `classes` generic probably has further requirements.
        #[unsafe(method(nodeWithFileNamed:securelyWithClasses:andError:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn nodeWithFileNamed_securelyWithClasses_andError(
            filename: &NSString,
            classes: &NSSet<AnyClass>,
            mtm: MainThreadMarker,
        ) -> Result<Retained<Self>, Retained<NSError>>;
    );
}

/// Methods declared on superclass `NSObject`.
#[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
#[cfg(target_os = "macos")]
impl SKSpriteNode {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
    );
}