1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-15 19:43:28 +01:00

Backends: SDL: Fixed drag'n drop crossing a viewport border losing mouse coordinates. (#5710, #5012)

Amend 51bbc7065
This commit is contained in:
ocornut 2022-11-10 16:22:34 +01:00
parent a571933f8b
commit d7aca168ee
2 changed files with 18 additions and 7 deletions

View File

@ -103,6 +103,7 @@ struct ImGui_ImplSDL2_Data
int PendingMouseLeaveFrame;
char* ClipboardTextData;
bool MouseCanUseGlobalState;
bool MouseCanReportHoveredViewport; // This is hard to use/unreliable on SDL so we'll set ImGuiBackendFlags_HasMouseHoveredViewport dynamically based on state.
bool UseVulkan;
ImGui_ImplSDL2_Data() { memset((void*)this, 0, sizeof(*this)); }
@ -381,15 +382,17 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer, void
if (mouse_can_use_global_state)
io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; // We can create multi-viewports on the Platform side (optional)
// SDL on Linux/OSX doesn't report events for unfocused windows (see https://github.com/ocornut/imgui/issues/4960)
#ifndef __APPLE__
if (mouse_can_use_global_state)
io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport;// We can call io.AddMouseViewportEvent() with correct data (optional)
#endif
bd->Window = window;
bd->Renderer = renderer;
// SDL on Linux/OSX doesn't report events for unfocused windows (see https://github.com/ocornut/imgui/issues/4960)
// We will use 'MouseCanReportHoveredViewport' to set 'ImGuiBackendFlags_HasMouseHoveredViewport' dynamically each frame.
bd->MouseCanUseGlobalState = mouse_can_use_global_state;
#ifndef __APPLE__
bd->MouseCanReportHoveredViewport = bd->MouseCanUseGlobalState;
#else
bd->MouseCanReportHoveredViewport = false;
#endif
io.SetClipboardTextFn = ImGui_ImplSDL2_SetClipboardText;
io.GetClipboardTextFn = ImGui_ImplSDL2_GetClipboardText;
@ -509,7 +512,7 @@ static void ImGui_ImplSDL2_UpdateMouseData()
// We forward mouse input when hovered or captured (via SDL_MOUSEMOTION) or when focused (below)
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
// SDL_CaptureMouse() let the OS know e.g. that our imgui drag outside the SDL window boundaries shouldn't e.g. trigger other operations outside
SDL_CaptureMouse((bd->MouseButtonsDown != 0 && ImGui::GetDragDropPayload() == nullptr) ? SDL_TRUE : SDL_FALSE);
SDL_CaptureMouse((bd->MouseButtonsDown != 0) ? SDL_TRUE : SDL_FALSE);
SDL_Window* focused_window = SDL_GetKeyboardFocus();
const bool is_app_focused = (focused_window && (bd->Window == focused_window || ImGui::FindViewportByPlatformHandle((void*)focused_window)));
#else
@ -694,6 +697,13 @@ void ImGui_ImplSDL2_NewFrame()
io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
}
// Our io.AddMouseViewportEvent() calls will only be valid when not capturing.
// Technically speaking testing for 'bd->MouseButtonsDown == 0' would be more rygorous, but testing for payload reduces noise and potential side-effects.
if (bd->MouseCanReportHoveredViewport && ImGui::GetDragDropPayload() == nullptr)
io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport;
else
io.BackendFlags &= ~ImGuiBackendFlags_HasMouseHoveredViewport;
ImGui_ImplSDL2_UpdateMouseData();
ImGui_ImplSDL2_UpdateMouseCursor();

View File

@ -295,6 +295,7 @@ Docking+Viewports Branch:
- Docking+Viewports: Fixed undocking window node causing parent viewports to become unresponsive
in certain situation (e.g. hidden tab bar). (#5503) [@rokups]
- Backends: SDL: Fixed building backend under non-OSX Apple targets (e.g. iPhone). (#5665)
- Backends: SDL: Fixed drag'n drop crossing a viewport border losing mouse coordinates. (#5710, #5012)
- Backends: GLFW: Fixed leftover static variable preventing from changing or
reinitializing backend while application is running. (#4616, #5434) [@rtoumazet]