From f7f7dd4d315aa066abe46f791692659911f4efb1 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Wed, 26 Sep 2007 11:30:18 +0000 Subject: [PATCH] Renamed Keyboard and Mouse to KeyboardDevice and MouseDevice respectively, to avoid name classes. --- .../Input/{Keyboard.cs => KeyboardDevice.cs} | 41 ++++-- .../OpenTK/Input/{Mouse.cs => MouseDevice.cs} | 120 +++++++++++++----- 2 files changed, 116 insertions(+), 45 deletions(-) rename Source/OpenTK/Input/{Keyboard.cs => KeyboardDevice.cs} (75%) rename Source/OpenTK/Input/{Mouse.cs => MouseDevice.cs} (57%) diff --git a/Source/OpenTK/Input/Keyboard.cs b/Source/OpenTK/Input/KeyboardDevice.cs similarity index 75% rename from Source/OpenTK/Input/Keyboard.cs rename to Source/OpenTK/Input/KeyboardDevice.cs index 6c1b96d6..551acbee 100644 --- a/Source/OpenTK/Input/Keyboard.cs +++ b/Source/OpenTK/Input/KeyboardDevice.cs @@ -15,7 +15,7 @@ using System.Diagnostics; namespace OpenTK.Input { - public sealed class Keyboard : IKeyboard + public sealed class KeyboardDevice : IInputDevice { //private IKeyboard keyboard; private bool[] keys = new bool[(int)Key.MaxKeys]; @@ -26,7 +26,7 @@ namespace OpenTK.Input #region --- Constructors --- - public Keyboard() + public KeyboardDevice() { } @@ -34,39 +34,53 @@ namespace OpenTK.Input #region --- IKeyboard members --- - public bool this[Key k] + /// + /// Gets a value indicating the status of the specified Key. + /// + /// The Key to check. + /// True if the Key is pressed, false otherwise. + public bool this[Key key] { - get { return keys[(int)k]; } + get { return keys[(int)key]; } internal set { - if (keys[(int)k] != value || KeyRepeat) + if (keys[(int)key] != value || KeyRepeat) { - keys[(int)k] = value; + keys[(int)key] = value; if (value && KeyDown != null) { - KeyDown(this, k); + KeyDown(this, key); } else if (!value && KeyUp != null) { - KeyUp(this, k); + KeyUp(this, key); } } } } + /// + /// Gets an integer representing the number of keys on this KeyboardDevice. + /// public int NumberOfKeys { get { return numKeys; } internal set { numKeys = value; } } + /// + /// Gets an integer representing the number of function keys (F-keys) on this KeyboardDevice. + /// public int NumberOfFunctionKeys { get { return numFKeys; } internal set { numFKeys = value; } } + /// + /// Gets a value indicating the number of led indicators on this KeyboardDevice. + /// public int NumberOfLeds { get { return numLeds; } @@ -74,7 +88,7 @@ namespace OpenTK.Input } /// - /// Device dependent ID. + /// Gets an IntPtr representing a device dependent ID. /// public IntPtr DeviceID { @@ -85,7 +99,7 @@ namespace OpenTK.Input #region public bool KeyRepeat /// - /// Gets or sets a value indicating whether key repeat is turned on or off. + /// Gets or sets a value indicating whether key repeat status. /// /// /// Setting key repeat to on will generate multiple KeyDown events when a key is held pressed. @@ -137,13 +151,16 @@ namespace OpenTK.Input public override string ToString() { //return base.ToString(); - return String.Format("ID: {0} (keys: {1}, function keys: {2}, leds: {3})", - DeviceID, NumberOfKeys, NumberOfFunctionKeys, NumberOfLeds); + return String.Format("ID: {0} ({1}). Keys: {2}, Function keys: {3}, Leds: {4}", + DeviceID, Description, NumberOfKeys, NumberOfFunctionKeys, NumberOfLeds); } #endregion } + public delegate void KeyDownEvent(KeyboardDevice sender, Key key); + public delegate void KeyUpEvent(KeyboardDevice sender, Key key); + #region public enum Key : int /// diff --git a/Source/OpenTK/Input/Mouse.cs b/Source/OpenTK/Input/MouseDevice.cs similarity index 57% rename from Source/OpenTK/Input/Mouse.cs rename to Source/OpenTK/Input/MouseDevice.cs index c6147d51..3594fcdf 100644 --- a/Source/OpenTK/Input/Mouse.cs +++ b/Source/OpenTK/Input/MouseDevice.cs @@ -10,7 +10,10 @@ using System.Text; namespace OpenTK.Input { - public sealed class Mouse : IMouse + /// + /// The MouseDevice class represents a mouse device and provides methods to query its status. + /// + public sealed class MouseDevice : IInputDevice { private string description; private int numButtons, numWheels; @@ -20,12 +23,18 @@ namespace OpenTK.Input #region --- IInputDevice Members --- + /// + /// Gets a string describing this MouseDevice. + /// public string Description { get { return description; } internal set { description = value; } } + /// + /// Gets an value indicating the InputDeviceType of this InputDevice. + /// public InputDeviceType DeviceType { get { return InputDeviceType.Mouse; } @@ -35,24 +44,36 @@ namespace OpenTK.Input #region --- IMouse Members --- + /// + /// Gets an integer representing the number of buttons on this MouseDevice. + /// public int NumberOfButtons { get { return numButtons; } internal set { numButtons = value; } } + /// + /// Gets an integer representing the number of wheels on this MouseDevice. + /// public int NumberOfWheels { get { return numWheels; } internal set { numWheels = value; } } + /// + /// Gets an IntPtr representing a device dependent ID. + /// public IntPtr DeviceID { get { return id; } internal set { id = value; } } + /// + /// Gets an integer representing the absolute wheel position. + /// public int Wheel { get { return wheel; } @@ -62,7 +83,10 @@ namespace OpenTK.Input } } - internal int WheelDelta + /// + /// Gets an integer representing the relative wheel movement. + /// + public int WheelDelta { get { @@ -76,32 +100,52 @@ namespace OpenTK.Input } } + /// + /// Gets an integer representing the absolute x position of the pointer, in screen pixel coordinates. + /// public int X { get { return x; } internal set { x = value; } } + /// + /// Gets an integer representing the absolute y position of the pointer, in screen pixel coordinates. + /// public int Y { get { return y; } internal set { y = value; } } + /// + /// Gets an integer representing the relative x movement of the pointer, in pixel coordinates. + /// public int XDelta { get { return delta_x; } internal set { delta_x = value; } } + /// + /// Gets an integer representing the relative y movement of the pointer, in pixel coordinates. + /// public int YDelta { get { return delta_y; } internal set { delta_y = value; } } - public event MouseMoveEvent Move; + //public event MouseMoveEvent Move; + + /// + /// Occurs when a button is pressed. + /// public event MouseButtonDownEvent ButtonDown; + + /// + /// Occurs when a button is released. + /// public event MouseButtonUpEvent ButtonUp; #endregion @@ -121,8 +165,8 @@ namespace OpenTK.Input ButtonUp(this, b); } button[(int)b] = value; + //System.Diagnostics.Debug.Print("Mouse button {0} {1}", b, value ? "down" : "up"); } - get { return button[(int)b]; @@ -130,8 +174,33 @@ namespace OpenTK.Input } #endregion + + #region --- Public Methods --- + + public override int GetHashCode() + { + //return base.GetHashCode(); + return (int)(numButtons ^ numWheels ^ id.GetHashCode() ^ description.GetHashCode()); + } + + public override string ToString() + { + return String.Format("ID: {0} ({1}). Buttons: {2}, Wheels: {3}", + DeviceID, Description, NumberOfButtons, NumberOfWheels); + } + + #endregion } + //public delegate void MouseMoveEvent(MouseDevice sender, MouseMoveData key); + public delegate void MouseButtonDownEvent(MouseDevice sender, MouseButton button); + public delegate void MouseButtonUpEvent(MouseDevice sender, MouseButton button); + + #region public enum MouseButton + + /// + /// Enumerates all possible mouse buttons. + /// public enum MouseButton { Left = 0, @@ -149,37 +218,20 @@ namespace OpenTK.Input LastButton } - public class MouseWheel - { - private int position; - private int delta; + #endregion - /// - /// Gets the absolute position of the mouse wheel. - /// - public int Position - { - get { return position; } - internal set { position = value; } - } + #region internal class MouseMoveData - /// - /// Gets the relative movement of the mouse wheel. - /// - public int Delta - { - get { return delta; } - internal set { delta = value; } - } - } - - public class MouseMoveData + /// + /// Not used yet. + /// + internal class MouseMoveData { private int x; private int y; private int deltaX; private int deltaY; - private MouseWheel wheel; + private int wheel, deltaWheel; /// /// Gets the absolute X position of the mouse in screen pixel coordinates. @@ -220,10 +272,12 @@ namespace OpenTK.Input /// /// Gets data relevant to the mouse wheel. /// - public MouseWheel Wheel - { - get { return wheel; } - internal set { wheel = value; } - } + //public MouseWheel Wheel + //{ + // get { return wheel; } + // internal set { wheel = value; } + //} } + + #endregion }