add: the method of drawing arcs

This commit is contained in:
Haibo 2018-11-20 15:56:56 +08:00 committed by Nomango
parent 57b528d67f
commit ab2c6092e8
4 changed files with 50 additions and 0 deletions

View File

@ -452,6 +452,22 @@ namespace easy2d
} }
} }
void Canvas::AddArc(Point const & point, Point const & radius, float rotation, bool clockwise, bool is_small)
{
if (current_sink_)
{
current_sink_->AddArc(
D2D1::ArcSegment(
point,
D2D1_SIZE_F{ radius.x, radius.y },
rotation,
clockwise ? D2D1_SWEEP_DIRECTION_CLOCKWISE : D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE,
is_small ? D2D1_ARC_SIZE_SMALL : D2D1_ARC_SIZE_LARGE
)
);
}
}
void Canvas::StrokePath() void Canvas::StrokePath()
{ {
render_target_->DrawGeometry( render_target_->DrawGeometry(

View File

@ -157,6 +157,15 @@ namespace easy2d
Point const& point3 /* 贝塞尔曲线的终点 */ Point const& point3 /* 贝塞尔曲线的终点 */
); );
// 添加弧线
void AddArc(
Point const& point, /* 终点 */
Point const& radius, /* 椭圆半径 */
float rotation, /* 椭圆旋转角度 */
bool clockwise = true, /* 顺时针 or 逆时针 */
bool is_small = true /* 是否取小于 180° 的弧 */
);
// 路径描边 // 路径描边
void StrokePath(); void StrokePath();

View File

@ -392,6 +392,22 @@ namespace easy2d
} }
} }
void PathGeometry::AddArc(Point const & point, Point const & radius, float rotation, bool clockwise, bool is_small)
{
if (current_sink_)
{
current_sink_->AddArc(
D2D1::ArcSegment(
point,
D2D1_SIZE_F{ radius.x, radius.y },
rotation,
clockwise ? D2D1_SWEEP_DIRECTION_CLOCKWISE : D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE,
is_small ? D2D1_ARC_SIZE_SMALL : D2D1_ARC_SIZE_LARGE
)
);
}
}
void PathGeometry::ClearPath() void PathGeometry::ClearPath()
{ {
geo_ = nullptr; geo_ = nullptr;

View File

@ -258,6 +258,15 @@ namespace easy2d
Point const& point3 /* 贝塞尔曲线的终点 */ Point const& point3 /* 贝塞尔曲线的终点 */
); );
// 添加弧线
void AddArc(
Point const& point, /* 终点 */
Point const& radius, /* 椭圆半径 */
float rotation, /* 椭圆旋转角度 */
bool clockwise = true, /* 顺时针 or 逆时针 */
bool is_small = true /* 是否取小于 180° 的弧 */
);
// 清除路径 // 清除路径
void ClearPath(); void ClearPath();