From 5051190b010ac5a642260fdfde494f17ebc1615f Mon Sep 17 00:00:00 2001 From: "Stefanos A." Date: Wed, 2 Oct 2013 17:55:30 +0200 Subject: [PATCH] MouseButtonUp and MouseMove fixes MouseMove no longer leaves the window borders when the cursor is invisible. MouseButtonUp events are now reported even when they occur outside the window. This aligns SDL2 behavior with the native drivers. --- .../OpenTK/Platform/SDL2/Sdl2NativeWindow.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs b/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs index d8e60943..06bbcce9 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs @@ -211,6 +211,15 @@ namespace OpenTK.Platform.SDL2 static void ProcessButtonEvent(Sdl2NativeWindow window, SDL.SDL_Event ev) { bool button_pressed = ev.button.state == SDL.SDL_PRESSED; + + // We need MouseUp events to be reported even if they occur + // outside the window. SetWindowGrab ensures we get them. + if (window.CursorVisible) + { + SDL.SDL_SetWindowGrab(window.window.Handle, + button_pressed ? SDL.SDL_bool.SDL_TRUE : SDL.SDL_bool.SDL_FALSE); + } + switch (ev.button.button) { case (byte)SDL.SDL_BUTTON_LEFT: @@ -244,16 +253,7 @@ namespace OpenTK.Platform.SDL2 static void ProcessMotionEvent(Sdl2NativeWindow window, SDL.SDL_Event ev) { - if (window.CursorVisible) - { window.mouse.Position = new Point(ev.motion.x, ev.motion.y); - } - else - { - window.mouse.Position = new Point( - window.mouse.X + ev.motion.xrel, - window.mouse.Y + ev.motion.yrel); - } } static void ProcessWheelEvent(Sdl2NativeWindow window, SDL.SDL_Event ev)