Skip to content

Commit

Permalink
fix: draw_ellipse/draw_polyline broken #1425 (#1430)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt authored Nov 18, 2021
1 parent 00f90b7 commit da71b60
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
14 changes: 10 additions & 4 deletions DearPyGui/src/core/AppItems/drawing/mvDrawEllipse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace Marvel {
points.reserve(_segments + 1);
for (int i = 0; i <= _segments; i++)
{
points.push_back(mvVec4{ cx + cosf(i*radian_inc) * width, cy + sinf(i * radian_inc) * height, 0.0f, 1.0f });
points.push_back(mvVec4{ cx + cosf(i*radian_inc) * width/2.0f, cy + sinf(i * radian_inc) * height/2.0f, 0.0f, 1.0f });
}
_points = std::move(points);
_dirty = false;
Expand All @@ -93,7 +93,11 @@ namespace Marvel {
if (mvClipPoint(_clipViewport, tpmax)) return;
}

// this is disgusting; we should not be allocating
// every frame. Fix ASAP
std::vector<mvVec4> points = _points;
std::vector<ImVec2> finalpoints;
finalpoints.reserve(_points.size());

for(auto& point : points)
point = _transform * point;
Expand All @@ -105,6 +109,7 @@ namespace Marvel {
ImVec2 impoint = ImPlot::PlotToPixels(point);
point.x = impoint.x;
point.y = impoint.y;
finalpoints.push_back(impoint);
}
}
else
Expand All @@ -113,18 +118,19 @@ namespace Marvel {
{
point.x += x;
point.y += y;
finalpoints.push_back(ImVec2{ point.x, point.y });
}
}

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

void mvDrawEllipse::handleSpecificRequiredArgs(PyObject* dict)
Expand Down
10 changes: 8 additions & 2 deletions DearPyGui/src/core/AppItems/drawing/mvDrawPolyline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ namespace Marvel {
mvVec4 start = { x, y };

std::vector<mvVec4> points = _points;
std::vector<ImVec2> finalpoints;
finalpoints.reserve(_points.size());

for (auto& point : points)
point = _transform * point;
Expand Down Expand Up @@ -80,17 +82,21 @@ namespace Marvel {
ImVec2 impoint = ImPlot::PlotToPixels(point);
point.x = impoint.x;
point.y = impoint.y;
finalpoints.push_back(impoint);
}

drawlist->AddPolyline((const ImVec2*)const_cast<const mvVec4*>(points.data()), (int)_points.size(), _color,
drawlist->AddPolyline(finalpoints.data(), (int)finalpoints.size(), _color,
_closed, ImPlot::GetCurrentContext()->Mx * _thickness);
}
else
{
for (auto& point : points)
{
point = point + start;
finalpoints.push_back(ImVec2{ point.x, point.y });
}

drawlist->AddPolyline((const ImVec2*)const_cast<const mvVec4*>(points.data()), (int)_points.size(), _color,
drawlist->AddPolyline(finalpoints.data(), (int)finalpoints.size(), _color,
_closed, _thickness);
}

Expand Down

0 comments on commit da71b60

Please sign in to comment.