mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-07-21 15:08:37 +00:00
[Input] Improve SDL2 and Windows GetCursorState
This commit is contained in:
parent
f4a3cab0e0
commit
bb8dfe4304
|
@ -264,7 +264,7 @@ namespace OpenTK.Input
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
string b = Convert.ToString(buttons, 2).PadLeft(10, '0');
|
string b = Convert.ToString(buttons, 2).PadLeft(10, '0');
|
||||||
return String.Format("[MouseState: X={0}, Y={1}, Scroll={2}, Buttons={3}, IsConnected={4}]",
|
return String.Format("[X={0}, Y={1}, Scroll={2}, Buttons={3}, IsConnected={4}]",
|
||||||
X, Y, Scroll, b, IsConnected);
|
X, Y, Scroll, b, IsConnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,15 +124,16 @@ namespace OpenTK.Platform.SDL2
|
||||||
int x, y;
|
int x, y;
|
||||||
var buttons = SDL.GetMouseState(out x, out y);
|
var buttons = SDL.GetMouseState(out x, out y);
|
||||||
|
|
||||||
var state = new MouseState();
|
var c = new MouseState();
|
||||||
state.SetIsConnected(true);
|
c.SetIsConnected(true);
|
||||||
state.X = x;
|
c.X = x;
|
||||||
state.Y = y;
|
c.Y = y;
|
||||||
state[MouseButton.Left] = (buttons & ButtonFlags.Left) != 0;
|
c.SetScrollAbsolute(state.Scroll.X, state.Scroll.Y); // we cannot query the scrollwheel directly
|
||||||
state[MouseButton.Middle] = (buttons & ButtonFlags.Middle) != 0;
|
c[MouseButton.Left] = (buttons & ButtonFlags.Left) != 0;
|
||||||
state[MouseButton.Right] = (buttons & ButtonFlags.Right) != 0;
|
c[MouseButton.Middle] = (buttons & ButtonFlags.Middle) != 0;
|
||||||
state[MouseButton.Button1] = (buttons & ButtonFlags.X1) != 0;
|
c[MouseButton.Right] = (buttons & ButtonFlags.Right) != 0;
|
||||||
state[MouseButton.Button2] = (buttons & ButtonFlags.X2) != 0;
|
c[MouseButton.Button1] = (buttons & ButtonFlags.X1) != 0;
|
||||||
|
c[MouseButton.Button2] = (buttons & ButtonFlags.X2) != 0;
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -350,25 +350,14 @@ namespace OpenTK.Platform.Windows
|
||||||
|
|
||||||
public MouseState GetCursorState()
|
public MouseState GetCursorState()
|
||||||
{
|
{
|
||||||
var state = new MouseState();
|
// For simplicity, get hardware state
|
||||||
state.SetIsConnected(true);
|
// and simply overwrite its x and y location
|
||||||
|
|
||||||
POINT p = new POINT();
|
POINT p = new POINT();
|
||||||
Functions.GetCursorPos(ref p);
|
Functions.GetCursorPos(ref p);
|
||||||
bool left = Functions.GetKeyState(VirtualKeys.LBUTTON) != 0;
|
|
||||||
bool right = Functions.GetKeyState(VirtualKeys.RBUTTON) != 0;
|
|
||||||
bool middle = Functions.GetKeyState(VirtualKeys.MBUTTON) != 0;
|
|
||||||
bool x1 = Functions.GetKeyState(VirtualKeys.XBUTTON1) != 0;
|
|
||||||
bool x2 = Functions.GetKeyState(VirtualKeys.XBUTTON2) != 0;
|
|
||||||
|
|
||||||
|
var state = GetState();
|
||||||
state.X = p.X;
|
state.X = p.X;
|
||||||
state.Y = p.Y;
|
state.Y = p.Y;
|
||||||
state[MouseButton.Left] = left;
|
|
||||||
state[MouseButton.Right] = right;
|
|
||||||
state[MouseButton.Middle] = middle;
|
|
||||||
state[MouseButton.Button1] = x1;
|
|
||||||
state[MouseButton.Button2] = x2;
|
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue