objc2-game-controller 0.3.2

Bindings to the GameController framework
Documentation
//! 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>;
    );
}