diff --git a/Source/OpenTK/Input/JoystickCapabilities.cs b/Source/OpenTK/Input/JoystickCapabilities.cs
index 3bfab7a1..1e5f88ab 100644
--- a/Source/OpenTK/Input/JoystickCapabilities.cs
+++ b/Source/OpenTK/Input/JoystickCapabilities.cs
@@ -40,21 +40,23 @@ namespace OpenTK.Input
{
byte axis_count;
byte button_count;
- byte dpad_count;
+ byte hat_count;
bool is_connected;
#region Constructors
- internal JoystickCapabilities(int axis_count, int button_count, bool is_connected)
+ internal JoystickCapabilities(int axis_count, int button_count, int hat_count, bool is_connected)
{
- if (axis_count < 0 || axis_count >= JoystickState.MaxAxes)
+ if (axis_count < 0 || axis_count > JoystickState.MaxAxes)
throw new ArgumentOutOfRangeException("axis_count");
- if (button_count < 0 || button_count >= JoystickState.MaxButtons)
+ if (button_count < 0 || button_count > JoystickState.MaxButtons)
throw new ArgumentOutOfRangeException("axis_count");
+ if (hat_count < 0 || hat_count > JoystickState.MaxHats)
+ throw new ArgumentOutOfRangeException("hat_count");
this.axis_count = (byte)axis_count;
this.button_count = (byte)button_count;
- this.dpad_count = 0; // Todo: either remove dpad_count or add it as a parameter
+ this.hat_count = (byte)hat_count;
this.is_connected = is_connected;
}
@@ -78,6 +80,14 @@ namespace OpenTK.Input
get { return button_count; }
}
+ ///
+ /// Gets the number of hats supported by this .
+ ///
+ public int HatCount
+ {
+ get { return hat_count; }
+ }
+
///
/// Gets a value indicating whether this is connected.
///
@@ -94,8 +104,8 @@ namespace OpenTK.Input
public override string ToString()
{
return String.Format(
- "{{Axes: {0}; Buttons: {1}; IsConnected: {2}}}",
- AxisCount, ButtonCount, IsConnected);
+ "{{Axes: {0}; Buttons: {1}; Hats: {2}; IsConnected: {2}}}",
+ AxisCount, ButtonCount, HatCount, IsConnected);
}
///
@@ -108,6 +118,7 @@ namespace OpenTK.Input
return
AxisCount.GetHashCode() ^
ButtonCount.GetHashCode() ^
+ HatCount.GetHashCode() ^
IsConnected.GetHashCode();
}
@@ -126,15 +137,6 @@ namespace OpenTK.Input
#endregion
- #region Private Members
-
- int DPadCount
- {
- get { return dpad_count; }
- }
-
- #endregion
-
#region IEquatable Members
///
@@ -148,6 +150,7 @@ namespace OpenTK.Input
return
AxisCount == other.AxisCount &&
ButtonCount == other.ButtonCount &&
+ HatCount == other.HatCount &&
IsConnected == other.IsConnected;
}
diff --git a/Source/OpenTK/Platform/MacOS/HIDInput.cs b/Source/OpenTK/Platform/MacOS/HIDInput.cs
index f54e97c4..1ff19830 100755
--- a/Source/OpenTK/Platform/MacOS/HIDInput.cs
+++ b/Source/OpenTK/Platform/MacOS/HIDInput.cs
@@ -441,7 +441,7 @@ namespace OpenTK.Platform.MacOS
joy = new JoystickData();
int axes = 0;
int buttons = 0;
- int dpads = 0;
+ int hats = 0;
CFStringRef name_ref = NativeMethods.IOHIDDeviceGetProperty(device, NativeMethods.IOHIDProductKey);
string name = CF.CFStringGetCString(name_ref);
@@ -475,7 +475,7 @@ namespace OpenTK.Platform.MacOS
break;
case HIDUsageGD.Hatswitch:
- dpads++;
+ hats++;
break;
}
break;
@@ -499,7 +499,7 @@ namespace OpenTK.Platform.MacOS
joy.Name = name;
joy.Guid = guid;
joy.State.SetIsConnected(true);
- joy.Capabilities = new JoystickCapabilities(axes, buttons, true);
+ joy.Capabilities = new JoystickCapabilities(axes, buttons, hats, true);
// Map button elements to JoystickButtons
for (int button = 0; button < button_elements.Count; button++)
diff --git a/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs b/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs
index f097b000..71ab3eea 100644
--- a/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs
+++ b/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs
@@ -656,6 +656,7 @@ namespace OpenTK.Platform.SDL2
return new JoystickCapabilities(
joystick.Axis.Count,
joystick.Button.Count,
+ joystick.Details.HatCount,
joystick.Details.IsConnected);
}
return new JoystickCapabilities();
diff --git a/Source/OpenTK/Platform/Windows/WinMMJoystick.cs b/Source/OpenTK/Platform/Windows/WinMMJoystick.cs
index 313abdd9..b5e73dca 100644
--- a/Source/OpenTK/Platform/Windows/WinMMJoystick.cs
+++ b/Source/OpenTK/Platform/Windows/WinMMJoystick.cs
@@ -269,7 +269,10 @@ namespace OpenTK.Platform.Windows
if (result == JoystickError.NoError)
{
JoystickCapabilities caps = new JoystickCapabilities(
- mmcaps.NumAxes, mmcaps.NumButtons, true);
+ mmcaps.NumAxes,
+ mmcaps.NumButtons,
+ (mmcaps.Capabilities & JoystCapsFlags.HasPov) != 0 ? 1 : 0,
+ true);
//if ((caps.Capabilities & JoystCapsFlags.HasPov) != 0)
// gpcaps.DPadCount++;
return caps;
diff --git a/Source/OpenTK/Platform/X11/X11Joystick.cs b/Source/OpenTK/Platform/X11/X11Joystick.cs
index 5aaf60d3..8fb7178b 100644
--- a/Source/OpenTK/Platform/X11/X11Joystick.cs
+++ b/Source/OpenTK/Platform/X11/X11Joystick.cs
@@ -484,7 +484,10 @@ namespace OpenTK.Platform.X11
{
JoystickDevice js = sticks[index_to_stick[index]];
caps = new JoystickCapabilities(
- js.Axis.Count, js.Button.Count, js.Details.State.IsConnected);
+ js.Axis.Count,
+ js.Button.Count,
+ 0, // hats not supported by /dev/js
+ js.Details.State.IsConnected);
}
return caps;
}