From e3fd9e1374d72b3e220ef502309c01192b9d5e41 Mon Sep 17 00:00:00 2001 From: thefiddler Date: Tue, 6 May 2014 09:36:30 +0200 Subject: [PATCH] [SDL] Avoid CursorVisible = true cursor jump --- Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs b/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs index 3bfc54e1..3f52e425 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs @@ -397,6 +397,16 @@ namespace OpenTK.Platform.SDL2 SDL.ShowCursor(!grab); SDL.SetWindowGrab(window.Handle, grab); SDL.SetRelativeMouseMode(grab); + if (!grab) + { + // Move the cursor to the current position + // in order to avoid a sudden jump when it + // becomes visible again + float scale = Width / (float)Size.Width; + SDL.WarpMouseInWindow(window.Handle, + (int)Math.Round(MouseState.X / scale), + (int)Math.Round(MouseState.Y / scale)); + } } // Hack to force WindowState events to be pumped