objc2_game_controller/generated/
GCDevicePhysicalInput.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::*;
6
7use crate::*;
8
9extern_protocol!(
10    /// An objecting conforming to
11    /// `GCDevicePhysicalInput`provides properties and
12    /// methods for accessing common physical elements - buttons, thumbsticks, dpads,
13    /// etc - of a device.
14    ///
15    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcdevicephysicalinput?language=objc)
16    #[cfg(feature = "GCDevicePhysicalInputState")]
17    pub unsafe trait GCDevicePhysicalInput: GCDevicePhysicalInputState {
18        #[cfg(feature = "GCDevice")]
19        /// The device that this profile is mapping input from.
20        #[unsafe(method(device))]
21        #[unsafe(method_family = none)]
22        unsafe fn device(&self) -> Option<Retained<ProtocolObject<dyn GCDevice>>>;
23
24        #[cfg(all(feature = "GCPhysicalInputElement", feature = "block2"))]
25        /// Set this block to be notified when a value on a element changed.  If multiple
26        /// elements change this block will be called for each element that changed.
27        ///
28        /// The block is called on the
29        /// `queue`configured for the physical input.
30        ///
31        ///
32        /// Parameter `element`: The element that has been modified.
33        #[unsafe(method(elementValueDidChangeHandler))]
34        #[unsafe(method_family = none)]
35        unsafe fn elementValueDidChangeHandler(
36            &self,
37        ) -> *mut block2::Block<
38            dyn Fn(
39                NonNull<ProtocolObject<dyn GCDevicePhysicalInput>>,
40                NonNull<ProtocolObject<dyn GCPhysicalInputElement>>,
41            ),
42        >;
43
44        #[cfg(all(feature = "GCPhysicalInputElement", feature = "block2"))]
45        /// Setter for [`elementValueDidChangeHandler`][Self::elementValueDidChangeHandler].
46        #[unsafe(method(setElementValueDidChangeHandler:))]
47        #[unsafe(method_family = none)]
48        unsafe fn setElementValueDidChangeHandler(
49            &self,
50            element_value_did_change_handler: Option<
51                &block2::Block<
52                    dyn Fn(
53                        NonNull<ProtocolObject<dyn GCDevicePhysicalInput>>,
54                        NonNull<ProtocolObject<dyn GCPhysicalInputElement>>,
55                    ),
56                >,
57            >,
58        );
59
60        /// Polls the current state vector of the physical input and saves it to a new
61        /// instance.
62        ///
63        /// If your application is heavily multithreaded this may also be useful to
64        /// guarantee atomicity of input handling as a snapshot will not change based on
65        /// further device input once it is taken.
66        ///
67        ///
68        /// Returns: An input state with the duplicated state vector of the current input.
69        #[unsafe(method(capture))]
70        #[unsafe(method_family = none)]
71        unsafe fn capture(&self) -> Retained<ProtocolObject<dyn GCDevicePhysicalInputState>>;
72
73        #[cfg(feature = "block2")]
74        /// Set this block to be notified when a new input state is available.  Your
75        /// handler should repeatedly call
76        /// `-nextInputState`until it returns
77        /// `nil`to
78        /// drain the pending input states from the queue.
79        ///
80        /// physicalInput.inputStateQueueDepth = 20;
81        /// physicalInput.inputStateAvailableHandler = ^(__kindof id
82        /// <GCDevicePhysicalInput
83        /// > physicalInput) {
84        /// id
85        /// <GCDevicePhysicalInputState
86        /// , GCDevicePhysicalInputStateDiff> nextInputState;
87        /// while ((nextInputState = [physicalInput nextInputState])) {
88        ///
89        /// // You can grab the individual states of all elements that your app
90        /// // is interested in.
91        /// id
92        /// <GCButtonElement
93        /// > buttonA = nextInputState.buttons[GCInputButtonA];
94        /// BOOL buttonAPressed = buttonA.pressedInput.pressed;
95        /// if (buttonAPressed) {
96        /// // Handle button A pressed
97        /// }
98        ///
99        /// // Your code can first query whether an element's input value changed
100        /// // from the prior input state.
101        /// GCDevicePhysicalInputElementChange buttonAChange = [nextInputState changeForElement:buttonA];
102        /// if (buttonAChange == GCDevicePhysicalInputElementChanged) {
103        /// // Handle button A input changed
104        /// }
105        ///
106        /// // Or, your code can request an enumerator of elements with input
107        /// // values that changed from the prior input state
108        /// for (id
109        /// <GCPhysicalInputElement
110        /// > changedElement in nextInputState.changedElements) {
111        ///
112        /// }
113        /// }
114        /// };
115        #[unsafe(method(inputStateAvailableHandler))]
116        #[unsafe(method_family = none)]
117        unsafe fn inputStateAvailableHandler(
118            &self,
119        ) -> *mut block2::Block<dyn Fn(NonNull<ProtocolObject<dyn GCDevicePhysicalInput>>)>;
120
121        #[cfg(feature = "block2")]
122        /// Setter for [`inputStateAvailableHandler`][Self::inputStateAvailableHandler].
123        #[unsafe(method(setInputStateAvailableHandler:))]
124        #[unsafe(method_family = none)]
125        unsafe fn setInputStateAvailableHandler(
126            &self,
127            input_state_available_handler: Option<
128                &block2::Block<dyn Fn(NonNull<ProtocolObject<dyn GCDevicePhysicalInput>>)>,
129            >,
130        );
131
132        /// The maximum number of input states to buffer.  If your application does not
133        /// drain the pending input states in the queue before this limit is reached, older
134        /// input states will be discarded - resulting in your application "missing" input
135        /// state changes.
136        ///
137        /// The default value is
138        /// `one`(no buffering).  Smaller values are ignored.  A
139        /// value of
140        /// `20`should be more than enough to ensure no input state changes
141        /// are missed.
142        #[unsafe(method(inputStateQueueDepth))]
143        #[unsafe(method_family = none)]
144        unsafe fn inputStateQueueDepth(&self) -> NSInteger;
145
146        /// Setter for [`inputStateQueueDepth`][Self::inputStateQueueDepth].
147        #[unsafe(method(setInputStateQueueDepth:))]
148        #[unsafe(method_family = none)]
149        unsafe fn setInputStateQueueDepth(&self, input_state_queue_depth: NSInteger);
150
151        #[cfg(feature = "GCDevicePhysicalInputStateDiff")]
152        /// Pop the oldest pending input state from the queue.  This method returns
153        /// `nil`when there are no more input states pending.
154        #[unsafe(method(nextInputState))]
155        #[unsafe(method_family = none)]
156        unsafe fn nextInputState(
157            &self,
158        ) -> Option<
159            Retained<
160                AnyObject, /* GCDevicePhysicalInputState+ GCDevicePhysicalInputStateDiff */
161            >,
162        >;
163    }
164);