From b2ade5f3ada2091a7b01d93e3ddaf238a5d9247e Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 6 Oct 2026 18:02:37 +0200 Subject: [PATCH] DrawList: AddRectFilled: add support for ImDrawFlags_StrokeLegacy to handle inverted coordinates + non-AA path. Fix cases 207 and 251 in testbed. + add braces near an IM_APPEND_TRI() to silence PVS-Studio reasonable warning "V640 The code's operational logic does not correspond with its formatting" --- docs/CHANGELOG.txt | 1 + imgui_draw.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 63c7ed07b..f93dfe8d6 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -146,6 +146,7 @@ Breaking Changes: - Legacy `AddRect()` rounding on -> visible but very glitchy. - Legacy `AddRectFilled()` rounding off -> visible and correct. - Legacy `AddRectFilled()` rounding on -> visible but very glitchy. + - Use `ImDrawFlags_StrokeLegacy` to use old rendering for cases without rounding, or fix coordinates. - Merged `ImDrawListFlags` into `ImDrawFlags`. `ImDrawListFlags` was rarely used directly and generally setup by the ImGui context. Keep inline redirection enums (will obsolete). - `ImDrawListFlags_AntiAliasedLines` -> `ImDrawFlags_AALines` diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 4cf094c57..83ceaddc0 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -871,6 +871,7 @@ float ImDrawList::_CalculateCenterBiasedOffset(float thickness) IM_MSVC_RUNTIME_CHECKS_RESTORE // Check if R is considered to be worthy rounding. Can be only used within ImDrawList due to use of _FringeScale. +// FIXME-OPT: Given unused padding space in ImDrawList would it make sense to store 0.25f * _FringeScale? #define IM_HAS_ROUNDING(RAD) ((RAD) >= (0.25f * _FringeScale)) // On AddPolyline() and AddConvexPolyFilled() we intentionally avoid using ImVec2 and superfluous function calls to optimize debug/non-inlined builds. @@ -2306,7 +2307,9 @@ void ImDrawList::_AddRectTinyRounding(const ImVec2& p_min, const ImVec2& p_max, // Arc if (is_rounded) for (int i = 0; i < arc_point_count - 1; i++) + { IM_APPEND_TRI(stem_idx, arc_idx + i, arc_idx + i + 1); + } // Connect with previous IM_APPEND_TRI(base_idx + 0, arc_idx, stem_idx); @@ -2539,6 +2542,13 @@ void ImDrawList::AddRectFilled(const ImVec2& p_min, const ImVec2& p_max, ImU32 c const float min_dim = ImMin(width, height); flags |= Flags; + if ((flags & ImDrawFlags_StrokeMask_) == ImDrawFlags_StrokeLegacy && rounding < 0.5f) IM_UNLIKELY + { + PrimReserve(6, 4); + PrimRect(p_min, p_max, col); + return; + } + // The rect is smaller than pixel in one dimension. if (min_dim < _FringeScale) IM_UNLIKELY {