From b9a8e365dea405675ec79caa6e5089ae0010e535 Mon Sep 17 00:00:00 2001 From: thefiddler Date: Tue, 31 Dec 2013 14:09:17 +0100 Subject: [PATCH] [Input] Added IJoystickDriver2.GetGuid() API --- Source/OpenTK/Input/IJoystickDriver2.cs | 1 + Source/OpenTK/Input/Joystick.cs | 5 +++++ Source/OpenTK/Platform/MacOS/HIDInput.cs | 5 +++++ .../OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs | 17 ++++++++++++++++- Source/OpenTK/Platform/Windows/WinMMJoystick.cs | 12 ++++++++++++ Source/OpenTK/Platform/X11/X11Joystick.cs | 5 +++++ 6 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Source/OpenTK/Input/IJoystickDriver2.cs b/Source/OpenTK/Input/IJoystickDriver2.cs index 1359d1de..8e536aaf 100644 --- a/Source/OpenTK/Input/IJoystickDriver2.cs +++ b/Source/OpenTK/Input/IJoystickDriver2.cs @@ -37,5 +37,6 @@ namespace OpenTK.Input { JoystickState GetState(int index); JoystickCapabilities GetCapabilities(int index); + Guid GetGuid(int index); } } diff --git a/Source/OpenTK/Input/Joystick.cs b/Source/OpenTK/Input/Joystick.cs index 378b11f4..2b10cfb9 100644 --- a/Source/OpenTK/Input/Joystick.cs +++ b/Source/OpenTK/Input/Joystick.cs @@ -48,6 +48,11 @@ namespace OpenTK.Input return implementation.GetState(index); } + internal static Guid GetGuid(int index) + { + return implementation.GetGuid(index); + } + //public string GetName(int index) //{ // return implementation.GetName(index); diff --git a/Source/OpenTK/Platform/MacOS/HIDInput.cs b/Source/OpenTK/Platform/MacOS/HIDInput.cs index 0967afef..9090e703 100755 --- a/Source/OpenTK/Platform/MacOS/HIDInput.cs +++ b/Source/OpenTK/Platform/MacOS/HIDInput.cs @@ -381,6 +381,11 @@ namespace OpenTK.Platform.MacOS return new JoystickCapabilities(); } + Guid IJoystickDriver2.GetGuid(int index) + { + return new Guid(); + } + #endregion #region NativeMethods diff --git a/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs b/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs index 01c72b82..25b6b253 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs @@ -38,9 +38,10 @@ namespace OpenTK.Platform.SDL2 readonly MappedGamePadDriver gamepad_driver = new MappedGamePadDriver(); bool disposed; - struct Sdl2JoystickDetails + class Sdl2JoystickDetails { public IntPtr Handle { get; set; } + public Guid Guid { get; set; } public int HatCount { get; set; } public int BallCount { get; set; } public bool IsConnected { get; set; } @@ -99,6 +100,7 @@ namespace OpenTK.Platform.SDL2 joystick = new JoystickDevice(id, num_axes, num_buttons); joystick.Description = SDL.JoystickName(handle); joystick.Details.Handle = handle; + joystick.Details.Guid = SDL.JoystickGetGUID(handle).ToGuid(); joystick.Details.HatCount = num_hats; joystick.Details.BallCount = num_balls; @@ -606,6 +608,19 @@ namespace OpenTK.Platform.SDL2 return new JoystickCapabilities(); } + Guid IJoystickDriver2.GetGuid(int index) + { + Guid guid = new Guid(); + if (IsJoystickValid(index)) + { + JoystickDevice joystick = + (JoystickDevice)joysticks[index]; + + return joystick.Details.Guid; + } + return guid; + } + #endregion #region IDisposable Members diff --git a/Source/OpenTK/Platform/Windows/WinMMJoystick.cs b/Source/OpenTK/Platform/Windows/WinMMJoystick.cs index fa84aba1..313abdd9 100644 --- a/Source/OpenTK/Platform/Windows/WinMMJoystick.cs +++ b/Source/OpenTK/Platform/Windows/WinMMJoystick.cs @@ -333,6 +333,18 @@ namespace OpenTK.Platform.Windows return state; } + public Guid GetGuid(int index) + { + Guid guid = new Guid(); + + if (IsValid(index)) + { + // Todo: implement WinMM Guid retrieval + } + + return guid; + } + #endregion #region IDisposable diff --git a/Source/OpenTK/Platform/X11/X11Joystick.cs b/Source/OpenTK/Platform/X11/X11Joystick.cs index 36fac9f2..5f76dd54 100644 --- a/Source/OpenTK/Platform/X11/X11Joystick.cs +++ b/Source/OpenTK/Platform/X11/X11Joystick.cs @@ -290,6 +290,11 @@ namespace OpenTK.Platform.X11 throw new NotImplementedException(); } + Guid IJoystickDriver2.GetGuid(int index) + { + throw new NotImplementedException(); + } + #endregion } }