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