Skip to content

Commit

Permalink
fix: drawing thickness (#2001)
Browse files Browse the repository at this point in the history
* fix: correct thickness for non-transparent circles in mvDrawCircle (#1997)

* fix: correct outline thickness for filled drawing primitives (#1997)
  • Loading branch information
v-ein authored Jan 8, 2023
1 parent a9dcb0d commit 523526e
Showing 1 changed file with 31 additions and 45 deletions.
76 changes: 31 additions & 45 deletions src/mvDrawings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ void mvDrawArrow::draw(ImDrawList* drawlist, float x, float y)

if (ImPlot::GetCurrentContext()->CurrentPlot)
{
drawlist->AddLine(ImPlot::PlotToPixels(tp1), ImPlot::PlotToPixels(tp1), _color, (float)ImPlot::GetCurrentContext()->Mx * _thickness);
drawlist->AddTriangle(ImPlot::PlotToPixels(tpp1), ImPlot::PlotToPixels(tpp2), ImPlot::PlotToPixels(tpp3), _color, (float)ImPlot::GetCurrentContext()->Mx * _thickness);
drawlist->AddTriangleFilled(ImPlot::PlotToPixels(tpp1), ImPlot::PlotToPixels(tpp2), ImPlot::PlotToPixels(tpp3), _color);
drawlist->AddLine(ImPlot::PlotToPixels(tp1), ImPlot::PlotToPixels(tp2), _color, (float)ImPlot::GetCurrentContext()->Mx * _thickness);
drawlist->AddTriangle(ImPlot::PlotToPixels(tpp1), ImPlot::PlotToPixels(tpp2), ImPlot::PlotToPixels(tpp3), _color, (float)ImPlot::GetCurrentContext()->Mx * _thickness);
}
else
{
mvVec2 start = { x, y };
drawlist->AddTriangleFilled(tpp1 + start, tpp2 + start, tpp3 + start, _color);
drawlist->AddLine(tp1 + start, tp2 + start, _color, _thickness);
drawlist->AddTriangle(tpp1 + start, tpp2 + start, tpp3 + start, _color, _thickness);
drawlist->AddTriangleFilled(tpp1 + start, tpp2 + start, tpp3 + start, _color);
}
}

Expand Down Expand Up @@ -385,19 +385,17 @@ void mvDrawCircle::draw(ImDrawList* drawlist, float x, float y)

if (ImPlot::GetCurrentContext()->CurrentPlot)
{
if (_fill.r >= 0.0f)
drawlist->AddCircleFilled(ImPlot::PlotToPixels(tcenter), ImPlot::GetCurrentContext()->Mx * _radius, _fill, _segments);
drawlist->AddCircle(ImPlot::PlotToPixels(tcenter), ImPlot::GetCurrentContext()->Mx * _radius, _color,
ImPlot::GetCurrentContext()->Mx * _segments, _thickness);
if (_fill.r < 0.0f)
return;
drawlist->AddCircleFilled(ImPlot::PlotToPixels(tcenter), ImPlot::GetCurrentContext()->Mx * _radius, _fill, _segments);
}
else
{
mvVec2 start = { x, y };
if (_fill.r >= 0.0f)
drawlist->AddCircleFilled(tcenter + start, _radius, _fill, _segments);
drawlist->AddCircle(tcenter + start, _radius, _color, _segments, _thickness);
if (_fill.r < 0.0f)
return;
drawlist->AddCircleFilled(tcenter + start, _radius, _fill, _segments);
}
}

Expand Down Expand Up @@ -521,15 +519,14 @@ void mvDrawEllipse::draw(ImDrawList* drawlist, float x, float y)
}
}

if (_fill.r >= 0.0f)
drawlist->AddConvexPolyFilled(finalpoints.data(), (int)finalpoints.size(), _fill);
if (ImPlot::GetCurrentContext()->CurrentPlot)
drawlist->AddPolyline(finalpoints.data(), (int)finalpoints.size(),
_color, false, ImPlot::GetCurrentContext()->Mx * _thickness);
else
drawlist->AddPolyline(finalpoints.data(), (int)finalpoints.size(),
_color, false, _thickness);
if (_fill.r < 0.0f)
return;
drawlist->AddConvexPolyFilled(finalpoints.data(), (int)finalpoints.size(), _fill);
}

void mvDrawEllipse::handleSpecificRequiredArgs(PyObject* dict)
Expand Down Expand Up @@ -1187,11 +1184,8 @@ void mvDrawPolygon::draw(ImDrawList* drawlist, float x, float y)
finalpoints.push_back(ImVec2{ point.x, point.y });
}
}
// TODO: Find a way to store lines and only calc new fill lines when dirty similar to ellipse
drawlist->AddPolyline(finalpoints.data(), (int)finalpoints.size(), _color, false, _thickness);
if (_fill.r < 0.0f)
return;

if (_fill.r >= 0.0f)
{
size_t i;
int y;
Expand Down Expand Up @@ -1269,6 +1263,8 @@ void mvDrawPolygon::draw(ImDrawList* drawlist, float x, float y)
}
delete[] polyints;
}
// TODO: Find a way to store lines and only calc new fill lines when dirty similar to ellipse
drawlist->AddPolyline(finalpoints.data(), (int)finalpoints.size(), _color, false, _thickness);
}

void mvDrawPolygon::handleSpecificRequiredArgs(PyObject* dict)
Expand Down Expand Up @@ -1455,20 +1451,18 @@ void mvDrawQuad::draw(ImDrawList* drawlist, float x, float y)

if (ImPlot::GetCurrentContext()->CurrentPlot)
{
if (_fill.r >= 0.0f)
drawlist->AddQuadFilled(ImPlot::PlotToPixels(tp1), ImPlot::PlotToPixels(tp2), ImPlot::PlotToPixels(tp3),
ImPlot::PlotToPixels(tp4), _fill);
drawlist->AddQuad(ImPlot::PlotToPixels(tp1), ImPlot::PlotToPixels(tp2), ImPlot::PlotToPixels(tp3),
ImPlot::PlotToPixels(tp4), _color, ImPlot::GetCurrentContext()->Mx * _thickness);
if (_fill.r < 0.0f)
return;
drawlist->AddQuadFilled(ImPlot::PlotToPixels(tp1), ImPlot::PlotToPixels(tp2), ImPlot::PlotToPixels(tp3),
ImPlot::PlotToPixels(tp4), _fill);
}
else
{
mvVec2 start = { x, y };
if (_fill.r >= 0.0f)
drawlist->AddQuadFilled(tp1 + start, tp2 + start, tp3 + start, tp4 + start, _fill);
drawlist->AddQuad(tp1 + start, tp2 + start, tp3 + start, tp4 + start, _color, _thickness);
if (_fill.r < 0.0f)
return;
drawlist->AddQuadFilled(tp1 + start, tp2 + start, tp3 + start, tp4 + start, _fill);
}
}

Expand Down Expand Up @@ -1563,29 +1557,21 @@ void mvDrawRect::draw(ImDrawList* drawlist, float x, float y)

if (ImPlot::GetCurrentContext()->CurrentPlot)
{
drawlist->AddRect(ImPlot::PlotToPixels(tpmin), ImPlot::PlotToPixels(tpmax), _color,
ImPlot::GetCurrentContext()->Mx * _rounding, ImDrawCornerFlags_All, ImPlot::GetCurrentContext()->Mx * _thickness);
if (_multicolor)
{
drawlist->AddRectFilledMultiColor(ImPlot::PlotToPixels(tpmin), ImPlot::PlotToPixels(tpmax), _color_bottom_right, _color_bottom_left, _color_upper_left, _color_upper_right);
return;
}
if (_fill.r < 0.0f)
return;
drawlist->AddRectFilled(ImPlot::PlotToPixels(tpmin), ImPlot::PlotToPixels(tpmax), _fill, ImPlot::GetCurrentContext()->Mx * _rounding, ImDrawCornerFlags_All);
else if (_fill.r >= 0.0f)
drawlist->AddRectFilled(ImPlot::PlotToPixels(tpmin), ImPlot::PlotToPixels(tpmax), _fill, ImPlot::GetCurrentContext()->Mx * _rounding, ImDrawCornerFlags_All);
drawlist->AddRect(ImPlot::PlotToPixels(tpmin), ImPlot::PlotToPixels(tpmax), _color,
ImPlot::GetCurrentContext()->Mx * _rounding, ImDrawCornerFlags_All, ImPlot::GetCurrentContext()->Mx * _thickness);
}
else
{
mvVec2 start = { x, y };
drawlist->AddRect(tpmin + start, tpmax + start, _color, _rounding, ImDrawCornerFlags_All, _thickness);
if (_multicolor)
{
drawlist->AddRectFilledMultiColor(tpmin + start, tpmax + start, _color_bottom_right, _color_bottom_left, _color_upper_left, _color_upper_right);
return;
}
if (_fill.r < 0.0f)
return;
drawlist->AddRectFilled(tpmin + start, tpmax + start, _fill, _rounding, ImDrawCornerFlags_All);
else if (_fill.r >= 0.0f)
drawlist->AddRectFilled(tpmin + start, tpmax + start, _fill, _rounding, ImDrawCornerFlags_All);
drawlist->AddRect(tpmin + start, tpmax + start, _color, _rounding, ImDrawCornerFlags_All, _thickness);
}
}

Expand Down Expand Up @@ -1764,20 +1750,20 @@ void mvDrawTriangle::draw(ImDrawList* drawlist, float x, float y)

if (ImPlot::GetCurrentContext()->CurrentPlot)
{
if (_fill.r >= 0.0f)
{
drawlist->AddTriangleFilled(ImPlot::PlotToPixels(tp1), ImPlot::PlotToPixels(tp2), ImPlot::PlotToPixels(tp3),
_fill);
}
drawlist->AddTriangle(ImPlot::PlotToPixels(tp1), ImPlot::PlotToPixels(tp2), ImPlot::PlotToPixels(tp3),
_color, ImPlot::GetCurrentContext()->Mx * _thickness);
if (_fill.r < 0.0f)
return;
drawlist->AddTriangleFilled(ImPlot::PlotToPixels(tp1), ImPlot::PlotToPixels(tp2), ImPlot::PlotToPixels(tp3),
_fill);
}
else
{
mvVec2 start = { x, y };
if (_fill.r >= 0.0f)
drawlist->AddTriangleFilled(tp1 + start, tp2 + start, tp3 + start, _fill);
drawlist->AddTriangle(tp1 + start, tp2 + start, tp3 + start, _color, _thickness);
if (_fill.r < 0.0f)
return;
drawlist->AddTriangleFilled(tp1 + start, tp2 + start, tp3 + start, _fill);
}
}

Expand Down

0 comments on commit 523526e

Please sign in to comment.