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 objc2_foundation::*;

use crate::*;

extern_class!(
    /// A GCExtendedGamepadSnapshot snapshot is a concrete GCExtendedGamepad implementation. It can be used directly in an
    /// application to implement controller input replays. It is also returned as the result of polling a controller.
    ///
    /// The current snapshotData is readily available to access as NSData. A developer can serialize this to any
    /// destination necessary using the NSData API.
    ///
    /// The data contains some version of a GCExtendedGamepadSnapShotData structure.
    ///
    ///
    /// See: -[GCExtendedGamepad saveSnapshot]
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcextendedgamepadsnapshot?language=objc)
    #[unsafe(super(GCExtendedGamepad, GCPhysicalInputProfile, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(all(feature = "GCExtendedGamepad", feature = "GCPhysicalInputProfile"))]
    #[deprecated = "Use the -[GCController controllerWithExtendedGamepad] method instead"]
    pub struct GCExtendedGamepadSnapshot;
);

#[cfg(all(feature = "GCExtendedGamepad", feature = "GCPhysicalInputProfile"))]
extern_conformance!(
    unsafe impl NSObjectProtocol for GCExtendedGamepadSnapshot {}
);

#[cfg(all(feature = "GCExtendedGamepad", feature = "GCPhysicalInputProfile"))]
impl GCExtendedGamepadSnapshot {
    extern_methods!(
        #[deprecated = "Use the -[GCController controllerWithExtendedGamepad] method instead"]
        #[unsafe(method(snapshotData))]
        #[unsafe(method_family = none)]
        pub unsafe fn snapshotData(&self) -> Retained<NSData>;

        /// Setter for [`snapshotData`][Self::snapshotData].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[deprecated = "Use the -[GCController controllerWithExtendedGamepad] method instead"]
        #[unsafe(method(setSnapshotData:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setSnapshotData(&self, snapshot_data: &NSData);

        #[deprecated = "Use the -[GCController controllerWithExtendedGamepad] method instead"]
        #[unsafe(method(initWithSnapshotData:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithSnapshotData(this: Allocated<Self>, data: &NSData) -> Retained<Self>;

        #[cfg(feature = "GCController")]
        #[deprecated = "Use the -[GCController controllerWithExtendedGamepad] method instead"]
        #[unsafe(method(initWithController:snapshotData:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithController_snapshotData(
            this: Allocated<Self>,
            controller: &GCController,
            data: &NSData,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
#[cfg(all(feature = "GCExtendedGamepad", feature = "GCPhysicalInputProfile"))]
impl GCExtendedGamepadSnapshot {
    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>;
    );
}

/// [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcextendedgamepadsnapshotdataversion?language=objc)
// NS_ENUM
#[deprecated = "Use the -[GCController controllerWithExtendedGamepad] method instead"]
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct GCExtendedGamepadSnapshotDataVersion(pub NSInteger);
impl GCExtendedGamepadSnapshotDataVersion {
    #[doc(alias = "GCExtendedGamepadSnapshotDataVersion1")]
    #[deprecated = "Use the -[GCController controllerWithExtendedGamepad] method instead"]
    pub const Version1: Self = Self(0x0100);
    #[doc(alias = "GCExtendedGamepadSnapshotDataVersion2")]
    #[deprecated = "Use the -[GCController controllerWithExtendedGamepad] method instead"]
    pub const Version2: Self = Self(0x0101);
}

unsafe impl Encode for GCExtendedGamepadSnapshotDataVersion {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for GCExtendedGamepadSnapshotDataVersion {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccurrentextendedgamepadsnapshotdataversion?language=objc)
    #[deprecated = "Use the -[GCController controllerWithExtendedGamepad] method instead"]
    pub static GCCurrentExtendedGamepadSnapshotDataVersion: GCExtendedGamepadSnapshotDataVersion;
}

/// [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcextendedgamepadsnapshotdata?language=objc)
#[repr(C, packed)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct GCExtendedGamepadSnapshotData {
    pub version: u16,
    pub size: u16,
    pub dpadX: c_float,
    pub dpadY: c_float,
    pub buttonA: c_float,
    pub buttonB: c_float,
    pub buttonX: c_float,
    pub buttonY: c_float,
    pub leftShoulder: c_float,
    pub rightShoulder: c_float,
    pub leftThumbstickX: c_float,
    pub leftThumbstickY: c_float,
    pub rightThumbstickX: c_float,
    pub rightThumbstickY: c_float,
    pub leftTrigger: c_float,
    pub rightTrigger: c_float,
    pub supportsClickableThumbsticks: Bool,
    pub leftThumbstickButton: Bool,
    pub rightThumbstickButton: Bool,
}

unsafe impl Encode for GCExtendedGamepadSnapshotData {
    const ENCODING: Encoding = Encoding::Struct(
        "?",
        &[
            <u16>::ENCODING,
            <u16>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <Bool>::ENCODING,
            <Bool>::ENCODING,
            <Bool>::ENCODING,
        ],
    );
}

unsafe impl RefEncode for GCExtendedGamepadSnapshotData {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

impl GCExtendedGamepadSnapshotData {
    /// Fills out a snapshot from any compatible NSData source
    ///
    ///
    /// Returns: NO if data is nil, snapshotData is nil or the contents of data does not contain a compatible snapshot. YES for all other cases.
    ///
    /// # Safety
    ///
    /// `snapshot_data` must be a valid pointer or null.
    #[doc(alias = "GCExtendedGamepadSnapshotDataFromNSData")]
    #[deprecated = "Use the -[GCController controllerWithExtendedGamepad] method instead"]
    #[inline]
    pub unsafe fn from_ns_data(
        snapshot_data: *mut GCExtendedGamepadSnapshotData,
        data: Option<&NSData>,
    ) -> bool {
        extern "C-unwind" {
            fn GCExtendedGamepadSnapshotDataFromNSData(
                snapshot_data: *mut GCExtendedGamepadSnapshotData,
                data: Option<&NSData>,
            ) -> Bool;
        }
        unsafe { GCExtendedGamepadSnapshotDataFromNSData(snapshot_data, data) }.as_bool()
    }
}

/// Creates an NSData object from a snapshot.
/// If the version and size is not set in the snapshot the data will automatically have the version GCCurrentExtendedGamepadSnapshotDataVersion and sizeof(GCExtendedGamepadSnapshotData) set as the values implicitly.
///
///
/// Returns: nil if the snapshot is NULL, otherwise an NSData instance compatible with GCExtendedGamepadSnapshot.snapshotData
///
/// # Safety
///
/// `snapshot_data` must be a valid pointer or null.
#[deprecated = "Use the -[GCController controllerWithExtendedGamepad] method instead"]
#[inline]
pub unsafe extern "C-unwind" fn NSDataFromGCExtendedGamepadSnapshotData(
    snapshot_data: *mut GCExtendedGamepadSnapshotData,
) -> Option<Retained<NSData>> {
    extern "C-unwind" {
        fn NSDataFromGCExtendedGamepadSnapshotData(
            snapshot_data: *mut GCExtendedGamepadSnapshotData,
        ) -> *mut NSData;
    }
    let ret = unsafe { NSDataFromGCExtendedGamepadSnapshotData(snapshot_data) };
    unsafe { Retained::retain_autoreleased(ret) }
}

/// [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcextendedgamepadsnapshotdatav100?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct GCExtendedGamepadSnapShotDataV100 {
    pub version: u16,
    pub size: u16,
    pub dpadX: c_float,
    pub dpadY: c_float,
    pub buttonA: c_float,
    pub buttonB: c_float,
    pub buttonX: c_float,
    pub buttonY: c_float,
    pub leftShoulder: c_float,
    pub rightShoulder: c_float,
    pub leftThumbstickX: c_float,
    pub leftThumbstickY: c_float,
    pub rightThumbstickX: c_float,
    pub rightThumbstickY: c_float,
    pub leftTrigger: c_float,
    pub rightTrigger: c_float,
}

unsafe impl Encode for GCExtendedGamepadSnapShotDataV100 {
    const ENCODING: Encoding = Encoding::Struct(
        "?",
        &[
            <u16>::ENCODING,
            <u16>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
            <c_float>::ENCODING,
        ],
    );
}

unsafe impl RefEncode for GCExtendedGamepadSnapShotDataV100 {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

impl GCExtendedGamepadSnapShotDataV100 {
    /// Fills out a v100 snapshot from any compatible NSData source
    ///
    ///
    /// Returns: NO if data is nil, snapshotData is nil or the contents of data does not contain a compatible snapshot. YES for all other cases.
    ///
    /// # Safety
    ///
    /// `snapshot_data` must be a valid pointer or null.
    #[doc(alias = "GCExtendedGamepadSnapShotDataV100FromNSData")]
    #[deprecated = "Use the -[GCController controllerWithExtendedGamepad] method instead"]
    #[inline]
    pub unsafe fn from_ns_data(
        snapshot_data: *mut GCExtendedGamepadSnapShotDataV100,
        data: Option<&NSData>,
    ) -> bool {
        extern "C-unwind" {
            fn GCExtendedGamepadSnapShotDataV100FromNSData(
                snapshot_data: *mut GCExtendedGamepadSnapShotDataV100,
                data: Option<&NSData>,
            ) -> Bool;
        }
        unsafe { GCExtendedGamepadSnapShotDataV100FromNSData(snapshot_data, data) }.as_bool()
    }
}

/// Creates an NSData object from a v100 snapshot.
/// If the version and size is not set in the snapshot the data will automatically have version 0x100 and sizeof(GCExtendedGamepadSnapShotDataV100) set as the values implicitly.
///
///
/// Returns: nil if the snapshot is NULL, otherwise an NSData instance compatible with GCExtendedGamepadSnapshot.snapshotData
///
/// # Safety
///
/// `snapshot_data` must be a valid pointer or null.
#[deprecated = "Use the -[GCController controllerWithExtendedGamepad] method instead"]
#[inline]
pub unsafe extern "C-unwind" fn NSDataFromGCExtendedGamepadSnapShotDataV100(
    snapshot_data: *mut GCExtendedGamepadSnapShotDataV100,
) -> Option<Retained<NSData>> {
    extern "C-unwind" {
        fn NSDataFromGCExtendedGamepadSnapShotDataV100(
            snapshot_data: *mut GCExtendedGamepadSnapShotDataV100,
        ) -> *mut NSData;
    }
    let ret = unsafe { NSDataFromGCExtendedGamepadSnapShotDataV100(snapshot_data) };
    unsafe { Retained::retain_autoreleased(ret) }
}

#[deprecated = "renamed to `GCExtendedGamepadSnapshotData::from_ns_data`"]
#[inline]
pub unsafe extern "C-unwind" fn GCExtendedGamepadSnapshotDataFromNSData(
    snapshot_data: *mut GCExtendedGamepadSnapshotData,
    data: Option<&NSData>,
) -> bool {
    extern "C-unwind" {
        fn GCExtendedGamepadSnapshotDataFromNSData(
            snapshot_data: *mut GCExtendedGamepadSnapshotData,
            data: Option<&NSData>,
        ) -> Bool;
    }
    unsafe { GCExtendedGamepadSnapshotDataFromNSData(snapshot_data, data) }.as_bool()
}

#[deprecated = "renamed to `GCExtendedGamepadSnapShotDataV100::from_ns_data`"]
#[inline]
pub unsafe extern "C-unwind" fn GCExtendedGamepadSnapShotDataV100FromNSData(
    snapshot_data: *mut GCExtendedGamepadSnapShotDataV100,
    data: Option<&NSData>,
) -> bool {
    extern "C-unwind" {
        fn GCExtendedGamepadSnapShotDataV100FromNSData(
            snapshot_data: *mut GCExtendedGamepadSnapShotDataV100,
            data: Option<&NSData>,
        ) -> Bool;
    }
    unsafe { GCExtendedGamepadSnapShotDataV100FromNSData(snapshot_data, data) }.as_bool()
}