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
//! 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::*;
/// Represents the current state of a touch event on a touchpad.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gctouchstate?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct GCTouchState(pub NSInteger);
impl GCTouchState {
#[doc(alias = "GCTouchStateUp")]
pub const Up: Self = Self(0);
#[doc(alias = "GCTouchStateDown")]
pub const Down: Self = Self(1);
#[doc(alias = "GCTouchStateMoving")]
pub const Moving: Self = Self(2);
}
unsafe impl Encode for GCTouchState {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for GCTouchState {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// Set this block if you want to be notified when an axis or the touch state changes.
///
///
/// Parameter `touchpad`: the touchpad collection whose axes or touch state has been modified.
///
/// Parameter `xValue`: the value x axis was set to at the time the handler fired.
///
/// Parameter `yValue`: the value y axis was set to at the time the handler fired.
///
/// Parameter `buttonValue`: the value of the touch surface button at the time the handler fired.
///
/// Parameter `buttonPressed`: the pressed state of the touch surface button at the time the handler fired.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollertouchpadhandler?language=objc)
#[cfg(all(feature = "GCControllerElement", feature = "block2"))]
pub type GCControllerTouchpadHandler =
*mut block2::DynBlock<dyn Fn(NonNull<GCControllerTouchpad>, c_float, c_float, c_float, Bool)>;
extern_class!(
/// A touchpad is a touch-based two axis input with a notion of "touch state". It keeps track of
/// whether the touchpad is actively being touched, and generates events based on a
/// change in touch state.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollertouchpad?language=objc)
#[unsafe(super(GCControllerElement, NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
#[cfg(feature = "GCControllerElement")]
pub struct GCControllerTouchpad;
);
#[cfg(feature = "GCControllerElement")]
extern_conformance!(
unsafe impl NSObjectProtocol for GCControllerTouchpad {}
);
#[cfg(feature = "GCControllerElement")]
impl GCControllerTouchpad {
extern_methods!(
#[cfg(feature = "GCControllerButtonInput")]
/// Button is the button built into the touch surface.
#[unsafe(method(button))]
#[unsafe(method_family = none)]
pub unsafe fn button(&self) -> Retained<GCControllerButtonInput>;
#[cfg(feature = "block2")]
/// Called when a touch event begins on the touchpad.
///
/// # Safety
///
/// The returned block's argument 1 must be a valid pointer.
#[unsafe(method(touchDown))]
#[unsafe(method_family = none)]
pub unsafe fn touchDown(&self) -> GCControllerTouchpadHandler;
#[cfg(feature = "block2")]
/// Setter for [`touchDown`][Self::touchDown].
///
/// This is [copied][objc2_foundation::NSCopying::copy] when set.
///
/// # Safety
///
/// `touch_down` must be a valid pointer or null.
#[unsafe(method(setTouchDown:))]
#[unsafe(method_family = none)]
pub unsafe fn setTouchDown(&self, touch_down: GCControllerTouchpadHandler);
#[cfg(feature = "block2")]
/// Called when a touch event continues on the touchpad, but not when it begins or ends.
///
/// # Safety
///
/// The returned block's argument 1 must be a valid pointer.
#[unsafe(method(touchMoved))]
#[unsafe(method_family = none)]
pub unsafe fn touchMoved(&self) -> GCControllerTouchpadHandler;
#[cfg(feature = "block2")]
/// Setter for [`touchMoved`][Self::touchMoved].
///
/// This is [copied][objc2_foundation::NSCopying::copy] when set.
///
/// # Safety
///
/// `touch_moved` must be a valid pointer or null.
#[unsafe(method(setTouchMoved:))]
#[unsafe(method_family = none)]
pub unsafe fn setTouchMoved(&self, touch_moved: GCControllerTouchpadHandler);
#[cfg(feature = "block2")]
/// Called when a touch event ends on the touchpad.
///
/// # Safety
///
/// The returned block's argument 1 must be a valid pointer.
#[unsafe(method(touchUp))]
#[unsafe(method_family = none)]
pub unsafe fn touchUp(&self) -> GCControllerTouchpadHandler;
#[cfg(feature = "block2")]
/// Setter for [`touchUp`][Self::touchUp].
///
/// This is [copied][objc2_foundation::NSCopying::copy] when set.
///
/// # Safety
///
/// `touch_up` must be a valid pointer or null.
#[unsafe(method(setTouchUp:))]
#[unsafe(method_family = none)]
pub unsafe fn setTouchUp(&self, touch_up: GCControllerTouchpadHandler);
#[cfg(feature = "GCControllerDirectionPad")]
/// The touch surface is a 2-axis control that represents the position of a touch event on the touchpad.
///
/// The axes will indicate the most recent touch position - a non-zero value does not indicate that the
/// surface is being touched, and a value of (0, 0) does not indicate the surface is not being touched.
///
///
/// See: touchState - Should be polled in conjunction with touchSurface to determine if values are valid
#[unsafe(method(touchSurface))]
#[unsafe(method_family = none)]
pub unsafe fn touchSurface(&self) -> Retained<GCControllerDirectionPad>;
/// Indicates the current state of the touch event on the touchpad.
#[unsafe(method(touchState))]
#[unsafe(method_family = none)]
pub unsafe fn touchState(&self) -> GCTouchState;
/// The touchpad can use the raw position values of its surface as D-pad values, or it can create a virtual dpad centered around the first contact point with the surface.
///
/// If NO; a smaller sliding window is created around the initial touch point and subsequent movement is relative to that center. Movement outside the window will slide the window with it to re-center it. This is great for surfaces where there is no clear sense of a middle and drift over time is an issue.
///
/// If YES; the absolute values are used and any drift will have to managed manually either through user traning or by a developer using the dpad.
///
/// The default value for this property is YES, meaning the touch surface's raw positional values are reported.
#[unsafe(method(reportsAbsoluteTouchSurfaceValues))]
#[unsafe(method_family = none)]
pub unsafe fn reportsAbsoluteTouchSurfaceValues(&self) -> bool;
/// Setter for [`reportsAbsoluteTouchSurfaceValues`][Self::reportsAbsoluteTouchSurfaceValues].
#[unsafe(method(setReportsAbsoluteTouchSurfaceValues:))]
#[unsafe(method_family = none)]
pub unsafe fn setReportsAbsoluteTouchSurfaceValues(
&self,
reports_absolute_touch_surface_values: bool,
);
/// Sets the normalized value for the touchpad's axes, as well as its current touch and button state.
///
///
/// Note: If the controller's snapshot flag is set to NO, this method has no effect.
///
/// See: touchSurface
///
/// See: touchState
#[unsafe(method(setValueForXAxis:yAxis:touchDown:buttonValue:))]
#[unsafe(method_family = none)]
pub unsafe fn setValueForXAxis_yAxis_touchDown_buttonValue(
&self,
x_axis: c_float,
y_axis: c_float,
touch_down: bool,
button_value: c_float,
);
);
}
/// Methods declared on superclass `NSObject`.
#[cfg(feature = "GCControllerElement")]
impl GCControllerTouchpad {
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>;
);
}