mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-07-10 15:17:32 +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);
|
return controllers.ContainsKey(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
GamePadAxes TranslateAxes(IntPtr gamecontroller)
|
GamePadAxes GetBoundAxes(IntPtr gamecontroller)
|
||||||
{
|
{
|
||||||
GamePadAxes axes = 0;
|
GamePadAxes axes = 0;
|
||||||
axes |= IsAxisBind(gamecontroller, GameControllerAxis.LeftX) ? GamePadAxes.LeftX : 0;
|
axes |= IsAxisBind(gamecontroller, GameControllerAxis.LeftX) ? GamePadAxes.LeftX : 0;
|
||||||
|
@ -127,7 +127,7 @@ namespace OpenTK.Platform.SDL2
|
||||||
return axes;
|
return axes;
|
||||||
}
|
}
|
||||||
|
|
||||||
Buttons TranslateButtons(IntPtr gamecontroller)
|
Buttons GetBoundButtons(IntPtr gamecontroller)
|
||||||
{
|
{
|
||||||
Buttons buttons = 0;
|
Buttons buttons = 0;
|
||||||
buttons |= IsButtonBind(gamecontroller, GameControllerButton.A) ? Buttons.A : 0;
|
buttons |= IsButtonBind(gamecontroller, GameControllerButton.A) ? Buttons.A : 0;
|
||||||
|
@ -162,6 +162,33 @@ namespace OpenTK.Platform.SDL2
|
||||||
return bind.BindType == GameControllerBindType.Button;
|
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
|
#endregion
|
||||||
|
|
||||||
#region Public Members
|
#region Public Members
|
||||||
|
@ -287,8 +314,8 @@ namespace OpenTK.Platform.SDL2
|
||||||
SDL.JoystickNumAxes(joystick);
|
SDL.JoystickNumAxes(joystick);
|
||||||
pad.Capabilities = new GamePadCapabilities(
|
pad.Capabilities = new GamePadCapabilities(
|
||||||
GamePadType.GamePad,
|
GamePadType.GamePad,
|
||||||
TranslateAxes(joystick),
|
GetBoundAxes(joystick),
|
||||||
TranslateButtons(joystick),
|
GetBoundButtons(joystick),
|
||||||
true);
|
true);
|
||||||
pad.State.SetConnected(true);
|
pad.State.SetConnected(true);
|
||||||
|
|
||||||
|
@ -322,7 +349,7 @@ namespace OpenTK.Platform.SDL2
|
||||||
int id = ev.Which;
|
int id = ev.Which;
|
||||||
if (IsControllerValid(id))
|
if (IsControllerValid(id))
|
||||||
{
|
{
|
||||||
controllers[id].State.SetAxis((GamePadAxes)ev.Axis, ev.Value);
|
controllers[id].State.SetAxis(TranslateAxis(ev.Axis), ev.Value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue