diff --git a/Source/OpenTK/Platform/SDL2/Sdl2.cs b/Source/OpenTK/Platform/SDL2/Sdl2.cs index 163d393b..5aa6dad4 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2.cs @@ -137,7 +137,28 @@ namespace OpenTK.Platform.SDL2 [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GameControllerGetAxis", ExactSpelling = true)] public static extern short GameControllerGetAxis(IntPtr gamecontroller, GameControllerAxis axis); - /// > + /// + /// Gets the SDL joystick layer binding for the specified game controller axis + /// + /// Pointer to a game controller instance returned by GameControllerOpen. + /// A value from the GameControllerAxis enumeration + /// A GameControllerButtonBind instance describing the specified binding + [SuppressUnmanagedCodeSecurity] + [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GameControllerGetBindForAxis", ExactSpelling = true)] + public static extern GameControllerButtonBind GameControllerGetBindForAxis(IntPtr gamecontroller, GameControllerAxis axis); + + /// + /// Gets the SDL joystick layer binding for the specified game controller button + /// + /// Pointer to a game controller instance returned by GameControllerOpen. + /// A value from the GameControllerButton enumeration + /// A GameControllerButtonBind instance describing the specified binding + [SuppressUnmanagedCodeSecurity] + [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GameControllerGetBindForButton", ExactSpelling = true)] + public static extern GameControllerButtonBind GameControllerGetBindForButton( + IntPtr gamecontroller, GameControllerButton button); + + /// /// Gets the current state of a button on a game controller. /// /// A game controller handle previously opened with GameControllerOpen. @@ -147,6 +168,15 @@ namespace OpenTK.Platform.SDL2 [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GameControllerGetButton", ExactSpelling = true)] public static extern bool GameControllerGetButton(IntPtr gamecontroller, GameControllerButton button); + /// + /// Retrieve the joystick handle that corresponds to the specified game controller. + /// + /// A game controller handle previously opened with GameControllerOpen. + /// A handle to a joystick, or IntPtr.Zero in case of error. The pointer is owned by the callee. Use SDL.GetError to retrieve error information + [SuppressUnmanagedCodeSecurity] + [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GameControllerGetJoystick", ExactSpelling = true)] + public static extern IntPtr GameControllerGetJoystick(IntPtr gamecontroller); + /// /// Opens a game controller for use. /// @@ -587,6 +617,14 @@ namespace OpenTK.Platform.SDL2 Max } + enum GameControllerBindType : byte + { + None = 0, + Button, + Axis, + Hat + } + [Flags] enum HatPosition : byte { @@ -1277,6 +1315,21 @@ namespace OpenTK.Platform.SDL2 #endif } + [StructLayout(LayoutKind.Explicit)] + struct GameControllerButtonBind + { + [FieldOffset(0)] + public GameControllerBindType BindType; + [FieldOffset(4)] + public Button Button; + [FieldOffset(4)] + public GameControllerAxis Axis; + [FieldOffset(4)] + public int Hat; + [FieldOffset(8)] + public int HatMask; + } + struct JoyAxisEvent { public EventType Type;