Lock mouse position

This commit is contained in:
teinarss
2019-05-01 10:53:08 +02:00
committed by abcdefg30
parent 7bbfd823d0
commit ffd3834849
11 changed files with 101 additions and 73 deletions

View File

@@ -30,6 +30,7 @@ namespace OpenRA.Platforms.Default
Size windowSize;
Size surfaceSize;
float windowScale;
int2 mousePosition;
internal IntPtr Window
{
@@ -276,6 +277,22 @@ namespace OpenRA.Platforms.Default
}
}
public void SetRelativeMouseMode(bool mode)
{
if (mode)
{
int x, y;
SDL.SDL_GetMouseState(out x, out y);
mousePosition = 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);
}
}
internal void WindowSizeChanged()
{
// The ratio between pixels and points can change when moving between displays in OSX