• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_LIB_UI_PAINTING_PATH_H_
6 #define FLUTTER_LIB_UI_PAINTING_PATH_H_
7 
8 #include "flutter/lib/ui/dart_wrapper.h"
9 #include "flutter/lib/ui/painting/rrect.h"
10 #include "third_party/skia/include/core/SkPath.h"
11 #include "third_party/skia/include/pathops/SkPathOps.h"
12 
13 namespace tonic {
14 class DartLibraryNatives;
15 }  // namespace tonic
16 
17 namespace flutter {
18 
19 class CanvasPath : public RefCountedDartWrappable<CanvasPath> {
20   DEFINE_WRAPPERTYPEINFO();
21   FML_FRIEND_MAKE_REF_COUNTED(CanvasPath);
22 
23  public:
24   ~CanvasPath() override;
Create()25   static fml::RefPtr<CanvasPath> Create() {
26     return fml::MakeRefCounted<CanvasPath>();
27   }
28 
CreateFrom(const SkPath & src)29   static fml::RefPtr<CanvasPath> CreateFrom(const SkPath& src) {
30     fml::RefPtr<CanvasPath> path = CanvasPath::Create();
31     path->path_ = src;
32     return path;
33   }
34 
35   int getFillType();
36   void setFillType(int fill_type);
37 
38   void moveTo(float x, float y);
39   void relativeMoveTo(float x, float y);
40   void lineTo(float x, float y);
41   void relativeLineTo(float x, float y);
42   void quadraticBezierTo(float x1, float y1, float x2, float y2);
43   void relativeQuadraticBezierTo(float x1, float y1, float x2, float y2);
44   void cubicTo(float x1, float y1, float x2, float y2, float x3, float y3);
45   void relativeCubicTo(float x1,
46                        float y1,
47                        float x2,
48                        float y2,
49                        float x3,
50                        float y3);
51   void conicTo(float x1, float y1, float x2, float y2, float w);
52   void relativeConicTo(float x1, float y1, float x2, float y2, float w);
53   void arcTo(float left,
54              float top,
55              float right,
56              float bottom,
57              float startAngle,
58              float sweepAngle,
59              bool forceMoveTo);
60   void arcToPoint(float arcEndX,
61                   float arcEndY,
62                   float radiusX,
63                   float radiusY,
64                   float xAxisRotation,
65                   bool isLargeArc,
66                   bool isClockwiseDirection);
67   void relativeArcToPoint(float arcEndDeltaX,
68                           float arcEndDeltaY,
69                           float radiusX,
70                           float radiusY,
71                           float xAxisRotation,
72                           bool isLargeArc,
73                           bool isClockwiseDirection);
74   void addRect(float left, float top, float right, float bottom);
75   void addOval(float left, float top, float right, float bottom);
76   void addArc(float left,
77               float top,
78               float right,
79               float bottom,
80               float startAngle,
81               float sweepAngle);
82   void addPolygon(const tonic::Float32List& points, bool close);
83   void addRRect(const RRect& rrect);
84   void addPath(CanvasPath* path, double dx, double dy);
85   void addPathWithMatrix(CanvasPath* path,
86                          double dx,
87                          double dy,
88                          tonic::Float64List& matrix4);
89   void extendWithPath(CanvasPath* path, double dx, double dy);
90   void extendWithPathAndMatrix(CanvasPath* path,
91                                double dx,
92                                double dy,
93                                tonic::Float64List& matrix4);
94   void close();
95   void reset();
96   bool contains(double x, double y);
97   fml::RefPtr<CanvasPath> shift(double dx, double dy);
98   fml::RefPtr<CanvasPath> transform(tonic::Float64List& matrix4);
99   tonic::Float32List getBounds();
100   bool op(CanvasPath* path1, CanvasPath* path2, int operation);
101   fml::RefPtr<CanvasPath> clone();
102 
path()103   const SkPath& path() const { return path_; }
104 
105   static void RegisterNatives(tonic::DartLibraryNatives* natives);
106 
107  private:
108   CanvasPath();
109 
110   SkPath path_;
111 };
112 
113 }  // namespace flutter
114 
115 #endif  // FLUTTER_LIB_UI_PAINTING_PATH_H_
116