• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef PATH_H
17 #define PATH_H
18 
19 #include <memory>
20 #include <vector>
21 
22 #include "drawing/engine_adapter/impl_interface/path_impl.h"
23 #include "utils/matrix.h"
24 #include "utils/point.h"
25 #include "utils/rect.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace Drawing {
30 enum class PathDirection {
31     CW_DIRECTION,
32     CCW_DIRECTION,
33 };
34 
35 enum class PathFillType {
36     WINDING,
37     EVENTODD,
38     INVERSE_WINDING,
39     INVERSE_EVENTODD,
40 };
41 
42 enum class PathOp {
43     DIFFERENCE,
44     INTERSECT,
45     UNION,
46     XOR,
47     REVERSE_DIFFERENCE,
48 };
49 
50 class Path {
51 public:
52     Path() noexcept;
53     Path(const Path& p) noexcept;
54     Path &operator=(const Path& p) noexcept;
55     virtual ~Path();
56 
57     void MoveTo(scalar x, scalar y);
58     void LineTo(scalar x, scalar y);
59     void ArcTo(scalar pt1X, scalar pt1Y, scalar pt2X, scalar pt2Y, scalar startAngle, scalar sweepAngle);
60     void ArcTo(const Point& pt1, const Point& pt2, scalar startAngle, scalar sweepAngle);
61     void ArcTo(scalar rx, scalar ry, scalar angle, PathDirection direction, scalar endX, scalar endY);
62     void CubicTo(scalar ctrlPt1X, scalar ctrlPt1Y, scalar ctrlPt2X, scalar ctrlPt2Y, scalar endPtX, scalar endPtY);
63     void CubicTo(const Point& ctrlPt1, const Point& ctrlPt2, const Point& endPt);
64     void QuadTo(scalar ctrlPtX, scalar ctrlPtY, scalar endPtX, scalar endPtY);
65     void QuadTo(const Point& ctrlPt, const Point endPt);
66 
67     void AddRect(const Rect& rect, PathDirection dir = PathDirection::CW_DIRECTION);
68     void AddRect(scalar left, scalar top, scalar right, scalar bottom, PathDirection dir = PathDirection::CW_DIRECTION);
69 
70     void AddOval(const Rect& oval, PathDirection dir = PathDirection::CW_DIRECTION);
71     void AddArc(const Rect& oval, scalar startAngle, scalar sweepAngle);
72     void AddPoly(const std::vector<Point>& points, int count, bool close);
73     void AddCircle(scalar x, scalar y, scalar radius, PathDirection dir = PathDirection::CW_DIRECTION);
74     void AddRoundRect(
75         const Rect& rect, scalar xRadius, scalar yRadius, PathDirection dir = PathDirection::CW_DIRECTION);
76 
77     void AddPath(const Path& src, scalar dx, scalar dy);
78     void AddPath(const Path& src);
79     void AddPath(const Path& src, const Matrix& matrix);
80 
81     Rect GetBounds() const;
82     void SetFillStyle(PathFillType fillstyle);
83 
84     bool Interpolate(const Path& ending, scalar weight, Path& out);
85     void Transform(const Matrix& matrix);
86     void Offset(scalar dx, scalar dy);
87     bool Op(const Path& path1, Path& path2, PathOp op);
88 
89     void Reset();
90 
91     void Close();
92 
93     template<typename T>
GetImpl()94     const std::shared_ptr<T> GetImpl() const
95     {
96         return impl_->DowncastingTo<T>();
97     }
98 
99 private:
100     std::shared_ptr<PathImpl> impl_;
101 };
102 } // namespace Drawing
103 } // namespace Rosen
104 } // namespace OHOS
105 #endif
106