From 98f25f94aab60cdaa375a9e4532ae5b532cee905 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 1 Jun 2026 17:20:17 +0200 Subject: [PATCH] DrawList: renamed ImDrawFlags_StrokeCenterAligned to ImDrawFlags_StrokeCenterBiased. --- imgui.h | 2 +- imgui_demo.cpp | 2 +- imgui_draw.cpp | 28 ++++++++++++++-------------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/imgui.h b/imgui.h index 26953c791..11cb62c4f 100644 --- a/imgui.h +++ b/imgui.h @@ -3460,7 +3460,7 @@ enum ImDrawFlags_ // 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_StrokeCenterAligned = 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. Does not animate well! + 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. 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_StrokeMask_ = 0x07 << 16, diff --git a/imgui_demo.cpp b/imgui_demo.cpp index bc849e35e..3d65606ed 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -10448,7 +10448,7 @@ static void ShowExampleAppCustomRendering(bool* p_open) ImGui::RadioButton("Default", &stroke_flags, ImDrawFlags_None); ImGui::SameLine(); ImGui::RadioButton("Inside", &stroke_flags, ImDrawFlags_StrokeInside); ImGui::SameLine(); ImGui::RadioButton("Center", &stroke_flags, ImDrawFlags_StrokeCenter); ImGui::SameLine(); - ImGui::RadioButton("CenterAligned", &stroke_flags, ImDrawFlags_StrokeCenterAligned); ImGui::SameLine(); + ImGui::RadioButton("CenterBiased", &stroke_flags, ImDrawFlags_StrokeCenterBiased); ImGui::SameLine(); ImGui::RadioButton("Outside", &stroke_flags, ImDrawFlags_StrokeOutside); ImGui::SameLine(); ImGui::RadioButton("Legacy", &stroke_flags, ImDrawFlags_StrokeLegacy); ImGui::CheckboxFlags("MiterOnly", &other_flags, ImDrawFlags_MiterOnly); ImGui::SameLine(); diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 3946c0950..3ac88fed1 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -819,12 +819,12 @@ void ImDrawList::PrimQuadUV(const ImVec2& a, const ImVec2& b, const ImVec2& c, c } -static float CalculateCenterAlignedOffset(float thickness, float _FringeScale) +static float CalculateCenterBiasedOffset(float thickness, float _FringeScale) { // Old jumpy one. // return IM_TRUNC(thickness * 0.5f / _FringeScale) * _FringeScale; - // Calculate outside offset for stroke position CenterAligned + // Calculate outside offset for stroke position ImDrawFlags_StrokeCenterBiased // so that one side the of the line is always at pixel boundary. // On integer thickness both sides of the line are on pixel boundary. const float screen_thickness = thickness / _FringeScale; @@ -877,8 +877,8 @@ void ImDrawList::_AddPolyline(const ImVec2* points, ImVec2* normals, float* sqr_ float thickness0 = (thickness + fringe) * 0.5f; // Center (or legacy) if (stroke_pos == ImDrawFlags_StrokeOutside) thickness0 = thickness + fringe * 0.5f; - else if (stroke_pos == ImDrawFlags_StrokeCenterAligned) - thickness0 = CalculateCenterAlignedOffset(thickness, _FringeScale) + fringe * 0.5f; + else if (stroke_pos == ImDrawFlags_StrokeCenterBiased) + thickness0 = CalculateCenterBiasedOffset(thickness, _FringeScale) + fringe * 0.5f; else if (stroke_pos == ImDrawFlags_StrokeInside) thickness0 = fringe * 0.5f; float thickness1 = (thickness + fringe) - thickness0; @@ -2156,8 +2156,8 @@ void ImDrawList::AddLineH(float min_x, float max_x, float y, ImU32 col, float th float top_y = y; // Inside if (stroke_pos == ImDrawFlags_StrokeCenter) top_y -= thickness * 0.5f; - else if (stroke_pos == ImDrawFlags_StrokeCenterAligned) - top_y -= CalculateCenterAlignedOffset(thickness, _FringeScale); + else if (stroke_pos == ImDrawFlags_StrokeCenterBiased) + top_y -= CalculateCenterBiasedOffset(thickness, _FringeScale); else if (stroke_pos == ImDrawFlags_StrokeOutside) top_y -= thickness; @@ -2204,8 +2204,8 @@ void ImDrawList::AddLineV(float x, float min_y, float max_y, ImU32 col, float th float left_x = x; // Inside if (stroke_pos == ImDrawFlags_StrokeCenter) left_x -= thickness * 0.5f; - else if (stroke_pos == ImDrawFlags_StrokeCenterAligned) - left_x -= CalculateCenterAlignedOffset(thickness, _FringeScale); + else if (stroke_pos == ImDrawFlags_StrokeCenterBiased) + left_x -= CalculateCenterBiasedOffset(thickness, _FringeScale); else if (stroke_pos == ImDrawFlags_StrokeOutside) left_x -= thickness; @@ -2515,8 +2515,8 @@ void ImDrawList::AddRect(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, fl float offset = 0.0f; // Inside if (stroke_pos == ImDrawFlags_StrokeCenter) offset = thickness * 0.5f; - else if (stroke_pos == ImDrawFlags_StrokeCenterAligned) - offset = CalculateCenterAlignedOffset(thickness, _FringeScale); + else if (stroke_pos == ImDrawFlags_StrokeCenterBiased) + offset = CalculateCenterBiasedOffset(thickness, _FringeScale); else if (stroke_pos == ImDrawFlags_StrokeOutside) offset = thickness; outer_min.x -= offset; @@ -2816,8 +2816,8 @@ void ImDrawList::AddCircle(const ImVec2& center, float radius, ImU32 col, int nu float outer_radius = radius; if (stroke_pos == ImDrawFlags_StrokeCenter) outer_radius = radius + thickness * 0.5f; - else if (stroke_pos == ImDrawFlags_StrokeCenterAligned) - outer_radius = radius + CalculateCenterAlignedOffset(thickness, _FringeScale); + else if (stroke_pos == ImDrawFlags_StrokeCenterBiased) + outer_radius = radius + CalculateCenterBiasedOffset(thickness, _FringeScale); else if (stroke_pos == ImDrawFlags_StrokeInside) outer_radius = radius; else if (stroke_pos == ImDrawFlags_StrokeOutside) @@ -2903,8 +2903,8 @@ void ImDrawList::AddNgon(const ImVec2& center, float radius, ImU32 col, int num_ float outer_radius = radius; if (stroke_pos == ImDrawFlags_StrokeCenter) outer_radius = radius + miter_thickness * 0.5f; - else if (stroke_pos == ImDrawFlags_StrokeCenterAligned) - outer_radius = radius + CalculateCenterAlignedOffset(miter_thickness, _FringeScale); + else if (stroke_pos == ImDrawFlags_StrokeCenterBiased) + outer_radius = radius + CalculateCenterBiasedOffset(miter_thickness, _FringeScale); else if (stroke_pos == ImDrawFlags_StrokeInside) outer_radius = radius; else if (stroke_pos == ImDrawFlags_StrokeOutside)