From 6bc526676c45186ff8420fac3ecca71a3c3e87df Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 10 Sep 2020 11:02:40 +0200 Subject: [PATCH] Viewports: Comments, removed unnecessary use of ViewportFrontMostStampCount (the LastFrontMostStampCount is enough) --- imgui.cpp | 13 ++++++------- imgui_internal.h | 2 -- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index cb26785d..b8de6caf 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3493,7 +3493,7 @@ void ImGui::UpdateMouseMovingWindowNewFrame() g.MouseViewport = moving_window->Viewport; // Clear the NoInput window flag set by the Viewport system - moving_window->Viewport->Flags &= ~ImGuiViewportFlags_NoInputs; + moving_window->Viewport->Flags &= ~ImGuiViewportFlags_NoInputs; // FIXME-VIEWPORT: Test engine managed to crash here because Viewport was NULL. ClearActiveID(); g.MovingWindow = NULL; @@ -11523,6 +11523,7 @@ void ImGui::UpdatePlatformWindows() // Update our implicit z-order knowledge of platform windows, which is used when the back-end cannot provide io.MouseHoveredViewport. // When setting Platform_GetWindowFocus, it is expected that the platform back-end can handle calls without crashing if it doesn't have data stored. + // FIXME-VIEWPORT: We should use this information to also set dear imgui-side focus, allowing us to handle os-level alt+tab. if (g.PlatformIO.Platform_GetWindowFocus != NULL) { ImGuiViewportP* focused_viewport = NULL; @@ -11533,12 +11534,10 @@ void ImGui::UpdatePlatformWindows() if (g.PlatformIO.Platform_GetWindowFocus(viewport)) focused_viewport = viewport; } - if (focused_viewport && g.PlatformLastFocusedViewport != focused_viewport->ID) - { - if (focused_viewport->LastFrontMostStampCount != g.ViewportFrontMostStampCount) - focused_viewport->LastFrontMostStampCount = ++g.ViewportFrontMostStampCount; - g.PlatformLastFocusedViewport = focused_viewport->ID; - } + + // Store a tag so we can infer z-order easily from all our windows + if (focused_viewport && focused_viewport->LastFrontMostStampCount != g.ViewportFrontMostStampCount) + focused_viewport->LastFrontMostStampCount = ++g.ViewportFrontMostStampCount; } } diff --git a/imgui_internal.h b/imgui_internal.h index 607ae378..98c231ac 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1353,7 +1353,6 @@ struct ImGuiContext ImGuiViewportP* CurrentViewport; // We track changes of viewport (happening in Begin) so we can call Platform_OnChangedViewport() ImGuiViewportP* MouseViewport; ImGuiViewportP* MouseLastHoveredViewport; // Last known viewport that was hovered by mouse (even if we are not hovering any viewport any more) + honoring the _NoInputs flag. - ImGuiID PlatformLastFocusedViewport; // Record of last focused platform window/viewport, when this changes we stamp the viewport as front-most int ViewportFrontMostStampCount; // Every time the front-most window changes, we stamp its viewport with an incrementing counter // Gamepad/keyboard Navigation @@ -1558,7 +1557,6 @@ struct ImGuiContext CurrentDpiScale = 0.0f; CurrentViewport = NULL; MouseViewport = MouseLastHoveredViewport = NULL; - PlatformLastFocusedViewport = 0; ViewportFrontMostStampCount = 0; NavWindow = NULL;