Skip to content

Instantly share code, notes, and snippets.

@tj-devel709
Created July 15, 2019 21:08
Show Gist options
  • Save tj-devel709/711e7f515dcbb8309bb13a46c117d877 to your computer and use it in GitHub Desktop.
Save tj-devel709/711e7f515dcbb8309bb13a46c117d877 to your computer and use it in GitHub Desktop.
//
// gamecontroller.cs: binding for iOS (7+) GameController framework
//
// Authors:
// Aaron Bockover (abock@xamarin.com)
//
// Copyright 2013, 2015 Xamarin Inc.
using System;
using CoreFoundation;
using Foundation;
using ObjCRuntime;
using OpenTK;
#if MONOMAC
using AppKit;
using UIViewController = AppKit.NSViewController;
#else
using UIKit;
#endif
namespace GameController {
[iOS (7,0)]
[Mac (10,9, onlyOn64: true)]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor] // The GCControllerElement class is never instantiated directly.
partial interface GCControllerElement {
// NOTE: ArgumentSemantic.Weak if ARC, ArgumentSemantic.Assign otherwise;
// currently MonoTouch is not ARC, neither is Xammac, so go with assign.
[Export ("collection", ArgumentSemantic.Assign)]
GCControllerElement Collection { get; }
[Export ("analog")]
bool IsAnalog { [Bind ("isAnalog")] get; }
}
delegate void GCControllerAxisValueChangedHandler (GCControllerAxisInput axis, float /* float, not CGFloat */ value);
[iOS (7,0)]
[Mac (10,9, onlyOn64: true)]
[BaseType (typeof (GCControllerElement))]
[DisableDefaultCtor] // return nil handle -> only exposed as getter
partial interface GCControllerAxisInput {
[Export ("valueChangedHandler", ArgumentSemantic.Copy)]
GCControllerAxisValueChangedHandler ValueChangedHandler { get; set; }
[Export ("value")]
float Value { get; } /* float, not CGFloat */
[Export ("setValue:")]
void SetValue (float value);
}
delegate void GCControllerButtonValueChanged (GCControllerButtonInput button, float /* float, not CGFloat */ buttonValue, bool pressed);
[iOS (7,0), Mac (10,9, onlyOn64: true)]
[BaseType (typeof (GCControllerElement))]
[DisableDefaultCtor] // return nil handle -> only exposed as getter
partial interface GCControllerButtonInput {
#if !XAMCORE_4_0
[Obsolete ("Use the 'ValueChangedHandler' property.")]
[Wrap ("ValueChangedHandler = handler;", IsVirtual = true)]
void SetValueChangedHandler (GCControllerButtonValueChanged handler);
#endif
[NullAllowed]
[Export ("valueChangedHandler", ArgumentSemantic.Copy)]
GCControllerButtonValueChanged ValueChangedHandler { get; set; }
[Export ("value")]
float Value { get; } /* float, not CGFloat */
[Export ("pressed")]
bool IsPressed { [Bind ("isPressed")] get; }
[Export ("setValue:")]
void SetValue (float value);
#if !XAMCORE_4_0
[iOS (8,0), Mac (10,10)]
[Obsolete ("Use the 'PressedChangedHandler' property.")]
[Wrap ("PressedChangedHandler = handler;", IsVirtual = true)]
void SetPressedChangedHandler (GCControllerButtonValueChanged handler);
#endif
[iOS (8,0), Mac (10,10), TV (13,0)]
[NullAllowed]
[Export ("pressedChangedHandler", ArgumentSemantic.Copy)]
GCControllerButtonValueChanged PressedChangedHandler { get; set; }
}
delegate void GCControllerDirectionPadValueChangedHandler (GCControllerDirectionPad dpad, float /* float, not CGFloat */ xValue, float /* float, not CGFloat */ yValue);
[iOS (7,0)]
[Mac (10,9, onlyOn64: true)]
[BaseType (typeof (GCControllerElement))]
[DisableDefaultCtor] // return nil handle -> only exposed as getter
partial interface GCControllerDirectionPad {
[Export ("valueChangedHandler", ArgumentSemantic.Copy)]
GCControllerDirectionPadValueChangedHandler ValueChangedHandler { get; set; }
[Export ("xAxis")]
GCControllerAxisInput XAxis { get; }
[Export ("yAxis")]
GCControllerAxisInput YAxis { get; }
[Export ("up")]
GCControllerButtonInput Up { get; }
[Export ("down")]
GCControllerButtonInput Down { get; }
[Export ("left")]
GCControllerButtonInput Left { get; }
[Export ("right")]
GCControllerButtonInput Right { get; }
[Export ("setValueForXAxis:yAxis:")]
void SetValueForXAxis (float xAxis, float yAxis);
}
delegate void GCGamepadValueChangedHandler (GCGamepad gamepad, GCControllerElement element);
[Deprecated (PlatformName.MacOSX, 10, 12, message: "Use GCExtendedGamepad instead")]
[Deprecated (PlatformName.iOS, 10, 0, message: "Use GCExtendedGamepad instead")]
[Deprecated (PlatformName.TvOS, 10, 0, message: "Use GCExtendedGamepad instead")]
[iOS (7,0)]
[Mac (10,9, onlyOn64: true)]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor] // return nil handle -> only exposed as getter
partial interface GCGamepad {
[Export ("controller", ArgumentSemantic.Assign)]
GCController Controller { get; }
[Export ("valueChangedHandler", ArgumentSemantic.Copy)]
GCGamepadValueChangedHandler ValueChangedHandler { get; set; }
[Export ("saveSnapshot")]
GCGamepadSnapshot SaveSnapshot { get; }
[Export ("dpad")]
GCControllerDirectionPad DPad { get; }
[Export ("buttonA")]
GCControllerButtonInput ButtonA { get; }
[Export ("buttonB")]
GCControllerButtonInput ButtonB { get; }
[Export ("buttonX")]
GCControllerButtonInput ButtonX { get; }
[Export ("buttonY")]
GCControllerButtonInput ButtonY { get; }
[Export ("leftShoulder")]
GCControllerButtonInput LeftShoulder { get; }
[Export ("rightShoulder")]
GCControllerButtonInput RightShoulder { get; }
}
[Deprecated (PlatformName.MacOSX, 10, 15, message: "GCGamepad has been deprecated, use GCExtendedGamepad instead")]
[Deprecated (PlatformName.iOS, 13, 0, message: "GCGamepad has been deprecated, use GCExtendedGamepad instead")]
[Deprecated (PlatformName.TvOS, 13, 0, message: "GCGamepad has been deprecated, use GCExtendedGamepad instead")]
[iOS (7,0)]
[Mac (10,9, onlyOn64: true)]
[BaseType (typeof (GCGamepad))]
[DisableDefaultCtor]
partial interface GCGamepadSnapshot {
[Export ("snapshotData", ArgumentSemantic.Copy)]
NSData SnapshotData { get; set; }
[Export ("initWithSnapshotData:")]
IntPtr Constructor (NSData data);
[Export ("initWithController:snapshotData:")]
IntPtr Constructor (GCController controller, NSData data);
}
delegate void GCExtendedGamepadValueChangedHandler (GCExtendedGamepad gamepad, GCControllerElement element);
[iOS (7,0)]
[Mac (10,9, onlyOn64: true)]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor] // return nil handle -> only exposed as getter
partial interface GCExtendedGamepad {
[Export ("controller", ArgumentSemantic.Assign)]
GCController Controller { get; }
[Export ("valueChangedHandler", ArgumentSemantic.Copy)]
GCExtendedGamepadValueChangedHandler ValueChangedHandler { get; set; }
[Deprecated (PlatformName.MacOSX, 10, 15, message: "GCExtendedGamepadSnapshot has been deprecated, use [GCController capture] instead")]
[Deprecated (PlatformName.iOS, 13, 0, message: "GCExtendedGamepadSnapshot has been deprecated, use [GCController capture] instead")]
[Introduced (PlatformName.TvOS, 7, 0, message: "GCExtendedGamepadSnapshot has been deprecated, use [GCController capture] instead")]
[Deprecated (PlatformName.TvOS, 13, 0, message: "GCExtendedGamepadSnapshot has been deprecated, use [GCController capture] instead")]
[Export ("saveSnapshot")]
GCExtendedGamepadSnapshot SaveSnapshot ();
[Export ("dpad")]
GCControllerDirectionPad DPad { get; }
[Export ("buttonA")]
GCControllerButtonInput ButtonA { get; }
[Export ("buttonB")]
GCControllerButtonInput ButtonB { get; }
[Export ("buttonX")]
GCControllerButtonInput ButtonX { get; }
[Export ("buttonY")]
GCControllerButtonInput ButtonY { get; }
[Export ("leftThumbstick")]
GCControllerDirectionPad LeftThumbstick { get; }
[Export ("rightThumbstick")]
GCControllerDirectionPad RightThumbstick { get; }
[Export ("leftShoulder")]
GCControllerButtonInput LeftShoulder { get; }
[Export ("rightShoulder")]
GCControllerButtonInput RightShoulder { get; }
[Export ("leftTrigger")]
GCControllerButtonInput LeftTrigger { get; }
[Export ("rightTrigger")]
GCControllerButtonInput RightTrigger { get; }
[TV (12, 1), Mac (10, 14, 1, onlyOn64: true), iOS (12, 1)]
[NullAllowed, Export ("leftThumbstickButton")]
GCControllerButtonInput LeftThumbstickButton { get; }
[TV (12, 1), Mac (10, 14, 1, onlyOn64: true), iOS (12, 1)]
[NullAllowed, Export ("rightThumbstickButton")]
GCControllerButtonInput RightThumbstickButton { get; }
[TV (13, 0), Mac (10, 15, onlyOn64: true), iOS (13, 0)]
[Export ("buttonMenu")]
GCControllerButtonInput ButtonMenu { get; }
[TV (13, 0), Mac (10, 15, onlyOn64: true), iOS (13, 0)]
[NullAllowed, Export ("buttonOptions")]
GCControllerButtonInput ButtonOptions { get; }
[TV (13,0), Mac (10,15, onlyOn64: true), iOS (13,0)]
[Export ("setStateFromExtendedGamepad:")]
void SetState (GCExtendedGamepad extendedGamepad);
}
[iOS (7,0)]
[Mac (10,9, onlyOn64: true)]
[Deprecated (PlatformName.MacOSX, 10, 15, message: "GCExtendedGamepadSnapshot has been deprecated, use [GCController controllerWithExtendedGamepad] instead")]
[Deprecated (PlatformName.iOS, 13, 0, message: "GCExtendedGamepadSnapshot has been deprecated, use [GCController controllerWithExtendedGamepad] instead")]
[Introduced (PlatformName.TvOS, 9, 0, message: "GCExtendedGamepadSnapshot has been deprecated, use [GCController controllerWithExtendedGamepad] instead")]
[Deprecated (PlatformName.TvOS, 13, 0, message: "GCExtendedGamepadSnapshot has been deprecated, use [GCController controllerWithExtendedGamepad] instead")]
[BaseType (typeof (GCExtendedGamepad))]
[DisableDefaultCtor]
partial interface GCExtendedGamepadSnapshot {
[Export ("snapshotData", ArgumentSemantic.Copy)]
NSData SnapshotData { get; set; }
[Export ("initWithSnapshotData:")]
IntPtr Constructor (NSData data);
[Export ("initWithController:snapshotData:")]
IntPtr Constructor (GCController controller, NSData data);
[Deprecated (PlatformName.MacOSX, 10, 15, message: "GCExtendedGamepadSnapshot has been deprecated, use [GCController controllerWithExtendedGamepad] instead")]
[Deprecated (PlatformName.iOS, 13, 0, message: "GCExtendedGamepadSnapshot has been deprecated, use [GCController controllerWithExtendedGamepad] instead")]
[Deprecated (PlatformName.TvOS, 13, 0, message: "GCExtendedGamepadSnapshot has been deprecated, use [GCController controllerWithExtendedGamepad] instead")]
[TV (12, 2), Mac (10, 14, 4, onlyOn64: true), iOS (12, 2)]
[Field ("GCCurrentExtendedGamepadSnapshotDataVersion")]
GCExtendedGamepadSnapshotDataVersion DataVersion { get; }
}
#if !XAMCORE_2_0
delegate void GCControllerPausedHandler (GCController controller);
#endif
[iOS (7,0), Mac (10,9, onlyOn64: true)]
[BaseType (typeof (NSObject))]
partial interface GCController {
[Deprecated (PlatformName.MacOSX, 10, 15, message: "controllerPausedHandler has been deprecated. Use the Menu button found on the controller's profile, if it exists.")]
[Deprecated (PlatformName.iOS, 13, 0, message: "controllerPausedHandler has been deprecated. Use the Menu button found on the controller's profile, if it exists.")]
[Introduced (PlatformName.TvOS, 9, 0, message: "controllerPausedHandler has been deprecated. Use the Menu button found on the controller's profile, if it exists.")]
[Deprecated (PlatformName.TvOS, 13, 0, message: "controllerPausedHandler has been deprecated. Use the Menu button found on the controller's profile, if it exists.")]
[Export ("controllerPausedHandler", ArgumentSemantic.Copy)]
#if XAMCORE_2_0
Action<GCController> ControllerPausedHandler { get; set; }
#else
GCControllerPausedHandler ControllerPausedHandler { get; set; }
#endif
[Export ("vendorName", ArgumentSemantic.Copy)]
string VendorName { get; }
[Export ("attachedToDevice")]
bool AttachedToDevice { [Bind ("isAttachedToDevice")] get; }
[Export ("playerIndex")]
#if XAMCORE_4_0
// enum only added in iOS9 / OSX 10.11 - but with compatible values
GCControllerPlayerIndex PlayerIndex { get; set; }
#else
nint PlayerIndex { get; set; }
#endif
[Deprecated (PlatformName.MacOSX, 10, 12)]
[Deprecated (PlatformName.iOS, 10, 0)]
[Introduced (PlatformName.TvOS, 7, 0)]
[Deprecated (PlatformName.TvOS, 10, 0)]
[Export ("gamepad", ArgumentSemantic.Retain)]
GCGamepad Gamepad { get; }
[Export ("extendedGamepad", ArgumentSemantic.Retain)]
GCExtendedGamepad ExtendedGamepad { get; }
[Mac (10,12, onlyOn64: true)]
[iOS (10,0)]
[TV (13,0)]
[NullAllowed, Export ("microGamepad", ArgumentSemantic.Retain)]
GCMicroGamepad MicroGamepad { get; }
[Static, Export ("controllers")]
GCController [] Controllers { get; }
[Static, Export ("startWirelessControllerDiscoveryWithCompletionHandler:")]
[Async]
void StartWirelessControllerDiscovery ([NullAllowed] Action completionHandler);
[Static, Export ("stopWirelessControllerDiscovery")]
void StopWirelessControllerDiscovery ();
[Notification, Field ("GCControllerDidConnectNotification")]
NSString DidConnectNotification { get; }
[Notification, Field ("GCControllerDidDisconnectNotification")]
NSString DidDisconnectNotification { get; }
[iOS (8,0), Mac (10,10), TV(13,0)]
[Export ("motion", ArgumentSemantic.Retain)]
GCMotion Motion { get; }
[iOS (9,0)][Mac (10,11)]
[Export ("handlerQueue", ArgumentSemantic.Retain)]
DispatchQueue HandlerQueue { get; set; }
[TV (13, 0), Mac (10, 15, onlyOn64: true), iOS (13, 0)]
[Export ("productCategory")]
string ProductCategory { get; }
[TV (13, 0), Mac (10, 15, onlyOn64: true), iOS (13, 0)]
[Export ("snapshot")]
bool Snapshot { [Bind ("isSnapshot")] get; }
[TV (13, 0), Mac (10, 15, onlyOn64: true), iOS (13, 0)]
[Export ("capture")]
GCController Capture { get; }
[TV (13, 0), Mac (10, 15, onlyOn64: true), iOS (13, 0)]
[Static]
[Export ("controllerWithMicroGamepad")]
GCController ControllerWithMicroGamepad { get; }
[TV (13, 0), Mac (10, 15, onlyOn64: true), iOS (13, 0)]
[Static]
[Export ("controllerWithExtendedGamepad")]
GCController ControllerWithExtendedGamepad { get; }
}
[iOS (8,0), Mac (10,10, onlyOn64: true), TV (13,0)]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor] // access thru GCController.Motion - returns a nil Handle
partial interface GCMotion {
[Export ("controller", ArgumentSemantic.Assign)]
GCController Controller { get; }
#if !XAMCORE_4_0
[Obsolete ("Use the 'ValueChangedHandler' property.")]
[Wrap ("ValueChangedHandler = handler;", IsVirtual = true)]
void SetValueChangedHandler (Action<GCMotion> handler);
#endif
[NullAllowed]
[Export ("valueChangedHandler", ArgumentSemantic.Copy)]
Action<GCMotion> ValueChangedHandler { get; set; }
[Export ("gravity", ArgumentSemantic.Assign)]
Vector3d Gravity { get; }
[Export ("userAcceleration", ArgumentSemantic.Assign)]
Vector3d UserAcceleration { get; }
[TV (11,0)]
[Export ("attitude", ArgumentSemantic.Assign)]
Quaterniond Attitude { get; }
[TV (11,0), iOS (11,0), Mac (10,13)]
[Export ("rotationRate", ArgumentSemantic.Assign)]
Vector3d RotationRate { get; }
[TV (11,0)]
[iOS (11,0)]
[Mac (10,13, onlyOn64: true)]
[Export ("hasAttitudeAndRotationRate")]
bool HasAttitudeAndRotationRate { get; }
[TV (13,0), Mac (10,15, onlyOn64: true), iOS (13,0)]
[Export ("setGravity:")]
void SetGravity (GCAcceleration gravity);
[TV (13,0), Mac (10,15, onlyOn64: true), iOS (13,0)]
[Export ("setUserAcceleration:")]
void SetUserAcceleration (GCAcceleration userAcceleration);
[TV (13,0), Mac (10,15, onlyOn64: true), iOS (13,0)]
[Export ("setAttitude:")]
void SetAttitude (GCQuaternion attitude);
[TV (13,0), Mac (10,15, onlyOn64: true), iOS (13,0)]
[Export ("setRotationRate:")]
void SetRotationRate (GCRotationRate rotationRate);
[TV (13,0), Mac (10,15, onlyOn64: true), iOS (13,0)]
[Export ("setStateFromMotion:")]
void SetState (GCMotion motion);
}
[Mac (10,11, onlyOn64: true)]
[iOS (10,0)]
[TV (9,0)]
delegate void GCMicroGamepadValueChangedHandler (GCMicroGamepad gamepad, GCControllerElement element);
[Mac (10,11, onlyOn64: true)]
[iOS (10,0)]
[TV (9,0)]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
interface GCMicroGamepad {
[Export ("controller", ArgumentSemantic.Assign)]
GCController Controller { get; }
[NullAllowed, Export ("valueChangedHandler", ArgumentSemantic.Copy)]
GCMicroGamepadValueChangedHandler ValueChangedHandler { get; set; }
[Deprecated (PlatformName.MacOSX, 10, 15, message: "GCExtendedGamepadSnapshot has been deprecated, use [GCController capture] instead")]
[Deprecated (PlatformName.iOS, 13, 0, message: "GCExtendedGamepadSnapshot has been deprecated, use [GCController capture] instead")]
[Deprecated (PlatformName.TvOS, 13, 0, message: "GCExtendedGamepadSnapshot has been deprecated, use [GCController capture] instead")]
[Export ("saveSnapshot")]
GCMicroGamepadSnapshot SaveSnapshot { get; }
[Export ("dpad", ArgumentSemantic.Retain)]
GCControllerDirectionPad Dpad { get; }
[Export ("buttonA", ArgumentSemantic.Retain)]
GCControllerButtonInput ButtonA { get; }
[Export ("buttonX", ArgumentSemantic.Retain)]
GCControllerButtonInput ButtonX { get; }
[Export ("reportsAbsoluteDpadValues")]
bool ReportsAbsoluteDpadValues { get; set; }
[Export ("allowsRotation")]
bool AllowsRotation { get; set; }
[TV (13, 0), Mac (10, 15, onlyOn64: true), iOS (13, 0)]
[Export ("buttonMenu")]
GCControllerButtonInput ButtonMenu { get; }
[TV (13,0), Mac (10,15, onlyOn64: true), iOS (13,0)]
[Export ("setStateFromExtendedGamepad:")]
void SetStateFromExtendedGamepad (GCExtendedGamepad extendedGamepad);
}
[Deprecated (PlatformName.MacOSX, 10, 15, message: "GCMicroGamepadSnapshot has been deprecated, use [GCController capture] instead")]
[Deprecated (PlatformName.iOS, 13, 0, message: "GCMicroGamepadSnapshot has been deprecated, use [GCController capture] instead")]
[Deprecated (PlatformName.TvOS, 13, 0, message: "GCMicroGamepadSnapshot has been deprecated, use [GCController capture] instead")]
[Mac (10,12, onlyOn64: true)]
[iOS (10,0)]
[TV (9,0)]
[BaseType (typeof (GCMicroGamepad))]
interface GCMicroGamepadSnapshot {
[Export ("snapshotData", ArgumentSemantic.Copy)]
NSData SnapshotData { get; set; }
[Export ("initWithSnapshotData:")]
IntPtr Constructor (NSData data);
[Export ("initWithController:snapshotData:")]
IntPtr Constructor (GCController controller, NSData data);
[Deprecated (PlatformName.MacOSX, 10, 15, message: "GCMicroGamepadSnapshot has been deprecated, use [GCController controllerWithMicroGamepad] instead")]
[Deprecated (PlatformName.iOS, 13, 0, message: "GCMicroGamepadSnapshot has been deprecated, use [GCController controllerWithMicroGamepad] instead")]
[Deprecated (PlatformName.TvOS, 13, 0, message: "GCMicroGamepadSnapshot has been deprecated, use [GCController controllerWithMicroGamepad] instead")]
[TV (12, 2), Mac (10, 14, 4, onlyOn64: true), iOS (12, 2)]
[Field ("GCCurrentMicroGamepadSnapshotDataVersion")]
GCMicroGamepadSnapshotDataVersion DataVersion { get; }
}
[Mac (10,12, onlyOn64: true)]
[iOS (10,0)]
[TV (9,0)]
[BaseType (typeof (UIViewController))]
interface GCEventViewController {
// inlined ctor
[Export ("initWithNibName:bundle:")]
[PostGet ("NibBundle")]
IntPtr Constructor ([NullAllowed] string nibName, [NullAllowed] NSBundle bundle);
[Export ("controllerUserInteractionEnabled")]
bool ControllerUserInteractionEnabled { get; set; }
}
}
//
// GCMotion.cs: extensions to GCMotion iOS API
//
// Authors:
// TJ Lambert (t-anlamb@microsoft.com)
//
// Copyright 2019 Microsoft Corporation.
using System;
using ObjCRuntime;
using Foundation;
namespace GameController {
[iOS (13,0,0), Mac (10,15, onlyOn64: true), TV (13,0)]
public struct GCAcceleration {
public double X;
public double Y;
public double Z;
}
[iOS (13,0,0), Mac (10,15, onlyOn64: true), TV (13,0)]
public struct GCRotationRate {
public double X;
public double Y;
public double Z;
}
[iOS (13,0,0), Mac (10,15, onlyOn64: true), TV (13,0)]
public struct GCQuaternion {
public double X;
public double Y;
public double Z;
public double W;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment