objc2_game_controller/generated/
GCMicroGamepadSnapshot.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::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11    /// A GCMicroGamepadSnapshot snapshot is a concrete GCMicroGamepad implementation. It can be used directly in an
12    /// application to implement controller input replays. It is also returned as the result of polling
13    /// a controller.
14    ///
15    /// The current snapshotData is readily available to access as NSData. A developer can serialize this to any
16    /// destination necessary using the NSData API.
17    ///
18    /// The data contains some version of a GCMicroGamepadSnapShotData structure.
19    ///
20    ///
21    /// See: -[GCMicroGamepad saveSnapshot]
22    ///
23    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcmicrogamepadsnapshot?language=objc)
24    #[unsafe(super(GCMicroGamepad, GCPhysicalInputProfile, NSObject))]
25    #[derive(Debug, PartialEq, Eq, Hash)]
26    #[cfg(all(feature = "GCMicroGamepad", feature = "GCPhysicalInputProfile"))]
27    #[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
28    pub struct GCMicroGamepadSnapshot;
29);
30
31#[cfg(all(feature = "GCMicroGamepad", feature = "GCPhysicalInputProfile"))]
32extern_conformance!(
33    unsafe impl NSObjectProtocol for GCMicroGamepadSnapshot {}
34);
35
36#[cfg(all(feature = "GCMicroGamepad", feature = "GCPhysicalInputProfile"))]
37impl GCMicroGamepadSnapshot {
38    extern_methods!(
39        #[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
40        #[unsafe(method(snapshotData))]
41        #[unsafe(method_family = none)]
42        pub unsafe fn snapshotData(&self) -> Retained<NSData>;
43
44        /// Setter for [`snapshotData`][Self::snapshotData].
45        ///
46        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
47        #[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
48        #[unsafe(method(setSnapshotData:))]
49        #[unsafe(method_family = none)]
50        pub unsafe fn setSnapshotData(&self, snapshot_data: &NSData);
51
52        #[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
53        #[unsafe(method(initWithSnapshotData:))]
54        #[unsafe(method_family = init)]
55        pub unsafe fn initWithSnapshotData(this: Allocated<Self>, data: &NSData) -> Retained<Self>;
56
57        #[cfg(feature = "GCController")]
58        #[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
59        #[unsafe(method(initWithController:snapshotData:))]
60        #[unsafe(method_family = init)]
61        pub unsafe fn initWithController_snapshotData(
62            this: Allocated<Self>,
63            controller: &GCController,
64            data: &NSData,
65        ) -> Retained<Self>;
66    );
67}
68
69/// Methods declared on superclass `NSObject`.
70#[cfg(all(feature = "GCMicroGamepad", feature = "GCPhysicalInputProfile"))]
71impl GCMicroGamepadSnapshot {
72    extern_methods!(
73        #[unsafe(method(init))]
74        #[unsafe(method_family = init)]
75        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
76
77        #[unsafe(method(new))]
78        #[unsafe(method_family = new)]
79        pub unsafe fn new() -> Retained<Self>;
80    );
81}
82
83/// [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcmicrogamepadsnapshotdataversion?language=objc)
84// NS_ENUM
85#[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
86#[repr(transparent)]
87#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
88pub struct GCMicroGamepadSnapshotDataVersion(pub NSInteger);
89impl GCMicroGamepadSnapshotDataVersion {
90    #[doc(alias = "GCMicroGamepadSnapshotDataVersion1")]
91    #[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
92    pub const Version1: Self = Self(0x0100);
93}
94
95unsafe impl Encode for GCMicroGamepadSnapshotDataVersion {
96    const ENCODING: Encoding = NSInteger::ENCODING;
97}
98
99unsafe impl RefEncode for GCMicroGamepadSnapshotDataVersion {
100    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
101}
102
103extern "C" {
104    /// [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccurrentmicrogamepadsnapshotdataversion?language=objc)
105    #[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
106    pub static GCCurrentMicroGamepadSnapshotDataVersion: GCMicroGamepadSnapshotDataVersion;
107}
108
109/// [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcmicrogamepadsnapshotdata?language=objc)
110#[repr(C, packed)]
111#[derive(Clone, Copy, Debug, PartialEq)]
112pub struct GCMicroGamepadSnapshotData {
113    pub version: u16,
114    pub size: u16,
115    pub dpadX: c_float,
116    pub dpadY: c_float,
117    pub buttonA: c_float,
118    pub buttonX: c_float,
119}
120
121unsafe impl Encode for GCMicroGamepadSnapshotData {
122    const ENCODING: Encoding = Encoding::Struct(
123        "?",
124        &[
125            <u16>::ENCODING,
126            <u16>::ENCODING,
127            <c_float>::ENCODING,
128            <c_float>::ENCODING,
129            <c_float>::ENCODING,
130            <c_float>::ENCODING,
131        ],
132    );
133}
134
135unsafe impl RefEncode for GCMicroGamepadSnapshotData {
136    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
137}
138
139impl GCMicroGamepadSnapshotData {
140    /// Fills out a snapshot from any compatible NSData source
141    ///
142    ///
143    /// Returns: NO if data is nil, snapshotData is nil or the contents of data does not contain a compatible snapshot. YES for all other cases.
144    ///
145    /// # Safety
146    ///
147    /// `snapshot_data` must be a valid pointer or null.
148    #[doc(alias = "GCMicroGamepadSnapshotDataFromNSData")]
149    #[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
150    #[inline]
151    pub unsafe fn from_ns_data(
152        snapshot_data: *mut GCMicroGamepadSnapshotData,
153        data: Option<&NSData>,
154    ) -> bool {
155        extern "C-unwind" {
156            fn GCMicroGamepadSnapshotDataFromNSData(
157                snapshot_data: *mut GCMicroGamepadSnapshotData,
158                data: Option<&NSData>,
159            ) -> Bool;
160        }
161        unsafe { GCMicroGamepadSnapshotDataFromNSData(snapshot_data, data) }.as_bool()
162    }
163}
164
165/// Creates an NSData object from a snapshot.
166/// If the version and size is not set in the snapshot the data will automatically have version GCCurrentMicroGamepadSnapshotDataVersion and sizeof(GCMicroGamepadSnapshotData) set as the values implicitly.
167///
168///
169/// Returns: nil if the snapshot is NULL, otherwise an NSData instance compatible with GCGamepadSnapshot.snapshotData
170///
171/// # Safety
172///
173/// `snapshot_data` must be a valid pointer or null.
174#[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
175#[inline]
176pub unsafe extern "C-unwind" fn NSDataFromGCMicroGamepadSnapshotData(
177    snapshot_data: *mut GCMicroGamepadSnapshotData,
178) -> Option<Retained<NSData>> {
179    extern "C-unwind" {
180        fn NSDataFromGCMicroGamepadSnapshotData(
181            snapshot_data: *mut GCMicroGamepadSnapshotData,
182        ) -> *mut NSData;
183    }
184    let ret = unsafe { NSDataFromGCMicroGamepadSnapshotData(snapshot_data) };
185    unsafe { Retained::retain_autoreleased(ret) }
186}
187
188/// [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcmicrogamepadsnapshotdatav100?language=objc)
189#[repr(C, packed)]
190#[derive(Clone, Copy, Debug, PartialEq)]
191pub struct GCMicroGamepadSnapShotDataV100 {
192    pub version: u16,
193    pub size: u16,
194    pub dpadX: c_float,
195    pub dpadY: c_float,
196    pub buttonA: c_float,
197    pub buttonX: c_float,
198}
199
200unsafe impl Encode for GCMicroGamepadSnapShotDataV100 {
201    const ENCODING: Encoding = Encoding::Struct(
202        "?",
203        &[
204            <u16>::ENCODING,
205            <u16>::ENCODING,
206            <c_float>::ENCODING,
207            <c_float>::ENCODING,
208            <c_float>::ENCODING,
209            <c_float>::ENCODING,
210        ],
211    );
212}
213
214unsafe impl RefEncode for GCMicroGamepadSnapShotDataV100 {
215    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
216}
217
218impl GCMicroGamepadSnapShotDataV100 {
219    /// Fills out a v100 snapshot from any compatible NSData source
220    ///
221    ///
222    /// Returns: NO if data is nil, snapshotData is nil or the contents of data does not contain a compatible snapshot. YES for all other cases.
223    ///
224    /// # Safety
225    ///
226    /// `snapshot_data` must be a valid pointer or null.
227    #[doc(alias = "GCMicroGamepadSnapShotDataV100FromNSData")]
228    #[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
229    #[inline]
230    pub unsafe fn from_ns_data(
231        snapshot_data: *mut GCMicroGamepadSnapShotDataV100,
232        data: Option<&NSData>,
233    ) -> bool {
234        extern "C-unwind" {
235            fn GCMicroGamepadSnapShotDataV100FromNSData(
236                snapshot_data: *mut GCMicroGamepadSnapShotDataV100,
237                data: Option<&NSData>,
238            ) -> Bool;
239        }
240        unsafe { GCMicroGamepadSnapShotDataV100FromNSData(snapshot_data, data) }.as_bool()
241    }
242}
243
244/// Creates an NSData object from a v100 snapshot.
245/// If the version and size is not set in the snapshot the data will automatically have version 0x100 and sizeof(GCMicroGamepadSnapShotDataV100) set as the values implicitly.
246///
247///
248/// Returns: nil if the snapshot is NULL, otherwise an NSData instance compatible with GCGamepadSnapshot.snapshotData
249///
250/// # Safety
251///
252/// `snapshot_data` must be a valid pointer or null.
253#[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
254#[inline]
255pub unsafe extern "C-unwind" fn NSDataFromGCMicroGamepadSnapShotDataV100(
256    snapshot_data: *mut GCMicroGamepadSnapShotDataV100,
257) -> Option<Retained<NSData>> {
258    extern "C-unwind" {
259        fn NSDataFromGCMicroGamepadSnapShotDataV100(
260            snapshot_data: *mut GCMicroGamepadSnapShotDataV100,
261        ) -> *mut NSData;
262    }
263    let ret = unsafe { NSDataFromGCMicroGamepadSnapShotDataV100(snapshot_data) };
264    unsafe { Retained::retain_autoreleased(ret) }
265}
266
267#[deprecated = "renamed to `GCMicroGamepadSnapshotData::from_ns_data`"]
268#[inline]
269pub unsafe extern "C-unwind" fn GCMicroGamepadSnapshotDataFromNSData(
270    snapshot_data: *mut GCMicroGamepadSnapshotData,
271    data: Option<&NSData>,
272) -> bool {
273    extern "C-unwind" {
274        fn GCMicroGamepadSnapshotDataFromNSData(
275            snapshot_data: *mut GCMicroGamepadSnapshotData,
276            data: Option<&NSData>,
277        ) -> Bool;
278    }
279    unsafe { GCMicroGamepadSnapshotDataFromNSData(snapshot_data, data) }.as_bool()
280}
281
282#[deprecated = "renamed to `GCMicroGamepadSnapShotDataV100::from_ns_data`"]
283#[inline]
284pub unsafe extern "C-unwind" fn GCMicroGamepadSnapShotDataV100FromNSData(
285    snapshot_data: *mut GCMicroGamepadSnapShotDataV100,
286    data: Option<&NSData>,
287) -> bool {
288    extern "C-unwind" {
289        fn GCMicroGamepadSnapShotDataV100FromNSData(
290            snapshot_data: *mut GCMicroGamepadSnapShotDataV100,
291            data: Option<&NSData>,
292        ) -> Bool;
293    }
294    unsafe { GCMicroGamepadSnapShotDataV100FromNSData(snapshot_data, data) }.as_bool()
295}