From 873afffd8f1ec7ed828721ddb11e4feb7dcdc6f7 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 27 Jul 2026 19:57:03 +0200 Subject: [PATCH] DrawList: inverted ImDrawFlags_NoAAEnds into ImDrawFlags_AAEnds. --- docs/CHANGELOG.txt | 6 +++--- imgui.h | 4 ++-- imgui_demo.cpp | 4 ++-- imgui_draw.cpp | 16 ++++++++-------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index d06d1f572..be4c80ca0 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -77,7 +77,7 @@ HOW TO UPDATE? Being anti-aliased diagonal lines, they won't look particularly better or worse, just slightly offset. It'll likely only be noticeable if you carefully combined them with other primitives for a pixel-perfect result. - Old AddLine({x1, y1}, {x2, y2}, col) == AddLine({x1, y1}, {x2, y2}, col, thickness, ImDrawFlags_StrokeLegacy); // Offset by +0.5f + disable AA ends. - == AddLine({x1 + 0.5f, y1 + 0.5f}, {x2+ 0.5f, y2 + 0.5f}, col, thickness, ImDrawFlags_NoAAEnds); // Same + == AddLine({x1 + 0.5f, y1 + 0.5f}, {x2+ 0.5f, y2 + 0.5f}, col, thickness); // Same This reapplies the old offset, and should get you exactly the same result you previously got for thickness=1.0f lines. But said result was sometimes ambiguous and renderer dependent. (#3116, #3258, #2441) - Old AddLine() did not have anti-aliased ends, which could create gaps when rendering shapes out @@ -93,8 +93,8 @@ HOW TO UPDATE? but the artifacts should be more localized. The new implementation attempted to favor simple implementation and robustness over the corner case accuracy. - Added anti-aliasing ends, most noticeable for thick lines. - - Added `ImDrawFlags_NoAAEnds` flag to disable anti-aliased line ends (slightly faster - and reduce vertex/index data). + - Added `ImDrawFlags_AAEnds` flag to enable anti-aliased line ends. Enabling AA Ends by + default would be more "correct", but it is slower and increase vertex/index data. - Added `ImDrawFlags_MiterOnly` flag to disable using beveled corner (closer to legacy rendering, slightly faster, but corners sharpers than 90 degrees may expand far out). Automatically used by AddRect(), AddCircle(), AddNgon(), AddEllipse() etc functions diff --git a/imgui.h b/imgui.h index 0afe29435..24264dba0 100644 --- a/imgui.h +++ b/imgui.h @@ -3433,14 +3433,14 @@ enum ImDrawFlags_ ImDrawFlags_Closed = 1 << 9, // PathStroke(), AddPolyline(): specify that shape should be closed. ImDrawFlags_MiterOnly = 1 << 10, // PathStroke(), AddPolyline(): use miter corners only. This assumes that the input polyline does not have corners sharper than 90 degrees. Slightly faster. ImDrawFlags_SquareCap = 1 << 11, // PathStroke(), AddPolyline(): use square cap line ends. - ImDrawFlags_NoAAEnds = 1 << 12, // PathStroke(), AddPolyline(): do not generate anti-aliased line ends. This can speed up single line rendering. + ImDrawFlags_AAEnds = 1 << 12, // PathStroke(), AddPolyline(): generate anti-aliased line ends. // Stroke position relative to the shape outline ImDrawFlags_StrokeInside = 1 << 16, // Draw stroke inside of the shape outline (default for closed shapes and AddLineH, AddLineV functions) ImDrawFlags_StrokeCenter = 2 << 16, // Draw stroke at the center of the shape outline (default for paths, bezier, and AddLine functions) ImDrawFlags_StrokeCenterBiased = 3 << 16, // Draw stroke at the center of the shape outline, so that half thickness rounded down will be outside, and rest inside the shape outline. Useful for axis-aligned shapes: AddLineH, AddLineV, AddRect. Does not animate well! ImDrawFlags_StrokeOutside = 4 << 16, // Draw stroke outside of the shape outline - ImDrawFlags_StrokeLegacy = 5 << 16, // Use legacy positioning + enable MiterOnly and NoAAEnds flags. + ImDrawFlags_StrokeLegacy = 5 << 16, // Use legacy positioning + enable MiterOnly, disable AAEnds flags. ImDrawFlags_StrokeMask_ = 0x07 << 16, ImDrawFlags_InvalidMask_ = ~0x7FFFFFF0, // == 0x8000000F, diff --git a/imgui_demo.cpp b/imgui_demo.cpp index b38b732bd..80be1f9ea 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -10453,7 +10453,7 @@ static void ShowExampleAppCustomRendering(bool* p_open) ImGui::ColorEdit4("Stroke Color", &colf_stroke.x); ImGui::ColorEdit4("Fill Color", &colf_fill.x); - static ImDrawFlags stroke_flags = ImDrawFlags_None; + static ImDrawFlags stroke_flags = ImDrawFlags_AAEnds; static ImDrawFlags other_flags = ImDrawFlags_None; ImGui::Text("Stroke Flags:"); ImGui::RadioButton("Default", &stroke_flags, ImDrawFlags_None); ImGui::SameLine(); @@ -10464,7 +10464,7 @@ static void ShowExampleAppCustomRendering(bool* p_open) ImGui::RadioButton("Legacy", &stroke_flags, ImDrawFlags_StrokeLegacy); ImGui::CheckboxFlags("MiterOnly", &other_flags, ImDrawFlags_MiterOnly); ImGui::SameLine(); ImGui::CheckboxFlags("SquareCap", &other_flags, ImDrawFlags_SquareCap); ImGui::SameLine(); - ImGui::CheckboxFlags("NoAAEnds", &other_flags, ImDrawFlags_NoAAEnds); + ImGui::CheckboxFlags("AAEnds", &other_flags, ImDrawFlags_AAEnds); ImGui::Spacing(); const ImDrawFlags flags = stroke_flags | other_flags; diff --git a/imgui_draw.cpp b/imgui_draw.cpp index f3a297d9a..422647660 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -981,14 +981,14 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32 tex_uvs.z = _Data->TexUvWhitePixel.y; // v tex_uvs.w = 0.0f; // 1/thickness, unused. fringe = 0.0f; - flags |= ImDrawFlags_NoAAEnds; + flags &= ~ImDrawFlags_AAEnds; } const ImU32 col_trans = col & ~IM_COL32_A_MASK; const ImDrawFlags stroke_pos = _GetStrokePos(flags, ImDrawFlags_StrokeCenter); if (stroke_pos == ImDrawFlags_StrokeLegacy) - flags |= ImDrawFlags_MiterOnly | ImDrawFlags_NoAAEnds; + flags = (flags | ImDrawFlags_MiterOnly) & ~ImDrawFlags_AAEnds; const bool closed = (flags & ImDrawFlags_Closed) != 0; const bool miters_only = (flags & ImDrawFlags_MiterOnly) != 0; @@ -1060,7 +1060,7 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32 p1.y -= dir.y * half_thickness; } - if (flags & ImDrawFlags_NoAAEnds) + if ((flags & ImDrawFlags_AAEnds) == 0) { base_idx = (int)_VtxCurrentIdx; IM_APPEND_VTX(p1.x - n1.x * thickness0, p1.y - n1.y * thickness0, uv0, col); @@ -1246,7 +1246,7 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32 p1.y += dir.y * half_thickness; } - if (flags & ImDrawFlags_NoAAEnds) + if ((flags & ImDrawFlags_AAEnds) == 0) { IM_APPEND_VTX(p1.x - n1.x * thickness0, p1.y - n1.y * thickness0, uv0, col); IM_APPEND_VTX(p1.x + n1.x * thickness1, p1.y + n1.y * thickness1, uv1, col); @@ -2218,7 +2218,7 @@ void ImDrawList::_AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float t tex_uvs.z = _Data->TexUvWhitePixel.y; // v tex_uvs.w = 0.0f; // 1/thickness, unused. fringe = 0.0f; - flags |= ImDrawFlags_NoAAEnds; + flags &= ~ImDrawFlags_AAEnds; } float dir_x = p2.x - p1.x; @@ -2234,7 +2234,7 @@ void ImDrawList::_AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float t const ImDrawFlags stroke_pos = _GetStrokePos(flags, ImDrawFlags_StrokeCenter); if (stroke_pos == ImDrawFlags_StrokeLegacy) - flags |= ImDrawFlags_MiterOnly | ImDrawFlags_NoAAEnds; + flags = (flags | ImDrawFlags_MiterOnly) & ~ImDrawFlags_AAEnds; float thickness0 = (thickness + fringe) * 0.5f; // Center (or legacy) if (stroke_pos == ImDrawFlags_StrokeOutside) @@ -2259,7 +2259,7 @@ void ImDrawList::_AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float t const float half_aa = _FringeScale * 0.5f; // Used for end caps, does not use "fringe" since end cap AA is not using the texture. const float half_thickness = thickness * 0.5f; - if (flags & ImDrawFlags_NoAAEnds) + if ((flags & ImDrawFlags_AAEnds) == 0) PrimReserve(2*3, 4); else PrimReserve(6*3, 8); @@ -2280,7 +2280,7 @@ void ImDrawList::_AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float t } // Start cap - if (flags & ImDrawFlags_NoAAEnds) + if ((flags & ImDrawFlags_AAEnds) == 0) { base_idx = (int)_VtxCurrentIdx; IM_APPEND_VTX(p1_x - norm_x * thickness0, p1_y - norm_y * thickness0, uv0, col);