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 GCGamepadSnapshot snapshot is a concrete GCGamepad 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 GCGamepadSnapShotData structure.
    ///
    ///
    /// See: -[GCGamepad saveSnapshot]
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcgamepadsnapshot?language=objc)
    #[unsafe(super(GCGamepad, GCPhysicalInputProfile, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(all(feature = "GCGamepad", feature = "GCPhysicalInputProfile"))]
    #[deprecated = "Use GCExtendedGamepad instead"]
    pub struct GCGamepadSnapshot;
);

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

#[cfg(all(feature = "GCGamepad", feature = "GCPhysicalInputProfile"))]
impl GCGamepadSnapshot {
    extern_methods!(
        #[deprecated = "Use GCExtendedGamepad 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 GCExtendedGamepad instead"]
        #[unsafe(method(setSnapshotData:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setSnapshotData(&self, snapshot_data: &NSData);

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

        #[cfg(feature = "GCController")]
        #[deprecated = "Use GCExtendedGamepad 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 = "GCGamepad", feature = "GCPhysicalInputProfile"))]
impl GCGamepadSnapshot {
    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/gcgamepadsnapshotdatav100?language=objc)
#[repr(C, packed)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct GCGamepadSnapShotDataV100 {
    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,
}

unsafe impl Encode for GCGamepadSnapShotDataV100 {
    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,
        ],
    );
}

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

impl GCGamepadSnapShotDataV100 {
    /// 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 = "GCGamepadSnapShotDataV100FromNSData")]
    #[deprecated = "Use GCExtendedGamepad instead"]
    #[inline]
    pub unsafe fn from_ns_data(
        snapshot_data: *mut GCGamepadSnapShotDataV100,
        data: Option<&NSData>,
    ) -> bool {
        extern "C-unwind" {
            fn GCGamepadSnapShotDataV100FromNSData(
                snapshot_data: *mut GCGamepadSnapShotDataV100,
                data: Option<&NSData>,
            ) -> Bool;
        }
        unsafe { GCGamepadSnapShotDataV100FromNSData(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(GCGamepadSnapShotDataV100) set as the values implicitly.
///
///
/// Returns: nil if the snapshot is NULL, otherwise an NSData instance compatible with GCGamepadSnapshot.snapshotData
///
/// # Safety
///
/// `snapshot_data` must be a valid pointer or null.
#[deprecated = "Use GCExtendedGamepad instead"]
#[inline]
pub unsafe extern "C-unwind" fn NSDataFromGCGamepadSnapShotDataV100(
    snapshot_data: *mut GCGamepadSnapShotDataV100,
) -> Option<Retained<NSData>> {
    extern "C-unwind" {
        fn NSDataFromGCGamepadSnapShotDataV100(
            snapshot_data: *mut GCGamepadSnapShotDataV100,
        ) -> *mut NSData;
    }
    let ret = unsafe { NSDataFromGCGamepadSnapShotDataV100(snapshot_data) };
    unsafe { Retained::retain_autoreleased(ret) }
}

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