[Input] Improve SDL2 and Windows GetCursorState

This commit is contained in:
thefiddler 2014-05-10 01:44:27 +02:00
parent f4a3cab0e0
commit bb8dfe4304
3 changed files with 15 additions and 25 deletions

View file

@ -264,7 +264,7 @@ namespace OpenTK.Input
public override string ToString()
{
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);
}

View file

@ -123,16 +123,17 @@ namespace OpenTK.Platform.SDL2
{
int x, y;
var buttons = SDL.GetMouseState(out x, out y);
var state = new MouseState();
state.SetIsConnected(true);
state.X = x;
state.Y = y;
state[MouseButton.Left] = (buttons & ButtonFlags.Left) != 0;
state[MouseButton.Middle] = (buttons & ButtonFlags.Middle) != 0;
state[MouseButton.Right] = (buttons & ButtonFlags.Right) != 0;
state[MouseButton.Button1] = (buttons & ButtonFlags.X1) != 0;
state[MouseButton.Button2] = (buttons & ButtonFlags.X2) != 0;
var c = new MouseState();
c.SetIsConnected(true);
c.X = x;
c.Y = y;
c.SetScrollAbsolute(state.Scroll.X, state.Scroll.Y); // we cannot query the scrollwheel directly
c[MouseButton.Left] = (buttons & ButtonFlags.Left) != 0;
c[MouseButton.Middle] = (buttons & ButtonFlags.Middle) != 0;
c[MouseButton.Right] = (buttons & ButtonFlags.Right) != 0;
c[MouseButton.Button1] = (buttons & ButtonFlags.X1) != 0;
c[MouseButton.Button2] = (buttons & ButtonFlags.X2) != 0;
return state;
}

View file

@ -350,25 +350,14 @@ namespace OpenTK.Platform.Windows
public MouseState GetCursorState()
{
var state = new MouseState();
state.SetIsConnected(true);
// For simplicity, get hardware state
// and simply overwrite its x and y location
POINT p = new POINT();
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.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;
}