mirror of
https://github.com/ocornut/imgui.git
synced 2026-08-19 03:52:37 +08:00
DrawList: added ImDrawFlags_NoAAEnds which allows to disable line end AA.
This commit is contained in:
@@ -3446,13 +3446,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.
|
||||
|
||||
// Stroke position relative to the shape outline
|
||||
ImDrawFlags_StrokeInside = 1 << 16, // Draw stroke inside of the shape outline (Default)
|
||||
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
|
||||
ImDrawFlags_StrokeCenterPixelAligned = 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.
|
||||
ImDrawFlags_StrokeOutside = 4 << 16, // Draw stroke outside of the shape outline
|
||||
ImDrawFlags_StrokeLegacy = 5 << 16, // Use legacy position
|
||||
ImDrawFlags_StrokeLegacy = 5 << 16, // Use legacy positioning + enable MiterOnly and NoAAEnds flags.
|
||||
ImDrawFlags_StrokeMask_ = 0x07 << 16,
|
||||
|
||||
ImDrawFlags_InvalidMask_ = ~0x7FFFFFF0, // == 0x8000000F,
|
||||
|
||||
+2
-1
@@ -10440,6 +10440,7 @@ static void ShowExampleAppCustomRendering(bool* p_open)
|
||||
ImGui::SameLine(); ImGui::RadioButton("Legacy", &flags, ImDrawFlags_StrokeLegacy);
|
||||
ImGui::CheckboxFlags("MiterOnly", &flags, ImDrawFlags_MiterOnly);
|
||||
ImGui::SameLine(); ImGui::CheckboxFlags("SquareCap", &flags, ImDrawFlags_SquareCap);
|
||||
ImGui::SameLine(); ImGui::CheckboxFlags("NoAAEnds", &flags, ImDrawFlags_NoAAEnds);
|
||||
|
||||
const ImVec2 p = ImGui::GetCursorScreenPos();
|
||||
const ImU32 col = ImColor(colf);
|
||||
@@ -10478,7 +10479,7 @@ static void ShowExampleAppCustomRendering(bool* p_open)
|
||||
float side_step = 3.141592f * 0.5f;
|
||||
for (int side = 0; side < 4; side++)
|
||||
{
|
||||
float t = (float)ImGui::GetTime() * 0.3f + side * side_step;
|
||||
float t = (float)ImGui::GetTime() * 0.1f + side * side_step;
|
||||
ImVec2 center(x + sz * 0.5f, y + sz * 0.5f);
|
||||
draw_list->AddLine({ center.x + cosf(t) * sz * 0.5f, center.y + sinf(t) * sz * 0.5f }, { center.x + cosf(t + side_step) * sz * 0.5f, center.y + sinf(t + side_step) * sz * 0.5f }, col, th, flags);
|
||||
}
|
||||
|
||||
+49
-26
@@ -929,21 +929,31 @@ void ImDrawList::_AddPolyline(const ImVec2* points, ImVec2* normals, float* sqr_
|
||||
const ImVec2 dir(n1.y, -n1.x);
|
||||
if (flags & ImDrawFlags_SquareCap)
|
||||
p1 -= dir * half_thickness;
|
||||
const ImVec2 pa = p1 - dir * half_aa;
|
||||
const ImVec2 pb = p1 + dir * half_aa;
|
||||
|
||||
base_idx = (int)_VtxCurrentIdx;
|
||||
IM_APPEND_VTX(pa.x - n1.x * thickness0, pa.y - n1.y * thickness0, uv0, col_trans);
|
||||
IM_APPEND_VTX(pa.x + n1.x * thickness1, pa.y + n1.y * thickness1, uv1, col_trans);
|
||||
if (flags & ImDrawFlags_NoAAEnds)
|
||||
{
|
||||
base_idx = (int)_VtxCurrentIdx;
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
const ImVec2 pa = p1 - dir * half_aa;
|
||||
const ImVec2 pb = p1 + dir * half_aa;
|
||||
|
||||
int next_base_idx = (int)_VtxCurrentIdx;
|
||||
IM_APPEND_VTX(pb.x - n1.x * thickness0, pb.y - n1.y * thickness0, uv0, col);
|
||||
IM_APPEND_VTX(pb.x + n1.x * thickness1, pb.y + n1.y * thickness1 , uv1, col);
|
||||
base_idx = (int)_VtxCurrentIdx;
|
||||
IM_APPEND_VTX(pa.x - n1.x * thickness0, pa.y - n1.y * thickness0, uv0, col_trans);
|
||||
IM_APPEND_VTX(pa.x + n1.x * thickness1, pa.y + n1.y * thickness1, uv1, col_trans);
|
||||
|
||||
// AA cap
|
||||
IM_APPEND_TRI(base_idx+0, base_idx+2, base_idx+3);
|
||||
IM_APPEND_TRI(base_idx+0, base_idx+3, base_idx+1);
|
||||
base_idx = next_base_idx;
|
||||
int next_base_idx = (int)_VtxCurrentIdx;
|
||||
IM_APPEND_VTX(pb.x - n1.x * thickness0, pb.y - n1.y * thickness0, uv0, col);
|
||||
IM_APPEND_VTX(pb.x + n1.x * thickness1, pb.y + n1.y * thickness1, uv1, col);
|
||||
|
||||
// AA cap
|
||||
IM_APPEND_TRI(base_idx + 0, base_idx + 2, base_idx + 3);
|
||||
IM_APPEND_TRI(base_idx + 0, base_idx + 3, base_idx + 1);
|
||||
base_idx = next_base_idx;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1101,24 +1111,37 @@ void ImDrawList::_AddPolyline(const ImVec2* points, ImVec2* normals, float* sqr_
|
||||
const ImVec2 dir(n1.y, -n1.x);
|
||||
if (flags & ImDrawFlags_SquareCap)
|
||||
p1 += dir * half_thickness;
|
||||
const ImVec2 pa = p1 - dir * half_aa;
|
||||
const ImVec2 pb = p1 + dir * half_aa;
|
||||
|
||||
int next_base_idx = (int)_VtxCurrentIdx;
|
||||
IM_APPEND_VTX(pa.x - n1.x * thickness0, pa.y - n1.y * thickness0, uv0, col);
|
||||
IM_APPEND_VTX(pa.x + n1.x * thickness1, pa.y + n1.y * thickness1, uv1, col);
|
||||
if (flags & ImDrawFlags_NoAAEnds)
|
||||
{
|
||||
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);
|
||||
|
||||
IM_APPEND_VTX(pb.x - n1.x * thickness0, pb.y - n1.y * thickness0, uv0, col_trans);
|
||||
IM_APPEND_VTX(pb.x + n1.x * thickness1, pb.y + n1.y * thickness1, uv1, col_trans);
|
||||
// Connect
|
||||
IM_APPEND_TRI(base_idx + 0, base_idx + 2, base_idx + 3);
|
||||
IM_APPEND_TRI(base_idx + 0, base_idx + 3, base_idx + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
const ImVec2 pa = p1 - dir * half_aa;
|
||||
const ImVec2 pb = p1 + dir * half_aa;
|
||||
|
||||
// Connect
|
||||
IM_APPEND_TRI(base_idx+0, base_idx+2, base_idx+3);
|
||||
IM_APPEND_TRI(base_idx+0, base_idx+3, base_idx+1);
|
||||
base_idx = next_base_idx;
|
||||
int next_base_idx = (int)_VtxCurrentIdx;
|
||||
IM_APPEND_VTX(pa.x - n1.x * thickness0, pa.y - n1.y * thickness0, uv0, col);
|
||||
IM_APPEND_VTX(pa.x + n1.x * thickness1, pa.y + n1.y * thickness1, uv1, col);
|
||||
|
||||
// AA cap
|
||||
IM_APPEND_TRI(base_idx+0, base_idx+2, base_idx+3);
|
||||
IM_APPEND_TRI(base_idx+0, base_idx+3, base_idx+1);
|
||||
IM_APPEND_VTX(pb.x - n1.x * thickness0, pb.y - n1.y * thickness0, uv0, col_trans);
|
||||
IM_APPEND_VTX(pb.x + n1.x * thickness1, pb.y + n1.y * thickness1, uv1, col_trans);
|
||||
|
||||
// Connect
|
||||
IM_APPEND_TRI(base_idx + 0, base_idx + 2, base_idx + 3);
|
||||
IM_APPEND_TRI(base_idx + 0, base_idx + 3, base_idx + 1);
|
||||
base_idx = next_base_idx;
|
||||
|
||||
// AA cap
|
||||
IM_APPEND_TRI(base_idx + 0, base_idx + 2, base_idx + 3);
|
||||
IM_APPEND_TRI(base_idx + 0, base_idx + 3, base_idx + 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user