mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-02-24 09:56:58 +00:00
[Input] MouseDevice is now based on MouseState
This way we have a single state representation (MouseState), shared by all mouse APIs and events.
This commit is contained in:
parent
e093fd23f6
commit
67359a5d90
|
@ -48,12 +48,8 @@ namespace OpenTK.Input
|
||||||
string description;
|
string description;
|
||||||
IntPtr id;
|
IntPtr id;
|
||||||
int numButtons, numWheels;
|
int numButtons, numWheels;
|
||||||
readonly bool[] button_state = new bool[Enum.GetValues(typeof(MouseButton)).Length];
|
|
||||||
float wheel, last_wheel;
|
MouseState state;
|
||||||
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
|
#if COMPAT_REV1519
|
||||||
int wheel_last_accessed = 0;
|
int wheel_last_accessed = 0;
|
||||||
Point pos_last_accessed = new Point();
|
Point pos_last_accessed = new Point();
|
||||||
|
@ -139,8 +135,7 @@ namespace OpenTK.Input
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Wheel
|
public int Wheel
|
||||||
{
|
{
|
||||||
get { return (int)Math.Round(wheel, MidpointRounding.AwayFromZero); }
|
get { return state.Wheel; }
|
||||||
internal set { WheelPrecise = value; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -148,20 +143,7 @@ namespace OpenTK.Input
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float WheelPrecise
|
public float WheelPrecise
|
||||||
{
|
{
|
||||||
get { return wheel; }
|
get { return state.WheelPrecise; }
|
||||||
internal set
|
|
||||||
{
|
|
||||||
wheel = value;
|
|
||||||
|
|
||||||
wheel_args.X = pos.X;
|
|
||||||
wheel_args.Y = pos.Y;
|
|
||||||
wheel_args.ValuePrecise = wheel;
|
|
||||||
wheel_args.DeltaPrecise = wheel - last_wheel;
|
|
||||||
|
|
||||||
WheelChanged(this, wheel_args);
|
|
||||||
|
|
||||||
last_wheel = wheel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -173,7 +155,7 @@ namespace OpenTK.Input
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int X
|
public int X
|
||||||
{
|
{
|
||||||
get { return pos.X; }
|
get { return state.X; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -185,7 +167,7 @@ namespace OpenTK.Input
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Y
|
public int Y
|
||||||
{
|
{
|
||||||
get { return pos.Y; }
|
get { return state.Y; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -201,21 +183,11 @@ namespace OpenTK.Input
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return button_state[(int)button];
|
return state[button];
|
||||||
}
|
}
|
||||||
internal set
|
internal set
|
||||||
{
|
{
|
||||||
bool previous_state = button_state[(int)button];
|
state[button] = value;
|
||||||
button_state[(int)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, button_args);
|
|
||||||
else if (!value && previous_state)
|
|
||||||
ButtonUp(this, button_args);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,30 +197,34 @@ namespace OpenTK.Input
|
||||||
|
|
||||||
#region --- Internal Members ---
|
#region --- Internal Members ---
|
||||||
|
|
||||||
#region internal Point Position
|
internal void SetState(MouseState state)
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets a System.Drawing.Point representing the absolute position of the pointer, in window pixel coordinates.
|
|
||||||
/// </summary>
|
|
||||||
internal Point Position
|
|
||||||
{
|
{
|
||||||
get
|
this.state = state;
|
||||||
{
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
pos = value;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
internal void HandleMouseDown(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
SetState(e.Mouse);
|
||||||
|
ButtonDown(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void HandleMouseUp(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
SetState(e.Mouse);
|
||||||
|
ButtonUp(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void HandleMouseMove(object sender, MouseMoveEventArgs e)
|
||||||
|
{
|
||||||
|
SetState(e.Mouse);
|
||||||
|
Move(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void HandleMouseWheel(object sender, MouseWheelEventArgs e)
|
||||||
|
{
|
||||||
|
SetState(e.Mouse);
|
||||||
|
WheelChanged(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -313,8 +289,8 @@ namespace OpenTK.Input
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
int result = (int)Math.Round(wheel - wheel_last_accessed, MidpointRounding.AwayFromZero);
|
int result = (int)Math.Round(state.WheelPrecise - wheel_last_accessed, MidpointRounding.AwayFromZero);
|
||||||
wheel_last_accessed = (int)wheel;
|
wheel_last_accessed = state.Wheel;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,8 +307,8 @@ namespace OpenTK.Input
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
int result = pos.X - pos_last_accessed.X;
|
int result = state.X - pos_last_accessed.X;
|
||||||
pos_last_accessed.X = pos.X;
|
pos_last_accessed.X = state.X;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -349,8 +325,8 @@ namespace OpenTK.Input
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
int result = pos.Y - pos_last_accessed.Y;
|
int result = state.Y - pos_last_accessed.Y;
|
||||||
pos_last_accessed.Y = pos.Y;
|
pos_last_accessed.Y = state.Y;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue