mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-11 01:35:40 +00:00
[Input] Implemented MappedGamePadDriver.GetCapabilities()
This commit is contained in:
parent
f0fbb26efe
commit
a0dad7f698
|
@ -52,13 +52,18 @@ namespace OpenTK.Platform
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
class MappedGamePadDriver : IGamePadDriver
|
class MappedGamePadDriver : IGamePadDriver
|
||||||
{
|
{
|
||||||
|
readonly Dictionary<Guid, GamePadMap> configurations =
|
||||||
|
new Dictionary<Guid, GamePadMap>();
|
||||||
|
|
||||||
public GamePadState GetState(int index)
|
public GamePadState GetState(int index)
|
||||||
{
|
{
|
||||||
JoystickState joy = Joystick.GetState(index);
|
JoystickState joy = Joystick.GetState(index);
|
||||||
GamePadState pad = new GamePadState();
|
GamePadState pad = new GamePadState();
|
||||||
if (joy.IsConnected)
|
if (joy.IsConnected)
|
||||||
{
|
{
|
||||||
GamePadMapping mapping = new GamePadMapping();//GamePadMapping.Lookup()
|
GamePadMap map = GetConfiguration(Joystick.GetGuid(index));
|
||||||
|
|
||||||
|
|
||||||
// Todo: implement mapping
|
// Todo: implement mapping
|
||||||
}
|
}
|
||||||
return pad;
|
return pad;
|
||||||
|
@ -67,10 +72,19 @@ namespace OpenTK.Platform
|
||||||
public GamePadCapabilities GetCapabilities(int index)
|
public GamePadCapabilities GetCapabilities(int index)
|
||||||
{
|
{
|
||||||
JoystickCapabilities joy = Joystick.GetCapabilities(index);
|
JoystickCapabilities joy = Joystick.GetCapabilities(index);
|
||||||
GamePadCapabilities pad = new GamePadCapabilities();
|
GamePadCapabilities pad;
|
||||||
if (joy.IsConnected)
|
if (joy.IsConnected)
|
||||||
{
|
{
|
||||||
// Todo: implement mapping
|
GamePadMap map = GetConfiguration(Joystick.GetGuid(index));
|
||||||
|
pad = new GamePadCapabilities(
|
||||||
|
GamePadType.GamePad, // Todo: detect different types
|
||||||
|
TranslateAxes(map),
|
||||||
|
TranslateButtons(map),
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pad = new GamePadCapabilities();
|
||||||
}
|
}
|
||||||
return pad;
|
return pad;
|
||||||
}
|
}
|
||||||
|
@ -79,5 +93,61 @@ namespace OpenTK.Platform
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Private Members
|
||||||
|
|
||||||
|
GamePadMap GetConfiguration(Guid guid)
|
||||||
|
{
|
||||||
|
if (!configurations.ContainsKey(guid))
|
||||||
|
{
|
||||||
|
GamePadMap map = GamePadMap.GetConfiguration(guid);
|
||||||
|
configurations.Add(guid, map);
|
||||||
|
}
|
||||||
|
return configurations[guid];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsMapped(MapItem item)
|
||||||
|
{
|
||||||
|
return item.Type != MapType.Unmapped;
|
||||||
|
}
|
||||||
|
|
||||||
|
GamePadAxes TranslateAxes(GamePadMap map)
|
||||||
|
{
|
||||||
|
GamePadAxes axes = 0;
|
||||||
|
axes |= IsMapped(map.LeftAxisX) ? GamePadAxes.LeftX : 0;
|
||||||
|
axes |= IsMapped(map.LeftAxisY) ? GamePadAxes.LeftY : 0;
|
||||||
|
axes |= IsMapped(map.RightAxisX) ? GamePadAxes.RightX : 0;
|
||||||
|
axes |= IsMapped(map.RightAxisY) ? GamePadAxes.RightY : 0;
|
||||||
|
axes |= IsMapped(map.LeftTrigger) ? GamePadAxes.LeftTrigger : 0;
|
||||||
|
axes |= IsMapped(map.RightTrigger) ? GamePadAxes.RightTrigger : 0;
|
||||||
|
return axes;
|
||||||
|
}
|
||||||
|
|
||||||
|
Buttons TranslateButtons(GamePadMap map)
|
||||||
|
{
|
||||||
|
Buttons buttons = 0;
|
||||||
|
buttons |= IsMapped(map.A) ? Buttons.A : 0;
|
||||||
|
buttons |= IsMapped(map.B) ? Buttons.B : 0;
|
||||||
|
buttons |= IsMapped(map.X) ? Buttons.X : 0;
|
||||||
|
buttons |= IsMapped(map.Y) ? Buttons.Y : 0;
|
||||||
|
buttons |= IsMapped(map.Start) ? Buttons.Start : 0;
|
||||||
|
buttons |= IsMapped(map.Back) ? Buttons.Back : 0;
|
||||||
|
buttons |= IsMapped(map.BigButton) ? Buttons.BigButton : 0;
|
||||||
|
buttons |= IsMapped(map.LeftShoulder) ? Buttons.LeftShoulder : 0;
|
||||||
|
buttons |= IsMapped(map.RightShoulder) ? Buttons.RightShoulder : 0;
|
||||||
|
buttons |= IsMapped(map.LeftStick) ? Buttons.LeftStick : 0;
|
||||||
|
buttons |= IsMapped(map.RightStick) ? Buttons.RightStick : 0;
|
||||||
|
return buttons;
|
||||||
|
}
|
||||||
|
|
||||||
|
// bool TranslateDPad(GamePadMap map)
|
||||||
|
// {
|
||||||
|
// pad.HasDPadDownButton = IsMapped(map.DPadDown);
|
||||||
|
// pad.HasDPadUpButton = IsMapped(map.DPadUp);
|
||||||
|
// pad.HasDPadLeftButton = IsMapped(map.DPadLeft);
|
||||||
|
// pad.HasDPadRightButton = IsMapped(map.DPadRight);
|
||||||
|
// }
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue