objc2-game-controller 0.3.2

Bindings to the GameController framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;

use crate::*;

/// A 3 dimensional acceleration vector measured as scalar multiples of earth's gravitational acceleration, G.
///
/// The azimuth direction is assumed to be (0, 0, 1), so a device held at rest with the z axis aligned with the azimuth
/// is assumed to have gravitation applying the vector (0, 0, -1).
///
/// Field: x X-axis acceleration as a scalar multiple of earth's gravitational acceleration, G.
/// Field: y Y-axis acceleration as a scalar multiple of earth's gravitational acceleration, G.
/// Field: z Z-axis acceleration as a scalar multiple of earth's gravitational acceleration, G.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcacceleration?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct GCAcceleration {
    pub x: c_double,
    pub y: c_double,
    pub z: c_double,
}

unsafe impl Encode for GCAcceleration {
    const ENCODING: Encoding = Encoding::Struct(
        "?",
        &[
            <c_double>::ENCODING,
            <c_double>::ENCODING,
            <c_double>::ENCODING,
        ],
    );
}

unsafe impl RefEncode for GCAcceleration {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// A structure containing 3-axis rotation rate data.
///
/// Field: x   X-axis rotation rate in radians/second. The sign follows the right hand
/// rule (i.e. if the right hand is wrapped around the X axis such that the
/// tip of the thumb points toward positive X, a positive rotation is one
/// toward the tips of the other 4 fingers).
///
/// Field: y   Y-axis rotation rate in radians/second. The sign follows the right hand
/// rule (i.e. if the right hand is wrapped around the Y axis such that the
/// tip of the thumb points toward positive Y, a positive rotation is one
/// toward the tips of the other 4 fingers).
/// Field: z
/// Z-axis rotation rate in radians/second. The sign follows the right hand
/// rule (i.e. if the right hand is wrapped around the Z axis such that the
/// tip of the thumb points toward positive Z, a positive rotation is one
/// toward the tips of the other 4 fingers).
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcrotationrate?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct GCRotationRate {
    pub x: c_double,
    pub y: c_double,
    pub z: c_double,
}

unsafe impl Encode for GCRotationRate {
    const ENCODING: Encoding = Encoding::Struct(
        "?",
        &[
            <c_double>::ENCODING,
            <c_double>::ENCODING,
            <c_double>::ENCODING,
        ],
    );
}

unsafe impl RefEncode for GCRotationRate {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// A structure containing 3-axis rotation data. The angles are rotated in order or pitch then yaw then roll.
///
/// Field: pitch X-axis rotation in radians. The sign follows the right hand
/// rule (i.e. if the right hand is wrapped around the X axis such that the
/// tip of the thumb points toward positive X, a positive rotation is one
/// toward the tips of the other 4 fingers).
///
/// Field: yaw   Y-axis rotation in radians. The sign follows the right hand
/// rule (i.e. if the right hand is wrapped around the Y axis such that the
/// tip of the thumb points toward positive Y, a positive rotation is one
/// toward the tips of the other 4 fingers).
///
/// Field: roll  Z-axis rotation in radians. The sign follows the right hand
/// rule (i.e. if the right hand is wrapped around the Z axis such that the
/// tip of the thumb points toward positive Z, a positive rotation is one
/// toward the tips of the other 4 fingers).
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gceulerangles?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct GCEulerAngles {
    pub pitch: c_double,
    pub yaw: c_double,
    pub roll: c_double,
}

unsafe impl Encode for GCEulerAngles {
    const ENCODING: Encoding = Encoding::Struct(
        "?",
        &[
            <c_double>::ENCODING,
            <c_double>::ENCODING,
            <c_double>::ENCODING,
        ],
    );
}

unsafe impl RefEncode for GCEulerAngles {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// Represents a quaternion (one way of parameterizing attitude).
/// If q is an instance of GCQuaternion, mathematically it represents the following quaternion:
///
/// q.x*i + q.y*j + q.z*k + q.w
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcquaternion?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct GCQuaternion {
    pub x: c_double,
    pub y: c_double,
    pub z: c_double,
    pub w: c_double,
}

unsafe impl Encode for GCQuaternion {
    const ENCODING: Encoding = Encoding::Struct(
        "GCQuaternion",
        &[
            <c_double>::ENCODING,
            <c_double>::ENCODING,
            <c_double>::ENCODING,
            <c_double>::ENCODING,
        ],
    );
}

unsafe impl RefEncode for GCQuaternion {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// Called whenever a motion value changed.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcmotionvaluechangedhandler?language=objc)
#[cfg(feature = "block2")]
pub type GCMotionValueChangedHandler = *mut block2::DynBlock<dyn Fn(NonNull<GCMotion>)>;

extern_class!(
    /// A profile for getting motion input from a controller that has the ability to measure acceleration
    /// and rotation rate.
    ///
    /// You check for the availablity of motion inputs by getting the motion property
    /// of a controller. If that returns a nil value; motion is not available. A non-nil value is a valid
    /// GCMotion profile that is able to provide motion input.
    ///
    ///
    /// See: GCController.motion
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcmotion?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct GCMotion;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for GCMotion {}
);

impl GCMotion {
    extern_methods!(
        #[cfg(feature = "GCController")]
        /// A profile keeps a reference to the controller that it is mapping input from.
        ///
        ///
        /// See: GCController
        #[unsafe(method(controller))]
        #[unsafe(method_family = none)]
        pub unsafe fn controller(&self) -> Option<Retained<GCController>>;

        #[cfg(feature = "block2")]
        /// # Safety
        ///
        /// The returned block's argument must be a valid pointer.
        #[unsafe(method(valueChangedHandler))]
        #[unsafe(method_family = none)]
        pub unsafe fn valueChangedHandler(&self) -> GCMotionValueChangedHandler;

        #[cfg(feature = "block2")]
        /// Setter for [`valueChangedHandler`][Self::valueChangedHandler].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// `value_changed_handler` must be a valid pointer or null.
        #[unsafe(method(setValueChangedHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setValueChangedHandler(
            &self,
            value_changed_handler: GCMotionValueChangedHandler,
        );

        /// If this property is returns YES, you are responsible for setting sensorsActive to YES when you need motion data from the controller.
        ///
        /// Some controllers, such as the Siri Remote, automatically activate and deactivate motion sensors. In such a case, this property
        /// will return NO.
        ///
        ///
        /// See: sensorsActive
        #[unsafe(method(sensorsRequireManualActivation))]
        #[unsafe(method_family = none)]
        pub unsafe fn sensorsRequireManualActivation(&self) -> bool;

        /// Set this property to YES when you wish to receive motion data from the controller. When you set this property to NO, the motion sensors
        /// will be disabled and the GCMotion profile will not be updated.
        ///
        ///
        /// Note: It is highly recommended that you only enable sensor during the period of time you directly need motion data. Motion sensors
        /// can drain controller battery, device battery, and needlessly consume Bluetooth bandwidth.
        ///
        ///
        /// See: sensorsRequireManualActivation
        #[unsafe(method(sensorsActive))]
        #[unsafe(method_family = none)]
        pub unsafe fn sensorsActive(&self) -> bool;

        /// Setter for [`sensorsActive`][Self::sensorsActive].
        #[unsafe(method(setSensorsActive:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setSensorsActive(&self, sensors_active: bool);

        /// Returns YES if the controller is capable of reporting gravity and user acceleration separately.
        ///
        ///
        /// Note: Some controllers do not separate gravity from user acceleration, and only report the total acceleration of the controller.
        /// Query whether the connected controller has the ability to separate gravity and user acceleration, and it doesn’t, use acceleration instead.
        ///
        ///
        /// See: acceleration
        #[unsafe(method(hasGravityAndUserAcceleration))]
        #[unsafe(method_family = none)]
        pub unsafe fn hasGravityAndUserAcceleration(&self) -> bool;

        /// The gravity vector expressed in the controller's reference frame.
        ///
        /// Note that the total acceleration of the controller is equal to gravity plus userAcceleration.
        ///
        ///
        /// See: userAcceleration
        ///
        /// See: acceleration
        #[unsafe(method(gravity))]
        #[unsafe(method_family = none)]
        pub unsafe fn gravity(&self) -> GCAcceleration;

        /// The acceleration that the user is giving to the controller.
        ///
        /// Note that the total acceleration of the controller is equal to gravity plus userAcceleration.
        ///
        ///
        /// See: gravity
        ///
        /// See: acceleration
        #[unsafe(method(userAcceleration))]
        #[unsafe(method_family = none)]
        pub unsafe fn userAcceleration(&self) -> GCAcceleration;

        /// The total acceleration of the controller.
        ///
        ///
        /// See: gravity
        ///
        /// See: userAcceleration
        #[unsafe(method(acceleration))]
        #[unsafe(method_family = none)]
        pub unsafe fn acceleration(&self) -> GCAcceleration;

        /// The controller generating the motion data has sensors that can accurately determine the current attitude and rotation rate. If this is enabled the motion data for attitude and rotation rate are usable for inputs.
        #[deprecated = "Use -hasAttitude and -hasRotationRate methods instead"]
        #[unsafe(method(hasAttitudeAndRotationRate))]
        #[unsafe(method_family = none)]
        pub unsafe fn hasAttitudeAndRotationRate(&self) -> bool;

        /// The controller generating the motion data has sensors that can accurately determine the current attitude. If this is enabled the motion data for attitude is usable for inputs.
        #[unsafe(method(hasAttitude))]
        #[unsafe(method_family = none)]
        pub unsafe fn hasAttitude(&self) -> bool;

        /// The controller generating the motion data has sensors that can accurately determine the current rotation rate. If this is enabled the motion data for rotation rate is usable for inputs.
        #[unsafe(method(hasRotationRate))]
        #[unsafe(method_family = none)]
        pub unsafe fn hasRotationRate(&self) -> bool;

        /// The current attitude of the controller.
        ///
        ///
        /// Note: Remotes without accurate attitude and rotation rate can not determine a stable attitude so the values will be (0,0,0,1) at all times.
        ///
        /// See: hasAttitude
        ///
        /// See: GCMicroGamepad
        #[unsafe(method(attitude))]
        #[unsafe(method_family = none)]
        pub unsafe fn attitude(&self) -> GCQuaternion;

        /// The current rotation rate of the controller.
        ///
        ///
        /// Note: Remotes without accurate attitude and rotation rate can not determine a stable rotation rate so the values will be (0,0,0) at all times.
        ///
        /// See: hasRotationRate
        ///
        /// See: GCMicroGamepad
        #[unsafe(method(rotationRate))]
        #[unsafe(method_family = none)]
        pub unsafe fn rotationRate(&self) -> GCRotationRate;

        /// Sets the gravity vector expressed in the controller's reference frame.
        ///
        ///
        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
        ///
        /// See: gravity
        #[unsafe(method(setGravity:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setGravity(&self, gravity: GCAcceleration);

        /// Sets the acceleration that the user is giving to the controller.
        ///
        ///
        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
        ///
        /// See: userAcceleration
        #[unsafe(method(setUserAcceleration:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setUserAcceleration(&self, user_acceleration: GCAcceleration);

        /// Sets the acceleration that the user is giving to the controller.
        ///
        ///
        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
        ///
        /// See: userAcceleration
        #[unsafe(method(setAcceleration:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAcceleration(&self, acceleration: GCAcceleration);

        /// Sets the current rotation rate of the controller.
        ///
        ///
        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
        ///
        /// See: attitude
        #[unsafe(method(setAttitude:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAttitude(&self, attitude: GCQuaternion);

        /// Sets the current rotation rate of the controller.
        ///
        ///
        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
        ///
        /// See: rotationRate
        #[unsafe(method(setRotationRate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setRotationRate(&self, rotation_rate: GCRotationRate);

        /// Sets the state vector of the motion profile to a copy of the input motion profile's state vector.
        ///
        ///
        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
        ///
        /// See: GCController.snapshot
        #[unsafe(method(setStateFromMotion:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setStateFromMotion(&self, motion: &GCMotion);
    );
}

/// Methods declared on superclass `NSObject`.
impl GCMotion {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}