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 #[unsafe(method(setQueue:))]
43 #[unsafe(method_family = none)]
44 unsafe fn setQueue(&self, queue: Option<&DispatchQueue>);
45
46 #[cfg(all(feature = "GCPhysicalInputElement", feature = "block2"))]
47 /// Set this block to be notified when a value on a element changed. If multiple
48 /// elements change this block will be called for each element that changed.
49 ///
50 /// The block is called on the
51 /// `queue`configured for the physical input.
52 ///
53 ///
54 /// Parameter `element`: The element that has been modified.
55 #[unsafe(method(elementValueDidChangeHandler))]
56 #[unsafe(method_family = none)]
57 unsafe fn elementValueDidChangeHandler(
58 &self,
59 ) -> *mut block2::DynBlock<
60 dyn Fn(
61 NonNull<ProtocolObject<dyn GCDevicePhysicalInput>>,
62 NonNull<ProtocolObject<dyn GCPhysicalInputElement>>,
63 ),
64 >;
65
66 #[cfg(all(feature = "GCPhysicalInputElement", feature = "block2"))]
67 /// Setter for [`elementValueDidChangeHandler`][Self::elementValueDidChangeHandler].
68 #[unsafe(method(setElementValueDidChangeHandler:))]
69 #[unsafe(method_family = none)]
70 unsafe fn setElementValueDidChangeHandler(
71 &self,
72 element_value_did_change_handler: Option<
73 &block2::DynBlock<
74 dyn Fn(
75 NonNull<ProtocolObject<dyn GCDevicePhysicalInput>>,
76 NonNull<ProtocolObject<dyn GCPhysicalInputElement>>,
77 ),
78 >,
79 >,
80 );
81
82 /// Polls the current state vector of the physical input and saves it to a new
83 /// instance.
84 ///
85 /// If your application is heavily multithreaded this may also be useful to
86 /// guarantee atomicity of input handling as a snapshot will not change based on
87 /// further device input once it is taken.
88 ///
89 ///
90 /// Returns: An input state with the duplicated state vector of the current input.
91 #[unsafe(method(capture))]
92 #[unsafe(method_family = none)]
93 unsafe fn capture(&self) -> Retained<ProtocolObject<dyn GCDevicePhysicalInputState>>;
94
95 #[cfg(feature = "block2")]
96 /// Set this block to be notified when a new input state is available. Your
97 /// handler should repeatedly call
98 /// `-nextInputState`until it returns
99 /// `nil`to
100 /// drain the pending input states from the queue.
101 ///
102 /// physicalInput.inputStateQueueDepth = 20;
103 /// physicalInput.inputStateAvailableHandler = ^(__kindof id
104 /// <GCDevicePhysicalInput
105 /// > physicalInput) {
106 /// id
107 /// <GCDevicePhysicalInputState
108 /// , GCDevicePhysicalInputStateDiff> nextInputState;
109 /// while ((nextInputState = [physicalInput nextInputState])) {
110 ///
111 /// // You can grab the individual states of all elements that your app
112 /// // is interested in.
113 /// id
114 /// <GCButtonElement
115 /// > buttonA = nextInputState.buttons[GCInputButtonA];
116 /// BOOL buttonAPressed = buttonA.pressedInput.pressed;
117 /// if (buttonAPressed) {
118 /// // Handle button A pressed
119 /// }
120 ///
121 /// // Your code can first query whether an element's input value changed
122 /// // from the prior input state.
123 /// GCDevicePhysicalInputElementChange buttonAChange = [nextInputState changeForElement:buttonA];
124 /// if (buttonAChange == GCDevicePhysicalInputElementChanged) {
125 /// // Handle button A input changed
126 /// }
127 ///
128 /// // Or, your code can request an enumerator of elements with input
129 /// // values that changed from the prior input state
130 /// for (id
131 /// <GCPhysicalInputElement
132 /// > changedElement in nextInputState.changedElements) {
133 ///
134 /// }
135 /// }
136 /// };
137 #[unsafe(method(inputStateAvailableHandler))]
138 #[unsafe(method_family = none)]
139 unsafe fn inputStateAvailableHandler(
140 &self,
141 ) -> *mut block2::DynBlock<dyn Fn(NonNull<ProtocolObject<dyn GCDevicePhysicalInput>>)>;
142
143 #[cfg(feature = "block2")]
144 /// Setter for [`inputStateAvailableHandler`][Self::inputStateAvailableHandler].
145 #[unsafe(method(setInputStateAvailableHandler:))]
146 #[unsafe(method_family = none)]
147 unsafe fn setInputStateAvailableHandler(
148 &self,
149 input_state_available_handler: Option<
150 &block2::DynBlock<dyn Fn(NonNull<ProtocolObject<dyn GCDevicePhysicalInput>>)>,
151 >,
152 );
153
154 /// The maximum number of input states to buffer. If your application does not
155 /// drain the pending input states in the queue before this limit is reached, older
156 /// input states will be discarded - resulting in your application "missing" input
157 /// state changes.
158 ///
159 /// The default value is
160 /// `one`(no buffering). Smaller values are ignored. A
161 /// value of
162 /// `20`should be more than enough to ensure no input state changes
163 /// are missed.
164 #[unsafe(method(inputStateQueueDepth))]
165 #[unsafe(method_family = none)]
166 unsafe fn inputStateQueueDepth(&self) -> NSInteger;
167
168 /// Setter for [`inputStateQueueDepth`][Self::inputStateQueueDepth].
169 #[unsafe(method(setInputStateQueueDepth:))]
170 #[unsafe(method_family = none)]
171 unsafe fn setInputStateQueueDepth(&self, input_state_queue_depth: NSInteger);
172
173 #[cfg(feature = "GCDevicePhysicalInputStateDiff")]
174 /// Pop the oldest pending input state from the queue. This method returns
175 /// `nil`when there are no more input states pending.
176 #[unsafe(method(nextInputState))]
177 #[unsafe(method_family = none)]
178 unsafe fn nextInputState(
179 &self,
180 ) -> Option<
181 Retained<
182 AnyObject, /* GCDevicePhysicalInputState+ GCDevicePhysicalInputStateDiff */
183 >,
184 >;
185 }
186);