14 enum class Direction { CCW, CW };
16 enum class Element : uchar { MoveTo, LineTo, CubicTo, Close };
18 void moveTo(const VPointF &p);
19 void moveTo(float x, float y);
20 void lineTo(const VPointF &p);
21 void lineTo(float x, float y);
22 void cubicTo(const VPointF &c1, const VPointF &c2, const VPointF &e);
23 void cubicTo(float c1x, float c1y, float c2x, float c2y, float ex,
25 void arcTo(const VRectF &rect, float startAngle, float sweepLength,
29 void reserve(int pts, int elms);
31 void addCircle(float cx, float cy, float radius,
32 VPath::Direction dir = Direction::CW);
33 void addOval(const VRectF &rect, VPath::Direction dir = Direction::CW);
34 void addRoundRect(const VRectF &rect, float rx, float ry,
35 VPath::Direction dir = Direction::CW);
36 void addRoundRect(const VRectF &rect, float roundness,
37 VPath::Direction dir = Direction::CW);
38 void addRect(const VRectF &rect, VPath::Direction dir = Direction::CW);
39 void addPolystar(float points, float innerRadius, float outerRadius,
40 float innerRoundness, float outerRoundness,
41 float startAngle, float cx, float cy,
42 VPath::Direction dir = Direction::CW);
43 void addPolygon(float points, float radius, float roundness,
44 float startAngle, float cx, float cy,
45 VPath::Direction dir = Direction::CW);
46 void addPath(const VPath &path);
47 void transform(const VMatrix &m);
49 const std::vector<VPath::Element> &elements() const;
50 const std::vector<VPointF> & points() const;
51 void clone(const VPath &srcPath);
55 bool empty() const { return m_elements.empty(); }
56 void moveTo(float x, float y);
57 void lineTo(float x, float y);
58 void cubicTo(float cx1, float cy1, float cx2, float cy2, float ex, float ey);
61 void reserve(int, int);
62 void checkNewSegment();
64 void transform(const VMatrix &m);
66 void addRoundRect(const VRectF &, float, float, VPath::Direction);
67 void addRoundRect(const VRectF &, float, VPath::Direction);
68 void addRect(const VRectF &, VPath::Direction);
69 void arcTo(const VRectF &, float, float, bool);
70 void addCircle(float, float, float, VPath::Direction);
71 void addOval(const VRectF &, VPath::Direction);
72 void addPolystar(float points, float innerRadius, float outerRadius,
73 float innerRoundness, float outerRoundness,
74 float startAngle, float cx, float cy,
75 VPath::Direction dir = Direction::CW);
76 void addPolygon(float points, float radius, float roundness,
77 float startAngle, float cx, float cy,
78 VPath::Direction dir = Direction::CW);
79 void addPath(const VPathData &path);
80 const std::vector<VPath::Element> &elements() const
84 const std::vector<VPointF> &points() const { return m_points; }
85 std::vector<VPointF> m_points;
86 std::vector<VPath::Element> m_elements;
89 mutable float mLength{0};
90 mutable bool mLengthDirty{true};
94 vcow_ptr<VPathData> d;
97 inline bool VPath::empty() const
102 inline void VPath::moveTo(const VPointF &p)
104 d.write().moveTo(p.x(), p.y());
107 inline void VPath::lineTo(const VPointF &p)
109 d.write().lineTo(p.x(), p.y());
112 inline void VPath::close()
117 inline void VPath::reset()
122 inline void VPath::reserve(int pts, int elms)
124 d.write().reserve(pts, elms);
127 inline int VPath::segments() const
129 return d->segments();
132 inline float VPath::length() const
134 // TODO re-calculate when there is a change
138 inline void VPath::cubicTo(const VPointF &c1, const VPointF &c2,
141 d.write().cubicTo(c1.x(), c1.y(), c2.x(), c2.y(), e.x(), e.y());
144 inline void VPath::lineTo(float x, float y)
146 d.write().lineTo(x, y);
149 inline void VPath::moveTo(float x, float y)
151 d.write().moveTo(x, y);
154 inline void VPath::cubicTo(float c1x, float c1y, float c2x, float c2y, float ex,
157 d.write().cubicTo(c1x, c1y, c2x, c2y, ex, ey);
160 inline void VPath::transform(const VMatrix &m)
162 d.write().transform(m);
165 inline void VPath::arcTo(const VRectF &rect, float startAngle,
166 float sweepLength, bool forceMoveTo)
168 d.write().arcTo(rect, startAngle, sweepLength, forceMoveTo);
171 inline void VPath::addRect(const VRectF &rect, VPath::Direction dir)
173 d.write().addRect(rect, dir);
176 inline void VPath::addRoundRect(const VRectF &rect, float rx, float ry,
177 VPath::Direction dir)
179 d.write().addRoundRect(rect, rx, ry, dir);
182 inline void VPath::addRoundRect(const VRectF &rect, float roundness,
183 VPath::Direction dir)
185 d.write().addRoundRect(rect, roundness, dir);
188 inline void VPath::addCircle(float cx, float cy, float radius,
189 VPath::Direction dir)
191 d.write().addCircle(cx, cy, radius, dir);
194 inline void VPath::addOval(const VRectF &rect, VPath::Direction dir)
196 d.write().addOval(rect, dir);
199 inline void VPath::addPolystar(float points, float innerRadius,
200 float outerRadius, float innerRoundness,
201 float outerRoundness, float startAngle, float cx,
202 float cy, VPath::Direction dir)
204 d.write().addPolystar(points, innerRadius, outerRadius, innerRoundness,
205 outerRoundness, startAngle, cx, cy, dir);
208 inline void VPath::addPolygon(float points, float radius, float roundness,
209 float startAngle, float cx, float cy,
210 VPath::Direction dir)
212 d.write().addPolygon(points, radius, roundness, startAngle, cx, cy, dir);
215 inline void VPath::addPath(const VPath &path)
217 if (path.empty()) return;
222 d.write().addPath(path.d.read());
226 inline const std::vector<VPath::Element> &VPath::elements() const
228 return d->elements();
231 inline const std::vector<VPointF> &VPath::points() const
236 inline void VPath::clone(const VPath &srcPath)
238 d.write() = srcPath.d.read();