1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "draw/path.h"
17
18 #include "impl_factory.h"
19
20 namespace OHOS {
21 namespace Rosen {
22 namespace Drawing {
Path()23 Path::Path() noexcept : impl_(ImplFactory::CreatePathImpl()) {}
24
Path(const Path & other)25 Path::Path(const Path& other) noexcept
26 {
27 impl_.reset(other.impl_->Clone());
28 }
29
operator =(const Path & other)30 Path& Path::operator=(const Path &other) noexcept
31 {
32 impl_.reset(other.impl_->Clone());
33 return *this;
34 }
35
~Path()36 Path::~Path() {}
37
MoveTo(scalar x,scalar y)38 void Path::MoveTo(scalar x, scalar y)
39 {
40 impl_->MoveTo(x, y);
41 }
42
LineTo(scalar x,scalar y)43 void Path::LineTo(scalar x, scalar y)
44 {
45 impl_->LineTo(x, y);
46 }
47
ArcTo(scalar pt1X,scalar pt1Y,scalar pt2X,scalar pt2Y,scalar startAngle,scalar sweepAngle)48 void Path::ArcTo(scalar pt1X, scalar pt1Y, scalar pt2X, scalar pt2Y, scalar startAngle, scalar sweepAngle)
49 {
50 impl_->ArcTo(pt1X, pt1Y, pt2X, pt2Y, startAngle, sweepAngle);
51 }
52
ArcTo(const Point & pt1,const Point & pt2,scalar startAngle,scalar sweepAngle)53 void Path::ArcTo(const Point& pt1, const Point& pt2, scalar startAngle, scalar sweepAngle)
54 {
55 impl_->ArcTo(pt1.GetX(), pt1.GetY(), pt2.GetX(), pt2.GetY(), startAngle, sweepAngle);
56 }
57
ArcTo(scalar rx,scalar ry,scalar angle,PathDirection direction,scalar endX,scalar endY)58 void Path::ArcTo(scalar rx, scalar ry, scalar angle, PathDirection direction, scalar endX, scalar endY)
59 {
60 impl_->ArcTo(rx, ry, angle, direction, endX, endY);
61 }
62
CubicTo(scalar ctrlPt1X,scalar ctrlPt1Y,scalar ctrlPt2X,scalar ctrlPt2Y,scalar endPtX,scalar endPtY)63 void Path::CubicTo(scalar ctrlPt1X, scalar ctrlPt1Y, scalar ctrlPt2X, scalar ctrlPt2Y, scalar endPtX, scalar endPtY)
64 {
65 impl_->CubicTo(ctrlPt1X, ctrlPt1Y, ctrlPt2X, ctrlPt2Y, endPtX, endPtY);
66 }
67
CubicTo(const Point & ctrlPt1,const Point & ctrlPt2,const Point & endPt)68 void Path::CubicTo(const Point& ctrlPt1, const Point& ctrlPt2, const Point& endPt)
69 {
70 impl_->CubicTo(ctrlPt1.GetX(), ctrlPt1.GetY(), ctrlPt2.GetX(), ctrlPt2.GetY(), endPt.GetX(), endPt.GetY());
71 }
72
QuadTo(scalar ctrlPtX,scalar ctrlPtY,scalar endPtX,scalar endPtY)73 void Path::QuadTo(scalar ctrlPtX, scalar ctrlPtY, scalar endPtX, scalar endPtY)
74 {
75 impl_->QuadTo(ctrlPtX, ctrlPtY, endPtX, endPtY);
76 }
77
QuadTo(const Point & ctrlPt,const Point endPt)78 void Path::QuadTo(const Point& ctrlPt, const Point endPt)
79 {
80 impl_->QuadTo(ctrlPt.GetX(), ctrlPt.GetY(), endPt.GetX(), endPt.GetY());
81 }
82
AddRect(const Rect & rect,PathDirection dir)83 void Path::AddRect(const Rect& rect, PathDirection dir)
84 {
85 impl_->AddRect(rect.GetLeft(), rect.GetTop(), rect.GetRight(), rect.GetBottom(), dir);
86 }
87
AddRect(scalar left,scalar top,scalar right,scalar bottom,PathDirection dir)88 void Path::AddRect(scalar left, scalar top, scalar right, scalar bottom, PathDirection dir)
89 {
90 impl_->AddRect(left, top, right, bottom, dir);
91 }
92
AddOval(const Rect & oval,PathDirection dir)93 void Path::AddOval(const Rect& oval, PathDirection dir)
94 {
95 impl_->AddOval(oval.GetLeft(), oval.GetTop(), oval.GetRight(), oval.GetBottom(), dir);
96 }
97
AddArc(const Rect & oval,scalar startAngle,scalar sweepAngle)98 void Path::AddArc(const Rect& oval, scalar startAngle, scalar sweepAngle)
99 {
100 impl_->AddArc(oval.GetLeft(), oval.GetTop(), oval.GetRight(), oval.GetBottom(), startAngle, sweepAngle);
101 }
102
AddPoly(const std::vector<Point> & points,int count,bool close)103 void Path::AddPoly(const std::vector<Point>& points, int count, bool close)
104 {
105 impl_->AddPoly(points, count, close);
106 }
107
AddCircle(scalar x,scalar y,scalar radius,PathDirection dir)108 void Path::AddCircle(scalar x, scalar y, scalar radius, PathDirection dir)
109 {
110 impl_->AddCircle(x, y, radius, dir);
111 }
112
AddRoundRect(const Rect & rect,scalar xRadius,scalar yRadius,PathDirection dir)113 void Path::AddRoundRect(const Rect& rect, scalar xRadius, scalar yRadius, PathDirection dir)
114 {
115 impl_->AddRoundRect(rect.GetLeft(), rect.GetTop(), rect.GetRight(), rect.GetBottom(), xRadius, yRadius, dir);
116 }
117
AddPath(const Path & src,scalar dx,scalar dy)118 void Path::AddPath(const Path& src, scalar dx, scalar dy)
119 {
120 impl_->AddPath(src, dx, dy);
121 }
122
AddPath(const Path & src)123 void Path::AddPath(const Path& src)
124 {
125 impl_->AddPath(src);
126 }
127
AddPath(const Path & src,const Matrix & matrix)128 void Path::AddPath(const Path& src, const Matrix& matrix)
129 {
130 impl_->AddPathWithMatrix(src, matrix);
131 }
132
GetBounds() const133 Rect Path::GetBounds() const
134 {
135 return impl_->GetBounds();
136 }
137
SetFillStyle(PathFillType fillstyle)138 void Path::SetFillStyle(PathFillType fillstyle)
139 {
140 impl_->SetFillStyle(fillstyle);
141 }
142
Interpolate(const Path & ending,scalar weight,Path & out)143 bool Path::Interpolate(const Path& ending, scalar weight, Path& out)
144 {
145 return impl_->Interpolate(ending, weight, out);
146 }
147
Transform(const Matrix & matrix)148 void Path::Transform(const Matrix& matrix)
149 {
150 impl_->Transform(matrix);
151 }
152
Offset(scalar dx,scalar dy)153 void Path::Offset(scalar dx, scalar dy)
154 {
155 impl_->Offset(dx, dy);
156 }
157
Op(const Path & path1,Path & path2,PathOp op)158 bool Path::Op(const Path& path1, Path& path2, PathOp op)
159 {
160 return impl_->OpWith(path1, path2, op);
161 }
162
Reset()163 void Path::Reset()
164 {
165 impl_->Reset();
166 }
167
Close()168 void Path::Close()
169 {
170 impl_->Close();
171 }
172 } // namespace Drawing
173 } // namespace Rosen
174 } // namespace OHOS