objc2_game_controller/generated/
GCControllerTouchpad.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
9/// Represents the current state of a touch event on a touchpad.
10///
11/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gctouchstate?language=objc)
12// NS_ENUM
13#[repr(transparent)]
14#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
15pub struct GCTouchState(pub NSInteger);
16impl GCTouchState {
17    #[doc(alias = "GCTouchStateUp")]
18    pub const Up: Self = Self(0);
19    #[doc(alias = "GCTouchStateDown")]
20    pub const Down: Self = Self(1);
21    #[doc(alias = "GCTouchStateMoving")]
22    pub const Moving: Self = Self(2);
23}
24
25unsafe impl Encode for GCTouchState {
26    const ENCODING: Encoding = NSInteger::ENCODING;
27}
28
29unsafe impl RefEncode for GCTouchState {
30    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
31}
32
33/// Set this block if you want to be notified when an axis or the touch state changes.
34///
35///
36/// Parameter `touchpad`: the touchpad collection whose axes or touch state has been modified.
37///
38/// Parameter `xValue`: the value x axis was set to at the time the handler fired.
39///
40/// Parameter `yValue`: the value y axis was set to at the time the handler fired.
41///
42/// Parameter `buttonValue`: the value of the touch surface button at the time the handler fired.
43///
44/// Parameter `buttonPressed`: the pressed state of the touch surface button at the time the handler fired.
45///
46/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollertouchpadhandler?language=objc)
47#[cfg(all(feature = "GCControllerElement", feature = "block2"))]
48pub type GCControllerTouchpadHandler =
49    *mut block2::DynBlock<dyn Fn(NonNull<GCControllerTouchpad>, c_float, c_float, c_float, Bool)>;
50
51extern_class!(
52    /// A touchpad is a touch-based two axis input with a notion of "touch state". It keeps track of
53    /// whether the touchpad is actively being touched, and generates events based on a
54    /// change in touch state.
55    ///
56    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollertouchpad?language=objc)
57    #[unsafe(super(GCControllerElement, NSObject))]
58    #[derive(Debug, PartialEq, Eq, Hash)]
59    #[cfg(feature = "GCControllerElement")]
60    pub struct GCControllerTouchpad;
61);
62
63#[cfg(feature = "GCControllerElement")]
64extern_conformance!(
65    unsafe impl NSObjectProtocol for GCControllerTouchpad {}
66);
67
68#[cfg(feature = "GCControllerElement")]
69impl GCControllerTouchpad {
70    extern_methods!(
71        #[cfg(feature = "GCControllerButtonInput")]
72        /// Button is the buttonĀ built into the touch surface.
73        #[unsafe(method(button))]
74        #[unsafe(method_family = none)]
75        pub unsafe fn button(&self) -> Retained<GCControllerButtonInput>;
76
77        #[cfg(feature = "block2")]
78        /// Called when a touch event begins on the touchpad.
79        ///
80        /// # Safety
81        ///
82        /// The returned block's argument 1 must be a valid pointer.
83        #[unsafe(method(touchDown))]
84        #[unsafe(method_family = none)]
85        pub unsafe fn touchDown(&self) -> GCControllerTouchpadHandler;
86
87        #[cfg(feature = "block2")]
88        /// Setter for [`touchDown`][Self::touchDown].
89        ///
90        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
91        ///
92        /// # Safety
93        ///
94        /// `touch_down` must be a valid pointer or null.
95        #[unsafe(method(setTouchDown:))]
96        #[unsafe(method_family = none)]
97        pub unsafe fn setTouchDown(&self, touch_down: GCControllerTouchpadHandler);
98
99        #[cfg(feature = "block2")]
100        /// Called when a touch event continues on the touchpad, but not when it begins or ends.
101        ///
102        /// # Safety
103        ///
104        /// The returned block's argument 1 must be a valid pointer.
105        #[unsafe(method(touchMoved))]
106        #[unsafe(method_family = none)]
107        pub unsafe fn touchMoved(&self) -> GCControllerTouchpadHandler;
108
109        #[cfg(feature = "block2")]
110        /// Setter for [`touchMoved`][Self::touchMoved].
111        ///
112        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
113        ///
114        /// # Safety
115        ///
116        /// `touch_moved` must be a valid pointer or null.
117        #[unsafe(method(setTouchMoved:))]
118        #[unsafe(method_family = none)]
119        pub unsafe fn setTouchMoved(&self, touch_moved: GCControllerTouchpadHandler);
120
121        #[cfg(feature = "block2")]
122        /// Called when a touch event ends on the touchpad.
123        ///
124        /// # Safety
125        ///
126        /// The returned block's argument 1 must be a valid pointer.
127        #[unsafe(method(touchUp))]
128        #[unsafe(method_family = none)]
129        pub unsafe fn touchUp(&self) -> GCControllerTouchpadHandler;
130
131        #[cfg(feature = "block2")]
132        /// Setter for [`touchUp`][Self::touchUp].
133        ///
134        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
135        ///
136        /// # Safety
137        ///
138        /// `touch_up` must be a valid pointer or null.
139        #[unsafe(method(setTouchUp:))]
140        #[unsafe(method_family = none)]
141        pub unsafe fn setTouchUp(&self, touch_up: GCControllerTouchpadHandler);
142
143        #[cfg(feature = "GCControllerDirectionPad")]
144        /// The touch surface is a 2-axis control that represents the position of a touch event on the touchpad.
145        ///
146        /// The axes will indicate the most recent touch position - a non-zero value does not indicate that the
147        /// surface is being touched, and a value of (0, 0) does not indicate the surface is not being touched.
148        ///
149        ///
150        /// See: touchState - Should be polled in conjunction with touchSurface to determine if values are valid
151        #[unsafe(method(touchSurface))]
152        #[unsafe(method_family = none)]
153        pub unsafe fn touchSurface(&self) -> Retained<GCControllerDirectionPad>;
154
155        /// Indicates the current state of the touch event on the touchpad.
156        #[unsafe(method(touchState))]
157        #[unsafe(method_family = none)]
158        pub unsafe fn touchState(&self) -> GCTouchState;
159
160        /// 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.
161        ///
162        /// 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.
163        ///
164        /// 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.
165        ///
166        /// The default value for this property is YES, meaning the touch surface's raw positional values are reported.
167        #[unsafe(method(reportsAbsoluteTouchSurfaceValues))]
168        #[unsafe(method_family = none)]
169        pub unsafe fn reportsAbsoluteTouchSurfaceValues(&self) -> bool;
170
171        /// Setter for [`reportsAbsoluteTouchSurfaceValues`][Self::reportsAbsoluteTouchSurfaceValues].
172        #[unsafe(method(setReportsAbsoluteTouchSurfaceValues:))]
173        #[unsafe(method_family = none)]
174        pub unsafe fn setReportsAbsoluteTouchSurfaceValues(
175            &self,
176            reports_absolute_touch_surface_values: bool,
177        );
178
179        /// Sets the normalized value for the touchpad's axes, as well as its current touch and button state.
180        ///
181        ///
182        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
183        ///
184        /// See: touchSurface
185        ///
186        /// See: touchState
187        #[unsafe(method(setValueForXAxis:yAxis:touchDown:buttonValue:))]
188        #[unsafe(method_family = none)]
189        pub unsafe fn setValueForXAxis_yAxis_touchDown_buttonValue(
190            &self,
191            x_axis: c_float,
192            y_axis: c_float,
193            touch_down: bool,
194            button_value: c_float,
195        );
196    );
197}
198
199/// Methods declared on superclass `NSObject`.
200#[cfg(feature = "GCControllerElement")]
201impl GCControllerTouchpad {
202    extern_methods!(
203        #[unsafe(method(init))]
204        #[unsafe(method_family = init)]
205        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
206
207        #[unsafe(method(new))]
208        #[unsafe(method_family = new)]
209        pub unsafe fn new() -> Retained<Self>;
210    );
211}