blob: d70609ee6b1674e15b13440e8c3c13c47a29a0f9 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
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
26class GrPath : public GrPathSink {
27public:
28 GrPath();
29 GrPath(const GrPath&);
30 explicit GrPath(GrPathIter&);
31 virtual ~GrPath();
32
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000033 GrConvexHint getConvexHint() const { return fConvexHint; }
34 void setConvexHint(GrConvexHint hint) { fConvexHint = hint; }
reed@google.comac10a2d2010-12-22 21:39:39 +000035
36 void resetFromIter(GrPathIter*);
37
bsalomon@google.comd302f142011-03-03 13:54:13 +000038 bool operator ==(const GrPath& path) const;
39 bool operator !=(const GrPath& path) const { return !(*this == path); }
reed@google.comac10a2d2010-12-22 21:39:39 +000040 // 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
49 class Iter : public GrPathIter {
50 public:
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000051 /**
52 * Creates an uninitialized iterator
53 */
54 Iter();
55
reed@google.comac10a2d2010-12-22 21:39:39 +000056 Iter(const GrPath& path);
57
58 // overrides from GrPathIter
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000059 virtual GrPathCmd next(GrPoint points[]);
60 virtual GrConvexHint convexHint() const;
61 virtual GrPathCmd next();
reed@google.comac10a2d2010-12-22 21:39:39 +000062 virtual void rewind();
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000063
64 /**
65 * Sets iterator to begining of path
66 */
67 void reset(const GrPath& path);
reed@google.comac10a2d2010-12-22 21:39:39 +000068 private:
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000069 const GrPath* fPath;
reed@google.comac10a2d2010-12-22 21:39:39 +000070 GrPoint fLastPt;
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000071 int fCmdIndex;
reed@google.comac10a2d2010-12-22 21:39:39 +000072 int fPtIndex;
73 };
74
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000075 static void ConvexUnitTest();
reed@google.comac10a2d2010-12-22 21:39:39 +000076
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000077private:
78
79 GrTDArray<GrPathCmd> fCmds;
reed@google.comac10a2d2010-12-22 21:39:39 +000080 GrTDArray<GrPoint> fPts;
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000081 GrConvexHint fConvexHint;
reed@google.comac10a2d2010-12-22 21:39:39 +000082
83 // this ensures we have a moveTo at the start of each contour
84 inline void ensureMoveTo();
85
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000086 bool wasLastVerb(GrPathCmd cmd) const {
87 int count = fCmds.count();
88 return count > 0 && cmd == fCmds[count - 1];
reed@google.comac10a2d2010-12-22 21:39:39 +000089 }
90
91 friend class Iter;
reed@google.comc9218432011-01-25 19:05:12 +000092
93 typedef GrPathSink INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +000094};
95
96#endif
97