mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-09-19 07:37:11 +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 axis_count;
|
||||||
byte button_count;
|
byte button_count;
|
||||||
byte dpad_count;
|
byte hat_count;
|
||||||
bool is_connected;
|
bool is_connected;
|
||||||
|
|
||||||
#region Constructors
|
#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");
|
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");
|
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.axis_count = (byte)axis_count;
|
||||||
this.button_count = (byte)button_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;
|
this.is_connected = is_connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,6 +80,14 @@ namespace OpenTK.Input
|
||||||
get { return button_count; }
|
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>
|
/// <summary>
|
||||||
/// Gets a value indicating whether this <see cref="JoystickDevice"/> is connected.
|
/// Gets a value indicating whether this <see cref="JoystickDevice"/> is connected.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -94,8 +104,8 @@ namespace OpenTK.Input
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return String.Format(
|
return String.Format(
|
||||||
"{{Axes: {0}; Buttons: {1}; IsConnected: {2}}}",
|
"{{Axes: {0}; Buttons: {1}; Hats: {2}; IsConnected: {2}}}",
|
||||||
AxisCount, ButtonCount, IsConnected);
|
AxisCount, ButtonCount, HatCount, IsConnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -108,6 +118,7 @@ namespace OpenTK.Input
|
||||||
return
|
return
|
||||||
AxisCount.GetHashCode() ^
|
AxisCount.GetHashCode() ^
|
||||||
ButtonCount.GetHashCode() ^
|
ButtonCount.GetHashCode() ^
|
||||||
|
HatCount.GetHashCode() ^
|
||||||
IsConnected.GetHashCode();
|
IsConnected.GetHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,15 +137,6 @@ namespace OpenTK.Input
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Members
|
|
||||||
|
|
||||||
int DPadCount
|
|
||||||
{
|
|
||||||
get { return dpad_count; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IEquatable<JoystickCapabilities> Members
|
#region IEquatable<JoystickCapabilities> Members
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -148,6 +150,7 @@ namespace OpenTK.Input
|
||||||
return
|
return
|
||||||
AxisCount == other.AxisCount &&
|
AxisCount == other.AxisCount &&
|
||||||
ButtonCount == other.ButtonCount &&
|
ButtonCount == other.ButtonCount &&
|
||||||
|
HatCount == other.HatCount &&
|
||||||
IsConnected == other.IsConnected;
|
IsConnected == other.IsConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -441,7 +441,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
joy = new JoystickData();
|
joy = new JoystickData();
|
||||||
int axes = 0;
|
int axes = 0;
|
||||||
int buttons = 0;
|
int buttons = 0;
|
||||||
int dpads = 0;
|
int hats = 0;
|
||||||
|
|
||||||
CFStringRef name_ref = NativeMethods.IOHIDDeviceGetProperty(device, NativeMethods.IOHIDProductKey);
|
CFStringRef name_ref = NativeMethods.IOHIDDeviceGetProperty(device, NativeMethods.IOHIDProductKey);
|
||||||
string name = CF.CFStringGetCString(name_ref);
|
string name = CF.CFStringGetCString(name_ref);
|
||||||
|
@ -475,7 +475,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HIDUsageGD.Hatswitch:
|
case HIDUsageGD.Hatswitch:
|
||||||
dpads++;
|
hats++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -499,7 +499,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
joy.Name = name;
|
joy.Name = name;
|
||||||
joy.Guid = guid;
|
joy.Guid = guid;
|
||||||
joy.State.SetIsConnected(true);
|
joy.State.SetIsConnected(true);
|
||||||
joy.Capabilities = new JoystickCapabilities(axes, buttons, true);
|
joy.Capabilities = new JoystickCapabilities(axes, buttons, hats, true);
|
||||||
|
|
||||||
// Map button elements to JoystickButtons
|
// Map button elements to JoystickButtons
|
||||||
for (int button = 0; button < button_elements.Count; button++)
|
for (int button = 0; button < button_elements.Count; button++)
|
||||||
|
|
|
@ -656,6 +656,7 @@ namespace OpenTK.Platform.SDL2
|
||||||
return new JoystickCapabilities(
|
return new JoystickCapabilities(
|
||||||
joystick.Axis.Count,
|
joystick.Axis.Count,
|
||||||
joystick.Button.Count,
|
joystick.Button.Count,
|
||||||
|
joystick.Details.HatCount,
|
||||||
joystick.Details.IsConnected);
|
joystick.Details.IsConnected);
|
||||||
}
|
}
|
||||||
return new JoystickCapabilities();
|
return new JoystickCapabilities();
|
||||||
|
|
|
@ -269,7 +269,10 @@ namespace OpenTK.Platform.Windows
|
||||||
if (result == JoystickError.NoError)
|
if (result == JoystickError.NoError)
|
||||||
{
|
{
|
||||||
JoystickCapabilities caps = new JoystickCapabilities(
|
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)
|
//if ((caps.Capabilities & JoystCapsFlags.HasPov) != 0)
|
||||||
// gpcaps.DPadCount++;
|
// gpcaps.DPadCount++;
|
||||||
return caps;
|
return caps;
|
||||||
|
|
|
@ -484,7 +484,10 @@ namespace OpenTK.Platform.X11
|
||||||
{
|
{
|
||||||
JoystickDevice<X11JoyDetails> js = sticks[index_to_stick[index]];
|
JoystickDevice<X11JoyDetails> js = sticks[index_to_stick[index]];
|
||||||
caps = new JoystickCapabilities(
|
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;
|
return caps;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue