Skip to content

Commit

Permalink
Renamed internal RenderSortedWindows -> WindowsSortBuffer + cleanup p…
Browse files Browse the repository at this point in the history
…opup closing code
  • Loading branch information
ocornut committed Mar 26, 2015
1 parent fc25d71 commit a3086f4
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,7 @@ struct ImGuiState
int FrameCount;
int FrameCountRendered;
ImVector<ImGuiWindow*> Windows;
ImVector<ImGuiWindow*> WindowsSortBuffer;
ImGuiWindow* CurrentWindow; // Being drawn into
ImVector<ImGuiWindow*> CurrentWindowStack;
ImGuiWindow* FocusedWindow; // Will catch keyboard inputs
Expand Down Expand Up @@ -1124,7 +1125,6 @@ struct ImGuiState

// Render
ImVector<ImDrawList*> RenderDrawLists;
ImVector<ImGuiWindow*> RenderSortedWindows;

// Mouse cursor
ImGuiMouseCursor MouseCursor;
Expand Down Expand Up @@ -2034,7 +2034,7 @@ void ImGui::Shutdown()
g.StyleModifiers.clear();
g.FontStack.clear();
g.RenderDrawLists.clear();
g.RenderSortedWindows.clear();
g.WindowsSortBuffer.clear();
g.MouseCursorDrawList.ClearFreeMemory();
g.ColorEditModeStorage.Clear();
if (g.PrivateClipboard)
Expand Down Expand Up @@ -2142,18 +2142,18 @@ void ImGui::Render()

// Sort the window list so that all child windows are after their parent
// We cannot do that on FocusWindow() because childs may not exist yet
g.RenderSortedWindows.resize(0);
g.RenderSortedWindows.reserve(g.Windows.size());
g.WindowsSortBuffer.resize(0);
g.WindowsSortBuffer.reserve(g.Windows.size());
for (size_t i = 0; i != g.Windows.size(); i++)
{
ImGuiWindow* window = g.Windows[i];
if (window->Flags & ImGuiWindowFlags_ChildWindow) // if a child is visible its parent will add it
if (window->Visible)
continue;
AddWindowToSortedBuffer(window, g.RenderSortedWindows);
AddWindowToSortedBuffer(window, g.WindowsSortBuffer);
}
IM_ASSERT(g.Windows.size() == g.RenderSortedWindows.size()); // we done something wrong
g.Windows.swap(g.RenderSortedWindows);
IM_ASSERT(g.Windows.size() == g.WindowsSortBuffer.size()); // we done something wrong
g.Windows.swap(g.WindowsSortBuffer);

// Clear data for next frame
g.IO.MouseWheel = 0.0f;
Expand Down Expand Up @@ -3311,9 +3311,15 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_
}
if (window->Flags & ImGuiWindowFlags_Popup)
{
if ((g.IO.MouseClicked[0] && (!g.HoveredWindow || g.HoveredWindow->RootWindow != window)) || (!g.FocusedWindow || g.FocusedWindow->RootWindow != window))
if (p_opened)
if (p_opened)
{
if (g.IO.MouseClicked[0] && (!g.HoveredWindow || g.HoveredWindow->RootWindow != window))
*p_opened = false;
else if (!g.FocusedWindow)
*p_opened = false;
else if (g.FocusedWindow->RootWindow != window)// && !(g.FocusedWindow->RootWindow->Flags & ImGuiWindowFlags_Tooltip))
*p_opened = false;
}
}

// Save clipped aabb so we can access it in constant-time in FindHoveredWindow()
Expand Down

0 comments on commit a3086f4

Please sign in to comment.