From 12814a308b5cb7d1f383c9bd72a96d5f5cc6f8c6 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 16 Aug 2015 11:41:01 +1000 Subject: [PATCH] Simplify event classes, combine various input interfaces into one interfaces file. --- OpenTK/Input/IInputDevice.cs | 48 ----- OpenTK/Input/IInputDriver.cs | 23 --- OpenTK/Input/IJoystickDriver.cs | 44 ---- OpenTK/Input/IKeyboardDriver.cs | 23 --- OpenTK/Input/IMouseDriver.cs | 26 --- OpenTK/Input/Interfaces.cs | 63 ++++++ OpenTK/Input/KeyboardDevice.cs | 13 +- OpenTK/Input/KeyboardKeyEventArgs.cs | 83 -------- OpenTK/Input/MouseButton.cs | 65 ++---- OpenTK/Input/MouseDevice.cs | 295 +++------------------------ OpenTK/OpenTK.csproj | 7 +- 11 files changed, 114 insertions(+), 576 deletions(-) delete mode 100644 OpenTK/Input/IInputDevice.cs delete mode 100644 OpenTK/Input/IInputDriver.cs delete mode 100644 OpenTK/Input/IJoystickDriver.cs delete mode 100644 OpenTK/Input/IKeyboardDriver.cs delete mode 100644 OpenTK/Input/IMouseDriver.cs create mode 100644 OpenTK/Input/Interfaces.cs delete mode 100644 OpenTK/Input/KeyboardKeyEventArgs.cs diff --git a/OpenTK/Input/IInputDevice.cs b/OpenTK/Input/IInputDevice.cs deleted file mode 100644 index 9d03fb668..000000000 --- a/OpenTK/Input/IInputDevice.cs +++ /dev/null @@ -1,48 +0,0 @@ -#region --- License --- -/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos - * See license.txt for license info - */ -#endregion - -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenTK.Input -{ - /// - /// Defines a common interface for all input devices. - /// - public interface IInputDevice - { - /// - /// Gets a System.String with a unique description of this IInputDevice instance. - /// - string Description { get; } - - /// - /// Gets an OpenTK.Input.InputDeviceType value, representing the device type of this IInputDevice instance. - /// - InputDeviceType DeviceType { get; } - } - - /// - /// The type of the input device. - /// - public enum InputDeviceType - { - /// - /// Device is a keyboard. - /// - Keyboard, - /// - /// Device is a mouse. - /// - Mouse, - /// - /// Device is a Human Interface Device. Joysticks, joypads, pens - /// and some specific usb keyboards/mice fall into this category. - /// - Hid - } -} diff --git a/OpenTK/Input/IInputDriver.cs b/OpenTK/Input/IInputDriver.cs deleted file mode 100644 index a3d850461..000000000 --- a/OpenTK/Input/IInputDriver.cs +++ /dev/null @@ -1,23 +0,0 @@ -#region --- License --- -/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos - * See license.txt for license info - */ -#endregion - -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenTK.Input -{ - /// - /// Defines the interface for an input driver. - /// - public interface IInputDriver : IKeyboardDriver, IMouseDriver, IJoystickDriver, IDisposable - { - /// - /// Updates the state of the driver. - /// - void Poll(); - } -} diff --git a/OpenTK/Input/IJoystickDriver.cs b/OpenTK/Input/IJoystickDriver.cs deleted file mode 100644 index ecc6bbcd3..000000000 --- a/OpenTK/Input/IJoystickDriver.cs +++ /dev/null @@ -1,44 +0,0 @@ -#region License -// -// The Open Toolkit Library License -// -// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do -// so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -#endregion - -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenTK.Input -{ - /// - /// Defines the interface for JoystickDevice drivers. - /// - public interface IJoystickDriver - { - /// - /// Gets the list of available JoystickDevices. - /// - IList Joysticks { get; } - } -} diff --git a/OpenTK/Input/IKeyboardDriver.cs b/OpenTK/Input/IKeyboardDriver.cs deleted file mode 100644 index 0e26a6841..000000000 --- a/OpenTK/Input/IKeyboardDriver.cs +++ /dev/null @@ -1,23 +0,0 @@ -#region --- License --- -/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos - * See license.txt for license info - */ -#endregion - -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenTK.Input -{ - /// - /// Defines the interface for KeyboardDevice drivers. - /// - public interface IKeyboardDriver - { - /// - /// Gets the list of available KeyboardDevices. - /// - IList Keyboard { get; } - } -} diff --git a/OpenTK/Input/IMouseDriver.cs b/OpenTK/Input/IMouseDriver.cs deleted file mode 100644 index f71ca689b..000000000 --- a/OpenTK/Input/IMouseDriver.cs +++ /dev/null @@ -1,26 +0,0 @@ -#region --- License --- -/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos - * See license.txt for license info - */ -#endregion - -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Text; - -namespace OpenTK.Input -{ - /// - /// Defines the interface for MouseDevice drivers. - /// - public interface IMouseDriver - { - /// - /// Gets the list of available MouseDevices. - /// - IList Mouse { get; } - - Point DesktopCursorPos { get; set; } - } -} diff --git a/OpenTK/Input/Interfaces.cs b/OpenTK/Input/Interfaces.cs new file mode 100644 index 000000000..b43d09940 --- /dev/null +++ b/OpenTK/Input/Interfaces.cs @@ -0,0 +1,63 @@ +#region --- License --- +/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos + * See license.txt for license info + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Drawing; + +namespace OpenTK.Input { + + /// Defines a common interface for all input devices. + public interface IInputDevice { + + /// Gets a System.String with a unique description of this IInputDevice instance. + string Description { get; } + + /// Gets an OpenTK.Input.InputDeviceType value, representing the device type of this IInputDevice instance. + InputDeviceType DeviceType { get; } + } + + /// The type of the input device. + public enum InputDeviceType { + /// Device is a keyboard. + Keyboard, + /// Device is a mouse. + Mouse, + /// Device is a Human Interface Device. Joysticks, joypads, pens + /// and some specific usb keyboards/mice fall into this category. + Hid + } + + /// Defines the interface for an input driver. + public interface IInputDriver : IKeyboardDriver, IMouseDriver, IJoystickDriver, IDisposable { + + /// Updates the state of the driver. + void Poll(); + } + + /// Defines the interface for JoystickDevice drivers. + public interface IJoystickDriver { + + /// Gets the list of available JoystickDevices. + IList Joysticks { get; } + } + + /// Defines the interface for KeyboardDevice drivers. + public interface IKeyboardDriver { + + /// Gets the list of available KeyboardDevices. + IList Keyboard { get; } + } + + /// Defines the interface for MouseDevice drivers. + public interface IMouseDriver { + + /// Gets the list of available MouseDevices. + IList Mouse { get; } + + Point DesktopCursorPos { get; set; } + } +} diff --git a/OpenTK/Input/KeyboardDevice.cs b/OpenTK/Input/KeyboardDevice.cs index 34cd622a2..e7e54c79e 100644 --- a/OpenTK/Input/KeyboardDevice.cs +++ b/OpenTK/Input/KeyboardDevice.cs @@ -4,15 +4,8 @@ */ #endregion -#region --- Using directives --- - using System; -using OpenTK.Input; -using System.Diagnostics; - -#endregion - namespace OpenTK.Input { /// @@ -205,4 +198,10 @@ namespace OpenTK.Input #endregion } + + public class KeyboardKeyEventArgs : EventArgs { + + /// Gets the that generated this event. + public Key Key; + } } \ No newline at end of file diff --git a/OpenTK/Input/KeyboardKeyEventArgs.cs b/OpenTK/Input/KeyboardKeyEventArgs.cs deleted file mode 100644 index ac3ce8afc..000000000 --- a/OpenTK/Input/KeyboardKeyEventArgs.cs +++ /dev/null @@ -1,83 +0,0 @@ -#region License -// -// The Open Toolkit Library License -// -// Copyright (c) 2006 - 2009 the Open Toolkit library. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do -// so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -#endregion - -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenTK.Input -{ - /// - /// Defines the event data for events. - /// - /// - /// - /// Do not cache instances of this type outside their event handler. - /// If necessary, you can clone a KeyboardEventArgs instance using the - /// constructor. - /// - /// - public class KeyboardKeyEventArgs : EventArgs - { - #region Fields - - Key key; - - #endregion - - #region Constructors - - /// - /// Constructs a new KeyboardEventArgs instance. - /// - public KeyboardKeyEventArgs() { } - - /// - /// Constructs a new KeyboardEventArgs instance. - /// - /// An existing KeyboardEventArgs instance to clone. - public KeyboardKeyEventArgs(KeyboardKeyEventArgs args) - { - Key = args.Key; - } - - #endregion - - #region Public Members - - /// - /// Gets the that generated this event. - /// - public Key Key - { - get { return key; } - internal set { key = value; } - } - - #endregion - } -} diff --git a/OpenTK/Input/MouseButton.cs b/OpenTK/Input/MouseButton.cs index 98a3bb0c9..cdf984d25 100644 --- a/OpenTK/Input/MouseButton.cs +++ b/OpenTK/Input/MouseButton.cs @@ -26,67 +26,36 @@ #endregion using System; -using System.Collections.Generic; -using System.Text; -namespace OpenTK.Input -{ - /// - /// Enumerates all possible mouse buttons. - /// - public enum MouseButton - { - /// - /// The left mouse button. - /// +namespace OpenTK.Input { + + /// Enumerates all possible mouse buttons. + public enum MouseButton { + /// The left mouse button. Left = 0, - /// - /// The right mouse button. - /// + /// The right mouse button. Right, - /// - /// The middle mouse button. - /// + /// The middle mouse button. Middle, - /// - /// The first extra mouse button. - /// + /// The first extra mouse button. Button1, - /// - /// The second extra mouse button. - /// + /// The second extra mouse button. Button2, - /// - /// The third extra mouse button. - /// + /// The third extra mouse button. Button3, - /// - /// The fourth extra mouse button. - /// + /// The fourth extra mouse button. Button4, - /// - /// The fifth extra mouse button. - /// + /// The fifth extra mouse button. Button5, - /// - /// The sixth extra mouse button. - /// + /// The sixth extra mouse button. Button6, - /// - /// The seventh extra mouse button. - /// + /// The seventh extra mouse button. Button7, - /// - /// The eigth extra mouse button. - /// + /// The eigth extra mouse button. Button8, - /// - /// The ninth extra mouse button. - /// + /// The ninth extra mouse button. Button9, - /// - /// Indicates the last available mouse button. - /// + /// Indicates the last available mouse button. LastButton } } diff --git a/OpenTK/Input/MouseDevice.cs b/OpenTK/Input/MouseDevice.cs index d12673325..bbd79fc21 100644 --- a/OpenTK/Input/MouseDevice.cs +++ b/OpenTK/Input/MouseDevice.cs @@ -26,10 +26,7 @@ #endregion using System; -using System.Collections.Generic; -using System.Text; using System.Drawing; -using System.ComponentModel; namespace OpenTK.Input { @@ -287,285 +284,47 @@ namespace OpenTK.Input #endregion } - #region Event Arguments + public class MouseEventArgs : EventArgs { - /// - /// Defines the event data for events. - /// - /// - /// - /// Do not cache instances of this type outside their event handler. - /// If necessary, you can clone an instance using the - /// constructor. - /// - /// - public class MouseEventArgs : EventArgs - { - #region Fields + /// Gets the X position of the mouse for the event. + public int X; - int x, y; - - #endregion - - #region Constructors - - /// - /// Constructs a new instance. - /// - public MouseEventArgs() - { - } - - /// - /// Constructs a new instance. - /// - /// The X position. - /// The Y position. - public MouseEventArgs(int x, int y) - { - this.x = x; - this.y = y; - } - - /// - /// Constructs a new instance. - /// - /// The instance to clone. - public MouseEventArgs(MouseEventArgs args) - : this(args.x, args.y) - { - } - - #endregion - - #region Public Members - - /// - /// Gets the X position of the mouse for the event. - /// - public int X { get { return x; } internal set { x = value; } } - - /// - /// Gets the Y position of the mouse for the event. - /// - public int Y { get { return y; } internal set { y = value; } } - - /// - /// Gets a System.Drawing.Points representing the location of the mouse for the event. - /// - public Point Position { get { return new Point(x, y); } } - - #endregion + /// Gets the Y position of the mouse for the event. + public int Y; } - /// - /// Defines the event data for events. - /// - /// - /// - /// Do not cache instances of this type outside their event handler. - /// If necessary, you can clone an instance using the - /// constructor. - /// - /// - public class MouseMoveEventArgs : MouseEventArgs - { - #region Fields + public class MouseMoveEventArgs : MouseEventArgs { - int x_delta, y_delta; + /// Gets the change in X position produced by this event. + public int XDelta; - #endregion - - #region Constructors - - /// - /// Constructs a new instance. - /// - public MouseMoveEventArgs() { } - - /// - /// Constructs a new instance. - /// - /// The X position. - /// The Y position. - /// The change in X position produced by this event. - /// The change in Y position produced by this event. - public MouseMoveEventArgs(int x, int y, int xDelta, int yDelta) - : base(x, y) - { - XDelta = xDelta; - YDelta = yDelta; - } - - /// - /// Constructs a new instance. - /// - /// The instance to clone. - public MouseMoveEventArgs(MouseMoveEventArgs args) - : this(args.X, args.Y, args.XDelta, args.YDelta) - { - } - - #endregion - - #region Public Members - - /// - /// Gets the change in X position produced by this event. - /// - public int XDelta { get { return x_delta; } internal set { x_delta = value; } } - - /// - /// Gets the change in Y position produced by this event. - /// - public int YDelta { get { return y_delta; } internal set { y_delta = value; } } - - #endregion + /// Gets the change in Y position produced by this event. + public int YDelta; } - /// - /// Defines the event data for and events. - /// - /// - /// - /// Do not cache instances of this type outside their event handler. - /// If necessary, you can clone an instance using the - /// constructor. - /// - /// - public class MouseButtonEventArgs : MouseEventArgs - { - #region Fields + public class MouseButtonEventArgs : MouseEventArgs { + + /// The mouse button for the event. + public MouseButton Button; - MouseButton button; - bool pressed; - - #endregion - - #region Constructors - - /// - /// Constructs a new instance. - /// - public MouseButtonEventArgs() { } - - /// - /// Constructs a new instance. - /// - /// The X position. - /// The Y position. - /// The mouse button for the event. - /// The current state of the button. - public MouseButtonEventArgs(int x, int y, MouseButton button, bool pressed) - : base(x, y) - { - this.button = button; - this.pressed = pressed; - } - - /// - /// Constructs a new instance. - /// - /// The instance to clone. - public MouseButtonEventArgs(MouseButtonEventArgs args) - : this(args.X, args.Y, args.Button, args.IsPressed) - { - } - - #endregion - - #region Public Members - - /// - /// The mouse button for the event. - /// - public MouseButton Button { get { return button; } internal set { button = value; } } - - /// - /// Gets a System.Boolean representing the state of the mouse button for the event. - /// - public bool IsPressed { get { return pressed; } internal set { pressed = value; } } - - #endregion + /// Gets a System.Boolean representing the state of the mouse button for the event. + public bool IsPressed; } - /// - /// Defines the event data for events. - /// - /// - /// - /// Do not cache instances of this type outside their event handler. - /// If necessary, you can clone an instance using the - /// constructor. - /// - /// - public class MouseWheelEventArgs : MouseEventArgs - { - #region Fields + public class MouseWheelEventArgs : MouseEventArgs { - float value; - float delta; + /// Gets the value of the wheel in integer units. + /// To support high-precision mice, it is recommended to use instead. + public int Value { get { return (int)Math.Round(ValuePrecise, MidpointRounding.AwayFromZero); } } - #endregion + /// Gets the change in value of the wheel for this event in integer units. + /// To support high-precision mice, it is recommended to use instead. + public int Delta { get { return (int)Math.Round(DeltaPrecise, MidpointRounding.AwayFromZero); } } - #region Constructors + /// Gets the precise value of the wheel in floating-point units. + public float ValuePrecise; - /// - /// Constructs a new instance. - /// - public MouseWheelEventArgs() { } - - /// - /// Constructs a new instance. - /// - /// The X position. - /// The Y position. - /// The value of the wheel. - /// The change in value of the wheel for this event. - public MouseWheelEventArgs(int x, int y, int value, int delta) - : base(x, y) - { - this.value = value; - this.delta = delta; - } - - /// - /// Constructs a new instance. - /// - /// The instance to clone. - public MouseWheelEventArgs(MouseWheelEventArgs args) - : this(args.X, args.Y, args.Value, args.Delta) - { - } - - #endregion - - #region Public Members - - /// - /// Gets the value of the wheel in integer units. - /// To support high-precision mice, it is recommended to use instead. - /// - public int Value { get { return (int)Math.Round(value, MidpointRounding.AwayFromZero); } } - - /// - /// Gets the change in value of the wheel for this event in integer units. - /// To support high-precision mice, it is recommended to use instead. - /// - public int Delta { get { return (int)Math.Round(delta, MidpointRounding.AwayFromZero); } } - - /// - /// Gets the precise value of the wheel in floating-point units. - /// - public float ValuePrecise { get { return value; } internal set { this.value = value; } } - - /// - /// Gets the precise change in value of the wheel for this event in floating-point units. - /// - public float DeltaPrecise { get { return delta; } internal set { delta = value; } } - - #endregion + /// Gets the precise change in value of the wheel for this event in floating-point units. + public float DeltaPrecise; } - - #endregion } diff --git a/OpenTK/OpenTK.csproj b/OpenTK/OpenTK.csproj index 9f4b23ca6..3157a5594 100644 --- a/OpenTK/OpenTK.csproj +++ b/OpenTK/OpenTK.csproj @@ -72,15 +72,10 @@ - - - - - + -