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
//! 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::*;
#[cfg(feature = "objc2-core-graphics")]
use objc2_core_graphics::*;
#[cfg(feature = "objc2-core-image")]
#[cfg(not(target_os = "watchos"))]
use objc2_core_image::*;
use objc2_foundation::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/spritekit/sktexturefilteringmode?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SKTextureFilteringMode(pub NSInteger);
impl SKTextureFilteringMode {
#[doc(alias = "SKTextureFilteringNearest")]
pub const Nearest: Self = Self(0);
#[doc(alias = "SKTextureFilteringLinear")]
pub const Linear: Self = Self(1);
}
unsafe impl Encode for SKTextureFilteringMode {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for SKTextureFilteringMode {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
extern_class!(
/// A texture to be mapped onto SKSpriteNode instances.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/spritekit/sktexture?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct SKTexture;
);
extern_conformance!(
unsafe impl NSCoding for SKTexture {}
);
extern_conformance!(
unsafe impl NSCopying for SKTexture {}
);
unsafe impl CopyingHelper for SKTexture {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for SKTexture {}
);
extern_conformance!(
unsafe impl NSSecureCoding for SKTexture {}
);
impl SKTexture {
extern_methods!(
/// Create a texture from an image file. Behaves similar to imageNamed: in UIImage or NSImage
///
///
/// Parameter `name`: the name or path of the image to load.
#[unsafe(method(textureWithImageNamed:))]
#[unsafe(method_family = none)]
pub unsafe fn textureWithImageNamed(name: &NSString) -> Retained<Self>;
#[cfg(feature = "objc2-core-foundation")]
/// Create a texture that is a subrect of an existing texture. See textureRect property for details.
///
///
/// Parameter `rect`: the source rectangle to use in creating a logical copy of the given texture.
///
/// Parameter `texture`: the existing texture to reference in the copy.
#[unsafe(method(textureWithRect:inTexture:))]
#[unsafe(method_family = none)]
pub unsafe fn textureWithRect_inTexture(
rect: CGRect,
texture: &SKTexture,
) -> Retained<Self>;
#[cfg(feature = "objc2-core-foundation")]
/// Create a texture containing directional noise. The RGBA values in this
/// texture can be used as a normal map or as direction possibly with length. XYZ are a three dimensional direction, and A is a magnitude.
///
///
/// Parameter `size`: the size of the resulting texture.
///
/// Parameter `smoothness`: how similar neighboring pixels are. A value of zero is like static, one is smooth.
#[unsafe(method(textureVectorNoiseWithSmoothness:size:))]
#[unsafe(method_family = none)]
pub unsafe fn textureVectorNoiseWithSmoothness_size(
smoothness: CGFloat,
size: CGSize,
) -> Retained<Self>;
#[cfg(feature = "objc2-core-foundation")]
/// Create a texture containing colored noise. The noise texture is tileable with itself.
///
///
/// Parameter `size`: the size of the resulting texture.
///
/// Parameter `smoothness`: how similar neighboring pixels are. A value of zero is like static, one is smooth.
///
/// Parameter `grayscale`: if YES, RGB and A will all be the same. If no, RGB and A will all be different. A is not pre-multiplied, because the intent is that if you read a texel in a shader, all four values will be exactly the same value if grayscale, or four different, uncorrelated values if not grayscale.
#[unsafe(method(textureNoiseWithSmoothness:size:grayscale:))]
#[unsafe(method_family = none)]
pub unsafe fn textureNoiseWithSmoothness_size_grayscale(
smoothness: CGFloat,
size: CGSize,
grayscale: bool,
) -> Retained<Self>;
#[cfg(feature = "objc2-core-graphics")]
/// Create a texture from a CGImageRef.
///
///
/// Parameter `image`: the CGImageRef to create the texture from
#[unsafe(method(textureWithCGImage:))]
#[unsafe(method_family = none)]
pub unsafe fn textureWithCGImage(image: &CGImage) -> Retained<Self>;
#[cfg(feature = "objc2-app-kit")]
#[cfg(target_os = "macos")]
#[unsafe(method(textureWithImage:))]
#[unsafe(method_family = none)]
pub unsafe fn textureWithImage(image: &NSImage) -> Retained<Self>;
#[cfg(feature = "objc2-core-foundation")]
/// Create new texture with bitmap RGBA data in unsigned bytes. Data is copied once, additional changes to the data does not affect the texture. All pixel data is assumed to be premultiplied alpha.
///
///
/// Parameter `pixelData`: the pixelData to read in creating the texture.
///
/// Parameter `size`: the dimensions of the pixelData given.
#[unsafe(method(textureWithData:size:))]
#[unsafe(method_family = none)]
pub unsafe fn textureWithData_size(pixel_data: &NSData, size: CGSize) -> Retained<Self>;
#[cfg(feature = "objc2-core-foundation")]
#[unsafe(method(textureWithData:size:flipped:))]
#[unsafe(method_family = none)]
pub unsafe fn textureWithData_size_flipped(
pixel_data: &NSData,
size: CGSize,
flipped: bool,
) -> Retained<Self>;
#[cfg(feature = "objc2-core-foundation")]
/// Create new texture with bitmap RGBA data in unsigned bytes using a custom row length and row alignment. Data is copied once, additional changes to the data does not affect the texture. All pixel data is assumed to be premultiplied alpha.
///
///
/// Parameter `pixelData`: the data to use
///
/// Parameter `size`: the size in texels
///
/// Parameter `rowLength`: the length of each row in pixels (allows byte row pitches greater than the width for aligned data)
///
/// Parameter `alignment`: the byte alignment of the data, provide 0 for tightly packed data.
#[unsafe(method(textureWithData:size:rowLength:alignment:))]
#[unsafe(method_family = none)]
pub unsafe fn textureWithData_size_rowLength_alignment(
pixel_data: &NSData,
size: CGSize,
row_length: c_uint,
alignment: c_uint,
) -> Retained<Self>;
#[cfg(feature = "objc2-core-image")]
#[cfg(not(target_os = "watchos"))]
/// Create new texture by applying a CIFilter to an existing one. Any CIFilter that requires only a single "inputImage" and produces an "outputImage" is allowed.
///
///
/// Parameter `filter`: the CI filter to apply in the copy.
#[unsafe(method(textureByApplyingCIFilter:))]
#[unsafe(method_family = none)]
pub unsafe fn textureByApplyingCIFilter(&self, filter: &CIFilter) -> Retained<Self>;
/// Create new texture by generating a normal map texture.
#[unsafe(method(textureByGeneratingNormalMap))]
#[unsafe(method_family = none)]
pub unsafe fn textureByGeneratingNormalMap(&self) -> Retained<Self>;
#[cfg(feature = "objc2-core-foundation")]
/// Create new texture by generating a normal map texture.
///
///
/// Parameter `smoothness`: the smooth level of the generated normal map.
///
/// Parameter `contrast`: the scale applied to the generated normal map.
#[unsafe(method(textureByGeneratingNormalMapWithSmoothness:contrast:))]
#[unsafe(method_family = none)]
pub unsafe fn textureByGeneratingNormalMapWithSmoothness_contrast(
&self,
smoothness: CGFloat,
contrast: CGFloat,
) -> Retained<Self>;
#[cfg(feature = "objc2-core-foundation")]
/// Used to choose the area of the texture you want to display. The origin and size should both be in the range 0.0 - 1.0, values outside of this range produces unpredictable results. Defaults to the entire texture {(0,0) (1,1)}.
#[unsafe(method(textureRect))]
#[unsafe(method_family = none)]
pub unsafe fn textureRect(&self) -> CGRect;
#[cfg(feature = "objc2-core-foundation")]
/// The size of the texture's bitmap data in points.
#[unsafe(method(size))]
#[unsafe(method_family = none)]
pub unsafe fn size(&self) -> CGSize;
/// The filtering mode the texture should use when not drawn at native size. Defaults to SKTextureFilteringLinear.
#[unsafe(method(filteringMode))]
#[unsafe(method_family = none)]
pub unsafe fn filteringMode(&self) -> SKTextureFilteringMode;
/// Setter for [`filteringMode`][Self::filteringMode].
#[unsafe(method(setFilteringMode:))]
#[unsafe(method_family = none)]
pub unsafe fn setFilteringMode(&self, filtering_mode: SKTextureFilteringMode);
/// Request that the texture have mipmaps generated if possible. Only supported for power of 2 texture sizes.
#[unsafe(method(usesMipmaps))]
#[unsafe(method_family = none)]
pub unsafe fn usesMipmaps(&self) -> bool;
/// Setter for [`usesMipmaps`][Self::usesMipmaps].
#[unsafe(method(setUsesMipmaps:))]
#[unsafe(method_family = none)]
pub unsafe fn setUsesMipmaps(&self, uses_mipmaps: bool);
#[cfg(feature = "objc2-core-graphics")]
/// Convert the current SKTexture into a CGImageRef object
#[unsafe(method(CGImage))]
// required for soundness, method has `returns_retained` attribute.
#[unsafe(method_family = copy)]
pub unsafe fn CGImage(&self) -> Retained<CGImage>;
#[cfg(feature = "block2")]
/// Start a texture preload operation on an array of textures
///
///
/// Parameter `textures`: an array of SKTextures to be preloaded
///
/// Parameter `completionHandler`: will be called upon the preload completion
#[unsafe(method(preloadTextures:withCompletionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn preloadTextures_withCompletionHandler(
textures: &NSArray<SKTexture>,
completion_handler: &block2::DynBlock<dyn Fn()>,
);
#[cfg(feature = "block2")]
/// Request that this texture be loaded into vram on the next render update, with a callback handler.
#[unsafe(method(preloadWithCompletionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn preloadWithCompletionHandler(
&self,
completion_handler: &block2::DynBlock<dyn Fn()>,
);
);
}
/// Methods declared on superclass `NSObject`.
impl SKTexture {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub unsafe fn new() -> Retained<Self>;
);
}