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