Relative mouse pos

This commit is contained in:
teinarss
2019-06-09 20:34:37 +02:00
committed by abcdefg30
parent d7643602c1
commit f325a4d190
3 changed files with 16 additions and 10 deletions

View File

@@ -130,9 +130,14 @@ namespace OpenRA.Platforms.Default
case SDL.SDL_EventType.SDL_MOUSEMOTION:
{
var input = lockedMousePosition ?? new int2(e.motion.x, e.motion.y);
var mousePos = new int2(e.motion.x, e.motion.y);
var input = lockedMousePosition ?? mousePos;
var pos = EventPosition(device, input.X, input.Y);
var delta = EventPosition(device, e.motion.xrel, e.motion.yrel);
var delta = lockedMousePosition == null
? EventPosition(device, e.motion.xrel, e.motion.yrel)
: mousePos - lockedMousePosition.Value;
pendingMotion = new MouseInput(
MouseInputEvent.Move, lastButtonBits, pos, delta, mods, 0);

View File

@@ -284,11 +284,9 @@ namespace OpenRA.Platforms.Default
int x, y;
SDL.SDL_GetMouseState(out x, out y);
lockedMousePosition = new int2(x, y);
SDL.SDL_SetRelativeMouseMode(SDL.SDL_bool.SDL_TRUE);
}
else
{
SDL.SDL_SetRelativeMouseMode(SDL.SDL_bool.SDL_FALSE);
if (lockedMousePosition.HasValue)
SDL.SDL_WarpMouseInWindow(window, lockedMousePosition.Value.X, lockedMousePosition.Value.Y);
@@ -352,6 +350,9 @@ namespace OpenRA.Platforms.Default
{
VerifyThreadAffinity();
input.PumpInput(this, inputHandler, lockedMousePosition);
if (lockedMousePosition.HasValue)
SDL.SDL_WarpMouseInWindow(window, lockedMousePosition.Value.X, lockedMousePosition.Value.Y);
}
public string GetClipboardText()