mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-07-10 14:07:35 +00:00
Started implementing GamePad
This commit is contained in:
parent
e6a855f00a
commit
b5591e1eee
|
@ -6,5 +6,26 @@ namespace OpenTK.Input
|
|||
{
|
||||
interface IGamePadDriver
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves the combined <see cref="OpenTK.Input.GamePadState"/> for all gamepad devices.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="OpenTK.Input.GamePadState"/> structure containing the combined state for all gamepad devices.</returns>
|
||||
GamePadState GetState();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the <see cref="OpenTK.Input.GamePadState"/> for the specified gamepad device.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the keyboard device.</param>
|
||||
/// <returns>A <see cref="OpenTK.Input.GamePadState"/> structure containing the state of the gamepad device.</returns>
|
||||
GamePadState GetState(int index);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the device name for the gamepad device.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the gamepad device.</param>
|
||||
/// <returns>A <see cref="System.String"/> with the name of the specified device or <see cref="System.String.Empty"/>.</returns>
|
||||
/// <remarks>
|
||||
/// <para>If no device exists at the specified index, the return value is <see cref="System.String.Empty"/>.</para></remarks>
|
||||
string GetDeviceName(int index);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,6 +124,11 @@ namespace OpenTK.Platform
|
|||
return default_implementation.CreateMouseDriver();
|
||||
}
|
||||
|
||||
public OpenTK.Input.IGamePadDriver CreateGamePadDriver()
|
||||
{
|
||||
return default_implementation.CreateGamePadDriver();
|
||||
}
|
||||
|
||||
class UnsupportedPlatform : IPlatformFactory
|
||||
{
|
||||
#region Fields
|
||||
|
@ -178,7 +183,12 @@ namespace OpenTK.Platform
|
|||
{
|
||||
throw new PlatformNotSupportedException(error_string);
|
||||
}
|
||||
|
||||
|
||||
public OpenTK.Input.IGamePadDriver CreateGamePadDriver()
|
||||
{
|
||||
throw new PlatformNotSupportedException(error_string);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
|
|
@ -50,5 +50,7 @@ namespace OpenTK.Platform
|
|||
OpenTK.Input.IKeyboardDriver2 CreateKeyboardDriver();
|
||||
|
||||
OpenTK.Input.IMouseDriver2 CreateMouseDriver();
|
||||
|
||||
OpenTK.Input.IGamePadDriver CreateGamePadDriver();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace OpenTK.Platform.MacOS
|
|||
|
||||
// Requires Mac OS X 10.5 or higher.
|
||||
// Todo: create a driver for older installations. Maybe use CGGetLastMouseDelta for that?
|
||||
class HIDInput : IInputDriver2, IMouseDriver2, IKeyboardDriver2
|
||||
class HIDInput : IInputDriver2, IMouseDriver2, IKeyboardDriver2/*, IGamePadDriver*/
|
||||
{
|
||||
#region Fields
|
||||
|
||||
|
|
|
@ -86,6 +86,11 @@ namespace OpenTK.Platform.MacOS
|
|||
{
|
||||
return InputDriver.MouseDriver;
|
||||
}
|
||||
|
||||
public virtual OpenTK.Input.IGamePadDriver CreateGamePadDriver()
|
||||
{
|
||||
return InputDriver.GamePadDriver;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace OpenTK.Platform.Windows
|
|||
// Input driver for legacy (pre XP) Windows platforms.
|
||||
// Supports a single mouse and keyboard through async input.
|
||||
// Supports multiple joysticks through WinMM.
|
||||
sealed class WMInput : IInputDriver2, IMouseDriver2, IKeyboardDriver2, IGamePadDriver
|
||||
sealed class WMInput : IInputDriver2, IMouseDriver2, IKeyboardDriver2/*, IGamePadDriver*/ //HACK uncomment and implement
|
||||
{
|
||||
#region Fields
|
||||
|
||||
|
@ -111,7 +111,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
public IGamePadDriver GamePadDriver
|
||||
{
|
||||
get { return this; }
|
||||
get { return null; } //HACK return this when implemented.
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -83,6 +83,11 @@ namespace OpenTK.Platform.Windows
|
|||
{
|
||||
return InputDriver.MouseDriver;
|
||||
}
|
||||
|
||||
public virtual OpenTK.Input.IGamePadDriver CreateGamePadDriver()
|
||||
{
|
||||
return InputDriver.GamePadDriver;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ namespace OpenTK.Platform.Windows
|
|||
if ((caps.Capabilities & JoystCapsFlags.HasPov) != 0)
|
||||
num_axes += 2;
|
||||
|
||||
stick = new JoystickDevice<WinMMJoyDetails>(number, num_axes, caps.NumButtons);
|
||||
stick = new JoystickDevice<WinMMJoyDetails>(number, num_axes, caps.NumButtons);
|
||||
stick.Details = new WinMMJoyDetails(num_axes);
|
||||
|
||||
// Make sure to reverse the vertical axes, so that +1 points up and -1 points down.
|
||||
|
@ -427,5 +427,21 @@ namespace OpenTK.Platform.Windows
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//HACK implement
|
||||
public GamePadState GetState()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public GamePadState GetState(int index)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string GetDeviceName(int index)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,6 +91,11 @@ namespace OpenTK.Platform.X11
|
|||
return new X11Mouse(); // Always supported.
|
||||
}
|
||||
|
||||
public virtual OpenTK.Input.IGamePadDriver CreateGamePadDriver()
|
||||
{
|
||||
return new X11Joystick();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,13 +29,14 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace OpenTK.Platform.X11
|
||||
{
|
||||
struct X11JoyDetails { }
|
||||
|
||||
sealed class X11Joystick : IJoystickDriver
|
||||
sealed class X11Joystick : IJoystickDriver, IGamePadDriver
|
||||
{
|
||||
#region Fields
|
||||
|
||||
|
@ -58,8 +59,8 @@ namespace OpenTK.Platform.X11
|
|||
JoystickDevice stick = OpenJoystick(JoystickPath, number++);
|
||||
if (stick != null)
|
||||
{
|
||||
stick.Description = String.Format("USB Joystick {0} ({1} axes, {2} buttons, {3}{0})",
|
||||
number, stick.Axis.Count, stick.Button.Count, JoystickPath);
|
||||
//stick.Description = String.Format("USB Joystick {0} ({1} axes, {2} buttons, {3}{0})",
|
||||
//number, stick.Axis.Count, stick.Button.Count, JoystickPath);
|
||||
sticks.Add(stick);
|
||||
}
|
||||
}
|
||||
|
@ -70,8 +71,8 @@ namespace OpenTK.Platform.X11
|
|||
JoystickDevice stick = OpenJoystick(JoystickPathLegacy, number++);
|
||||
if (stick != null)
|
||||
{
|
||||
stick.Description = String.Format("USB Joystick {0} ({1} axes, {2} buttons, {3}{0})",
|
||||
number, stick.Axis.Count, stick.Button.Count, JoystickPathLegacy);
|
||||
//stick.Description = String.Format("USB Joystick {0} ({1} axes, {2} buttons, {3}{0})",
|
||||
//number, stick.Axis.Count, stick.Button.Count, JoystickPathLegacy);
|
||||
sticks.Add(stick);
|
||||
}
|
||||
}
|
||||
|
@ -153,6 +154,11 @@ namespace OpenTK.Platform.X11
|
|||
UnsafeNativeMethods.ioctl(fd, JoystickIoctlCode.Buttons, ref buttons);
|
||||
|
||||
stick = new JoystickDevice<X11JoyDetails>(fd, axes, buttons);
|
||||
|
||||
StringBuilder sb = new StringBuilder(128);
|
||||
UnsafeNativeMethods.ioctl(fd, JoystickIoctlCode.Name128, sb);
|
||||
stick.Description = sb.ToString();
|
||||
|
||||
Debug.Print("Found joystick on path {0}", path);
|
||||
}
|
||||
finally
|
||||
|
@ -186,7 +192,8 @@ namespace OpenTK.Platform.X11
|
|||
{
|
||||
Version = 0x80046a01,
|
||||
Axes = 0x80016a11,
|
||||
Buttons = 0x80016a12
|
||||
Buttons = 0x80016a12,
|
||||
Name128 = (2u << 30) | (0x6A << 8) | (0x13 << 0) | (128 << 16) //JSIOCGNAME(128), which is _IOC(_IO_READ, 'j', 0x13, len)
|
||||
}
|
||||
|
||||
static readonly string JoystickPath = "/dev/input/js";
|
||||
|
@ -203,6 +210,9 @@ namespace OpenTK.Platform.X11
|
|||
[DllImport("libc", SetLastError = true)]
|
||||
public static extern int ioctl(int d, JoystickIoctlCode request, ref int data);
|
||||
|
||||
[DllImport("libc", SetLastError = true)]
|
||||
public static extern int ioctl(int d, JoystickIoctlCode request, StringBuilder data);
|
||||
|
||||
[DllImport("libc", SetLastError = true)]
|
||||
public static extern int open([MarshalAs(UnmanagedType.LPStr)]string pathname, OpenFlags flags);
|
||||
|
||||
|
@ -248,5 +258,21 @@ namespace OpenTK.Platform.X11
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//HACK implement
|
||||
public GamePadState GetState()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public GamePadState GetState(int index)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string GetDeviceName(int index)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue