diff --git a/Source/OpenTK/Input/JoystickState.cs b/Source/OpenTK/Input/JoystickState.cs
index aad66590..ef18267f 100644
--- a/Source/OpenTK/Input/JoystickState.cs
+++ b/Source/OpenTK/Input/JoystickState.cs
@@ -42,12 +42,17 @@ namespace OpenTK.Input
// then we'll need to increase these limits.
internal const int MaxAxes = (int)JoystickAxis.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);
- unsafe fixed short axes[MaxAxes];
- int buttons;
int packet_number;
+ int buttons;
+ unsafe fixed short axes[MaxAxes];
+ JoystickHatState hat0;
+ JoystickHatState hat1;
+ JoystickHatState hat2;
+ JoystickHatState hat3;
bool is_connected;
#region Public Members
@@ -76,6 +81,28 @@ namespace OpenTK.Input
return (buttons & (1 << (int)button)) != 0 ? ButtonState.Pressed : ButtonState.Released;
}
+ ///
+ /// Gets the hat.
+ ///
+ /// The hat.
+ /// Hat.
+ 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();
+ }
+ }
+
///
/// Gets a value indicating whether the specified is currently pressed.
///
@@ -198,6 +225,9 @@ namespace OpenTK.Input
internal void SetButton(JoystickButton button, bool value)
{
int index = 1 << (int)button;
+ if (index < 0 || index >= MaxButtons)
+ throw new ArgumentOutOfRangeException("button");
+
if (value)
{
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)
{
is_connected = value;