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        #[deprecated = "Use GCExtendedGamepad instead"]
46        #[unsafe(method(setSnapshotData:))]
47        #[unsafe(method_family = none)]
48        pub unsafe fn setSnapshotData(&self, snapshot_data: &NSData);
49
50        #[deprecated = "Use GCExtendedGamepad 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 GCExtendedGamepad 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 = "GCGamepad", feature = "GCPhysicalInputProfile"))]
69impl GCGamepadSnapshot {
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/gcgamepadsnapshotdatav100?language=objc)
82#[repr(C)]
83#[derive(Clone, Copy, Debug, PartialEq)]
84pub struct GCGamepadSnapShotDataV100 {
85    pub version: u16,
86    pub size: u16,
87    pub dpadX: c_float,
88    pub dpadY: c_float,
89    pub buttonA: c_float,
90    pub buttonB: c_float,
91    pub buttonX: c_float,
92    pub buttonY: c_float,
93    pub leftShoulder: c_float,
94    pub rightShoulder: c_float,
95}
96
97unsafe impl Encode for GCGamepadSnapShotDataV100 {
98    const ENCODING: Encoding = Encoding::Struct(
99        "?",
100        &[
101            <u16>::ENCODING,
102            <u16>::ENCODING,
103            <c_float>::ENCODING,
104            <c_float>::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        ],
112    );
113}
114
115unsafe impl RefEncode for GCGamepadSnapShotDataV100 {
116    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
117}
118
119impl GCGamepadSnapShotDataV100 {
120    /// Fills out a v100 snapshot from any compatible NSData source
121    ///
122    ///
123    /// 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.
124    #[doc(alias = "GCGamepadSnapShotDataV100FromNSData")]
125    #[deprecated = "Use GCExtendedGamepad instead"]
126    #[inline]
127    pub unsafe fn from_ns_data(
128        snapshot_data: *mut GCGamepadSnapShotDataV100,
129        data: Option<&NSData>,
130    ) -> bool {
131        extern "C-unwind" {
132            fn GCGamepadSnapShotDataV100FromNSData(
133                snapshot_data: *mut GCGamepadSnapShotDataV100,
134                data: Option<&NSData>,
135            ) -> Bool;
136        }
137        unsafe { GCGamepadSnapShotDataV100FromNSData(snapshot_data, data) }.as_bool()
138    }
139}
140
141/// Creates an NSData object from a v100 snapshot.
142/// 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.
143///
144///
145/// Returns: nil if the snapshot is NULL, otherwise an NSData instance compatible with GCGamepadSnapshot.snapshotData
146#[deprecated = "Use GCExtendedGamepad instead"]
147#[inline]
148pub unsafe extern "C-unwind" fn NSDataFromGCGamepadSnapShotDataV100(
149    snapshot_data: *mut GCGamepadSnapShotDataV100,
150) -> Option<Retained<NSData>> {
151    extern "C-unwind" {
152        fn NSDataFromGCGamepadSnapShotDataV100(
153            snapshot_data: *mut GCGamepadSnapShotDataV100,
154        ) -> *mut NSData;
155    }
156    let ret = unsafe { NSDataFromGCGamepadSnapShotDataV100(snapshot_data) };
157    unsafe { Retained::retain_autoreleased(ret) }
158}
159
160#[deprecated = "renamed to `GCGamepadSnapShotDataV100::from_ns_data`"]
161#[inline]
162pub unsafe extern "C-unwind" fn GCGamepadSnapShotDataV100FromNSData(
163    snapshot_data: *mut GCGamepadSnapShotDataV100,
164    data: Option<&NSData>,
165) -> bool {
166    extern "C-unwind" {
167        fn GCGamepadSnapShotDataV100FromNSData(
168            snapshot_data: *mut GCGamepadSnapShotDataV100,
169            data: Option<&NSData>,
170        ) -> Bool;
171    }
172    unsafe { GCGamepadSnapShotDataV100FromNSData(snapshot_data, data) }.as_bool()
173}