Browse Source

Renamed internal RenderSortedWindows -> WindowsSortBuffer + cleanup popup closing code

ocornut 10 years ago
parent
commit
a3086f40fe
1 changed files with 15 additions and 9 deletions
  1. 15 9
      imgui.cpp

+ 15 - 9
imgui.cpp

@@ -1095,6 +1095,7 @@ struct ImGuiState
     int                     FrameCount;
     int                     FrameCount;
     int                     FrameCountRendered;
     int                     FrameCountRendered;
     ImVector<ImGuiWindow*>  Windows;
     ImVector<ImGuiWindow*>  Windows;
+    ImVector<ImGuiWindow*>  WindowsSortBuffer;
     ImGuiWindow*            CurrentWindow;                      // Being drawn into
     ImGuiWindow*            CurrentWindow;                      // Being drawn into
     ImVector<ImGuiWindow*>  CurrentWindowStack;
     ImVector<ImGuiWindow*>  CurrentWindowStack;
     ImGuiWindow*            FocusedWindow;                      // Will catch keyboard inputs
     ImGuiWindow*            FocusedWindow;                      // Will catch keyboard inputs
@@ -1124,7 +1125,6 @@ struct ImGuiState
 
 
     // Render
     // Render
     ImVector<ImDrawList*>   RenderDrawLists;
     ImVector<ImDrawList*>   RenderDrawLists;
-    ImVector<ImGuiWindow*>  RenderSortedWindows;
 
 
     // Mouse cursor
     // Mouse cursor
     ImGuiMouseCursor        MouseCursor;
     ImGuiMouseCursor        MouseCursor;
@@ -2034,7 +2034,7 @@ void ImGui::Shutdown()
     g.StyleModifiers.clear();
     g.StyleModifiers.clear();
     g.FontStack.clear();
     g.FontStack.clear();
     g.RenderDrawLists.clear();
     g.RenderDrawLists.clear();
-    g.RenderSortedWindows.clear();
+    g.WindowsSortBuffer.clear();
     g.MouseCursorDrawList.ClearFreeMemory();
     g.MouseCursorDrawList.ClearFreeMemory();
     g.ColorEditModeStorage.Clear();
     g.ColorEditModeStorage.Clear();
     if (g.PrivateClipboard)
     if (g.PrivateClipboard)
@@ -2142,18 +2142,18 @@ void ImGui::Render()
 
 
         // Sort the window list so that all child windows are after their parent
         // 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
         // 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++)
         for (size_t i = 0; i != g.Windows.size(); i++)
         {
         {
             ImGuiWindow* window = g.Windows[i];
             ImGuiWindow* window = g.Windows[i];
             if (window->Flags & ImGuiWindowFlags_ChildWindow)           // if a child is visible its parent will add it
             if (window->Flags & ImGuiWindowFlags_ChildWindow)           // if a child is visible its parent will add it
                 if (window->Visible)
                 if (window->Visible)
                     continue;
                     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
         // Clear data for next frame
         g.IO.MouseWheel = 0.0f;
         g.IO.MouseWheel = 0.0f;
@@ -3311,9 +3311,15 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_
         }
         }
         if (window->Flags & ImGuiWindowFlags_Popup)
         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;
                     *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()
         // Save clipped aabb so we can access it in constant-time in FindHoveredWindow()