00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef SkPath_DEFINED
00018 #define SkPath_DEFINED
00019
00020 #include "SkMatrix.h"
00021 #include "SkTDArray.h"
00022
00023 class SkFlattenableReadBuffer;
00024 class SkFlattenableWriteBuffer;
00025 class SkAutoPathBoundsUpdate;
00026 class SkString;
00027
00033 class SkPath {
00034 public:
00035 SkPath();
00036 SkPath(const SkPath&);
00037 ~SkPath();
00038
00039 SkPath& operator=(const SkPath&);
00040
00041 friend bool operator==(const SkPath&, const SkPath&);
00042 friend bool operator!=(const SkPath& a, const SkPath& b) {
00043 return !(a == b);
00044 }
00045
00046 enum FillType {
00050 kWinding_FillType,
00054 kEvenOdd_FillType,
00057 kInverseWinding_FillType,
00060 kInverseEvenOdd_FillType
00061 };
00062
00068 FillType getFillType() const { return (FillType)fFillType; }
00069
00075 void setFillType(FillType ft) { fFillType = SkToU8(ft); }
00076
00078 bool isInverseFillType() const { return (fFillType & 2) != 0; }
00079
00083 void toggleInverseFillType() { fFillType ^= 2; }
00084
00088 bool isConvex() const { return fIsConvex != 0; }
00089
00095 void setIsConvex(bool isConvex) { fIsConvex = (isConvex != 0); }
00096
00101 void reset();
00102
00108 void rewind();
00109
00114 bool isEmpty() const;
00115
00124 bool isRect(SkRect* rect) const;
00125
00132 int getPoints(SkPoint points[], int max) const;
00133
00135 void swap(SkPath& other);
00136
00142 const SkRect& getBounds() const {
00143 if (fBoundsIsDirty) {
00144 this->computeBounds();
00145 }
00146 return fBounds;
00147 }
00148
00154 void updateBoundsCache() const {
00155
00156 this->getBounds();
00157 }
00158
00159
00160
00167 void incReserve(unsigned extraPtCount);
00168
00174 void moveTo(SkScalar x, SkScalar y);
00175
00180 void moveTo(const SkPoint& p) {
00181 this->moveTo(p.fX, p.fY);
00182 }
00183
00193 void rMoveTo(SkScalar dx, SkScalar dy);
00194
00202 void lineTo(SkScalar x, SkScalar y);
00203
00210 void lineTo(const SkPoint& p) {
00211 this->lineTo(p.fX, p.fY);
00212 }
00213
00223 void rLineTo(SkScalar dx, SkScalar dy);
00224
00234 void quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2);
00235
00243 void quadTo(const SkPoint& p1, const SkPoint& p2) {
00244 this->quadTo(p1.fX, p1.fY, p2.fX, p2.fY);
00245 }
00246
00260 void rQuadTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2);
00261
00273 void cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
00274 SkScalar x3, SkScalar y3);
00275
00284 void cubicTo(const SkPoint& p1, const SkPoint& p2, const SkPoint& p3) {
00285 this->cubicTo(p1.fX, p1.fY, p2.fX, p2.fY, p3.fX, p3.fY);
00286 }
00287
00305 void rCubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
00306 SkScalar x3, SkScalar y3);
00307
00320 void arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
00321 bool forceMoveTo);
00322
00326 void arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
00327 SkScalar radius);
00328
00332 void arcTo(const SkPoint p1, const SkPoint p2, SkScalar radius) {
00333 this->arcTo(p1.fX, p1.fY, p2.fX, p2.fY, radius);
00334 }
00335
00339 void close();
00340
00341 enum Direction {
00343 kCW_Direction,
00345 kCCW_Direction
00346 };
00347
00352 void addRect(const SkRect& rect, Direction dir = kCW_Direction);
00353
00366 void addRect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom,
00367 Direction dir = kCW_Direction);
00368
00374 void addOval(const SkRect& oval, Direction dir = kCW_Direction);
00375
00386 void addCircle(SkScalar x, SkScalar y, SkScalar radius,
00387 Direction dir = kCW_Direction);
00388
00395 void addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle);
00396
00403 void addRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry,
00404 Direction dir = kCW_Direction);
00405
00413 void addRoundRect(const SkRect& rect, const SkScalar radii[],
00414 Direction dir = kCW_Direction);
00415
00421 void addPath(const SkPath& src, SkScalar dx, SkScalar dy);
00422
00425 void addPath(const SkPath& src) {
00426 SkMatrix m;
00427 m.reset();
00428 this->addPath(src, m);
00429 }
00430
00434 void addPath(const SkPath& src, const SkMatrix& matrix);
00435
00442 void offset(SkScalar dx, SkScalar dy, SkPath* dst) const;
00443
00449 void offset(SkScalar dx, SkScalar dy) {
00450 this->offset(dx, dy, this);
00451 }
00452
00459 void transform(const SkMatrix& matrix, SkPath* dst) const;
00460
00465 void transform(const SkMatrix& matrix) {
00466 this->transform(matrix, this);
00467 }
00468
00474 void getLastPt(SkPoint* lastPt) const;
00475
00482 void setLastPt(SkScalar x, SkScalar y);
00483
00489 void setLastPt(const SkPoint& p) {
00490 this->setLastPt(p.fX, p.fY);
00491 }
00492
00493 enum Verb {
00494 kMove_Verb,
00495 kLine_Verb,
00496 kQuad_Verb,
00497 kCubic_Verb,
00498 kClose_Verb,
00499 kDone_Verb
00500 };
00501
00505 class Iter {
00506 public:
00507 Iter();
00508 Iter(const SkPath&, bool forceClose);
00509
00510 void setPath(const SkPath&, bool forceClose);
00511
00518 Verb next(SkPoint pts[4]);
00519
00528 bool isCloseLine() const { return SkToBool(fCloseLine); }
00529
00533 bool isClosedContour() const;
00534
00535 private:
00536 const SkPoint* fPts;
00537 const uint8_t* fVerbs;
00538 const uint8_t* fVerbStop;
00539 SkPoint fMoveTo;
00540 SkPoint fLastPt;
00541 SkBool8 fForceClose;
00542 SkBool8 fNeedClose;
00543 SkBool8 fNeedMoveTo;
00544 SkBool8 fCloseLine;
00545
00546 bool cons_moveTo(SkPoint pts[1]);
00547 Verb autoClose(SkPoint pts[2]);
00548 };
00549
00550 #ifdef SK_DEBUG
00551
00552 void dump(bool forceClose, const char title[] = NULL) const;
00554 #endif
00555
00556 void flatten(SkFlattenableWriteBuffer&) const;
00557 void unflatten(SkFlattenableReadBuffer&);
00558
00563 void subdivide(SkScalar dist, bool bendLines, SkPath* dst = NULL) const;
00564
00565 SkDEBUGCODE(void validate() const;)
00566
00567 private:
00568 SkTDArray<SkPoint> fPts;
00569 SkTDArray<uint8_t> fVerbs;
00570 mutable SkRect fBounds;
00571 mutable uint8_t fBoundsIsDirty;
00572 uint8_t fFillType;
00573 uint8_t fIsConvex;
00574
00575
00576 void computeBounds() const;
00577
00578 friend class Iter;
00579 void cons_moveto();
00580
00581 friend class SkPathStroker;
00582
00583
00584
00585
00586 void pathTo(const SkPath& path);
00587
00588
00589
00590
00591
00592 void reversePathTo(const SkPath&);
00593
00594 friend const SkPoint* sk_get_path_points(const SkPath&, int index);
00595 friend class SkAutoPathBoundsUpdate;
00596 };
00597
00598 #endif
00599