objc2_sprite_kit/generated/
SKTexture.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::*;
11#[cfg(feature = "objc2-core-graphics")]
12use objc2_core_graphics::*;
13#[cfg(feature = "objc2-core-image")]
14#[cfg(not(target_os = "watchos"))]
15use objc2_core_image::*;
16use objc2_foundation::*;
17
18use crate::*;
19
20/// [Apple's documentation](https://developer.apple.com/documentation/spritekit/sktexturefilteringmode?language=objc)
21// NS_ENUM
22#[repr(transparent)]
23#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
24pub struct SKTextureFilteringMode(pub NSInteger);
25impl SKTextureFilteringMode {
26    #[doc(alias = "SKTextureFilteringNearest")]
27    pub const Nearest: Self = Self(0);
28    #[doc(alias = "SKTextureFilteringLinear")]
29    pub const Linear: Self = Self(1);
30}
31
32unsafe impl Encode for SKTextureFilteringMode {
33    const ENCODING: Encoding = NSInteger::ENCODING;
34}
35
36unsafe impl RefEncode for SKTextureFilteringMode {
37    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
38}
39
40extern_class!(
41    /// A texture to be mapped onto SKSpriteNode instances.
42    ///
43    /// See also [Apple's documentation](https://developer.apple.com/documentation/spritekit/sktexture?language=objc)
44    #[unsafe(super(NSObject))]
45    #[derive(Debug, PartialEq, Eq, Hash)]
46    pub struct SKTexture;
47);
48
49extern_conformance!(
50    unsafe impl NSCoding for SKTexture {}
51);
52
53extern_conformance!(
54    unsafe impl NSCopying for SKTexture {}
55);
56
57unsafe impl CopyingHelper for SKTexture {
58    type Result = Self;
59}
60
61extern_conformance!(
62    unsafe impl NSObjectProtocol for SKTexture {}
63);
64
65extern_conformance!(
66    unsafe impl NSSecureCoding for SKTexture {}
67);
68
69impl SKTexture {
70    extern_methods!(
71        /// Create a texture from an image file. Behaves similar to imageNamed: in UIImage or NSImage
72        ///
73        ///
74        /// Parameter `name`: the name or path of the image to load.
75        #[unsafe(method(textureWithImageNamed:))]
76        #[unsafe(method_family = none)]
77        pub unsafe fn textureWithImageNamed(name: &NSString) -> Retained<Self>;
78
79        #[cfg(feature = "objc2-core-foundation")]
80        /// Create a texture that is a subrect of an existing texture. See textureRect property for details.
81        ///
82        ///
83        /// Parameter `rect`: the source rectangle to use in creating a logical copy of the given texture.
84        ///
85        /// Parameter `texture`: the existing texture to reference in the copy.
86        #[unsafe(method(textureWithRect:inTexture:))]
87        #[unsafe(method_family = none)]
88        pub unsafe fn textureWithRect_inTexture(
89            rect: CGRect,
90            texture: &SKTexture,
91        ) -> Retained<Self>;
92
93        #[cfg(feature = "objc2-core-foundation")]
94        /// Create a texture containing directional noise. The RGBA values in this
95        /// 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.
96        ///
97        ///
98        /// Parameter `size`: the size of the resulting texture.
99        ///
100        /// Parameter `smoothness`: how similar neighboring pixels are. A value of zero is like static, one is smooth.
101        #[unsafe(method(textureVectorNoiseWithSmoothness:size:))]
102        #[unsafe(method_family = none)]
103        pub unsafe fn textureVectorNoiseWithSmoothness_size(
104            smoothness: CGFloat,
105            size: CGSize,
106        ) -> Retained<Self>;
107
108        #[cfg(feature = "objc2-core-foundation")]
109        /// Create a texture containing colored noise. The noise texture is tileable with itself.
110        ///
111        ///
112        /// Parameter `size`: the size of the resulting texture.
113        ///
114        /// Parameter `smoothness`: how similar neighboring pixels are. A value of zero is like static, one is smooth.
115        ///
116        /// 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.
117        #[unsafe(method(textureNoiseWithSmoothness:size:grayscale:))]
118        #[unsafe(method_family = none)]
119        pub unsafe fn textureNoiseWithSmoothness_size_grayscale(
120            smoothness: CGFloat,
121            size: CGSize,
122            grayscale: bool,
123        ) -> Retained<Self>;
124
125        #[cfg(feature = "objc2-core-graphics")]
126        /// Create a texture from a CGImageRef.
127        ///
128        ///
129        /// Parameter `image`: the CGImageRef to create the texture from
130        #[unsafe(method(textureWithCGImage:))]
131        #[unsafe(method_family = none)]
132        pub unsafe fn textureWithCGImage(image: &CGImage) -> Retained<Self>;
133
134        #[cfg(feature = "objc2-app-kit")]
135        #[cfg(target_os = "macos")]
136        #[unsafe(method(textureWithImage:))]
137        #[unsafe(method_family = none)]
138        pub unsafe fn textureWithImage(image: &NSImage) -> Retained<Self>;
139
140        #[cfg(feature = "objc2-core-foundation")]
141        /// 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.
142        ///
143        ///
144        /// Parameter `pixelData`: the pixelData to read in creating the texture.
145        ///
146        /// Parameter `size`: the dimensions of the pixelData given.
147        #[unsafe(method(textureWithData:size:))]
148        #[unsafe(method_family = none)]
149        pub unsafe fn textureWithData_size(pixel_data: &NSData, size: CGSize) -> Retained<Self>;
150
151        #[cfg(feature = "objc2-core-foundation")]
152        #[unsafe(method(textureWithData:size:flipped:))]
153        #[unsafe(method_family = none)]
154        pub unsafe fn textureWithData_size_flipped(
155            pixel_data: &NSData,
156            size: CGSize,
157            flipped: bool,
158        ) -> Retained<Self>;
159
160        #[cfg(feature = "objc2-core-foundation")]
161        /// 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.
162        ///
163        ///
164        /// Parameter `pixelData`: the data to use
165        ///
166        /// Parameter `size`: the size in texels
167        ///
168        /// Parameter `rowLength`: the length of each row in pixels (allows byte row pitches greater than the width for aligned data)
169        ///
170        /// Parameter `alignment`: the byte alignment of the data, provide 0 for tightly packed data.
171        #[unsafe(method(textureWithData:size:rowLength:alignment:))]
172        #[unsafe(method_family = none)]
173        pub unsafe fn textureWithData_size_rowLength_alignment(
174            pixel_data: &NSData,
175            size: CGSize,
176            row_length: c_uint,
177            alignment: c_uint,
178        ) -> Retained<Self>;
179
180        #[cfg(feature = "objc2-core-image")]
181        #[cfg(not(target_os = "watchos"))]
182        /// 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.
183        ///
184        ///
185        /// Parameter `filter`: the CI filter to apply in the copy.
186        #[unsafe(method(textureByApplyingCIFilter:))]
187        #[unsafe(method_family = none)]
188        pub unsafe fn textureByApplyingCIFilter(&self, filter: &CIFilter) -> Retained<Self>;
189
190        /// Create new texture by generating a normal map texture.
191        #[unsafe(method(textureByGeneratingNormalMap))]
192        #[unsafe(method_family = none)]
193        pub unsafe fn textureByGeneratingNormalMap(&self) -> Retained<Self>;
194
195        #[cfg(feature = "objc2-core-foundation")]
196        /// Create new texture by generating a normal map texture.
197        ///
198        ///
199        /// Parameter `smoothness`: the smooth level of the generated normal map.
200        ///
201        /// Parameter `contrast`: the scale applied to the generated normal map.
202        #[unsafe(method(textureByGeneratingNormalMapWithSmoothness:contrast:))]
203        #[unsafe(method_family = none)]
204        pub unsafe fn textureByGeneratingNormalMapWithSmoothness_contrast(
205            &self,
206            smoothness: CGFloat,
207            contrast: CGFloat,
208        ) -> Retained<Self>;
209
210        #[cfg(feature = "objc2-core-foundation")]
211        /// 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)}.
212        #[unsafe(method(textureRect))]
213        #[unsafe(method_family = none)]
214        pub unsafe fn textureRect(&self) -> CGRect;
215
216        #[cfg(feature = "objc2-core-foundation")]
217        /// The size of the texture's bitmap data in points.
218        #[unsafe(method(size))]
219        #[unsafe(method_family = none)]
220        pub unsafe fn size(&self) -> CGSize;
221
222        /// The filtering mode the texture should use when not drawn at native size. Defaults to SKTextureFilteringLinear.
223        #[unsafe(method(filteringMode))]
224        #[unsafe(method_family = none)]
225        pub unsafe fn filteringMode(&self) -> SKTextureFilteringMode;
226
227        /// Setter for [`filteringMode`][Self::filteringMode].
228        #[unsafe(method(setFilteringMode:))]
229        #[unsafe(method_family = none)]
230        pub unsafe fn setFilteringMode(&self, filtering_mode: SKTextureFilteringMode);
231
232        /// Request that the texture have mipmaps generated if possible. Only supported for power of 2 texture sizes.
233        #[unsafe(method(usesMipmaps))]
234        #[unsafe(method_family = none)]
235        pub unsafe fn usesMipmaps(&self) -> bool;
236
237        /// Setter for [`usesMipmaps`][Self::usesMipmaps].
238        #[unsafe(method(setUsesMipmaps:))]
239        #[unsafe(method_family = none)]
240        pub unsafe fn setUsesMipmaps(&self, uses_mipmaps: bool);
241
242        #[cfg(feature = "objc2-core-graphics")]
243        /// Convert the current SKTexture into a CGImageRef object
244        #[unsafe(method(CGImage))]
245        // required for soundness, method has `returns_retained` attribute.
246        #[unsafe(method_family = copy)]
247        pub unsafe fn CGImage(&self) -> Retained<CGImage>;
248
249        #[cfg(feature = "block2")]
250        /// Start a texture preload operation on an array of textures
251        ///
252        ///
253        /// Parameter `textures`: an array of SKTextures to be preloaded
254        ///
255        /// Parameter `completionHandler`: will be called upon the preload completion
256        #[unsafe(method(preloadTextures:withCompletionHandler:))]
257        #[unsafe(method_family = none)]
258        pub unsafe fn preloadTextures_withCompletionHandler(
259            textures: &NSArray<SKTexture>,
260            completion_handler: &block2::DynBlock<dyn Fn()>,
261        );
262
263        #[cfg(feature = "block2")]
264        /// Request that this texture be loaded into vram on the next render update, with a callback handler.
265        #[unsafe(method(preloadWithCompletionHandler:))]
266        #[unsafe(method_family = none)]
267        pub unsafe fn preloadWithCompletionHandler(
268            &self,
269            completion_handler: &block2::DynBlock<dyn Fn()>,
270        );
271    );
272}
273
274/// Methods declared on superclass `NSObject`.
275impl SKTexture {
276    extern_methods!(
277        #[unsafe(method(init))]
278        #[unsafe(method_family = init)]
279        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
280
281        #[unsafe(method(new))]
282        #[unsafe(method_family = new)]
283        pub unsafe fn new() -> Retained<Self>;
284    );
285}