From 20ecd2232db5e5f1ed73dc23a86cd69fd6b74edb Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Thu, 28 Oct 2010 08:41:48 +0000 Subject: [PATCH] Implemented equality operators. --- Source/OpenTK/Input/KeyboardState.cs | 75 ++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/Source/OpenTK/Input/KeyboardState.cs b/Source/OpenTK/Input/KeyboardState.cs index 612dc963..99dea373 100644 --- a/Source/OpenTK/Input/KeyboardState.cs +++ b/Source/OpenTK/Input/KeyboardState.cs @@ -84,6 +84,81 @@ namespace OpenTK.Input return !ReadBit((int)key); } + /// + /// Checks whether two instances are equal. + /// + /// + /// A instance. + /// + /// + /// A instance. + /// + /// + /// True if both left is equal to right; false otherwise. + /// + public static bool operator ==(KeyboardState left, KeyboardState right) + { + return left.Equals(right); + } + + /// + /// Checks whether two instances are not equal. + /// + /// + /// A instance. + /// + /// + /// A instance. + /// + /// + /// True if both left is not equal to right; false otherwise. + /// + public static bool operator !=(KeyboardState left, KeyboardState right) + { + return !left.Equals(right); + } + + /// + /// Compares to an object instance for equality. + /// + /// + /// The to compare to. + /// + /// + /// True if this instance is equal to obj; false otherwise. + /// + public override bool Equals(object obj) + { + if (obj is KeyboardState) + { + return this == (KeyboardState)obj; + } + else + { + return false; + } + } + + /// + /// Generates a hashcode for the current instance. + /// + /// + /// A represting the hashcode for this instance. + /// + public override int GetHashCode() + { + unsafe + { + fixed (int* k = Keys) + { + int hashcode = 0; + for (int i = 0; i < NumInts; i++) + hashcode ^= (k + i)->GetHashCode(); + return hashcode; + } + } + } + #endregion #region Internal Members