DrawList: renamed ImDrawFlags_StrokeCenterAligned to ImDrawFlags_StrokeCenterBiased.

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

View File

@ -3344,7 +3344,7 @@ enum ImDrawFlags_
// Stroke position relative to the shape outline // 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_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_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_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 and NoAAEnds flags.
ImDrawFlags_StrokeMask_ = 0x07 << 16, ImDrawFlags_StrokeMask_ = 0x07 << 16,

View File

@ -10425,7 +10425,7 @@ static void ShowExampleAppCustomRendering(bool* p_open)
ImGui::RadioButton("Default", &stroke_flags, ImDrawFlags_None); ImGui::SameLine(); ImGui::RadioButton("Default", &stroke_flags, ImDrawFlags_None); ImGui::SameLine();
ImGui::RadioButton("Inside", &stroke_flags, ImDrawFlags_StrokeInside); ImGui::SameLine(); ImGui::RadioButton("Inside", &stroke_flags, ImDrawFlags_StrokeInside); ImGui::SameLine();
ImGui::RadioButton("Center", &stroke_flags, ImDrawFlags_StrokeCenter); 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("Outside", &stroke_flags, ImDrawFlags_StrokeOutside); ImGui::SameLine();
ImGui::RadioButton("Legacy", &stroke_flags, ImDrawFlags_StrokeLegacy); ImGui::RadioButton("Legacy", &stroke_flags, ImDrawFlags_StrokeLegacy);
ImGui::CheckboxFlags("MiterOnly", &other_flags, ImDrawFlags_MiterOnly); ImGui::SameLine(); ImGui::CheckboxFlags("MiterOnly", &other_flags, ImDrawFlags_MiterOnly); ImGui::SameLine();

View File

@ -813,12 +813,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. // Old jumpy one.
// return IM_TRUNC(thickness * 0.5f / _FringeScale) * _FringeScale; // 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. // 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. // On integer thickness both sides of the line are on pixel boundary.
const float screen_thickness = thickness / _FringeScale; const float screen_thickness = thickness / _FringeScale;
@ -871,8 +871,8 @@ void ImDrawList::_AddPolyline(const ImVec2* points, ImVec2* normals, float* sqr_
float thickness0 = (thickness + fringe) * 0.5f; // Center (or legacy) float thickness0 = (thickness + fringe) * 0.5f; // Center (or legacy)
if (stroke_pos == ImDrawFlags_StrokeOutside) if (stroke_pos == ImDrawFlags_StrokeOutside)
thickness0 = thickness + fringe * 0.5f; thickness0 = thickness + fringe * 0.5f;
else if (stroke_pos == ImDrawFlags_StrokeCenterAligned) else if (stroke_pos == ImDrawFlags_StrokeCenterBiased)
thickness0 = CalculateCenterAlignedOffset(thickness, _FringeScale) + fringe * 0.5f; thickness0 = CalculateCenterBiasedOffset(thickness, _FringeScale) + fringe * 0.5f;
else if (stroke_pos == ImDrawFlags_StrokeInside) else if (stroke_pos == ImDrawFlags_StrokeInside)
thickness0 = fringe * 0.5f; thickness0 = fringe * 0.5f;
float thickness1 = (thickness + fringe) - thickness0; float thickness1 = (thickness + fringe) - thickness0;
@ -2150,8 +2150,8 @@ void ImDrawList::AddLineH(float min_x, float max_x, float y, ImU32 col, float th
float top_y = y; // Inside float top_y = y; // Inside
if (stroke_pos == ImDrawFlags_StrokeCenter) if (stroke_pos == ImDrawFlags_StrokeCenter)
top_y -= thickness * 0.5f; top_y -= thickness * 0.5f;
else if (stroke_pos == ImDrawFlags_StrokeCenterAligned) else if (stroke_pos == ImDrawFlags_StrokeCenterBiased)
top_y -= CalculateCenterAlignedOffset(thickness, _FringeScale); top_y -= CalculateCenterBiasedOffset(thickness, _FringeScale);
else if (stroke_pos == ImDrawFlags_StrokeOutside) else if (stroke_pos == ImDrawFlags_StrokeOutside)
top_y -= thickness; top_y -= thickness;
@ -2198,8 +2198,8 @@ void ImDrawList::AddLineV(float x, float min_y, float max_y, ImU32 col, float th
float left_x = x; // Inside float left_x = x; // Inside
if (stroke_pos == ImDrawFlags_StrokeCenter) if (stroke_pos == ImDrawFlags_StrokeCenter)
left_x -= thickness * 0.5f; left_x -= thickness * 0.5f;
else if (stroke_pos == ImDrawFlags_StrokeCenterAligned) else if (stroke_pos == ImDrawFlags_StrokeCenterBiased)
left_x -= CalculateCenterAlignedOffset(thickness, _FringeScale); left_x -= CalculateCenterBiasedOffset(thickness, _FringeScale);
else if (stroke_pos == ImDrawFlags_StrokeOutside) else if (stroke_pos == ImDrawFlags_StrokeOutside)
left_x -= thickness; left_x -= thickness;
@ -2509,8 +2509,8 @@ void ImDrawList::AddRect(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, fl
float offset = 0.0f; // Inside float offset = 0.0f; // Inside
if (stroke_pos == ImDrawFlags_StrokeCenter) if (stroke_pos == ImDrawFlags_StrokeCenter)
offset = thickness * 0.5f; offset = thickness * 0.5f;
else if (stroke_pos == ImDrawFlags_StrokeCenterAligned) else if (stroke_pos == ImDrawFlags_StrokeCenterBiased)
offset = CalculateCenterAlignedOffset(thickness, _FringeScale); offset = CalculateCenterBiasedOffset(thickness, _FringeScale);
else if (stroke_pos == ImDrawFlags_StrokeOutside) else if (stroke_pos == ImDrawFlags_StrokeOutside)
offset = thickness; offset = thickness;
outer_min.x -= offset; outer_min.x -= offset;
@ -2810,8 +2810,8 @@ void ImDrawList::AddCircle(const ImVec2& center, float radius, ImU32 col, int nu
float outer_radius = radius; float outer_radius = radius;
if (stroke_pos == ImDrawFlags_StrokeCenter) if (stroke_pos == ImDrawFlags_StrokeCenter)
outer_radius = radius + thickness * 0.5f; outer_radius = radius + thickness * 0.5f;
else if (stroke_pos == ImDrawFlags_StrokeCenterAligned) else if (stroke_pos == ImDrawFlags_StrokeCenterBiased)
outer_radius = radius + CalculateCenterAlignedOffset(thickness, _FringeScale); outer_radius = radius + CalculateCenterBiasedOffset(thickness, _FringeScale);
else if (stroke_pos == ImDrawFlags_StrokeInside) else if (stroke_pos == ImDrawFlags_StrokeInside)
outer_radius = radius; outer_radius = radius;
else if (stroke_pos == ImDrawFlags_StrokeOutside) else if (stroke_pos == ImDrawFlags_StrokeOutside)
@ -2897,8 +2897,8 @@ void ImDrawList::AddNgon(const ImVec2& center, float radius, ImU32 col, int num_
float outer_radius = radius; float outer_radius = radius;
if (stroke_pos == ImDrawFlags_StrokeCenter) if (stroke_pos == ImDrawFlags_StrokeCenter)
outer_radius = radius + miter_thickness * 0.5f; outer_radius = radius + miter_thickness * 0.5f;
else if (stroke_pos == ImDrawFlags_StrokeCenterAligned) else if (stroke_pos == ImDrawFlags_StrokeCenterBiased)
outer_radius = radius + CalculateCenterAlignedOffset(miter_thickness, _FringeScale); outer_radius = radius + CalculateCenterBiasedOffset(miter_thickness, _FringeScale);
else if (stroke_pos == ImDrawFlags_StrokeInside) else if (stroke_pos == ImDrawFlags_StrokeInside)
outer_radius = radius; outer_radius = radius;
else if (stroke_pos == ImDrawFlags_StrokeOutside) else if (stroke_pos == ImDrawFlags_StrokeOutside)