mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-23 08:45:37 +00:00
[Input] Added hat state to JoystickState
This commit is contained in:
parent
0cacdf6ae4
commit
801d6ead04
|
@ -42,12 +42,17 @@ namespace OpenTK.Input
|
||||||
// then we'll need to increase these limits.
|
// then we'll need to increase these limits.
|
||||||
internal const int MaxAxes = (int)JoystickAxis.Last + 1;
|
internal const int MaxAxes = (int)JoystickAxis.Last + 1;
|
||||||
internal const int MaxButtons = (int)JoystickButton.Last + 1;
|
internal const int MaxButtons = (int)JoystickButton.Last + 1;
|
||||||
|
internal const int MaxHats = (int)JoystickHat.Last + 1;
|
||||||
|
|
||||||
const float ConversionFactor = 1.0f / (short.MaxValue + 0.5f);
|
const float ConversionFactor = 1.0f / (short.MaxValue + 0.5f);
|
||||||
|
|
||||||
unsafe fixed short axes[MaxAxes];
|
|
||||||
int buttons;
|
|
||||||
int packet_number;
|
int packet_number;
|
||||||
|
int buttons;
|
||||||
|
unsafe fixed short axes[MaxAxes];
|
||||||
|
JoystickHatState hat0;
|
||||||
|
JoystickHatState hat1;
|
||||||
|
JoystickHatState hat2;
|
||||||
|
JoystickHatState hat3;
|
||||||
bool is_connected;
|
bool is_connected;
|
||||||
|
|
||||||
#region Public Members
|
#region Public Members
|
||||||
|
@ -76,6 +81,28 @@ namespace OpenTK.Input
|
||||||
return (buttons & (1 << (int)button)) != 0 ? ButtonState.Pressed : ButtonState.Released;
|
return (buttons & (1 << (int)button)) != 0 ? ButtonState.Pressed : ButtonState.Released;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the hat.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The hat.</returns>
|
||||||
|
/// <param name="hat">Hat.</param>
|
||||||
|
public JoystickHatState GetHat(JoystickHat hat)
|
||||||
|
{
|
||||||
|
switch (hat)
|
||||||
|
{
|
||||||
|
case JoystickHat.Hat0:
|
||||||
|
return hat0;
|
||||||
|
case JoystickHat.Hat1:
|
||||||
|
return hat1;
|
||||||
|
case JoystickHat.Hat2:
|
||||||
|
return hat2;
|
||||||
|
case JoystickHat.Hat3:
|
||||||
|
return hat3;
|
||||||
|
default:
|
||||||
|
return new JoystickHatState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether the specified <see cref="JoystickButton"/> is currently pressed.
|
/// Gets a value indicating whether the specified <see cref="JoystickButton"/> is currently pressed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -198,6 +225,9 @@ namespace OpenTK.Input
|
||||||
internal void SetButton(JoystickButton button, bool value)
|
internal void SetButton(JoystickButton button, bool value)
|
||||||
{
|
{
|
||||||
int index = 1 << (int)button;
|
int index = 1 << (int)button;
|
||||||
|
if (index < 0 || index >= MaxButtons)
|
||||||
|
throw new ArgumentOutOfRangeException("button");
|
||||||
|
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
buttons |= index;
|
buttons |= index;
|
||||||
|
@ -208,6 +238,23 @@ namespace OpenTK.Input
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void SetHat(JoystickHat hat, JoystickHatState value)
|
||||||
|
{
|
||||||
|
switch (hat)
|
||||||
|
{
|
||||||
|
case JoystickHat.Hat0:
|
||||||
|
hat0 = value;
|
||||||
|
case JoystickHat.Hat1:
|
||||||
|
hat1 = value;
|
||||||
|
case JoystickHat.Hat2:
|
||||||
|
hat2 = value;
|
||||||
|
case JoystickHat.Hat3:
|
||||||
|
hat3 = value;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException("hat");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal void SetIsConnected(bool value)
|
internal void SetIsConnected(bool value)
|
||||||
{
|
{
|
||||||
is_connected = value;
|
is_connected = value;
|
||||||
|
|
Loading…
Reference in a new issue