From 0b33acc92acb31f477703f8900a420d15f386335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Wed, 22 Nov 2017 08:48:43 +0100 Subject: [PATCH] UI - Fixed mouse behaviour when the pointer exits the window --- imgui_impl_sdl.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/imgui_impl_sdl.cc b/imgui_impl_sdl.cc index c089c6f..7484480 100644 --- a/imgui_impl_sdl.cc +++ b/imgui_impl_sdl.cc @@ -257,13 +257,15 @@ void ImGui_ImplSdl_NewFrame(SDL_Window *window , // (we already got mouse wheel, keyboard keys & characters from SDL_PollEvent()) int mx, my; Uint32 mouseMask = SDL_GetMouseState(&mx, &my); + static ImVec2 prevMouse{ -FLT_MAX , -FLT_MAX }; if ( mouseLock ) { io.MousePos = mousePos; } else { - if (SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_FOCUS) + if (SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_FOCUS) { io.MousePos = ImVec2((float)mx, (float)my); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) - else - io.MousePos = ImVec2(-1,-1); + prevMouse = io.MousePos; + } else + io.MousePos = prevMouse; } io.MouseDown[0] = g_MousePressed[0] || (mouseMask & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.