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        #[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
46        #[unsafe(method(setSnapshotData:))]
47        #[unsafe(method_family = none)]
48        pub unsafe fn setSnapshotData(&self, snapshot_data: &NSData);
49
50        #[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
51        #[unsafe(method(initWithSnapshotData:))]
52        #[unsafe(method_family = init)]
53        pub unsafe fn initWithSnapshotData(this: Allocated<Self>, data: &NSData) -> Retained<Self>;
54
55        #[cfg(feature = "GCController")]
56        #[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
57        #[unsafe(method(initWithController:snapshotData:))]
58        #[unsafe(method_family = init)]
59        pub unsafe fn initWithController_snapshotData(
60            this: Allocated<Self>,
61            controller: &GCController,
62            data: &NSData,
63        ) -> Retained<Self>;
64    );
65}
66
67/// Methods declared on superclass `NSObject`.
68#[cfg(all(feature = "GCMicroGamepad", feature = "GCPhysicalInputProfile"))]
69impl GCMicroGamepadSnapshot {
70    extern_methods!(
71        #[unsafe(method(init))]
72        #[unsafe(method_family = init)]
73        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
74
75        #[unsafe(method(new))]
76        #[unsafe(method_family = new)]
77        pub unsafe fn new() -> Retained<Self>;
78    );
79}
80
81/// [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcmicrogamepadsnapshotdataversion?language=objc)
82// NS_ENUM
83#[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
84#[repr(transparent)]
85#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
86pub struct GCMicroGamepadSnapshotDataVersion(pub NSInteger);
87impl GCMicroGamepadSnapshotDataVersion {
88    #[doc(alias = "GCMicroGamepadSnapshotDataVersion1")]
89    #[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
90    pub const Version1: Self = Self(0x0100);
91}
92
93unsafe impl Encode for GCMicroGamepadSnapshotDataVersion {
94    const ENCODING: Encoding = NSInteger::ENCODING;
95}
96
97unsafe impl RefEncode for GCMicroGamepadSnapshotDataVersion {
98    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
99}
100
101extern "C" {
102    /// [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccurrentmicrogamepadsnapshotdataversion?language=objc)
103    pub static GCCurrentMicroGamepadSnapshotDataVersion: GCMicroGamepadSnapshotDataVersion;
104}
105
106/// [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcmicrogamepadsnapshotdata?language=objc)
107#[repr(C)]
108#[derive(Clone, Copy, Debug, PartialEq)]
109pub struct GCMicroGamepadSnapshotData {
110    pub version: u16,
111    pub size: u16,
112    pub dpadX: c_float,
113    pub dpadY: c_float,
114    pub buttonA: c_float,
115    pub buttonX: c_float,
116}
117
118unsafe impl Encode for GCMicroGamepadSnapshotData {
119    const ENCODING: Encoding = Encoding::Struct(
120        "?",
121        &[
122            <u16>::ENCODING,
123            <u16>::ENCODING,
124            <c_float>::ENCODING,
125            <c_float>::ENCODING,
126            <c_float>::ENCODING,
127            <c_float>::ENCODING,
128        ],
129    );
130}
131
132unsafe impl RefEncode for GCMicroGamepadSnapshotData {
133    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
134}
135
136impl GCMicroGamepadSnapshotData {
137    /// Fills out a snapshot from any compatible NSData source
138    ///
139    ///
140    /// 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.
141    #[doc(alias = "GCMicroGamepadSnapshotDataFromNSData")]
142    #[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
143    #[inline]
144    pub unsafe fn from_ns_data(
145        snapshot_data: *mut GCMicroGamepadSnapshotData,
146        data: Option<&NSData>,
147    ) -> bool {
148        extern "C-unwind" {
149            fn GCMicroGamepadSnapshotDataFromNSData(
150                snapshot_data: *mut GCMicroGamepadSnapshotData,
151                data: Option<&NSData>,
152            ) -> Bool;
153        }
154        unsafe { GCMicroGamepadSnapshotDataFromNSData(snapshot_data, data) }.as_bool()
155    }
156}
157
158/// Creates an NSData object from a snapshot.
159/// 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.
160///
161///
162/// Returns: nil if the snapshot is NULL, otherwise an NSData instance compatible with GCGamepadSnapshot.snapshotData
163#[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
164#[inline]
165pub unsafe extern "C-unwind" fn NSDataFromGCMicroGamepadSnapshotData(
166    snapshot_data: *mut GCMicroGamepadSnapshotData,
167) -> Option<Retained<NSData>> {
168    extern "C-unwind" {
169        fn NSDataFromGCMicroGamepadSnapshotData(
170            snapshot_data: *mut GCMicroGamepadSnapshotData,
171        ) -> *mut NSData;
172    }
173    let ret = unsafe { NSDataFromGCMicroGamepadSnapshotData(snapshot_data) };
174    unsafe { Retained::retain_autoreleased(ret) }
175}
176
177/// [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcmicrogamepadsnapshotdatav100?language=objc)
178#[repr(C)]
179#[derive(Clone, Copy, Debug, PartialEq)]
180pub struct GCMicroGamepadSnapShotDataV100 {
181    pub version: u16,
182    pub size: u16,
183    pub dpadX: c_float,
184    pub dpadY: c_float,
185    pub buttonA: c_float,
186    pub buttonX: c_float,
187}
188
189unsafe impl Encode for GCMicroGamepadSnapShotDataV100 {
190    const ENCODING: Encoding = Encoding::Struct(
191        "?",
192        &[
193            <u16>::ENCODING,
194            <u16>::ENCODING,
195            <c_float>::ENCODING,
196            <c_float>::ENCODING,
197            <c_float>::ENCODING,
198            <c_float>::ENCODING,
199        ],
200    );
201}
202
203unsafe impl RefEncode for GCMicroGamepadSnapShotDataV100 {
204    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
205}
206
207impl GCMicroGamepadSnapShotDataV100 {
208    /// Fills out a v100 snapshot from any compatible NSData source
209    ///
210    ///
211    /// 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.
212    #[doc(alias = "GCMicroGamepadSnapShotDataV100FromNSData")]
213    #[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
214    #[inline]
215    pub unsafe fn from_ns_data(
216        snapshot_data: *mut GCMicroGamepadSnapShotDataV100,
217        data: Option<&NSData>,
218    ) -> bool {
219        extern "C-unwind" {
220            fn GCMicroGamepadSnapShotDataV100FromNSData(
221                snapshot_data: *mut GCMicroGamepadSnapShotDataV100,
222                data: Option<&NSData>,
223            ) -> Bool;
224        }
225        unsafe { GCMicroGamepadSnapShotDataV100FromNSData(snapshot_data, data) }.as_bool()
226    }
227}
228
229/// Creates an NSData object from a v100 snapshot.
230/// 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.
231///
232///
233/// Returns: nil if the snapshot is NULL, otherwise an NSData instance compatible with GCGamepadSnapshot.snapshotData
234#[deprecated = "Use the -[GCController controllerWithMicroGamepad] method instead"]
235#[inline]
236pub unsafe extern "C-unwind" fn NSDataFromGCMicroGamepadSnapShotDataV100(
237    snapshot_data: *mut GCMicroGamepadSnapShotDataV100,
238) -> Option<Retained<NSData>> {
239    extern "C-unwind" {
240        fn NSDataFromGCMicroGamepadSnapShotDataV100(
241            snapshot_data: *mut GCMicroGamepadSnapShotDataV100,
242        ) -> *mut NSData;
243    }
244    let ret = unsafe { NSDataFromGCMicroGamepadSnapShotDataV100(snapshot_data) };
245    unsafe { Retained::retain_autoreleased(ret) }
246}
247
248#[deprecated = "renamed to `GCMicroGamepadSnapshotData::from_ns_data`"]
249#[inline]
250pub unsafe extern "C-unwind" fn GCMicroGamepadSnapshotDataFromNSData(
251    snapshot_data: *mut GCMicroGamepadSnapshotData,
252    data: Option<&NSData>,
253) -> bool {
254    extern "C-unwind" {
255        fn GCMicroGamepadSnapshotDataFromNSData(
256            snapshot_data: *mut GCMicroGamepadSnapshotData,
257            data: Option<&NSData>,
258        ) -> Bool;
259    }
260    unsafe { GCMicroGamepadSnapshotDataFromNSData(snapshot_data, data) }.as_bool()
261}
262
263#[deprecated = "renamed to `GCMicroGamepadSnapShotDataV100::from_ns_data`"]
264#[inline]
265pub unsafe extern "C-unwind" fn GCMicroGamepadSnapShotDataV100FromNSData(
266    snapshot_data: *mut GCMicroGamepadSnapShotDataV100,
267    data: Option<&NSData>,
268) -> bool {
269    extern "C-unwind" {
270        fn GCMicroGamepadSnapShotDataV100FromNSData(
271            snapshot_data: *mut GCMicroGamepadSnapShotDataV100,
272            data: Option<&NSData>,
273        ) -> Bool;
274    }
275    unsafe { GCMicroGamepadSnapShotDataV100FromNSData(snapshot_data, data) }.as_bool()
276}