Browse Source

Merged GetBackgroundDrawList()/GetForegroundDrawList() and GetBackgroundDrawList(ImGuiViewport* viewport)/GetForegroundDrawList(ImGuiViewport* viewport) api entry points.

ocornut 1 year ago
parent
commit
3fec562da1
3 changed files with 10 additions and 16 deletions
  1. 4 0
      docs/CHANGELOG.txt
  2. 4 12
      imgui.cpp
  3. 2 4
      imgui.h

+ 4 - 0
docs/CHANGELOG.txt

@@ -105,6 +105,10 @@ Docking+Viewports Branch:
 
 - Windows, Menus: Fixed an issue where the size of sub-menu in their own viewport
   would be erroneously clamped to the size of main viewport. (#7730)
+- Merged GetBackgroundDrawList() and GetBackgroundDrawList(ImGuiViewport* viewport)
+  api entry points into a same one GetBackgroundDrawList(ImGuiViewport* viewport = NULL);
+- Merged GetForegroundDrawList() and GetForegroundDrawList(ImGuiViewport* viewport)
+  api entry points into a same one GetForegroundDrawList(ImGuiViewport* viewport = NULL);
 - Backends: SDL3: Update for introduction of SDL_GLContext from void*. (#7701, #7702)
   [@bcsanches]
 - Backends: Win32: Secondary viewports WndProc handler retrieve/set imgui context from

+ 4 - 12
imgui.cpp

@@ -4519,26 +4519,18 @@ static ImDrawList* GetViewportBgFgDrawList(ImGuiViewportP* viewport, size_t draw
 
 ImDrawList* ImGui::GetBackgroundDrawList(ImGuiViewport* viewport)
 {
+    if (viewport == NULL)
+        viewport = GImGui->CurrentWindow->Viewport;
     return GetViewportBgFgDrawList((ImGuiViewportP*)viewport, 0, "##Background");
 }
 
-ImDrawList* ImGui::GetBackgroundDrawList()
-{
-    ImGuiContext& g = *GImGui;
-    return GetBackgroundDrawList(g.CurrentWindow->Viewport);
-}
-
 ImDrawList* ImGui::GetForegroundDrawList(ImGuiViewport* viewport)
 {
+    if (viewport == NULL)
+        viewport = GImGui->CurrentWindow->Viewport;
     return GetViewportBgFgDrawList((ImGuiViewportP*)viewport, 1, "##Foreground");
 }
 
-ImDrawList* ImGui::GetForegroundDrawList()
-{
-    ImGuiContext& g = *GImGui;
-    return GetForegroundDrawList(g.CurrentWindow->Viewport);
-}
-
 ImDrawListSharedData* ImGui::GetDrawListSharedData()
 {
     return &GImGui->DrawListSharedData;

+ 2 - 4
imgui.h

@@ -935,10 +935,8 @@ namespace ImGui
     IMGUI_API ImGuiViewport* GetMainViewport();                                                 // return primary/default viewport. This can never be NULL.
 
     // Background/Foreground Draw Lists
-    IMGUI_API ImDrawList*   GetBackgroundDrawList();                                            // get background draw list for the viewport associated to the current window. this draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents.
-    IMGUI_API ImDrawList*   GetForegroundDrawList();                                            // get foreground draw list for the viewport associated to the current window. this draw list will be the last rendered one. Useful to quickly draw shapes/text over dear imgui contents.
-    IMGUI_API ImDrawList*   GetBackgroundDrawList(ImGuiViewport* viewport);                     // get background draw list for the given viewport. this draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents.
-    IMGUI_API ImDrawList*   GetForegroundDrawList(ImGuiViewport* viewport);                     // get foreground draw list for the given viewport. this draw list will be the last rendered one. Useful to quickly draw shapes/text over dear imgui contents.
+    IMGUI_API ImDrawList*   GetBackgroundDrawList(ImGuiViewport* viewport = NULL);              // get background draw list for the given viewport or viewport associated to the current window. this draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents.
+    IMGUI_API ImDrawList*   GetForegroundDrawList(ImGuiViewport* viewport = NULL);              // get foreground draw list for the given viewport or viewport associated to the current window. this draw list will be the top-most rendered one. Useful to quickly draw shapes/text over dear imgui contents.
 
     // Miscellaneous Utilities
     IMGUI_API bool          IsRectVisible(const ImVec2& size);                                  // test if rectangle (of given size, starting from cursor position) is visible / not clipped.