2007-08-10 09:27:13 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
2007-08-05 10:17:20 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace OpenTK.Input
|
|
|
|
|
{
|
2007-09-21 20:34:07 +00:00
|
|
|
|
public sealed class Mouse : IMouse
|
2007-08-05 10:17:20 +00:00
|
|
|
|
{
|
2007-09-21 20:34:07 +00:00
|
|
|
|
private string description;
|
|
|
|
|
private int numButtons, numWheels;
|
|
|
|
|
private IntPtr id;
|
|
|
|
|
private bool[] button = new bool[(int)MouseButton.LastButton];
|
2007-09-22 13:13:17 +00:00
|
|
|
|
private int wheel, x, y, wheel_delta, delta_x, delta_y;
|
2007-09-21 20:34:07 +00:00
|
|
|
|
|
2007-08-05 10:17:20 +00:00
|
|
|
|
#region --- IInputDevice Members ---
|
|
|
|
|
|
|
|
|
|
public string Description
|
|
|
|
|
{
|
2007-09-21 20:34:07 +00:00
|
|
|
|
get { return description; }
|
|
|
|
|
internal set { description = value; }
|
2007-08-05 10:17:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public InputDeviceType DeviceType
|
|
|
|
|
{
|
|
|
|
|
get { return InputDeviceType.Mouse; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2007-09-21 20:34:07 +00:00
|
|
|
|
|
|
|
|
|
#region --- IMouse Members ---
|
|
|
|
|
|
|
|
|
|
public int NumberOfButtons
|
|
|
|
|
{
|
|
|
|
|
get { return numButtons; }
|
|
|
|
|
internal set { numButtons = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int NumberOfWheels
|
|
|
|
|
{
|
|
|
|
|
get { return numWheels; }
|
|
|
|
|
internal set { numWheels = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IntPtr DeviceID
|
|
|
|
|
{
|
|
|
|
|
get { return id; }
|
|
|
|
|
internal set { id = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Wheel
|
|
|
|
|
{
|
|
|
|
|
get { return wheel; }
|
2007-09-22 13:13:17 +00:00
|
|
|
|
internal set
|
|
|
|
|
{
|
|
|
|
|
wheel = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal int WheelDelta
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int delta = wheel_delta;
|
|
|
|
|
//wheel_delta = 0;
|
|
|
|
|
return delta;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
wheel_delta = value;
|
|
|
|
|
}
|
2007-09-21 20:34:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int X
|
|
|
|
|
{
|
|
|
|
|
get { return x; }
|
|
|
|
|
internal set { x = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Y
|
|
|
|
|
{
|
|
|
|
|
get { return y; }
|
|
|
|
|
internal set { y = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-22 13:13:17 +00:00
|
|
|
|
public int XDelta
|
2007-09-21 20:34:07 +00:00
|
|
|
|
{
|
|
|
|
|
get { return delta_x; }
|
|
|
|
|
internal set { delta_x = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-22 13:13:17 +00:00
|
|
|
|
public int YDelta
|
2007-09-21 20:34:07 +00:00
|
|
|
|
{
|
|
|
|
|
get { return delta_y; }
|
|
|
|
|
internal set { delta_y = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public event MouseMoveEvent Move;
|
|
|
|
|
public event MouseButtonDownEvent ButtonDown;
|
|
|
|
|
public event MouseButtonUpEvent ButtonUp;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public bool this[MouseButton b]
|
|
|
|
|
|
|
|
|
|
public bool this[MouseButton b]
|
|
|
|
|
{
|
|
|
|
|
internal set
|
|
|
|
|
{
|
2007-09-21 22:39:16 +00:00
|
|
|
|
if (ButtonDown != null && value && !button[(int)b])
|
|
|
|
|
{
|
|
|
|
|
ButtonDown(this, b);
|
|
|
|
|
}
|
|
|
|
|
else if (ButtonUp != null && !value && button[(int)b])
|
|
|
|
|
{
|
|
|
|
|
ButtonUp(this, b);
|
|
|
|
|
}
|
2007-09-21 20:34:07 +00:00
|
|
|
|
button[(int)b] = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return button[(int)b];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum MouseButton
|
|
|
|
|
{
|
|
|
|
|
Left = 0,
|
|
|
|
|
Middle,
|
|
|
|
|
Right,
|
|
|
|
|
Button1,
|
|
|
|
|
Button2,
|
|
|
|
|
Button3,
|
|
|
|
|
Button4,
|
|
|
|
|
Button5,
|
|
|
|
|
Button6,
|
|
|
|
|
Button7,
|
|
|
|
|
Button8,
|
|
|
|
|
Button9,
|
|
|
|
|
LastButton
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class MouseWheel
|
|
|
|
|
{
|
|
|
|
|
private int position;
|
|
|
|
|
private int delta;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the absolute position of the mouse wheel.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Position
|
|
|
|
|
{
|
|
|
|
|
get { return position; }
|
|
|
|
|
internal set { position = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the relative movement of the mouse wheel.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Delta
|
|
|
|
|
{
|
|
|
|
|
get { return delta; }
|
|
|
|
|
internal set { delta = value; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class MouseMoveData
|
|
|
|
|
{
|
|
|
|
|
private int x;
|
|
|
|
|
private int y;
|
|
|
|
|
private int deltaX;
|
|
|
|
|
private int deltaY;
|
|
|
|
|
private MouseWheel wheel;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the absolute X position of the mouse in screen pixel coordinates.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int X
|
|
|
|
|
{
|
|
|
|
|
get { return x; }
|
|
|
|
|
internal set { x = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the absolute Y position of the mouse in screen pixel coordinates.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Y
|
|
|
|
|
{
|
|
|
|
|
get { return y; }
|
|
|
|
|
internal set { y = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the relative movement of the mouse in the X direction, in pixels.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int DeltaX
|
|
|
|
|
{
|
|
|
|
|
get { return deltaX; }
|
|
|
|
|
internal set { deltaX = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the relative movement of the mouse in the Y direction, in pixels.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int DeltaY
|
|
|
|
|
{
|
|
|
|
|
get { return deltaY; }
|
|
|
|
|
internal set { deltaY = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets data relevant to the mouse wheel.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public MouseWheel Wheel
|
|
|
|
|
{
|
|
|
|
|
get { return wheel; }
|
|
|
|
|
internal set { wheel = value; }
|
|
|
|
|
}
|
2007-08-05 10:17:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|