mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-07-21 14:08:28 +00:00
Sdl2JoystickDriver.Poll() and axis fixes
This commit is contained in:
parent
1434f0d3e9
commit
17b4f62151
|
@ -31,22 +31,24 @@ using OpenTK.Input;
|
||||||
|
|
||||||
namespace OpenTK.Platform.SDL2
|
namespace OpenTK.Platform.SDL2
|
||||||
{
|
{
|
||||||
using Sdl2Joystick = JoystickDevice<Sdl2JoystickDetails>;
|
|
||||||
|
|
||||||
class Sdl2JoystickDetails
|
|
||||||
{
|
|
||||||
public IntPtr Handle { get; set; }
|
|
||||||
public float RangeMultiplier { get { return 1.0f / 32768.0f; } }
|
|
||||||
}
|
|
||||||
|
|
||||||
class Sdl2JoystickDriver : IJoystickDriver, IGamePadDriver
|
class Sdl2JoystickDriver : IJoystickDriver, IGamePadDriver
|
||||||
{
|
{
|
||||||
readonly List<Sdl2Joystick> joysticks = new List<Sdl2Joystick>();
|
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<JoystickDevice> joysticks = new List<JoystickDevice>();
|
||||||
IList<JoystickDevice> joysticks_readonly;
|
IList<JoystickDevice> joysticks_readonly;
|
||||||
|
|
||||||
public Sdl2JoystickDriver()
|
public Sdl2JoystickDriver()
|
||||||
{
|
{
|
||||||
joysticks_readonly = (IList<JoystickDevice>)joysticks.AsReadOnly();
|
joysticks_readonly = joysticks.AsReadOnly();
|
||||||
|
|
||||||
|
RefreshJoysticks();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,12 +64,22 @@ namespace OpenTK.Platform.SDL2
|
||||||
JoystickDevice<Sdl2JoystickDetails> joystick = null;
|
JoystickDevice<Sdl2JoystickDetails> joystick = null;
|
||||||
int num_axes = 0;
|
int num_axes = 0;
|
||||||
int num_buttons = 0;
|
int num_buttons = 0;
|
||||||
|
int num_hats = 0;
|
||||||
|
int num_balls = 0;
|
||||||
|
|
||||||
IntPtr handle = SDL.SDL_JoystickOpen(i);
|
IntPtr handle = SDL.SDL_JoystickOpen(i);
|
||||||
if (handle != IntPtr.Zero)
|
if (handle != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
num_axes = SDL.SDL_JoystickNumAxes(handle);
|
num_axes = SDL.SDL_JoystickNumAxes(handle);
|
||||||
num_buttons = SDL.SDL_JoystickNumButtons(handle);
|
num_buttons = SDL.SDL_JoystickNumButtons(handle);
|
||||||
|
num_hats = SDL.SDL_JoystickNumHats(handle);
|
||||||
|
num_balls = SDL.SDL_JoystickNumBalls(handle);
|
||||||
|
|
||||||
joystick = new JoystickDevice<Sdl2JoystickDetails>(i, num_axes, num_buttons);
|
joystick = new JoystickDevice<Sdl2JoystickDetails>(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);
|
joysticks.Add(joystick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,8 +101,9 @@ namespace OpenTK.Platform.SDL2
|
||||||
public void Poll()
|
public void Poll()
|
||||||
{
|
{
|
||||||
SDL.SDL_JoystickUpdate();
|
SDL.SDL_JoystickUpdate();
|
||||||
foreach (Sdl2Joystick joystick in joysticks)
|
foreach (var j in joysticks)
|
||||||
{
|
{
|
||||||
|
var joystick = (JoystickDevice<Sdl2JoystickDetails>)j;
|
||||||
IntPtr handle = joystick.Details.Handle;
|
IntPtr handle = joystick.Details.Handle;
|
||||||
|
|
||||||
for (int i = 0; i < joystick.Axis.Count; i++)
|
for (int i = 0; i < joystick.Axis.Count; i++)
|
||||||
|
|
|
@ -58,6 +58,8 @@ namespace OpenTK.Platform.SDL2
|
||||||
IList<KeyboardDevice> keyboards = new List<KeyboardDevice>(1);
|
IList<KeyboardDevice> keyboards = new List<KeyboardDevice>(1);
|
||||||
IList<MouseDevice> mice = new List<MouseDevice>(1);
|
IList<MouseDevice> mice = new List<MouseDevice>(1);
|
||||||
|
|
||||||
|
readonly Sdl2JoystickDriver joystick_driver = new Sdl2JoystickDriver();
|
||||||
|
|
||||||
readonly SDL.SDL_EventFilter EventFilterDelegate = FilterEvents;
|
readonly SDL.SDL_EventFilter EventFilterDelegate = FilterEvents;
|
||||||
|
|
||||||
static readonly Dictionary<uint, Sdl2NativeWindow> windows =
|
static readonly Dictionary<uint, Sdl2NativeWindow> windows =
|
||||||
|
@ -862,6 +864,7 @@ namespace OpenTK.Platform.SDL2
|
||||||
|
|
||||||
public void Poll()
|
public void Poll()
|
||||||
{
|
{
|
||||||
|
joystick_driver.Poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -872,7 +875,7 @@ namespace OpenTK.Platform.SDL2
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return joystick_driver.Joysticks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue