diff --git a/Source/OpenTK/Input/MouseDevice.cs b/Source/OpenTK/Input/MouseDevice.cs
index dbbc3638..aba9524e 100644
--- a/Source/OpenTK/Input/MouseDevice.cs
+++ b/Source/OpenTK/Input/MouseDevice.cs
@@ -48,6 +48,9 @@ namespace OpenTK.Input
readonly bool[] button_state = new bool[Enum.GetValues(typeof(MouseButton)).Length];
int wheel, last_wheel;
Point pos = new Point(), last_pos = new Point();
+ MouseMoveEventArgs move_args = new MouseMoveEventArgs();
+ MouseButtonEventArgs button_args = new MouseButtonEventArgs();
+ MouseWheelEventArgs wheel_args = new MouseWheelEventArgs();
#if COMPAT_REV1519
int wheel_last_accessed = 0;
Point pos_last_accessed = new Point();
@@ -136,16 +139,14 @@ namespace OpenTK.Input
internal set
{
wheel = value;
- if (WheelChanged != null)
- WheelChanged(
- this,
- new MouseWheelEventArgs(
- pos.X,
- pos.Y,
- wheel,
- wheel - last_wheel
- )
- );
+
+ wheel_args.X = pos.X;
+ wheel_args.Y = pos.Y;
+ wheel_args.Value = wheel;
+ wheel_args.Delta = wheel - last_wheel;
+
+ WheelChanged(this, wheel_args );
+
last_wheel = wheel;
}
}
@@ -194,11 +195,14 @@ namespace OpenTK.Input
bool previous_state = button_state[(int)button];
button_state[(int)button] = value;
- MouseButtonEventArgs e = new MouseButtonEventArgs(pos.X, pos.Y, button, value);
+ button_args.X = pos.X;
+ button_args.Y = pos.Y;
+ button_args.Button = button;
+ button_args.IsPressed = value;
if (value && !previous_state)
- ButtonDown(this, e);
+ ButtonDown(this, button_args);
else if (!value && previous_state)
- ButtonUp(this, e);
+ ButtonUp(this, button_args);
}
}
@@ -218,7 +222,11 @@ namespace OpenTK.Input
set
{
pos = value;
- Move(this, new MouseMoveEventArgs(pos.X, pos.Y, pos.X - last_pos.X, pos.Y - last_pos.Y));
+ move_args.X = pos.X;
+ move_args.Y = pos.Y;
+ move_args.XDelta = pos.X - last_pos.X;
+ move_args.YDelta = pos.Y - last_pos.Y;
+ Move(this, move_args);
last_pos = pos;
}
}
@@ -232,31 +240,38 @@ namespace OpenTK.Input
///
/// Occurs when the mouse's position is moved.
///
- public event MouseMoveEventHandler Move = delegate(object sender, MouseMoveEventArgs e) { };
+ public event EventHandler Move = delegate { };
///
/// Occurs when a button is pressed.
///
- public event MouseButtonEventHandler ButtonDown = delegate(object sender, MouseButtonEventArgs e) { };
+ public event EventHandler ButtonDown = delegate { };
///
/// Occurs when a button is released.
///
- public event MouseButtonEventHandler ButtonUp = delegate(object sender, MouseButtonEventArgs e) { };
+ public event EventHandler ButtonUp = delegate { };
///
/// Occurs when one of the mouse wheels is moved.
///
- public event MouseWheelEventHandler WheelChanged = delegate(object sender, MouseWheelEventArgs e) { };
+ public event EventHandler WheelChanged = delegate { };
#region --- Overrides ---
+ ///
+ /// Calculates the hash code for this instance.
+ ///
+ ///
public override int GetHashCode()
{
- //return base.GetHashCode();
return (int)(numButtons ^ numWheels ^ id.GetHashCode() ^ description.GetHashCode());
}
+ ///
+ /// Returns a that describes this instance.
+ ///
+ /// A that describes this instance.
public override string ToString()
{
return String.Format("ID: {0} ({1}). Buttons: {2}, Wheels: {3}",
@@ -332,11 +347,89 @@ namespace OpenTK.Input
#region Event Arguments
- public struct MouseMoveEventArgs
+ ///
+ /// 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
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
+ }
+
+ ///
+ /// 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
+
int x_delta, y_delta;
#endregion
@@ -344,200 +437,181 @@ namespace OpenTK.Input
#region Constructors
///
- /// Initializes a new instance of the class.
+ /// 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)
{
- this.x = x;
- this.y = y;
- this.x_delta = xDelta;
- this.y_delta = yDelta;
}
#endregion
#region Public Members
- ///
- /// Gets the X position of the mouse for the event.
- ///
- public int X { get { return x; } }
-
- ///
- /// Gets the Y position of the mouse for the event.
- ///
- public int Y { get { return y; } }
-
- ///
- /// Gets a System.Drawing.Points representing the location of the mouse for the event.
- ///
- public Point Position { get { return new Point(x, y); } }
-
///
/// Gets the change in X position produced by this event.
///
- public int XDelta { get { return x_delta; } }
+ 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; } }
+ public int YDelta { get { return y_delta; } internal set { y_delta = value; } }
#endregion
}
///
- /// Provides data for the and events.
+ /// Defines the event data for and events.
///
- public struct MouseButtonEventArgs
+ ///
+ ///
+ /// 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
MouseButton button;
bool pressed;
- int x, y;
#endregion
#region Constructors
///
- /// Initializes a new instance of the class.
+ /// 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.
- internal MouseButtonEventArgs(int x, int y, MouseButton button, bool pressed)
+ public MouseButtonEventArgs(int x, int y, MouseButton button, bool pressed)
+ : base(x, y)
{
- this.x = x;
- this.y = 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
- ///
- /// Gets the X position of the mouse for the event.
- ///
- public int X { get { return x; } }
-
- ///
- /// Gets the Y position of the mouse for the event.
- ///
- public int Y { get { return y; } }
-
- ///
- /// Gets a System.Drawing.Points representing the location of the mouse for the event.
- ///
- public Point Position { get { return new Point(x, y); } }
-
///
/// The mouse button for the event.
///
- public MouseButton Button { get { return this.button; } }
+ 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; } }
+ public bool IsPressed { get { return pressed; } internal set { pressed = value; } }
#endregion
}
///
- /// Provides data for the event.
+ /// Defines the event data for events.
///
- public struct MouseWheelEventArgs
+ ///
+ ///
+ /// 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
int value;
int delta;
- int x, y;
#endregion
#region Constructors
///
- /// Initializes a new instance of the class.
+ /// 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.x = x;
- this.y = 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 X position of the mouse for the event.
+ /// Gets the value of the wheel.
///
- public int X { get { return x; } }
+ public int Value { get { return this.value; } internal set { this.value = value; } }
///
- /// Gets the Y position of the mouse for the event.
+ /// Gets the change in value of the wheel for this event.
///
- public int Y { get { return y; } }
-
- ///
- /// Gets a System.Drawing.Points representing the location of the mouse for the event.
- ///
- public Point Position { get { return new Point(x, y); } }
-
- ///
- /// The value of the wheel.
- ///
- public int Value { get { return value; } }
-
- ///
- /// The change in value of the wheel for this event.
- ///
- public int Delta { get { return delta; } }
+ public int Delta { get { return delta; } internal set { delta = value; } }
#endregion
}
#endregion
-
- #region Event Handlers
-
- ///
- /// Defines a event.
- ///
- /// The MouseDevice that generated this event.
- /// A that contains the event data.
- public delegate void MouseMoveEventHandler(object sender, MouseMoveEventArgs e);
-
- ///
- /// Defines a event.
- ///
- /// The MouseDevice that generated this event.
- /// A MouseWheelEventArgs that contains the event data.
- public delegate void MouseWheelEventHandler(object sender, MouseWheelEventArgs e);
-
- ///
- /// Defines the and events.
- ///
- /// The MouseDevice that generated this event.
- /// A that contains the event data.
- public delegate void MouseButtonEventHandler(object sender, MouseButtonEventArgs e);
-
- #endregion
}