Rework relative mouse events.

This commit is contained in:
teinarss
2019-05-06 19:34:03 +02:00
committed by abcdefg30
parent 647cc2698b
commit f07fb57e98
9 changed files with 42 additions and 30 deletions

View File

@@ -50,10 +50,9 @@ namespace OpenRA.Platforms.Default
return new int2(x, y);
}
public void PumpInput(Sdl2PlatformWindow device, IInputHandler inputHandler)
public void PumpInput(Sdl2PlatformWindow device, IInputHandler inputHandler, int2? lockedMousePosition)
{
var mods = MakeModifiers((int)SDL.SDL_GetModState());
var scrollDelta = 0;
inputHandler.ModifierKeys(mods);
MouseInput? pendingMotion = null;
@@ -98,9 +97,11 @@ namespace OpenRA.Platforms.Default
var button = MakeButton(e.button.button);
lastButtonBits |= button;
var pos = EventPosition(device, e.button.x, e.button.y);
var input = lockedMousePosition ?? new int2(e.button.x, e.button.y);
var pos = EventPosition(device, input.X, input.Y);
inputHandler.OnMouseInput(new MouseInput(
MouseInputEvent.Down, button, scrollDelta, pos, mods,
MouseInputEvent.Down, button, pos, int2.Zero, mods,
MultiTapDetection.DetectFromMouse(e.button.button, pos)));
break;
@@ -117,9 +118,11 @@ namespace OpenRA.Platforms.Default
var button = MakeButton(e.button.button);
lastButtonBits &= ~button;
var pos = EventPosition(device, e.button.x, e.button.y);
var input = lockedMousePosition ?? new int2(e.button.x, e.button.y);
var pos = EventPosition(device, input.X, input.Y);
inputHandler.OnMouseInput(new MouseInput(
MouseInputEvent.Up, button, scrollDelta, pos, mods,
MouseInputEvent.Up, button, pos, int2.Zero, mods,
MultiTapDetection.InfoFromMouse(e.button.button)));
break;
@@ -127,10 +130,11 @@ namespace OpenRA.Platforms.Default
case SDL.SDL_EventType.SDL_MOUSEMOTION:
{
var pos = EventPosition(device, e.motion.x, e.motion.y);
var input = lockedMousePosition ?? new int2(e.motion.x, e.motion.y);
var pos = EventPosition(device, input.X, input.Y);
var delta = EventPosition(device, e.motion.xrel, e.motion.yrel);
pendingMotion = new MouseInput(
MouseInputEvent.Move, lastButtonBits, scrollDelta,
pos, mods, 0);
MouseInputEvent.Move, lastButtonBits, pos, delta, mods, 0);
break;
}
@@ -139,8 +143,7 @@ namespace OpenRA.Platforms.Default
{
int x, y;
SDL.SDL_GetMouseState(out x, out y);
scrollDelta = e.wheel.y;
inputHandler.OnMouseInput(new MouseInput(MouseInputEvent.Scroll, MouseButton.None, scrollDelta, new int2(x, y), mods, 0));
inputHandler.OnMouseInput(new MouseInput(MouseInputEvent.Scroll, MouseButton.None, new int2(x, y), new int2(0, e.wheel.y), mods, 0));
break;
}

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Platforms.Default
Size windowSize;
Size surfaceSize;
float windowScale;
int2 mousePosition;
int2? lockedMousePosition;
internal IntPtr Window
{
@@ -283,13 +283,16 @@ namespace OpenRA.Platforms.Default
{
int x, y;
SDL.SDL_GetMouseState(out x, out y);
mousePosition = new int2(x, y);
lockedMousePosition = new int2(x, y);
SDL.SDL_SetRelativeMouseMode(SDL.SDL_bool.SDL_TRUE);
}
else
{
SDL.SDL_SetRelativeMouseMode(SDL.SDL_bool.SDL_FALSE);
SDL.SDL_WarpMouseInWindow(window, mousePosition.X, mousePosition.Y);
if (lockedMousePosition.HasValue)
SDL.SDL_WarpMouseInWindow(window, lockedMousePosition.Value.X, lockedMousePosition.Value.Y);
lockedMousePosition = null;
}
}
@@ -348,7 +351,7 @@ namespace OpenRA.Platforms.Default
public void PumpInput(IInputHandler inputHandler)
{
VerifyThreadAffinity();
input.PumpInput(this, inputHandler);
input.PumpInput(this, inputHandler, lockedMousePosition);
}
public string GetClipboardText()