mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-24 16:35:36 +00:00
Implemented IEquatable<> interface
This commit is contained in:
parent
7692243cd2
commit
cbc39f922d
|
@ -107,9 +107,37 @@ namespace OpenTK.Input
|
||||||
return !left.Equals(right);
|
return !left.Equals(right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return String.Format(
|
||||||
|
"{{ABXYLR: {0}{1}{2}{3}{4}{5}; Back: {6}; BigButton: {7}; LStick: {8}; RStick: {9}}}",
|
||||||
|
A == ButtonState.Pressed ? "1" : "0",
|
||||||
|
B == ButtonState.Pressed ? "1" : "0",
|
||||||
|
X == ButtonState.Pressed ? "1" : "0",
|
||||||
|
Y == ButtonState.Pressed ? "1" : "0",
|
||||||
|
LeftShoulder == ButtonState.Pressed ? "1" : "0",
|
||||||
|
RightShoulder == ButtonState.Pressed ? "1" : "0",
|
||||||
|
Back == ButtonState.Pressed ? "1" : "0",
|
||||||
|
BigButton == ButtonState.Pressed ? "1" : "0",
|
||||||
|
LeftStick == ButtonState.Pressed ? "1" : "0",
|
||||||
|
RightStick == ButtonState.Pressed ? "1" : "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return buttons.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
obj is GamePadButtons &&
|
||||||
|
Equals((GamePadButtons)obj);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region IEquatable Members
|
#region IEquatable<GamePadButtons> Members
|
||||||
|
|
||||||
public bool Equals(GamePadButtons other)
|
public bool Equals(GamePadButtons other)
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,7 +32,7 @@ using System;
|
||||||
namespace OpenTK.Input
|
namespace OpenTK.Input
|
||||||
{
|
{
|
||||||
|
|
||||||
public struct GamePadCapabilities
|
public struct GamePadCapabilities : IEquatable<GamePadCapabilities>
|
||||||
{
|
{
|
||||||
byte axis_count;
|
byte axis_count;
|
||||||
byte button_count;
|
byte button_count;
|
||||||
|
@ -62,6 +62,50 @@ namespace OpenTK.Input
|
||||||
get { return trackball_count; }
|
get { return trackball_count; }
|
||||||
internal set { trackball_count = (byte)value; }
|
internal set { trackball_count = (byte)value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(GamePadCapabilities left, GamePadCapabilities right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(GamePadCapabilities left, GamePadCapabilities right)
|
||||||
|
{
|
||||||
|
return !left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return String.Format(
|
||||||
|
"{{Axes: {0}; Buttons: {1}; DPads: {2}; Trackballs: {3}}}",
|
||||||
|
AxisCount, ButtonCount, DPadCount, TrackballCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return
|
||||||
|
AxisCount.GetHashCode() ^ ButtonCount.GetHashCode() ^
|
||||||
|
DPadCount.GetHashCode() ^ TrackballCount.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
obj is GamePadCapabilities &&
|
||||||
|
Equals((GamePadCapabilities)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IEquatable<GamePadCapabilities> Members
|
||||||
|
|
||||||
|
public bool Equals(GamePadCapabilities other)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
AxisCount == other.AxisCount &&
|
||||||
|
ButtonCount == other.ButtonCount &&
|
||||||
|
DPadCount == other.DPadCount &&
|
||||||
|
TrackballCount == other.TrackballCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ using System;
|
||||||
namespace OpenTK.Input
|
namespace OpenTK.Input
|
||||||
{
|
{
|
||||||
|
|
||||||
public struct GamePadDPad
|
public struct GamePadDPad : IEquatable<GamePadDPad>
|
||||||
{
|
{
|
||||||
[Flags]
|
[Flags]
|
||||||
enum DPadButtons : byte
|
enum DPadButtons : byte
|
||||||
|
@ -44,6 +44,8 @@ namespace OpenTK.Input
|
||||||
|
|
||||||
DPadButtons buttons;
|
DPadButtons buttons;
|
||||||
|
|
||||||
|
#region Public Members
|
||||||
|
|
||||||
internal GamePadDPad(Buttons state)
|
internal GamePadDPad(Buttons state)
|
||||||
{
|
{
|
||||||
// DPad butons are stored in the lower 4bits
|
// DPad butons are stored in the lower 4bits
|
||||||
|
@ -75,6 +77,42 @@ namespace OpenTK.Input
|
||||||
internal set { SetButton(DPadButtons.Right, value); }
|
internal set { SetButton(DPadButtons.Right, value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(GamePadDPad left, GamePadDPad right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(GamePadDPad left, GamePadDPad right)
|
||||||
|
{
|
||||||
|
return !left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return String.Format(
|
||||||
|
"{{ULDR: {0}{1}{2}{3}}}",
|
||||||
|
IsUp ? "1" : "0",
|
||||||
|
IsLeft ? "1" : "0",
|
||||||
|
IsDown ? "1" : "0",
|
||||||
|
IsRight ? "1" : "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return buttons.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
obj is GamePadDPad &&
|
||||||
|
Equals((GamePadDPad)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private Members
|
||||||
|
|
||||||
void SetButton(DPadButtons button, bool value)
|
void SetButton(DPadButtons button, bool value)
|
||||||
{
|
{
|
||||||
if (value)
|
if (value)
|
||||||
|
@ -86,5 +124,16 @@ namespace OpenTK.Input
|
||||||
buttons &= ~button;
|
buttons &= ~button;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IEquatable<GamePadDPad> Members
|
||||||
|
|
||||||
|
public bool Equals(GamePadDPad other)
|
||||||
|
{
|
||||||
|
return buttons == other.buttons;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace OpenTK.Input
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Encapsulates the state of a GamePad device.
|
/// Encapsulates the state of a GamePad device.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public struct GamePadState /*: IEquatable<GamePadState>*/
|
public struct GamePadState : IEquatable<GamePadState>
|
||||||
{
|
{
|
||||||
const float RangeMultiplier = 1.0f / (short.MaxValue + 1);
|
const float RangeMultiplier = 1.0f / (short.MaxValue + 1);
|
||||||
|
|
||||||
|
@ -62,6 +62,36 @@ namespace OpenTK.Input
|
||||||
get { return is_connected; }
|
get { return is_connected; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return String.Format(
|
||||||
|
"{{Buttons: {0}; DPad: {1}; IsConnected: {2}",
|
||||||
|
Buttons, DPad, IsConnected);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Buttons.GetHashCode() ^ DPad.GetHashCode() ^ IsConnected.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
obj is GamePadState &&
|
||||||
|
Equals((GamePadState)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IEquatable<GamePadState> Members
|
||||||
|
public bool Equals(GamePadState other)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
Buttons == other.Buttons &&
|
||||||
|
DPad == other.DPad &&
|
||||||
|
IsConnected == other.IsConnected;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Internal Members
|
#region Internal Members
|
||||||
|
|
Loading…
Reference in a new issue