Skip to content

Commit

Permalink
Viewports: Comments, removed unnecessary use of ViewportFrontMostStam…
Browse files Browse the repository at this point in the history
…pCount (the LastFrontMostStampCount is enough)
  • Loading branch information
ocornut committed Sep 16, 2020
1 parent e230ec5 commit 6bc5266
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 6 additions & 7 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}

Expand Down
2 changes: 0 additions & 2 deletions imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1558,7 +1557,6 @@ struct ImGuiContext
CurrentDpiScale = 0.0f;
CurrentViewport = NULL;
MouseViewport = MouseLastHoveredViewport = NULL;
PlatformLastFocusedViewport = 0;
ViewportFrontMostStampCount = 0;

NavWindow = NULL;
Expand Down

0 comments on commit 6bc5266

Please sign in to comment.