mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-09 00:15:32 +00:00
[Input] Added JoystickCapabilities.HatCount
This commit is contained in:
parent
168c45f0e2
commit
a7228274aa
|
@ -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; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of hats supported by this <see cref="JoystickDevice"/>.
|
||||
/// </summary>
|
||||
public int HatCount
|
||||
{
|
||||
get { return hat_count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this <see cref="JoystickDevice"/> is connected.
|
||||
/// </summary>
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -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<JoystickCapabilities> Members
|
||||
|
||||
/// <summary>
|
||||
|
@ -148,6 +150,7 @@ namespace OpenTK.Input
|
|||
return
|
||||
AxisCount == other.AxisCount &&
|
||||
ButtonCount == other.ButtonCount &&
|
||||
HatCount == other.HatCount &&
|
||||
IsConnected == other.IsConnected;
|
||||
}
|
||||
|
||||
|
|
|
@ -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++)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -484,7 +484,10 @@ namespace OpenTK.Platform.X11
|
|||
{
|
||||
JoystickDevice<X11JoyDetails> 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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue