Skip to content

Commit

Permalink
Add the Ellipses implementation. See : ocornut/imgui#2743
Browse files Browse the repository at this point in the history
  • Loading branch information
ebachard committed Aug 29, 2019
1 parent f45395e commit b52adc9
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Sources/src/3rdparty/imgui/imgui_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,29 @@ void ImDrawList::PathArcTo(const ImVec2& centre, float radius, float a_min, floa
}
}

void ImDrawList::PathEllipticalArcTo(const ImVec2& center, float radius_x, float radius_y, float rot, float a_min, float a_max, int num_segments)
{
_Path.reserve(_Path.Size + (num_segments + 1));

const float cos_rot = ImCos(rot);
const float sin_rot = ImSin(rot);
for (int i = 0; i <= num_segments; i++)
for(int i = 0; i <= num_segments; i++)
{
//const float a = a_min + ((float)i / (float)num_segments) * (a_max - a_min);
float a = a_min + ((float)i / (float)num_segments) * (a_max - a_min);
ImVec2 point(center.x + ImCos(a) * radius_x, center.y + ImSin(a) * radius_y);
point.x -= center.x;
point.y -= center.y;
const float rel_x = (point.x * cos_rot) - (point.y * sin_rot);
const float rel_y = (point.x * sin_rot) + (point.y * cos_rot);
point.x = rel_x + center.x;
point.y = rel_y + center.y;
_Path.push_back(point);
}
}


static void PathBezierToCasteljau(ImVector<ImVec2>* path, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float tess_tol, int level)
{
float dx = x4 - x1;
Expand Down Expand Up @@ -1094,6 +1117,28 @@ void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col,
PathFillConvex(col);
}

void ImDrawList::AddEllipse(const ImVec2& center, float radius_x, float radius_y, ImU32 col, float rot, int num_segments, float thickness)
{
if ((col & IM_COL32_A_MASK) == 0 || num_segments <= 2)
return;

// Because we are filling a closed shape we remove 1 from the count of segments/points
const float a_max = IM_PI * 2.0f * ((float)num_segments - 1.0f) / (float)num_segments;
PathEllipticalArcTo(center, radius_x, radius_y, rot, 0.0f, a_max, num_segments - 1);
PathStroke(col, true, thickness);
}

void ImDrawList::AddEllipseFilled(const ImVec2& center, float radius_x, float radius_y, ImU32 col, float rot, int num_segments)
{
if((col & IM_COL32_A_MASK) == 0 || num_segments <= 2)
return;

// Because we are filling a closed shape we remove 1 from the count of segments/points
const float a_max = IM_PI * 2.0f * ((float)num_segments - 1.0f) / (float)num_segments;
PathEllipticalArcTo(center, radius_x, radius_y, rot, 0.0f, a_max, num_segments - 1);
PathFillConvex(col);
}

void ImDrawList::AddBezierCurve(const ImVec2& pos0, const ImVec2& cp0, const ImVec2& cp1, const ImVec2& pos1, ImU32 col, float thickness, int num_segments)
{
if ((col & IM_COL32_A_MASK) == 0)
Expand Down

0 comments on commit b52adc9

Please sign in to comment.