From 3fec562da1d5af5f5c35e236e3e843ef0eadbcf3 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 28 Jun 2024 16:16:51 +0200 Subject: [PATCH] Merged GetBackgroundDrawList()/GetForegroundDrawList() and GetBackgroundDrawList(ImGuiViewport* viewport)/GetForegroundDrawList(ImGuiViewport* viewport) api entry points. --- docs/CHANGELOG.txt | 4 ++++ imgui.cpp | 16 ++++------------ imgui.h | 6 ++---- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 333a0a0c3..bd1adcdd1 100644 --- a/docs/CHANGELOG.txt +++ b/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 diff --git a/imgui.cpp b/imgui.cpp index ff69afd9f..b159e2a51 100644 --- a/imgui.cpp +++ b/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; diff --git a/imgui.h b/imgui.h index 7026368df..2d1c10c83 100644 --- a/imgui.h +++ b/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.