objc2_game_controller/generated/GCController.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 "C" {
11 /// Use these constants with NSNotificationCenter to listen to connection and disconnection events.
12 ///
13 /// Use GCControllerDidConnectNotification for observing connections of controllers.
14 /// Use GCControllerDidDisconnectNotification for observing disconnections of controllers.
15 ///
16 /// Connections and disconnections of controllers will also be reflected in the controllers array
17 /// of the GCController class.
18 ///
19 /// The 'object' property of the notification will contain the GCController that was connected or disconnected.
20 /// For example:
21 ///
22 /// - (void)controllerDidConnect:(NSNotification *)note {
23 ///
24 /// GCController *controller = note.object;
25 ///
26 /// ....
27 /// }
28 ///
29 ///
30 /// See: NSNotificationCenter
31 ///
32 /// See: GCController.controllers
33 ///
34 /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerdidconnectnotification?language=objc)
35 pub static GCControllerDidConnectNotification: &'static NSString;
36}
37
38extern "C" {
39 /// [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerdiddisconnectnotification?language=objc)
40 pub static GCControllerDidDisconnectNotification: &'static NSString;
41}
42
43extern "C" {
44 /// Use these constants with NSNotificationCenter to listen to a controller becoming the most recently used controller.
45 /// This is a good time to swap out UI to match the new current controller, and unregister any handlers with
46 /// the old current controller.
47 ///
48 /// The 'object' property of the notification will contain the GCController that became the current controller.
49 /// For example:
50 ///
51 /// - (void)controllerDidBecomeCurrent:(NSNotification *)note {
52 ///
53 /// GCController *controller = note.object;
54 ///
55 /// ...
56 /// }
57 ///
58 /// See: NSNotificationCenter
59 ///
60 /// See: GCController.controllers
61 ///
62 /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerdidbecomecurrentnotification?language=objc)
63 pub static GCControllerDidBecomeCurrentNotification: &'static NSString;
64}
65
66extern "C" {
67 /// [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerdidstopbeingcurrentnotification?language=objc)
68 pub static GCControllerDidStopBeingCurrentNotification: &'static NSString;
69}
70
71extern "C" {
72 /// Use this constant with NSNotificationCenter to listen to controller user customization events.
73 ///
74 /// When a user customizes the button mappings or other settings of a controller this notification will be
75 /// posted. This is a good time to swap out UI to match the new user settings. Users can modify game
76 /// controller settings through the Settings app on iOS, tvOS, and macOS.
77 ///
78 /// The 'object' property of the notification will contain the GCController that was customized.
79 /// For example:
80 ///
81 /// - (void)controllerDidConnect:(NSNotification *)note {
82 ///
83 /// GCController *controller = note.object;
84 ///
85 /// ....
86 /// }
87 ///
88 ///
89 /// See: NSNotificationCenter
90 ///
91 /// See: GCController.controllers
92 ///
93 /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerusercustomizationsdidchangenotification?language=objc)
94 pub static GCControllerUserCustomizationsDidChangeNotification: &'static NSString;
95}
96
97/// This is the player index that a connected controller will have if it has never been assigned a player index on the current system.
98/// Controllers retain the player index they have been assigned between game sessions, so if you wish to unset the player index of a
99/// controller set it back to this value.
100///
101/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerplayerindex?language=objc)
102// NS_ENUM
103#[repr(transparent)]
104#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
105pub struct GCControllerPlayerIndex(pub NSInteger);
106impl GCControllerPlayerIndex {
107 #[doc(alias = "GCControllerPlayerIndexUnset")]
108 pub const IndexUnset: Self = Self(-1);
109 #[doc(alias = "GCControllerPlayerIndex1")]
110 pub const Index1: Self = Self(0);
111 #[doc(alias = "GCControllerPlayerIndex2")]
112 pub const Index2: Self = Self(1);
113 #[doc(alias = "GCControllerPlayerIndex3")]
114 pub const Index3: Self = Self(2);
115 #[doc(alias = "GCControllerPlayerIndex4")]
116 pub const Index4: Self = Self(3);
117}
118
119unsafe impl Encode for GCControllerPlayerIndex {
120 const ENCODING: Encoding = NSInteger::ENCODING;
121}
122
123unsafe impl RefEncode for GCControllerPlayerIndex {
124 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
125}
126
127extern_class!(
128 /// Controllers are available to an application that links to GameController.framework. There are 2 ways to access controllers
129 /// paired to the system, adopt both to ensure the best user experience:
130 ///
131 /// 1: Querying for the the current array or controllers using [GCController controllers].
132 /// 2: Registering for Connection/Disconnection notifications from NSNotificationCenter.
133 ///
134 /// Only controllers that support one of the allowed profiles, such as GCExtendedGamepad, will be enumerated. Check for the profile
135 /// supported before using a controller in your application. Ignore a controller that doesn't support a profile that suits
136 /// your application, as the user will expect their controller to either be fully supported or not supported at all.
137 ///
138 /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontroller?language=objc)
139 #[unsafe(super(NSObject))]
140 #[derive(Debug, PartialEq, Eq, Hash)]
141 pub struct GCController;
142);
143
144#[cfg(feature = "GCDevice")]
145unsafe impl GCDevice for GCController {}
146
147unsafe impl NSObjectProtocol for GCController {}
148
149impl GCController {
150 extern_methods!(
151 #[cfg(feature = "block2")]
152 /// Set this block to be notified when a user intends to suspend or resume the current game state. A controller will have a button
153 /// dedicated to suspending and resuming play and invoking context sensitive actions. During event handling the system will
154 /// notify the application using this block such that the application can handle the suspension and resumption from the given controller.
155 ///
156 /// Use this to implement your canonical transition to a pause menu for example if that is your application's desired handling
157 /// of suspension in play. You may pause and resume based on game state as well so the event is only called each time the
158 /// pause/resume button is pressed.
159 ///
160 ///
161 /// Note: This handler has been deprecated in favor of the Menu button found on GCMicroGamepad and GCExtendedGamepad.
162 ///
163 /// See: microGamepad
164 ///
165 /// See: extendedGamepad
166 #[deprecated = "controllerPausedHandler has been deprecated. Use the Menu button found on the controller's profile, if it exists."]
167 #[unsafe(method(controllerPausedHandler))]
168 #[unsafe(method_family = none)]
169 pub unsafe fn controllerPausedHandler(
170 &self,
171 ) -> *mut block2::Block<dyn Fn(NonNull<GCController>)>;
172
173 #[cfg(feature = "block2")]
174 /// Setter for [`controllerPausedHandler`][Self::controllerPausedHandler].
175 #[deprecated = "controllerPausedHandler has been deprecated. Use the Menu button found on the controller's profile, if it exists."]
176 #[unsafe(method(setControllerPausedHandler:))]
177 #[unsafe(method_family = none)]
178 pub unsafe fn setControllerPausedHandler(
179 &self,
180 controller_paused_handler: Option<&block2::Block<dyn Fn(NonNull<GCController>)>>,
181 );
182
183 /// The most recently used game controller. If a user actuates a game controller input, that controller will become the current one.
184 ///
185 ///
186 /// Note: This is useful for single player games where you only care about whether an input is pressed, and not where it came from. You
187 /// will still need to register for changes to GCController.current so that your UI can remain up-to-date with the current controller.
188 #[unsafe(method(current))]
189 #[unsafe(method_family = none)]
190 pub unsafe fn current() -> Option<Retained<GCController>>;
191
192 /// Whether the current application should monitor and respond to game controller events when it is not the frontmost application.
193 ///
194 ///
195 /// not be forwarded to the application. Once the application becomes the frontmost application, game controller events will be forwarded.
196 ///
197 ///
198 /// Note: Starting with macOS Big Sur 11.3, shouldMonitorBackgroundEvents will be NO by default. For applications built prior to macOS Big Sur 11.3,
199 /// (or running on devices with an earlier version of macOS), shouldMonitorBackgroundEvents will be YES by default. On iOS and tvOS, this property is ignored.
200 #[unsafe(method(shouldMonitorBackgroundEvents))]
201 #[unsafe(method_family = none)]
202 pub unsafe fn shouldMonitorBackgroundEvents() -> bool;
203
204 /// Setter for [`shouldMonitorBackgroundEvents`][Self::shouldMonitorBackgroundEvents].
205 #[unsafe(method(setShouldMonitorBackgroundEvents:))]
206 #[unsafe(method_family = none)]
207 pub unsafe fn setShouldMonitorBackgroundEvents(should_monitor_background_events: bool);
208
209 /// A controller may be form fitting or otherwise closely attached to the device. This closeness to other inputs on the device
210 /// may suggest that interaction with the device may use other inputs easily. This is presented to developers to allow them to
211 /// make informed decisions about UI and interactions to choose for their game in this situation.
212 #[unsafe(method(isAttachedToDevice))]
213 #[unsafe(method_family = none)]
214 pub unsafe fn isAttachedToDevice(&self) -> bool;
215
216 /// A controller may represent a real device managed by the operating system, or a virtual snapshot created by the developer.
217 /// If a controller is directly created by the developer, it is considered to be a snapshot, allowing direct writes to any
218 /// GCControllerElement of its profiles. If the controller is not snapshot, the system will reject any write requests to GCControllerElement.
219 ///
220 ///
221 /// See: controllerWithMicroGamepad
222 ///
223 /// See: controllerWithExtendedGamepad
224 ///
225 /// See: capture
226 #[unsafe(method(isSnapshot))]
227 #[unsafe(method_family = none)]
228 pub unsafe fn isSnapshot(&self) -> bool;
229
230 /// A player index for the controller, defaults to GCControllerPlayerIndexUnset.
231 ///
232 /// This can be set both for the application to keep track of controllers and as a signal to make a controller display a player
233 /// index on a set of LEDs or some other mechanism.
234 ///
235 /// A controller is not guaranteed to have a visual display of the playerIndex, playerIndex does not persist for a controller
236 /// with regards to a system.
237 ///
238 /// Negative values less than GCControllerPlayerIndexUnset will just map back to GCControllerPlayerIndexUnset when read back.
239 #[unsafe(method(playerIndex))]
240 #[unsafe(method_family = none)]
241 pub unsafe fn playerIndex(&self) -> GCControllerPlayerIndex;
242
243 /// Setter for [`playerIndex`][Self::playerIndex].
244 #[unsafe(method(setPlayerIndex:))]
245 #[unsafe(method_family = none)]
246 pub unsafe fn setPlayerIndex(&self, player_index: GCControllerPlayerIndex);
247
248 #[cfg(feature = "GCControllerInput")]
249 /// Gets the input profile for the controller.
250 #[unsafe(method(input))]
251 #[unsafe(method_family = none)]
252 pub unsafe fn input(&self) -> Retained<GCControllerLiveInput>;
253
254 #[cfg(feature = "GCDeviceBattery")]
255 /// Gets the battery information if controller supports one
256 ///
257 /// This property is useful when you try to notify your user to change or charge controller before it runs out of battery life
258 /// or simply display the current battery level and status.
259 #[unsafe(method(battery))]
260 #[unsafe(method_family = none)]
261 pub unsafe fn battery(&self) -> Option<Retained<GCDeviceBattery>>;
262
263 #[cfg(feature = "GCPhysicalInputProfile")]
264 /// Gets the physical input profile for the controller.
265 ///
266 ///
267 /// Note: This is equivalent to the controller's microGamepad, or extendedGamepad instance.
268 ///
269 /// See: microGamepad
270 ///
271 /// See: extendedGamepad
272 #[unsafe(method(physicalInputProfile))]
273 #[unsafe(method_family = none)]
274 pub unsafe fn physicalInputProfile(&self) -> Retained<GCPhysicalInputProfile>;
275
276 #[cfg(all(feature = "GCGamepad", feature = "GCPhysicalInputProfile"))]
277 /// Gets the profile for the controller that suits current application.
278 ///
279 /// There are several supported profiles, with an additional optional profile for motion as well.
280 /// Each controller may be able to map its inputs into all profiles or just one kind of profile. Query for the controller
281 /// profile that suits your game, the simplest kind will be supported by the broadest variety
282 /// of controllers. A controller supporting the Extended Gamepad profile for example supports the Gamepad profile and more.
283 /// As such it can always be used just in the Gamepad profile if that suits the game.
284 ///
285 /// A physical controller that supports a profile must support it completely. That means that all buttons and axis inputs must
286 /// be valid inputs that a developer can utilize.
287 ///
288 /// If a controller does not support the given profile the returned value will be nil. Use this to filter controllers if the
289 /// application requires a specific kind of profile.
290 ///
291 /// See: motion
292 #[deprecated]
293 #[unsafe(method(gamepad))]
294 #[unsafe(method_family = none)]
295 pub unsafe fn gamepad(&self) -> Option<Retained<GCGamepad>>;
296
297 #[cfg(all(feature = "GCMicroGamepad", feature = "GCPhysicalInputProfile"))]
298 #[unsafe(method(microGamepad))]
299 #[unsafe(method_family = none)]
300 pub unsafe fn microGamepad(&self) -> Option<Retained<GCMicroGamepad>>;
301
302 #[cfg(all(feature = "GCExtendedGamepad", feature = "GCPhysicalInputProfile"))]
303 #[unsafe(method(extendedGamepad))]
304 #[unsafe(method_family = none)]
305 pub unsafe fn extendedGamepad(&self) -> Option<Retained<GCExtendedGamepad>>;
306
307 #[cfg(feature = "GCMotion")]
308 /// Gets the motion input profile. This profile is optional and may be available if the controller is attached to a device that supports motion.
309 /// If this is nil the controller does not support motion input and only the gamepad
310 /// &
311 /// extendedGamepad profiles are available.
312 ///
313 /// See: gamepad
314 ///
315 /// See: extendedGamepad
316 #[unsafe(method(motion))]
317 #[unsafe(method_family = none)]
318 pub unsafe fn motion(&self) -> Option<Retained<GCMotion>>;
319
320 #[cfg(feature = "GCDeviceLight")]
321 /// Gets the light for the controller, if one exists.
322 ///
323 /// A controller's light can be used to signal information to the player, such as using different light colors based on the player
324 /// index. It can also be used to react to in-game events and enhance user immersion.
325 #[unsafe(method(light))]
326 #[unsafe(method_family = none)]
327 pub unsafe fn light(&self) -> Option<Retained<GCDeviceLight>>;
328
329 #[cfg(feature = "GCDeviceHaptics")]
330 /// Gets the haptics for the controller, if one exists.
331 ///
332 /// Use this property to create CHHapticEngine instances according to your needs.
333 ///
334 ///
335 /// Note: Haptics are a drain on the controller's battery, and can be distracting when used excessively.
336 #[unsafe(method(haptics))]
337 #[unsafe(method_family = none)]
338 pub unsafe fn haptics(&self) -> Option<Retained<GCDeviceHaptics>>;
339
340 /// Polls the state vector of the controller and saves it to a new and writable instance of GCController.
341 ///
342 /// If your application is heavily multithreaded this may also be useful to guarantee atomicity of input handling as
343 /// a snapshot will not change based on user input once it is taken.
344 ///
345 ///
346 /// See: snapshot
347 ///
348 /// Returns: A new controller with the duplicated state vector of the current controller
349 #[unsafe(method(capture))]
350 #[unsafe(method_family = none)]
351 pub unsafe fn capture(&self) -> Retained<GCController>;
352
353 /// Get a list of controllers currently attached to the system.
354 ///
355 ///
356 /// See: GCControllerDidConnectNotification
357 ///
358 /// See: GCControllerDidDisconnectNotification
359 #[unsafe(method(controllers))]
360 #[unsafe(method_family = none)]
361 pub unsafe fn controllers() -> Retained<NSArray<GCController>>;
362
363 #[cfg(feature = "block2")]
364 /// Start discovery of new wireless controllers that are discoverable. This is an asynchronous and the supplied completionHandler
365 /// will get called once no more devices can be found. If there are already multiple controllers available for use, there
366 /// may be little reason to automatically start discovery of new wireless controllers. In this situation it may be best to
367 /// allow the user to start discovery manually via in-game UI.
368 ///
369 /// Once discovery has started new controllers will notify themselves as connected via GCControllerDidConnectNotification.
370 /// As the notification arrives the controller is also available in the controllers array.
371 ///
372 /// The completionHandler could be used to update UI and/or game state to indicate that no more controllers will be found
373 /// and the current set of controllers is what is available for use in the game.
374 ///
375 /// If a completionHandler was provided, it will be called once when discovery stops. Either from an explicit call to
376 /// stopWirelessControllerDiscovery or from timing out or stopping in its natural course of operation. Thus the
377 /// completionHandler will at most be called once per call to startWirelessControllerDiscoveryWithCompletionHandler:.
378 ///
379 /// The completionHandler may also not get called at all, if for example startWirelessControllerDiscoveryWithCompletionHandler:
380 /// is called multiple times during dicovery. For this case the net effect is that the completionHandler is replaced with each call
381 /// and only the last one set before discovery stops will be called.
382 ///
383 ///
384 /// Parameter `completionHandler`: an optional handler that is called when discovery stops. (may be nil, in which case you will not be notified when discovery stops)
385 ///
386 /// See: stopWirelessControllerDiscovery
387 ///
388 /// See: controllers
389 #[unsafe(method(startWirelessControllerDiscoveryWithCompletionHandler:))]
390 #[unsafe(method_family = none)]
391 pub unsafe fn startWirelessControllerDiscoveryWithCompletionHandler(
392 completion_handler: Option<&block2::Block<dyn Fn()>>,
393 );
394
395 /// If no more controllers are needed, depending on game state or number of controllers supported by a game, the discovery
396 /// process can be stopped. Calling stopWirelessControllerDiscovery when no discovery is currently in progress will return
397 /// immediately without any effect, thus it is safe to call even if the completionHandler of
398 /// startWirelessControllerDiscoveryWithCompletionHandler: has been called.
399 ///
400 ///
401 /// See: startWirelessControllerDiscoveryWithCompletionHandler:
402 #[unsafe(method(stopWirelessControllerDiscovery))]
403 #[unsafe(method_family = none)]
404 pub unsafe fn stopWirelessControllerDiscovery();
405
406 /// Creates a controller with a micro gamepad profile.
407 ///
408 /// This controller will be considered a snapshot, allowing developers to write to any GCControllerElement of its profiles.
409 ///
410 ///
411 /// See: snapshot
412 ///
413 /// Returns: A new controller with a micro gamepad profile
414 #[unsafe(method(controllerWithMicroGamepad))]
415 #[unsafe(method_family = none)]
416 pub unsafe fn controllerWithMicroGamepad() -> Retained<GCController>;
417
418 /// Creates a controller with an extended gamepad profile.
419 ///
420 /// This controller will be considered a snapshot, allowing developers to write to any GCControllerElement of its profiles.
421 ///
422 ///
423 /// See: snapshot
424 ///
425 /// Returns: A new controller with an extended gamepad profile
426 #[unsafe(method(controllerWithExtendedGamepad))]
427 #[unsafe(method_family = none)]
428 pub unsafe fn controllerWithExtendedGamepad() -> Retained<GCController>;
429 );
430}
431
432/// Methods declared on superclass `NSObject`.
433impl GCController {
434 extern_methods!(
435 #[unsafe(method(init))]
436 #[unsafe(method_family = init)]
437 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
438
439 #[unsafe(method(new))]
440 #[unsafe(method_family = new)]
441 pub unsafe fn new() -> Retained<Self>;
442 );
443}