objc2_game_controller/generated/
GCGamepadSnapshot.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 GCGamepadSnapshot snapshot is a concrete GCGamepad 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 GCGamepadSnapShotData structure.
19    ///
20    ///
21    /// See: -[GCGamepad saveSnapshot]
22    ///
23    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcgamepadsnapshot?language=objc)
24    #[unsafe(super(GCGamepad, GCPhysicalInputProfile, NSObject))]
25    #[derive(Debug, PartialEq, Eq, Hash)]
26    #[cfg(all(feature = "GCGamepad", feature = "GCPhysicalInputProfile"))]
27    #[deprecated = "Use GCExtendedGamepad instead"]
28    pub struct GCGamepadSnapshot;
29);
30
31#[cfg(all(feature = "GCGamepad", feature = "GCPhysicalInputProfile"))]
32extern_conformance!(
33    unsafe impl NSObjectProtocol for GCGamepadSnapshot {}
34);
35
36#[cfg(all(feature = "GCGamepad", feature = "GCPhysicalInputProfile"))]
37impl GCGamepadSnapshot {
38    extern_methods!(
39        #[deprecated = "Use GCExtendedGamepad 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 GCExtendedGamepad instead"]
48        #[unsafe(method(setSnapshotData:))]
49        #[unsafe(method_family = none)]
50        pub unsafe fn setSnapshotData(&self, snapshot_data: &NSData);
51
52        #[deprecated = "Use GCExtendedGamepad 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 GCExtendedGamepad 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 = "GCGamepad", feature = "GCPhysicalInputProfile"))]
71impl GCGamepadSnapshot {
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/gcgamepadsnapshotdatav100?language=objc)
84#[repr(C, packed)]
85#[derive(Clone, Copy, Debug, PartialEq)]
86pub struct GCGamepadSnapShotDataV100 {
87    pub version: u16,
88    pub size: u16,
89    pub dpadX: c_float,
90    pub dpadY: c_float,
91    pub buttonA: c_float,
92    pub buttonB: c_float,
93    pub buttonX: c_float,
94    pub buttonY: c_float,
95    pub leftShoulder: c_float,
96    pub rightShoulder: c_float,
97}
98
99unsafe impl Encode for GCGamepadSnapShotDataV100 {
100    const ENCODING: Encoding = Encoding::Struct(
101        "?",
102        &[
103            <u16>::ENCODING,
104            <u16>::ENCODING,
105            <c_float>::ENCODING,
106            <c_float>::ENCODING,
107            <c_float>::ENCODING,
108            <c_float>::ENCODING,
109            <c_float>::ENCODING,
110            <c_float>::ENCODING,
111            <c_float>::ENCODING,
112            <c_float>::ENCODING,
113        ],
114    );
115}
116
117unsafe impl RefEncode for GCGamepadSnapShotDataV100 {
118    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
119}
120
121impl GCGamepadSnapShotDataV100 {
122    /// Fills out a v100 snapshot from any compatible NSData source
123    ///
124    ///
125    /// 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.
126    ///
127    /// # Safety
128    ///
129    /// `snapshot_data` must be a valid pointer or null.
130    #[doc(alias = "GCGamepadSnapShotDataV100FromNSData")]
131    #[deprecated = "Use GCExtendedGamepad instead"]
132    #[inline]
133    pub unsafe fn from_ns_data(
134        snapshot_data: *mut GCGamepadSnapShotDataV100,
135        data: Option<&NSData>,
136    ) -> bool {
137        extern "C-unwind" {
138            fn GCGamepadSnapShotDataV100FromNSData(
139                snapshot_data: *mut GCGamepadSnapShotDataV100,
140                data: Option<&NSData>,
141            ) -> Bool;
142        }
143        unsafe { GCGamepadSnapShotDataV100FromNSData(snapshot_data, data) }.as_bool()
144    }
145}
146
147/// Creates an NSData object from a v100 snapshot.
148/// If the version and size is not set in the snapshot the data will automatically have version 0x100 and sizeof(GCGamepadSnapShotDataV100) set as the values implicitly.
149///
150///
151/// Returns: nil if the snapshot is NULL, otherwise an NSData instance compatible with GCGamepadSnapshot.snapshotData
152///
153/// # Safety
154///
155/// `snapshot_data` must be a valid pointer or null.
156#[deprecated = "Use GCExtendedGamepad instead"]
157#[inline]
158pub unsafe extern "C-unwind" fn NSDataFromGCGamepadSnapShotDataV100(
159    snapshot_data: *mut GCGamepadSnapShotDataV100,
160) -> Option<Retained<NSData>> {
161    extern "C-unwind" {
162        fn NSDataFromGCGamepadSnapShotDataV100(
163            snapshot_data: *mut GCGamepadSnapShotDataV100,
164        ) -> *mut NSData;
165    }
166    let ret = unsafe { NSDataFromGCGamepadSnapShotDataV100(snapshot_data) };
167    unsafe { Retained::retain_autoreleased(ret) }
168}
169
170#[deprecated = "renamed to `GCGamepadSnapShotDataV100::from_ns_data`"]
171#[inline]
172pub unsafe extern "C-unwind" fn GCGamepadSnapShotDataV100FromNSData(
173    snapshot_data: *mut GCGamepadSnapShotDataV100,
174    data: Option<&NSData>,
175) -> bool {
176    extern "C-unwind" {
177        fn GCGamepadSnapShotDataV100FromNSData(
178            snapshot_data: *mut GCGamepadSnapShotDataV100,
179            data: Option<&NSData>,
180        ) -> Bool;
181    }
182    unsafe { GCGamepadSnapShotDataV100FromNSData(snapshot_data, data) }.as_bool()
183}