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#include "third_party/tonic/typed_data/typed_list.h"
13
14namespace tonic {
15class DartLibraryNatives;
16} // namespace tonic
17
18namespace flutter {
19
20class CanvasPath : public RefCountedDartWrappable<CanvasPath> {
21 DEFINE_WRAPPERTYPEINFO();
22 FML_FRIEND_MAKE_REF_COUNTED(CanvasPath);
23
24 public:
25 ~CanvasPath() override;
26 static fml::RefPtr<CanvasPath> CreateNew(Dart_Handle path_handle) {
27 return fml::MakeRefCounted<CanvasPath>();
28 }
29
30 static fml::RefPtr<CanvasPath> Create(Dart_Handle path_handle) {
31 auto path = fml::MakeRefCounted<CanvasPath>();
32 path->AssociateWithDartWrapper(path_handle);
33 return path;
34 }
35
36 static fml::RefPtr<CanvasPath> CreateFrom(Dart_Handle path_handle,
37 const SkPath& src) {
38 fml::RefPtr<CanvasPath> path = CanvasPath::Create(path_handle);
39 path->path_ = src;
40 return path;
41 }
42
43 int getFillType();
44 void setFillType(int fill_type);
45
46 void moveTo(float x, float y);
47 void relativeMoveTo(float x, float y);
48 void lineTo(float x, float y);
49 void relativeLineTo(float x, float y);
50 void quadraticBezierTo(float x1, float y1, float x2, float y2);
51 void relativeQuadraticBezierTo(float x1, float y1, float x2, float y2);
52 void cubicTo(float x1, float y1, float x2, float y2, float x3, float y3);
53 void relativeCubicTo(float x1,
54 float y1,
55 float x2,
56 float y2,
57 float x3,
58 float y3);
59 void conicTo(float x1, float y1, float x2, float y2, float w);
60 void relativeConicTo(float x1, float y1, float x2, float y2, float w);
61 void arcTo(float left,
62 float top,
63 float right,
64 float bottom,
65 float startAngle,
66 float sweepAngle,
67 bool forceMoveTo);
68 void arcToPoint(float arcEndX,
69 float arcEndY,
70 float radiusX,
71 float radiusY,
72 float xAxisRotation,
73 bool isLargeArc,
74 bool isClockwiseDirection);
75 void relativeArcToPoint(float arcEndDeltaX,
76 float arcEndDeltaY,
77 float radiusX,
78 float radiusY,
79 float xAxisRotation,
80 bool isLargeArc,
81 bool isClockwiseDirection);
82 void addRect(float left, float top, float right, float bottom);
83 void addOval(float left, float top, float right, float bottom);
84 void addArc(float left,
85 float top,
86 float right,
87 float bottom,
88 float startAngle,
89 float sweepAngle);
90 void addPolygon(const tonic::Float32List& points, bool close);
91 void addRRect(const RRect& rrect);
92 void addPath(CanvasPath* path, double dx, double dy);
93 void addPathWithMatrix(CanvasPath* path,
94 double dx,
95 double dy,
96 tonic::Float64List& matrix4);
97 void extendWithPath(CanvasPath* path, double dx, double dy);
98 void extendWithPathAndMatrix(CanvasPath* path,
99 double dx,
100 double dy,
101 tonic::Float64List& matrix4);
102 void close();
103 void reset();
104 bool contains(double x, double y);
105 void shift(Dart_Handle path_handle, double dx, double dy);
106 void transform(Dart_Handle path_handle, tonic::Float64List& matrix4);
107 tonic::Float32List getBounds();
108 bool op(CanvasPath* path1, CanvasPath* path2, int operation);
109 void clone(Dart_Handle path_handle);
110
111 const SkPath& path() const { return path_; }
112
113 size_t GetAllocationSize() const override;
114
115 static void RegisterNatives(tonic::DartLibraryNatives* natives);
116
117 private:
118 CanvasPath();
119
120 SkPath path_;
121};
122
123} // namespace flutter
124
125#endif // FLUTTER_LIB_UI_PAINTING_PATH_H_
126