| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2010 Google Inc. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (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 |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 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. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | #ifndef GrPath_DEFINED |
| 19 | #define GrPath_DEFINED |
| 20 | |
| 21 | #include "GrPathSink.h" |
| 22 | #include "GrPathIter.h" |
| 23 | #include "GrTDArray.h" |
| 24 | #include "GrPoint.h" |
| 25 | |
| 26 | class GrPath : public GrPathSink { |
| 27 | public: |
| 28 | GrPath(); |
| 29 | GrPath(const GrPath&); |
| 30 | explicit GrPath(GrPathIter&); |
| 31 | virtual ~GrPath(); |
| 32 | |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 33 | GrConvexHint getConvexHint() const { return fConvexHint; } |
| 34 | void setConvexHint(GrConvexHint hint) { fConvexHint = hint; } |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 35 | |
| 36 | void resetFromIter(GrPathIter*); |
| 37 | |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 38 | bool operator ==(const GrPath& path) const; |
| 39 | bool operator !=(const GrPath& path) const { return !(*this == path); } |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 40 | // overrides from GrPathSink |
| 41 | |
| 42 | virtual void moveTo(GrScalar x, GrScalar y); |
| 43 | virtual void lineTo(GrScalar x, GrScalar y); |
| 44 | virtual void quadTo(GrScalar x0, GrScalar y0, GrScalar x1, GrScalar y1); |
| 45 | virtual void cubicTo(GrScalar x0, GrScalar y0, GrScalar x1, GrScalar y1, |
| 46 | GrScalar x2, GrScalar y2); |
| 47 | virtual void close(); |
| 48 | |
| reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 49 | /** |
| 50 | * Offset the path by (tx, ty), adding tx to the horizontal position |
| 51 | * and adds ty to the vertical position of every point. |
| 52 | */ |
| 53 | void offset(GrScalar tx, GrScalar ty); |
| 54 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 55 | class Iter : public GrPathIter { |
| 56 | public: |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 57 | /** |
| 58 | * Creates an uninitialized iterator |
| 59 | */ |
| 60 | Iter(); |
| 61 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 62 | Iter(const GrPath& path); |
| 63 | |
| 64 | // overrides from GrPathIter |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 65 | virtual GrPathCmd next(GrPoint points[]); |
| 66 | virtual GrConvexHint convexHint() const; |
| 67 | virtual GrPathCmd next(); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 68 | virtual void rewind(); |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * Sets iterator to begining of path |
| 72 | */ |
| 73 | void reset(const GrPath& path); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 74 | private: |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 75 | const GrPath* fPath; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 76 | GrPoint fLastPt; |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 77 | int fCmdIndex; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 78 | int fPtIndex; |
| 79 | }; |
| 80 | |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 81 | static void ConvexUnitTest(); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 82 | |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 83 | private: |
| 84 | |
| 85 | GrTDArray<GrPathCmd> fCmds; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 86 | GrTDArray<GrPoint> fPts; |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 87 | GrConvexHint fConvexHint; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 88 | |
| 89 | // this ensures we have a moveTo at the start of each contour |
| 90 | inline void ensureMoveTo(); |
| 91 | |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 92 | bool wasLastVerb(GrPathCmd cmd) const { |
| 93 | int count = fCmds.count(); |
| 94 | return count > 0 && cmd == fCmds[count - 1]; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | friend class Iter; |
| reed@google.com | c921843 | 2011-01-25 19:05:12 +0000 | [diff] [blame] | 98 | |
| 99 | typedef GrPathSink INHERITED; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | #endif |
| 103 | |