diff --git a/Source/OpenTK/Input/JoystickHatState.cs b/Source/OpenTK/Input/JoystickHatState.cs index 4e92dedb..63a3a943 100644 --- a/Source/OpenTK/Input/JoystickHatState.cs +++ b/Source/OpenTK/Input/JoystickHatState.cs @@ -34,7 +34,7 @@ namespace OpenTK.Input /// /// Describes the state of a joystick hat. /// - public struct JoystickHatState + public struct JoystickHatState : IEquatable { HatPosition position; @@ -113,6 +113,58 @@ namespace OpenTK.Input Position == HatPosition.DownRight; } } + + /// + /// Returns a that represents the current . + /// + /// A that represents the current . + public override string ToString() + { + return String.Format( + "{{{0}{1}{2}{3}}}", + IsUp ? "U" : String.Empty, + IsLeft ? "L" : String.Empty, + IsDown ? "D" : String.Empty, + IsRight ? "R" : String.Empty); + } + + /// + /// Serves as a hash function for a object. + /// + /// A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a + /// hash table. + public override int GetHashCode() + { + return Position.GetHashCode(); + } + + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare with the current . + /// true if the specified is equal to the current + /// ; otherwise, false. + public override bool Equals(object obj) + { + return + obj is JoystickHatState && + Equals((JoystickHatState)obj); + } + + #region IEquatable implementation + + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare with the current . + /// true if the specified is equal to the current + /// ; otherwise, false. + public bool Equals(JoystickHatState other) + { + return Position == other.Position; + } + + #endregion } }