From e3e4b7bdf5dede380bc227c238cbb2026ca6a47d Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 24 Apr 2018 17:09:50 +0200 Subject: [PATCH] Viewport: Fixed mouse hover flicker on mouse button release frame after moving a window. (#1542) Platform: Clarifying some comments in back-ends. --- TODO.txt | 1 + examples/imgui_impl_dx10.cpp | 10 ++++------ examples/imgui_impl_dx11.cpp | 10 ++++------ examples/imgui_impl_dx12.cpp | 4 +++- examples/imgui_impl_glfw.cpp | 8 +++++--- examples/imgui_impl_opengl2.cpp | 4 +++- examples/imgui_impl_opengl3.cpp | 4 +++- examples/imgui_impl_sdl2.cpp | 4 +++- examples/imgui_impl_vulkan.cpp | 5 ++++- examples/imgui_impl_win32.cpp | 4 +++- imgui.cpp | 6 +++++- 11 files changed, 38 insertions(+), 22 deletions(-) diff --git a/TODO.txt b/TODO.txt index 3fff67ed..69f88df7 100644 --- a/TODO.txt +++ b/TODO.txt @@ -262,6 +262,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - viewport: platform: introduce getfocus/setfocus api, so e.g. focus flags can be honored, imgui-side ctrl-tab can focus os window, OS alt-tab can focus imgui window etc. - viewport: store per-viewport/monitor DPI in .ini file so an application reload or main window changing DPI on reload can be properly patched for. - viewport: vulkan renderer implementation. + - viewport: fallback calculation of hovered window is very currently wrong without ImGuiBackendFlags_HasMouseHoveredViewport. typically affect half-overlapping viewported menus. - viewport: need to clarify how to use GetMousePos() from a user point of view. - inputs: we need an explicit flag about whether the imgui window is focused, to be able to distinguish focused key releases vs alt-tabbing all release behaviors. diff --git a/examples/imgui_impl_dx10.cpp b/examples/imgui_impl_dx10.cpp index db6f99d6..2201bb76 100644 --- a/examples/imgui_impl_dx10.cpp +++ b/examples/imgui_impl_dx10.cpp @@ -504,7 +504,9 @@ void ImGui_ImplDX10_NewFrame() } //-------------------------------------------------------------------------------------------------------- -// Platform Interface (Optional, for multi-viewport support) +// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT +// This is an _advanced_ and _optional_ feature, allowing the back-end to create and handle multiple viewports simultaneously. +// If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- struct ImGuiViewportDataDx10 @@ -581,11 +583,7 @@ static void ImGui_ImplDX10_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) ID3D10Texture2D* pBackBuffer = NULL; data->SwapChain->ResizeBuffers(0, (UINT)size.x, (UINT)size.y, DXGI_FORMAT_UNKNOWN, 0); data->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer)); - if (pBackBuffer == NULL) - { - fprintf(stderr, "ImGui_ImplDX10_SetWindowSize() can't created buffers.\n"); - return; - } + if (pBackBuffer == NULL) { fprintf(stderr, "ImGui_ImplDX10_SetWindowSize() failed creating buffers.\n"); return; } g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &data->RTView); pBackBuffer->Release(); } diff --git a/examples/imgui_impl_dx11.cpp b/examples/imgui_impl_dx11.cpp index 9f5b3824..d9308e04 100644 --- a/examples/imgui_impl_dx11.cpp +++ b/examples/imgui_impl_dx11.cpp @@ -512,7 +512,9 @@ void ImGui_ImplDX11_NewFrame() } //-------------------------------------------------------------------------------------------------------- -// Platform Interface (Optional, for multi-viewport support) +// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT +// This is an _advanced_ and _optional_ feature, allowing the back-end to create and handle multiple viewports simultaneously. +// If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- struct ImGuiViewportDataDx11 @@ -589,11 +591,7 @@ static void ImGui_ImplDX11_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) ID3D11Texture2D* pBackBuffer = NULL; data->SwapChain->ResizeBuffers(0, (UINT)size.x, (UINT)size.y, DXGI_FORMAT_UNKNOWN, 0); data->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer)); - if (pBackBuffer == NULL) - { - fprintf(stderr, "ImGui_ImplDX11_SetWindowSize() can't created buffers.\n"); - return; - } + if (pBackBuffer == NULL) { fprintf(stderr, "ImGui_ImplDX11_SetWindowSize() failed creating buffers.\n"); return; } g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &data->RTView); pBackBuffer->Release(); } diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index 9ae3a0d3..76d17b85 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -637,7 +637,9 @@ void ImGui_ImplDX12_NewFrame(ID3D12GraphicsCommandList* command_list) } //-------------------------------------------------------------------------------------------------------- -// Platform Interface (Optional, for multi-viewport support) +// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT +// This is an _advanced_ and _optional_ feature, allowing the back-end to create and handle multiple viewports simultaneously. +// If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- struct ImGuiViewportDataDx12 diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index 0c74aa2c..cd04bc48 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -317,9 +317,11 @@ void ImGui_ImplGlfw_NewFrame() ImGui::NewFrame(); } -// -------------------------------------------------------------------------------------------------------- -// Platform Windows -// -------------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------------- +// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT +// This is an _advanced_ and _optional_ feature, allowing the back-end to create and handle multiple viewports simultaneously. +// If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. +//-------------------------------------------------------------------------------------------------------- struct ImGuiViewportDataGlfw { diff --git a/examples/imgui_impl_opengl2.cpp b/examples/imgui_impl_opengl2.cpp index f4d848a8..e43b20ef 100644 --- a/examples/imgui_impl_opengl2.cpp +++ b/examples/imgui_impl_opengl2.cpp @@ -211,7 +211,9 @@ void ImGui_ImplOpenGL2_DestroyDeviceObjects() } //-------------------------------------------------------------------------------------------------------- -// Platform Interface (Optional, for multi-viewport support) +// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT +// This is an _advanced_ and _optional_ feature, allowing the back-end to create and handle multiple viewports simultaneously. +// If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- static void ImGui_ImplOpenGL2_RenderWindow(ImGuiViewport* viewport, void*) diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 99012c83..5217408f 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -330,7 +330,9 @@ void ImGui_ImplOpenGL3_DestroyDeviceObjects() } //-------------------------------------------------------------------------------------------------------- -// Platform Interface (Optional, for multi-viewport support) +// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT +// This is an _advanced_ and _optional_ feature, allowing the back-end to create and handle multiple viewports simultaneously. +// If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- static void ImGui_ImplOpenGL3_RenderWindow(ImGuiViewport* viewport, void*) diff --git a/examples/imgui_impl_sdl2.cpp b/examples/imgui_impl_sdl2.cpp index 6b25e906..089761bb 100644 --- a/examples/imgui_impl_sdl2.cpp +++ b/examples/imgui_impl_sdl2.cpp @@ -276,7 +276,9 @@ void ImGui_ImplSDL2_NewFrame(SDL_Window* window) } //-------------------------------------------------------------------------------------------------------- -// Platform Interface (Optional, for multi-viewport support) +// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT +// This is an _advanced_ and _optional_ feature, allowing the back-end to create and handle multiple viewports simultaneously. +// If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- struct ImGuiViewportDataSDL2 diff --git a/examples/imgui_impl_vulkan.cpp b/examples/imgui_impl_vulkan.cpp index 4824b0b1..9f46f04b 100644 --- a/examples/imgui_impl_vulkan.cpp +++ b/examples/imgui_impl_vulkan.cpp @@ -1059,7 +1059,10 @@ void ImGui_ImplVulkanH_DestroyWindowData(VkInstance instance, VkDevice device, I } //-------------------------------------------------------------------------------------------------------- -// Platform Interface (Optional, for multi-viewport support) +// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT +// This is an _advanced_ and _optional_ feature, allowing the back-end to create and handle multiple viewports simultaneously. +// If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. +//-------------------------------------------------------------------------------------------------------- // FIXME-PLATFORM: Vulkan support unfinished //-------------------------------------------------------------------------------------------------------- diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index b90b7a26..b4412d0e 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -390,7 +390,9 @@ static void ImGui_ImplWin32_SetImeInputPos(ImGuiViewport* viewport, ImVec2 pos) #endif //-------------------------------------------------------------------------------------------------------- -// Platform Windows +// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT +// This is an _advanced_ and _optional_ feature, allowing the back-end to create and handle multiple viewports simultaneously. +// If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- struct ImGuiViewportDataWin32 diff --git a/imgui.cpp b/imgui.cpp index cbdc1fe1..064b1937 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3357,7 +3357,11 @@ static void ImGui::UpdateMovingWindow() { UpdateTryMergeWindowIntoHostViewport(moving_window, g.MouseRefViewport); - // Clear the NoInput flag set by the Viewport system + // Patch the mouse viewport so that we don't hover under the moved window during the mouse released frame + if (!IsDragDropPayloadBeingAccepted()) + g.MouseRefViewport = moving_window->Viewport; + + // Clear the NoInput window flag set by the Viewport system moving_window->Viewport->Flags &= ~ImGuiViewportFlags_NoInputs; ClearActiveID();