From ab2c6092e8e68c0fdb9a3a952c1c25a4e8271b1f Mon Sep 17 00:00:00 2001 From: Haibo Date: Tue, 20 Nov 2018 15:56:56 +0800 Subject: [PATCH] add: the method of drawing arcs --- core/base/Canvas.cpp | 16 ++++++++++++++++ core/base/Canvas.h | 9 +++++++++ core/base/Geometry.cpp | 16 ++++++++++++++++ core/base/Geometry.h | 9 +++++++++ 4 files changed, 50 insertions(+) diff --git a/core/base/Canvas.cpp b/core/base/Canvas.cpp index 4b8be4e9..78e7d4dd 100644 --- a/core/base/Canvas.cpp +++ b/core/base/Canvas.cpp @@ -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() { render_target_->DrawGeometry( diff --git a/core/base/Canvas.h b/core/base/Canvas.h index 5e4375f3..ed6b4f7e 100644 --- a/core/base/Canvas.h +++ b/core/base/Canvas.h @@ -157,6 +157,15 @@ namespace easy2d Point const& point3 /* 贝塞尔曲线的终点 */ ); + // 添加弧线 + void AddArc( + Point const& point, /* 终点 */ + Point const& radius, /* 椭圆半径 */ + float rotation, /* 椭圆旋转角度 */ + bool clockwise = true, /* 顺时针 or 逆时针 */ + bool is_small = true /* 是否取小于 180° 的弧 */ + ); + // 路径描边 void StrokePath(); diff --git a/core/base/Geometry.cpp b/core/base/Geometry.cpp index f0f326a8..a0dc3102 100644 --- a/core/base/Geometry.cpp +++ b/core/base/Geometry.cpp @@ -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() { geo_ = nullptr; diff --git a/core/base/Geometry.h b/core/base/Geometry.h index 20043850..31c572e1 100644 --- a/core/base/Geometry.h +++ b/core/base/Geometry.h @@ -258,6 +258,15 @@ namespace easy2d Point const& point3 /* 贝塞尔曲线的终点 */ ); + // 添加弧线 + void AddArc( + Point const& point, /* 终点 */ + Point const& radius, /* 椭圆半径 */ + float rotation, /* 椭圆旋转角度 */ + bool clockwise = true, /* 顺时针 or 逆时针 */ + bool is_small = true /* 是否取小于 180° 的弧 */ + ); + // 清除路径 void ClearPath();