OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkPath_DEFINED | 8 #ifndef SkPath_DEFINED |
9 #define SkPath_DEFINED | 9 #define SkPath_DEFINED |
10 | 10 |
11 #include "SkMatrix.h" | 11 #include "SkMatrix.h" |
12 #include "SkPathRef.h" | 12 #include "SkPathRef.h" |
13 #include "SkRefCnt.h" | 13 #include "SkRefCnt.h" |
14 | 14 |
15 class SkReader32; | 15 class SkReader32; |
16 class SkWriter32; | 16 class SkWriter32; |
17 class SkAutoPathBoundsUpdate; | 17 class SkAutoPathBoundsUpdate; |
18 class SkString; | 18 class SkString; |
19 class SkRRect; | 19 class SkRRect; |
20 class SkWStream; | 20 class SkWStream; |
21 | 21 |
22 /** \class SkPath | 22 /** \class SkPath |
23 | 23 |
24 The SkPath class encapsulates compound (multiple contour) geometric paths | 24 The SkPath class encapsulates compound (multiple contour) geometric paths |
25 consisting of straight line segments, quadratic curves, and cubic curves. | 25 consisting of straight line segments, quadratic curves, and cubic curves. |
26 */ | 26 */ |
27 class SK_API SkPath { | 27 class SK_API SkPath { |
28 public: | 28 public: |
| 29 enum Direction { |
| 30 /** clockwise direction for adding closed contours */ |
| 31 kCW_Direction, |
| 32 /** counter-clockwise direction for adding closed contours */ |
| 33 kCCW_Direction, |
| 34 }; |
| 35 |
29 SkPath(); | 36 SkPath(); |
30 SkPath(const SkPath&); | 37 SkPath(const SkPath&); |
31 ~SkPath(); | 38 ~SkPath(); |
32 | 39 |
33 SkPath& operator=(const SkPath&); | 40 SkPath& operator=(const SkPath&); |
34 friend SK_API bool operator==(const SkPath&, const SkPath&); | 41 friend SK_API bool operator==(const SkPath&, const SkPath&); |
35 friend bool operator!=(const SkPath& a, const SkPath& b) { | 42 friend bool operator!=(const SkPath& a, const SkPath& b) { |
36 return !(a == b); | 43 return !(a == b); |
37 } | 44 } |
38 | 45 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 */ | 166 */ |
160 SK_ATTR_DEPRECATED("use setConvexity") | 167 SK_ATTR_DEPRECATED("use setConvexity") |
161 void setIsConvex(bool isConvex) { | 168 void setIsConvex(bool isConvex) { |
162 this->setConvexity(isConvex ? kConvex_Convexity : kConcave_Convexity); | 169 this->setConvexity(isConvex ? kConvex_Convexity : kConcave_Convexity); |
163 } | 170 } |
164 | 171 |
165 /** Returns true if the path is an oval. | 172 /** Returns true if the path is an oval. |
166 * | 173 * |
167 * @param rect returns the bounding rect of this oval. It's a circle | 174 * @param rect returns the bounding rect of this oval. It's a circle |
168 * if the height and width are the same. | 175 * if the height and width are the same. |
169 * | 176 * @param isCCW is the oval CCW (or CW if false). |
| 177 * @param start indicates where the contour starts on the oval (see |
| 178 * SkPath::addOval for intepretation of the index). |
170 * @return true if this path is an oval. | 179 * @return true if this path is an oval. |
171 * Tracking whether a path is an oval is considered an | 180 * Tracking whether a path is an oval is considered an |
172 * optimization for performance and so some paths that are in | 181 * optimization for performance and so some paths that are in |
173 * fact ovals can report false. | 182 * fact ovals can report false. |
174 */ | 183 */ |
175 bool isOval(SkRect* rect) const { return fPathRef->isOval(rect); } | 184 bool isOval(SkRect* rect, Direction* dir = nullptr, |
| 185 unsigned* start = nullptr) const { |
| 186 bool isCCW; |
| 187 bool result = fPathRef->isOval(rect, &isCCW, start); |
| 188 if (dir && result) { |
| 189 *dir = isCCW ? kCCW_Direction : kCW_Direction; |
| 190 } |
| 191 return result; |
| 192 } |
176 | 193 |
177 /** Returns true if the path is a round rect. | 194 /** Returns true if the path is a round rect. |
178 * | 195 * |
179 * @param rrect Returns the bounding rect and radii of this round rect. | 196 * @param rrect Returns the bounding rect and radii of this round rect. |
180 * | 197 * |
| 198 * @param isCCW is the rrect CCW (or CW if false). |
| 199 * @param start indicates where the contour starts on the rrect (see |
| 200 * SkPath::addRRect for intepretation of the index). |
| 201 * |
181 * @return true if this path is a round rect. | 202 * @return true if this path is a round rect. |
182 * Tracking whether a path is a round rect is considered an | 203 * Tracking whether a path is a round rect is considered an |
183 * optimization for performance and so some paths that are in | 204 * optimization for performance and so some paths that are in |
184 * fact round rects can report false. | 205 * fact round rects can report false. |
185 */ | 206 */ |
186 bool isRRect(SkRRect* rrect) const { return fPathRef->isRRect(rrect); } | 207 bool isRRect(SkRRect* rrect, Direction* dir = nullptr, |
| 208 unsigned* start = nullptr) const { |
| 209 bool isCCW; |
| 210 bool result = fPathRef->isRRect(rrect, &isCCW, start); |
| 211 if (dir && result) { |
| 212 *dir = isCCW ? kCCW_Direction : kCW_Direction; |
| 213 } |
| 214 return result; |
| 215 } |
187 | 216 |
188 /** Clear any lines and curves from the path, making it empty. This frees up | 217 /** Clear any lines and curves from the path, making it empty. This frees up |
189 internal storage associated with those segments. | 218 internal storage associated with those segments. |
190 On Android, does not change fSourcePath. | 219 On Android, does not change fSourcePath. |
191 */ | 220 */ |
192 void reset(); | 221 void reset(); |
193 | 222 |
194 /** Similar to reset(), in that all lines and curves are removed from the | 223 /** Similar to reset(), in that all lines and curves are removed from the |
195 path. However, any internal storage for those lines/curves is retained, | 224 path. However, any internal storage for those lines/curves is retained, |
196 making reuse of the path potentially faster. | 225 making reuse of the path potentially faster. |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 this->arcTo(p1.fX, p1.fY, p2.fX, p2.fY, radius); | 548 this->arcTo(p1.fX, p1.fY, p2.fX, p2.fY, radius); |
520 } | 549 } |
521 | 550 |
522 enum ArcSize { | 551 enum ArcSize { |
523 /** the smaller of the two possible SVG arcs. */ | 552 /** the smaller of the two possible SVG arcs. */ |
524 kSmall_ArcSize, | 553 kSmall_ArcSize, |
525 /** the larger of the two possible SVG arcs. */ | 554 /** the larger of the two possible SVG arcs. */ |
526 kLarge_ArcSize, | 555 kLarge_ArcSize, |
527 }; | 556 }; |
528 | 557 |
529 enum Direction { | |
530 /** clockwise direction for adding closed contours */ | |
531 kCW_Direction, | |
532 /** counter-clockwise direction for adding closed contours */ | |
533 kCCW_Direction, | |
534 }; | |
535 | |
536 /** | 558 /** |
537 * Append an elliptical arc from the current point in the format used by SV
G. | 559 * Append an elliptical arc from the current point in the format used by SV
G. |
538 * The center of the ellipse is computed to satisfy the constraints below. | 560 * The center of the ellipse is computed to satisfy the constraints below. |
539 * | 561 * |
540 * @param rx,ry The radii in the x and y directions respectively. | 562 * @param rx,ry The radii in the x and y directions respectively. |
541 * @param xAxisRotate The angle in degrees relative to the x-axis. | 563 * @param xAxisRotate The angle in degrees relative to the x-axis. |
542 * @param largeArc Determines whether the smallest or largest arc possible | 564 * @param largeArc Determines whether the smallest or largest arc possible |
543 * is drawn. | 565 * is drawn. |
544 * @param sweep Determines if the arc should be swept in an anti-clockwise
or | 566 * @param sweep Determines if the arc should be swept in an anti-clockwise
or |
545 * clockwise direction. Note that this enum value is opposite the SV
G | 567 * clockwise direction. Note that this enum value is opposite the SV
G |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 * -*- | 732 * -*- |
711 * | | | 733 * | | |
712 * 3 * * 1 | 734 * 3 * * 1 |
713 * | | | 735 * | | |
714 * -*- | 736 * -*- |
715 * 2 | 737 * 2 |
716 */ | 738 */ |
717 void addOval(const SkRect& oval, Direction dir, unsigned start); | 739 void addOval(const SkRect& oval, Direction dir, unsigned start); |
718 | 740 |
719 /** | 741 /** |
720 * Add a closed circle contour to the path | 742 * Add a closed circle contour to the path. The circle contour begins at |
| 743 * the right-most point (as though 1 were to addOval's 'start' param). |
721 * | 744 * |
722 * @param x The x-coordinate of the center of a circle to add as a | 745 * @param x The x-coordinate of the center of a circle to add as a |
723 * closed contour to the path | 746 * closed contour to the path |
724 * @param y The y-coordinate of the center of a circle to add as a | 747 * @param y The y-coordinate of the center of a circle to add as a |
725 * closed contour to the path | 748 * closed contour to the path |
726 * @param radius The radius of a circle to add as a closed contour to the | 749 * @param radius The radius of a circle to add as a closed contour to the |
727 * path | 750 * path |
728 * @param dir The direction to wind the circle's contour. | 751 * @param dir The direction to wind the circle's contour. |
729 */ | 752 */ |
730 void addCircle(SkScalar x, SkScalar y, SkScalar radius, | 753 void addCircle(SkScalar x, SkScalar y, SkScalar radius, |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 | 1190 |
1168 friend class SkAutoPathBoundsUpdate; | 1191 friend class SkAutoPathBoundsUpdate; |
1169 friend class SkAutoDisableOvalCheck; | 1192 friend class SkAutoDisableOvalCheck; |
1170 friend class SkAutoDisableDirectionCheck; | 1193 friend class SkAutoDisableDirectionCheck; |
1171 friend class SkBench_AddPathTest; // perf test reversePathTo | 1194 friend class SkBench_AddPathTest; // perf test reversePathTo |
1172 friend class PathTest_Private; // unit test reversePathTo | 1195 friend class PathTest_Private; // unit test reversePathTo |
1173 friend class ForceIsRRect_Private; // unit test isRRect | 1196 friend class ForceIsRRect_Private; // unit test isRRect |
1174 }; | 1197 }; |
1175 | 1198 |
1176 #endif | 1199 #endif |
OLD | NEW |