diff --git a/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs b/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs index 3fc0a9a4..7c05ff00 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs @@ -31,22 +31,24 @@ using OpenTK.Input; namespace OpenTK.Platform.SDL2 { - using Sdl2Joystick = JoystickDevice; - - class Sdl2JoystickDetails - { - public IntPtr Handle { get; set; } - public float RangeMultiplier { get { return 1.0f / 32768.0f; } } - } - class Sdl2JoystickDriver : IJoystickDriver, IGamePadDriver { - readonly List joysticks = new List(); + struct Sdl2JoystickDetails + { + public IntPtr Handle { get; set; } + public float RangeMultiplier { get { return 1.0f / 32768.0f; } } + public int HatCount { get; set; } + public int BallCount { get; set; } + } + + readonly List joysticks = new List(); IList joysticks_readonly; public Sdl2JoystickDriver() { - joysticks_readonly = (IList)joysticks.AsReadOnly(); + joysticks_readonly = joysticks.AsReadOnly(); + + RefreshJoysticks(); } @@ -62,12 +64,22 @@ namespace OpenTK.Platform.SDL2 JoystickDevice joystick = null; int num_axes = 0; int num_buttons = 0; + int num_hats = 0; + int num_balls = 0; + IntPtr handle = SDL.SDL_JoystickOpen(i); if (handle != IntPtr.Zero) { num_axes = SDL.SDL_JoystickNumAxes(handle); num_buttons = SDL.SDL_JoystickNumButtons(handle); + num_hats = SDL.SDL_JoystickNumHats(handle); + num_balls = SDL.SDL_JoystickNumBalls(handle); + joystick = new JoystickDevice(i, num_axes, num_buttons); + joystick.Description = SDL.SDL_JoystickName(handle); + joystick.Details.Handle = handle; + joystick.Details.HatCount = num_hats; + joystick.Details.BallCount = num_balls; joysticks.Add(joystick); } } @@ -89,8 +101,9 @@ namespace OpenTK.Platform.SDL2 public void Poll() { SDL.SDL_JoystickUpdate(); - foreach (Sdl2Joystick joystick in joysticks) + foreach (var j in joysticks) { + var joystick = (JoystickDevice)j; IntPtr handle = joystick.Details.Handle; for (int i = 0; i < joystick.Axis.Count; i++) diff --git a/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs b/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs index ccc2ffa3..a20a5cb6 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs @@ -58,6 +58,8 @@ namespace OpenTK.Platform.SDL2 IList keyboards = new List(1); IList mice = new List(1); + readonly Sdl2JoystickDriver joystick_driver = new Sdl2JoystickDriver(); + readonly SDL.SDL_EventFilter EventFilterDelegate = FilterEvents; static readonly Dictionary windows = @@ -862,6 +864,7 @@ namespace OpenTK.Platform.SDL2 public void Poll() { + joystick_driver.Poll(); } #endregion @@ -872,7 +875,7 @@ namespace OpenTK.Platform.SDL2 { get { - throw new NotImplementedException(); + return joystick_driver.Joysticks; } }