mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-24 17:05:37 +00:00
Fixed mouse delta handling.
This commit is contained in:
parent
b5fb1361ef
commit
e9e9ee5f9c
65
Source/OpenTK/Input/MouseButton.cs
Normal file
65
Source/OpenTK/Input/MouseButton.cs
Normal file
|
@ -0,0 +1,65 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Input
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumerates all possible mouse buttons.
|
||||
/// </summary>
|
||||
public enum MouseButton
|
||||
{
|
||||
/// <summary>
|
||||
/// The left mouse button.
|
||||
/// </summary>
|
||||
Left = 0,
|
||||
/// <summary>
|
||||
/// The middle mouse button.
|
||||
/// </summary>
|
||||
Middle,
|
||||
/// <summary>
|
||||
/// The right mouse button.
|
||||
/// </summary>
|
||||
Right,
|
||||
/// <summary>
|
||||
/// The first extra mouse button.
|
||||
/// </summary>
|
||||
Button1,
|
||||
/// <summary>
|
||||
/// The second extra mouse button.
|
||||
/// </summary>
|
||||
Button2,
|
||||
/// <summary>
|
||||
/// The third extra mouse button.
|
||||
/// </summary>
|
||||
Button3,
|
||||
/// <summary>
|
||||
/// The fourth extra mouse button.
|
||||
/// </summary>
|
||||
Button4,
|
||||
/// <summary>
|
||||
/// The fifth extra mouse button.
|
||||
/// </summary>
|
||||
Button5,
|
||||
/// <summary>
|
||||
/// The sixth extra mouse button.
|
||||
/// </summary>
|
||||
Button6,
|
||||
/// <summary>
|
||||
/// The seventh extra mouse button.
|
||||
/// </summary>
|
||||
Button7,
|
||||
/// <summary>
|
||||
/// The eigth extra mouse button.
|
||||
/// </summary>
|
||||
Button8,
|
||||
/// <summary>
|
||||
/// The ninth extra mouse button.
|
||||
/// </summary>
|
||||
Button9,
|
||||
/// <summary>
|
||||
/// Indicates the last available mouse button.
|
||||
/// </summary>
|
||||
LastButton
|
||||
}
|
||||
}
|
|
@ -20,8 +20,9 @@ namespace OpenTK.Input
|
|||
private int numButtons, numWheels;
|
||||
private IntPtr id;
|
||||
private bool[] button = new bool[(int)MouseButton.LastButton];
|
||||
private int wheel, last_wheel;
|
||||
private int wheel, wheel_last_accessed = 0;
|
||||
private Point pos = new Point();
|
||||
private Point pos_last_accessed = new Point();
|
||||
internal int last_x, last_y;
|
||||
|
||||
#region --- IInputDevice Members ---
|
||||
|
@ -47,6 +48,8 @@ namespace OpenTK.Input
|
|||
|
||||
#region --- Public Members ---
|
||||
|
||||
#region public int NumberOfButtons
|
||||
|
||||
/// <summary>
|
||||
/// Gets an integer representing the number of buttons on this MouseDevice.
|
||||
/// </summary>
|
||||
|
@ -56,6 +59,10 @@ namespace OpenTK.Input
|
|||
internal set { numButtons = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public int NumberOfWheels
|
||||
|
||||
/// <summary>
|
||||
/// Gets an integer representing the number of wheels on this MouseDevice.
|
||||
/// </summary>
|
||||
|
@ -65,6 +72,10 @@ namespace OpenTK.Input
|
|||
internal set { numWheels = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public IntPtr DeviceID
|
||||
|
||||
/// <summary>
|
||||
/// Gets an IntPtr representing a device dependent ID.
|
||||
/// </summary>
|
||||
|
@ -74,6 +85,10 @@ namespace OpenTK.Input
|
|||
internal set { id = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public int Wheel
|
||||
|
||||
/// <summary>
|
||||
/// Gets an integer representing the absolute wheel position.
|
||||
/// </summary>
|
||||
|
@ -82,11 +97,16 @@ namespace OpenTK.Input
|
|||
get { return wheel; }
|
||||
internal set
|
||||
{
|
||||
last_wheel = wheel;
|
||||
wheel = value;
|
||||
if (Move != null)
|
||||
Move(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public int WheelDelta
|
||||
|
||||
/// <summary>
|
||||
/// Gets an integer representing the relative wheel movement.
|
||||
/// </summary>
|
||||
|
@ -94,37 +114,40 @@ namespace OpenTK.Input
|
|||
{
|
||||
get
|
||||
{
|
||||
return wheel - last_wheel;
|
||||
int result = wheel - wheel_last_accessed;
|
||||
wheel_last_accessed = wheel;
|
||||
return wheel;
|
||||
}
|
||||
//internal set { wheel_delta = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public int X
|
||||
|
||||
/// <summary>
|
||||
/// Gets an integer representing the absolute x position of the pointer, in window pixel coordinates.
|
||||
/// </summary>
|
||||
public int X
|
||||
{
|
||||
get { return pos.X; }
|
||||
internal set
|
||||
{
|
||||
last_x = pos.X;
|
||||
pos.X = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public int Y
|
||||
|
||||
/// <summary>
|
||||
/// Gets an integer representing the absolute y position of the pointer, in window pixel coordinates.
|
||||
/// </summary>
|
||||
public int Y
|
||||
{
|
||||
get { return pos.Y; }
|
||||
internal set
|
||||
{
|
||||
last_y = pos.Y;
|
||||
pos.Y = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public int XDelta
|
||||
|
||||
/// <summary>
|
||||
/// Gets an integer representing the relative x movement of the pointer, in pixel coordinates.
|
||||
/// </summary>
|
||||
|
@ -132,12 +155,16 @@ namespace OpenTK.Input
|
|||
{
|
||||
get
|
||||
{
|
||||
//return delta_x;
|
||||
return pos.X - last_x;
|
||||
int result = pos.X - pos_last_accessed.X;
|
||||
pos_last_accessed.X = pos.X;
|
||||
return result;
|
||||
}
|
||||
//internal set { delta_x = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public int YDelta
|
||||
|
||||
/// <summary>
|
||||
/// Gets an integer representing the relative y movement of the pointer, in pixel coordinates.
|
||||
/// </summary>
|
||||
|
@ -145,25 +172,35 @@ namespace OpenTK.Input
|
|||
{
|
||||
get
|
||||
{
|
||||
//return delta_y;
|
||||
return pos.Y - last_y;
|
||||
int result = pos.Y - pos_last_accessed.Y;
|
||||
pos_last_accessed.Y = pos.Y;
|
||||
return result;
|
||||
}
|
||||
//internal set { delta_y = value; }
|
||||
}
|
||||
|
||||
#region public Point Position
|
||||
|
||||
/// <summary>
|
||||
/// Gets a System.Drawing.Point representing the absolute position of the pointer, in window pixel coordinates.
|
||||
/// </summary>
|
||||
public Point Position
|
||||
{
|
||||
get { return pos; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//public event MouseMoveEvent Move;
|
||||
#region internal Point Position
|
||||
|
||||
/// <summary>
|
||||
/// Sets a System.Drawing.Point representing the absolute position of the pointer, in window pixel coordinates.
|
||||
/// </summary>
|
||||
internal Point Position
|
||||
{
|
||||
set
|
||||
{
|
||||
pos = value;
|
||||
if (Move != null)
|
||||
Move(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the mouse, or one of its wheels, is moved.
|
||||
/// </summary>
|
||||
public event MouseMoveEvent Move;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a button is pressed.
|
||||
|
@ -202,6 +239,8 @@ namespace OpenTK.Input
|
|||
|
||||
#endregion
|
||||
|
||||
#region --- Overrides ---
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
//return base.GetHashCode();
|
||||
|
@ -215,33 +254,28 @@ namespace OpenTK.Input
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public delegate void MouseMoveEvent(MouseDevice sender);
|
||||
public delegate void MouseButtonDownEvent(MouseDevice sender, MouseButton button);
|
||||
public delegate void MouseButtonUpEvent(MouseDevice sender, MouseButton button);
|
||||
|
||||
#region public enum MouseButton
|
||||
|
||||
/// <summary>
|
||||
/// Enumerates all possible mouse buttons.
|
||||
/// Defines a MouseMove event.
|
||||
/// </summary>
|
||||
public enum MouseButton
|
||||
{
|
||||
Left = 0,
|
||||
Middle,
|
||||
Right,
|
||||
Button1,
|
||||
Button2,
|
||||
Button3,
|
||||
Button4,
|
||||
Button5,
|
||||
Button6,
|
||||
Button7,
|
||||
Button8,
|
||||
Button9,
|
||||
LastButton
|
||||
}
|
||||
/// <param name="sender">The MouseDevice that generated this event.</param>
|
||||
/// <param name="e">Not used.</param>
|
||||
public delegate void MouseMoveEvent(MouseDevice sender, EventArgs e);
|
||||
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// Defines the MouseButtonDown event.
|
||||
/// </summary>
|
||||
/// <param name="sender">The MouseDevice that generated this event.</param>
|
||||
/// <param name="button">The MouseButton that was pressed.</param>
|
||||
public delegate void MouseButtonDownEvent(MouseDevice sender, MouseButton button);
|
||||
|
||||
/// <summary>
|
||||
/// Defines the MouseButtonUp event.
|
||||
/// </summary>
|
||||
/// <param name="sender">The MouseDevice that generated this event.</param>
|
||||
/// <param name="button">The MouseButton that was released.</param>
|
||||
public delegate void MouseButtonUpEvent(MouseDevice sender, MouseButton button);
|
||||
}
|
||||
|
|
|
@ -66,8 +66,8 @@ namespace OpenTK.Platform.Windows
|
|||
// Mouse events:
|
||||
case WindowMessage.MOUSEMOVE:
|
||||
//case WindowMessage.NCMOUSEMOVE:
|
||||
mouse.X = msg.LParam.ToInt32() & 0x0000FFFF;
|
||||
mouse.Y = (int)(msg.LParam.ToInt32() & 0xFFFF0000) >> 16;
|
||||
mouse.Position = new System.Drawing.Point(msg.LParam.ToInt32() & 0x0000FFFF,
|
||||
(int)(msg.LParam.ToInt32() & 0xFFFF0000) >> 16);
|
||||
return;
|
||||
|
||||
case WindowMessage.MOUSEWHEEL:
|
||||
|
|
|
@ -155,10 +155,7 @@ namespace OpenTK.Platform.Windows
|
|||
Debug.Print("Registered mouse {0}", mouse.ToString());
|
||||
System.Drawing.Point p = new System.Drawing.Point();
|
||||
if (Functions.GetCursorPos(ref p))
|
||||
{
|
||||
mouse.X = p.X;
|
||||
mouse.Y = p.Y;
|
||||
}
|
||||
mouse.Position = p;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,13 +197,12 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
if ((rin.Data.Mouse.Flags & RawMouseFlags.MOUSE_MOVE_ABSOLUTE) != 0)
|
||||
{
|
||||
mouse.X = rin.Data.Mouse.LastX;
|
||||
mouse.Y = rin.Data.Mouse.LastY;
|
||||
mouse.Position = new System.Drawing.Point(rin.Data.Mouse.LastX, rin.Data.Mouse.LastY);
|
||||
}
|
||||
else
|
||||
{ // Seems like MOUSE_MOVE_RELATIVE is the default, unless otherwise noted.
|
||||
mouse.X += rin.Data.Mouse.LastX;
|
||||
mouse.Y += rin.Data.Mouse.LastY;
|
||||
mouse.Position = new System.Drawing.Point(mouse.X + rin.Data.Mouse.LastX,
|
||||
mouse.Y + rin.Data.Mouse.LastY);
|
||||
}
|
||||
|
||||
if ((rin.Data.Mouse.Flags & RawMouseFlags.MOUSE_VIRTUAL_DESKTOP) != 0)
|
||||
|
|
|
@ -159,39 +159,38 @@ namespace OpenTK.Platform.X11
|
|||
else if (e.ButtonEvent.button == 2) mouse[OpenTK.Input.MouseButton.Middle] = true;
|
||||
else if (e.ButtonEvent.button == 3) mouse[OpenTK.Input.MouseButton.Right] = true;
|
||||
else if (e.ButtonEvent.button == 4) mouse.Wheel++;
|
||||
else if (e.ButtonEvent.button == 5) mouse.Wheel--;
|
||||
else if (e.ButtonEvent.button == 6) mouse[OpenTK.Input.MouseButton.Button1] = true;
|
||||
else if (e.ButtonEvent.button == 7) mouse[OpenTK.Input.MouseButton.Button2] = true;
|
||||
else if (e.ButtonEvent.button == 8) mouse[OpenTK.Input.MouseButton.Button3] = true;
|
||||
else if (e.ButtonEvent.button == 9) mouse[OpenTK.Input.MouseButton.Button4] = true;
|
||||
else if (e.ButtonEvent.button == 10) mouse[OpenTK.Input.MouseButton.Button5] = true;
|
||||
else if (e.ButtonEvent.button == 11) mouse[OpenTK.Input.MouseButton.Button6] = true;
|
||||
else if (e.ButtonEvent.button == 12) mouse[OpenTK.Input.MouseButton.Button7] = true;
|
||||
else if (e.ButtonEvent.button == 13) mouse[OpenTK.Input.MouseButton.Button8] = true;
|
||||
else if (e.ButtonEvent.button == 5) mouse.Wheel--;
|
||||
else if (e.ButtonEvent.button == 6) mouse[OpenTK.Input.MouseButton.Button1] = true;
|
||||
else if (e.ButtonEvent.button == 7) mouse[OpenTK.Input.MouseButton.Button2] = true;
|
||||
else if (e.ButtonEvent.button == 8) mouse[OpenTK.Input.MouseButton.Button3] = true;
|
||||
else if (e.ButtonEvent.button == 9) mouse[OpenTK.Input.MouseButton.Button4] = true;
|
||||
else if (e.ButtonEvent.button == 10) mouse[OpenTK.Input.MouseButton.Button5] = true;
|
||||
else if (e.ButtonEvent.button == 11) mouse[OpenTK.Input.MouseButton.Button6] = true;
|
||||
else if (e.ButtonEvent.button == 12) mouse[OpenTK.Input.MouseButton.Button7] = true;
|
||||
else if (e.ButtonEvent.button == 13) mouse[OpenTK.Input.MouseButton.Button8] = true;
|
||||
else if (e.ButtonEvent.button == 14) mouse[OpenTK.Input.MouseButton.Button9] = true;
|
||||
//if ((e.state & (int)X11.MouseMask.Button4Mask) != 0) m.Wheel++;
|
||||
//if ((e.state & (int)X11.MouseMask.Button5Mask) != 0) m.Wheel--;
|
||||
//if ((e.state & (int)X11.MouseMask.Button5Mask) != 0) m.Wheel--;
|
||||
//Debug.Print("Button pressed: {0}", e.ButtonEvent.button);
|
||||
break;
|
||||
|
||||
case XEventName.ButtonRelease:
|
||||
case XEventName.ButtonRelease:
|
||||
if (e.ButtonEvent.button == 1) mouse[OpenTK.Input.MouseButton.Left] = false;
|
||||
else if (e.ButtonEvent.button == 2) mouse[OpenTK.Input.MouseButton.Middle] = false;
|
||||
else if (e.ButtonEvent.button == 3) mouse[OpenTK.Input.MouseButton.Right] = false;
|
||||
else if (e.ButtonEvent.button == 6) mouse[OpenTK.Input.MouseButton.Button1] = false;
|
||||
else if (e.ButtonEvent.button == 7) mouse[OpenTK.Input.MouseButton.Button2] = false;
|
||||
else if (e.ButtonEvent.button == 8) mouse[OpenTK.Input.MouseButton.Button3] = false;
|
||||
else if (e.ButtonEvent.button == 9) mouse[OpenTK.Input.MouseButton.Button4] = false;
|
||||
else if (e.ButtonEvent.button == 10) mouse[OpenTK.Input.MouseButton.Button5] = false;
|
||||
else if (e.ButtonEvent.button == 11) mouse[OpenTK.Input.MouseButton.Button6] = false;
|
||||
else if (e.ButtonEvent.button == 12) mouse[OpenTK.Input.MouseButton.Button7] = false;
|
||||
else if (e.ButtonEvent.button == 13) mouse[OpenTK.Input.MouseButton.Button8] = false;
|
||||
else if (e.ButtonEvent.button == 6) mouse[OpenTK.Input.MouseButton.Button1] = false;
|
||||
else if (e.ButtonEvent.button == 7) mouse[OpenTK.Input.MouseButton.Button2] = false;
|
||||
else if (e.ButtonEvent.button == 8) mouse[OpenTK.Input.MouseButton.Button3] = false;
|
||||
else if (e.ButtonEvent.button == 9) mouse[OpenTK.Input.MouseButton.Button4] = false;
|
||||
else if (e.ButtonEvent.button == 10) mouse[OpenTK.Input.MouseButton.Button5] = false;
|
||||
else if (e.ButtonEvent.button == 11) mouse[OpenTK.Input.MouseButton.Button6] = false;
|
||||
else if (e.ButtonEvent.button == 12) mouse[OpenTK.Input.MouseButton.Button7] = false;
|
||||
else if (e.ButtonEvent.button == 13) mouse[OpenTK.Input.MouseButton.Button8] = false;
|
||||
else if (e.ButtonEvent.button == 14) mouse[OpenTK.Input.MouseButton.Button9] = false;
|
||||
break;
|
||||
|
||||
case XEventName.MotionNotify:
|
||||
mouse.X = e.MotionEvent.x;
|
||||
mouse.Y = e.MotionEvent.y;
|
||||
mouse.Position = new System.Drawing.Point(mouse.X, mouse.Y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue