mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-10 23:35:29 +00:00
[SDL2] Explicitly enable joystick and gamepad events
This commit is contained in:
parent
2d303a6884
commit
9beb396c9e
|
@ -116,22 +116,11 @@ namespace OpenTK.Platform.SDL2
|
||||||
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_FreeSurface", ExactSpelling = true)]
|
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_FreeSurface", ExactSpelling = true)]
|
||||||
public static extern void FreeSurface(IntPtr surface);
|
public static extern void FreeSurface(IntPtr surface);
|
||||||
|
|
||||||
[SuppressUnmanagedCodeSecurity]
|
#region GameContoller
|
||||||
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GameControllerName", ExactSpelling = true)]
|
|
||||||
static extern IntPtr GameControllerNameInternal(IntPtr gamecontroller);
|
|
||||||
|
|
||||||
/// <summary>
|
[SuppressUnmanagedCodeSecurity]
|
||||||
/// Return the name for an openend game controller instance.
|
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GameControllerEventState", ExactSpelling = true)]
|
||||||
/// </summary>
|
public static extern EventState GameControllerEventState(EventState state);
|
||||||
/// <returns>The name of the game controller name.</returns>
|
|
||||||
/// <param name="gamecontroller">Pointer to a game controller instance returned by <c>GameControllerOpen</c>.</param>
|
|
||||||
public static string GameControllerName(IntPtr gamecontroller)
|
|
||||||
{
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
return new string((sbyte*)GameControllerNameInternal(gamecontroller));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[SuppressUnmanagedCodeSecurity]
|
[SuppressUnmanagedCodeSecurity]
|
||||||
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GameControllerGetAxis", ExactSpelling = true)]
|
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GameControllerGetAxis", ExactSpelling = true)]
|
||||||
|
@ -177,6 +166,27 @@ namespace OpenTK.Platform.SDL2
|
||||||
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GameControllerGetJoystick", ExactSpelling = true)]
|
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GameControllerGetJoystick", ExactSpelling = true)]
|
||||||
public static extern IntPtr GameControllerGetJoystick(IntPtr gamecontroller);
|
public static extern IntPtr GameControllerGetJoystick(IntPtr gamecontroller);
|
||||||
|
|
||||||
|
[SuppressUnmanagedCodeSecurity]
|
||||||
|
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetCurrentDisplayMode", ExactSpelling = true)]
|
||||||
|
public static extern int GetCurrentDisplayMode(int displayIndex, out DisplayMode mode);
|
||||||
|
|
||||||
|
[SuppressUnmanagedCodeSecurity]
|
||||||
|
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GameControllerName", ExactSpelling = true)]
|
||||||
|
static extern IntPtr GameControllerNameInternal(IntPtr gamecontroller);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return the name for an openend game controller instance.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The name of the game controller name.</returns>
|
||||||
|
/// <param name="gamecontroller">Pointer to a game controller instance returned by <c>GameControllerOpen</c>.</param>
|
||||||
|
public static string GameControllerName(IntPtr gamecontroller)
|
||||||
|
{
|
||||||
|
unsafe
|
||||||
|
{
|
||||||
|
return new string((sbyte*)GameControllerNameInternal(gamecontroller));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Opens a game controller for use.
|
/// Opens a game controller for use.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -189,9 +199,7 @@ namespace OpenTK.Platform.SDL2
|
||||||
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GameControllerOpen", ExactSpelling = true)]
|
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GameControllerOpen", ExactSpelling = true)]
|
||||||
public static extern IntPtr GameControllerOpen(int joystick_index);
|
public static extern IntPtr GameControllerOpen(int joystick_index);
|
||||||
|
|
||||||
[SuppressUnmanagedCodeSecurity]
|
#endregion
|
||||||
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetCurrentDisplayMode", ExactSpelling = true)]
|
|
||||||
public static extern int GetCurrentDisplayMode(int displayIndex, out DisplayMode mode);
|
|
||||||
|
|
||||||
[SuppressUnmanagedCodeSecurity]
|
[SuppressUnmanagedCodeSecurity]
|
||||||
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetDisplayBounds", ExactSpelling = true)]
|
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetDisplayBounds", ExactSpelling = true)]
|
||||||
|
@ -280,6 +288,10 @@ namespace OpenTK.Platform.SDL2
|
||||||
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickClose", ExactSpelling = true)]
|
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickClose", ExactSpelling = true)]
|
||||||
public static extern void JoystickClose(IntPtr joystick);
|
public static extern void JoystickClose(IntPtr joystick);
|
||||||
|
|
||||||
|
[SuppressUnmanagedCodeSecurity]
|
||||||
|
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickEventState", ExactSpelling = true)]
|
||||||
|
public static extern EventState JoystickEventState(EventState enabled);
|
||||||
|
|
||||||
[SuppressUnmanagedCodeSecurity]
|
[SuppressUnmanagedCodeSecurity]
|
||||||
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickGetAxis", ExactSpelling = true)]
|
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickGetAxis", ExactSpelling = true)]
|
||||||
public static extern short JoystickGetAxis(IntPtr joystick, int axis);
|
public static extern short JoystickGetAxis(IntPtr joystick, int axis);
|
||||||
|
@ -545,6 +557,13 @@ namespace OpenTK.Platform.SDL2
|
||||||
ES = 0x0004
|
ES = 0x0004
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum EventState
|
||||||
|
{
|
||||||
|
Query = -1,
|
||||||
|
Ignore = 0,
|
||||||
|
Enable = 1
|
||||||
|
}
|
||||||
|
|
||||||
enum EventType
|
enum EventType
|
||||||
{
|
{
|
||||||
FIRSTEVENT = 0,
|
FIRSTEVENT = 0,
|
||||||
|
|
|
@ -55,6 +55,9 @@ namespace OpenTK.Platform.SDL2
|
||||||
{
|
{
|
||||||
lock (SDL.Sync)
|
lock (SDL.Sync)
|
||||||
{
|
{
|
||||||
|
SDL.GameControllerEventState(EventState.Enable);
|
||||||
|
SDL.JoystickEventState(EventState.Enable);
|
||||||
|
|
||||||
EventFilterDelegate = Marshal.GetFunctionPointerForDelegate(EventFilterDelegate_GCUnsafe);
|
EventFilterDelegate = Marshal.GetFunctionPointerForDelegate(EventFilterDelegate_GCUnsafe);
|
||||||
driver_handle = new IntPtr(count++);
|
driver_handle = new IntPtr(count++);
|
||||||
DriverHandles.Add(driver_handle, this);
|
DriverHandles.Add(driver_handle, this);
|
||||||
|
|
Loading…
Reference in a new issue