From 523526eb966cfaef4fef279f08670eca06ae8f81 Mon Sep 17 00:00:00 2001 From: Vladimir Ein Date: Sun, 8 Jan 2023 05:49:33 +0500 Subject: [PATCH] fix: drawing thickness (#2001) * fix: correct thickness for non-transparent circles in mvDrawCircle (#1997) * fix: correct outline thickness for filled drawing primitives (#1997) --- src/mvDrawings.cpp | 76 +++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 45 deletions(-) diff --git a/src/mvDrawings.cpp b/src/mvDrawings.cpp index 478d5d747..d11ba71da 100644 --- a/src/mvDrawings.cpp +++ b/src/mvDrawings.cpp @@ -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); } } @@ -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); } } @@ -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) @@ -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; @@ -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) @@ -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); } } @@ -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); } } @@ -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); } }