DrawList: renamed ImDrawFlags_StrokeCenterAligned to ImDrawFlags_StrokeCenterBiased.

This commit is contained in:
ocornut
2026-06-01 17:20:17 +02:00
parent 19ff3b31d8
commit 98f25f94aa
3 changed files with 16 additions and 16 deletions

View File

@@ -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,

View File

@@ -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();

View File

@@ -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)