2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
30 enum class Direction { CCW, CW };
32 enum class Element : uchar { MoveTo, LineTo, CubicTo, Close };
35 void moveTo(const VPointF &p);
36 void moveTo(float x, float y);
37 void lineTo(const VPointF &p);
38 void lineTo(float x, float y);
39 void cubicTo(const VPointF &c1, const VPointF &c2, const VPointF &e);
40 void cubicTo(float c1x, float c1y, float c2x, float c2y, float ex,
42 void arcTo(const VRectF &rect, float startAngle, float sweepLength,
46 void reserve(int pts, int elms);
48 void addCircle(float cx, float cy, float radius,
49 VPath::Direction dir = Direction::CW);
50 void addOval(const VRectF &rect, VPath::Direction dir = Direction::CW);
51 void addRoundRect(const VRectF &rect, float rx, float ry,
52 VPath::Direction dir = Direction::CW);
53 void addRoundRect(const VRectF &rect, float roundness,
54 VPath::Direction dir = Direction::CW);
55 void addRect(const VRectF &rect, VPath::Direction dir = Direction::CW);
56 void addPolystar(float points, float innerRadius, float outerRadius,
57 float innerRoundness, float outerRoundness,
58 float startAngle, float cx, float cy,
59 VPath::Direction dir = Direction::CW);
60 void addPolygon(float points, float radius, float roundness,
61 float startAngle, float cx, float cy,
62 VPath::Direction dir = Direction::CW);
63 void addPath(const VPath &path);
64 void transform(const VMatrix &m);
66 const std::vector<VPath::Element> &elements() const;
67 const std::vector<VPointF> & points() const;
68 void clone(const VPath &srcPath);
69 bool unique() const { return d.unique();}
70 int refCount() const { return d.refCount();}
74 bool empty() const { return m_elements.empty(); }
75 bool null() const { return empty() && !m_elements.capacity();}
76 void moveTo(float x, float y);
77 void lineTo(float x, float y);
78 void cubicTo(float cx1, float cy1, float cx2, float cy2, float ex, float ey);
81 void reserve(int, int);
82 void checkNewSegment();
84 void transform(const VMatrix &m);
86 void addRoundRect(const VRectF &, float, float, VPath::Direction);
87 void addRoundRect(const VRectF &, float, VPath::Direction);
88 void addRect(const VRectF &, VPath::Direction);
89 void arcTo(const VRectF &, float, float, bool);
90 void addCircle(float, float, float, VPath::Direction);
91 void addOval(const VRectF &, VPath::Direction);
92 void addPolystar(float points, float innerRadius, float outerRadius,
93 float innerRoundness, float outerRoundness,
94 float startAngle, float cx, float cy,
95 VPath::Direction dir = Direction::CW);
96 void addPolygon(float points, float radius, float roundness,
97 float startAngle, float cx, float cy,
98 VPath::Direction dir = Direction::CW);
99 void addPath(const VPathData &path);
100 const std::vector<VPath::Element> &elements() const
104 const std::vector<VPointF> &points() const { return m_points; }
105 std::vector<VPointF> m_points;
106 std::vector<VPath::Element> m_elements;
109 mutable float mLength{0};
110 mutable bool mLengthDirty{true};
114 vcow_ptr<VPathData> d;
117 inline bool VPath::empty() const
123 * path is empty as well as null(no memory for data allocated yet).
125 inline bool VPath::null() const
130 inline void VPath::moveTo(const VPointF &p)
132 d.write().moveTo(p.x(), p.y());
135 inline void VPath::lineTo(const VPointF &p)
137 d.write().lineTo(p.x(), p.y());
140 inline void VPath::close()
145 inline void VPath::reset()
150 inline void VPath::reserve(int pts, int elms)
152 d.write().reserve(pts, elms);
155 inline int VPath::segments() const
157 return d->segments();
160 inline float VPath::length() const
165 inline void VPath::cubicTo(const VPointF &c1, const VPointF &c2,
168 d.write().cubicTo(c1.x(), c1.y(), c2.x(), c2.y(), e.x(), e.y());
171 inline void VPath::lineTo(float x, float y)
173 d.write().lineTo(x, y);
176 inline void VPath::moveTo(float x, float y)
178 d.write().moveTo(x, y);
181 inline void VPath::cubicTo(float c1x, float c1y, float c2x, float c2y, float ex,
184 d.write().cubicTo(c1x, c1y, c2x, c2y, ex, ey);
187 inline void VPath::transform(const VMatrix &m)
189 d.write().transform(m);
192 inline void VPath::arcTo(const VRectF &rect, float startAngle,
193 float sweepLength, bool forceMoveTo)
195 d.write().arcTo(rect, startAngle, sweepLength, forceMoveTo);
198 inline void VPath::addRect(const VRectF &rect, VPath::Direction dir)
200 d.write().addRect(rect, dir);
203 inline void VPath::addRoundRect(const VRectF &rect, float rx, float ry,
204 VPath::Direction dir)
206 d.write().addRoundRect(rect, rx, ry, dir);
209 inline void VPath::addRoundRect(const VRectF &rect, float roundness,
210 VPath::Direction dir)
212 d.write().addRoundRect(rect, roundness, dir);
215 inline void VPath::addCircle(float cx, float cy, float radius,
216 VPath::Direction dir)
218 d.write().addCircle(cx, cy, radius, dir);
221 inline void VPath::addOval(const VRectF &rect, VPath::Direction dir)
223 d.write().addOval(rect, dir);
226 inline void VPath::addPolystar(float points, float innerRadius,
227 float outerRadius, float innerRoundness,
228 float outerRoundness, float startAngle, float cx,
229 float cy, VPath::Direction dir)
231 d.write().addPolystar(points, innerRadius, outerRadius, innerRoundness,
232 outerRoundness, startAngle, cx, cy, dir);
235 inline void VPath::addPolygon(float points, float radius, float roundness,
236 float startAngle, float cx, float cy,
237 VPath::Direction dir)
239 d.write().addPolygon(points, radius, roundness, startAngle, cx, cy, dir);
242 inline void VPath::addPath(const VPath &path)
244 if (path.empty()) return;
249 d.write().addPath(path.d.read());
253 inline const std::vector<VPath::Element> &VPath::elements() const
255 return d->elements();
258 inline const std::vector<VPointF> &VPath::points() const
263 inline void VPath::clone(const VPath &srcPath)