UI - Fixed mouse behaviour when the pointer exits the window
This commit is contained in:
parent
f9a0b94055
commit
0b33acc92a
1 changed files with 5 additions and 3 deletions
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue