mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-23 13:15:29 +00:00
[SDL] Use TranslateAxis() to decode ControllerAxisEvent
SDL GameControllerAxis and GamePadAxes are not interchangeable. The driver will now correctly interpret incoming SDL messages and update the GamePadState for the relevant axis.
This commit is contained in:
parent
e997ddf9c6
commit
1b0a72472e
|
@ -115,7 +115,7 @@ namespace OpenTK.Platform.SDL2
|
|||
return controllers.ContainsKey(id);
|
||||
}
|
||||
|
||||
GamePadAxes TranslateAxes(IntPtr gamecontroller)
|
||||
GamePadAxes GetBoundAxes(IntPtr gamecontroller)
|
||||
{
|
||||
GamePadAxes axes = 0;
|
||||
axes |= IsAxisBind(gamecontroller, GameControllerAxis.LeftX) ? GamePadAxes.LeftX : 0;
|
||||
|
@ -127,7 +127,7 @@ namespace OpenTK.Platform.SDL2
|
|||
return axes;
|
||||
}
|
||||
|
||||
Buttons TranslateButtons(IntPtr gamecontroller)
|
||||
Buttons GetBoundButtons(IntPtr gamecontroller)
|
||||
{
|
||||
Buttons buttons = 0;
|
||||
buttons |= IsButtonBind(gamecontroller, GameControllerButton.A) ? Buttons.A : 0;
|
||||
|
@ -162,6 +162,33 @@ namespace OpenTK.Platform.SDL2
|
|||
return bind.BindType == GameControllerBindType.Button;
|
||||
}
|
||||
|
||||
GamePadAxes TranslateAxis(GameControllerAxis axis)
|
||||
{
|
||||
switch (axis)
|
||||
{
|
||||
case GameControllerAxis.LeftX:
|
||||
return GamePadAxes.LeftX;
|
||||
|
||||
case GameControllerAxis.LeftY:
|
||||
return GamePadAxes.LeftY;
|
||||
|
||||
case GameControllerAxis.RightX:
|
||||
return GamePadAxes.RightX;
|
||||
|
||||
case GameControllerAxis.RightY:
|
||||
return GamePadAxes.RightY;
|
||||
|
||||
case GameControllerAxis.TriggerLeft:
|
||||
return GamePadAxes.LeftTrigger;
|
||||
|
||||
case GameControllerAxis.TriggerRight:
|
||||
return GamePadAxes.RightTrigger;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(
|
||||
String.Format("[SDL] Unknown axis {0}", axis));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
@ -287,8 +314,8 @@ namespace OpenTK.Platform.SDL2
|
|||
SDL.JoystickNumAxes(joystick);
|
||||
pad.Capabilities = new GamePadCapabilities(
|
||||
GamePadType.GamePad,
|
||||
TranslateAxes(joystick),
|
||||
TranslateButtons(joystick),
|
||||
GetBoundAxes(joystick),
|
||||
GetBoundButtons(joystick),
|
||||
true);
|
||||
pad.State.SetConnected(true);
|
||||
|
||||
|
@ -322,7 +349,7 @@ namespace OpenTK.Platform.SDL2
|
|||
int id = ev.Which;
|
||||
if (IsControllerValid(id))
|
||||
{
|
||||
controllers[id].State.SetAxis((GamePadAxes)ev.Axis, ev.Value);
|
||||
controllers[id].State.SetAxis(TranslateAxis(ev.Axis), ev.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue