SkPath Class Reference

#include <SkPath.h>

Collaboration diagram for SkPath:
Collaboration graph
[legend]

List of all members.

Classes

class  Iter

Public Types

enum  FillType { kWinding_FillType, kEvenOdd_FillType, kInverseWinding_FillType, kInverseEvenOdd_FillType }
enum  Direction { kCW_Direction, kCCW_Direction }
enum  Verb {
  kMove_Verb, kLine_Verb, kQuad_Verb, kCubic_Verb,
  kClose_Verb, kDone_Verb
}

Public Member Functions

 SkPath ()
 SkPath (const SkPath &)
 ~SkPath ()
SkPathoperator= (const SkPath &)
FillType getFillType () const
void setFillType (FillType ft)
bool isInverseFillType () const
void toggleInverseFillType ()
bool isConvex () const
void setIsConvex (bool isConvex)
void reset ()
void rewind ()
bool isEmpty () const
bool isRect (SkRect *rect) const
int getPoints (SkPoint points[], int max) const
void swap (SkPath &other)
 Swap contents of this and other. Guaranteed not to throw.
const SkRectgetBounds () const
void updateBoundsCache () const
void incReserve (unsigned extraPtCount)
void moveTo (SkScalar x, SkScalar y)
void moveTo (const SkPoint &p)
void rMoveTo (SkScalar dx, SkScalar dy)
void lineTo (SkScalar x, SkScalar y)
void lineTo (const SkPoint &p)
void rLineTo (SkScalar dx, SkScalar dy)
void quadTo (SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2)
void quadTo (const SkPoint &p1, const SkPoint &p2)
void rQuadTo (SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2)
void cubicTo (SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3)
void cubicTo (const SkPoint &p1, const SkPoint &p2, const SkPoint &p3)
void rCubicTo (SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3)
void arcTo (const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo)
void arcTo (SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius)
void arcTo (const SkPoint p1, const SkPoint p2, SkScalar radius)
void close ()
void addRect (const SkRect &rect, Direction dir=kCW_Direction)
void addRect (SkScalar left, SkScalar top, SkScalar right, SkScalar bottom, Direction dir=kCW_Direction)
void addOval (const SkRect &oval, Direction dir=kCW_Direction)
void addCircle (SkScalar x, SkScalar y, SkScalar radius, Direction dir=kCW_Direction)
void addArc (const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle)
void addRoundRect (const SkRect &rect, SkScalar rx, SkScalar ry, Direction dir=kCW_Direction)
void addRoundRect (const SkRect &rect, const SkScalar radii[], Direction dir=kCW_Direction)
void addPath (const SkPath &src, SkScalar dx, SkScalar dy)
void addPath (const SkPath &src)
void addPath (const SkPath &src, const SkMatrix &matrix)
void offset (SkScalar dx, SkScalar dy, SkPath *dst) const
void offset (SkScalar dx, SkScalar dy)
void transform (const SkMatrix &matrix, SkPath *dst) const
void transform (const SkMatrix &matrix)
void getLastPt (SkPoint *lastPt) const
void setLastPt (SkScalar x, SkScalar y)
void setLastPt (const SkPoint &p)
void flatten (SkFlattenableWriteBuffer &) const
void unflatten (SkFlattenableReadBuffer &)
void subdivide (SkScalar dist, bool bendLines, SkPath *dst=NULL) const
void computeBounds () const
void cons_moveto ()
void pathTo (const SkPath &path)
void reversePathTo (const SkPath &)

Public Attributes

SkDEBUGCODE(void validate()
const ;) private SkTDArray
< uint8_t > 
fVerbs
SkRect fBounds
uint8_t fBoundsIsDirty
uint8_t fFillType
uint8_t fIsConvex

Friends

class Iter
class SkPathStroker
class SkAutoPathBoundsUpdate
bool operator== (const SkPath &, const SkPath &)
bool operator!= (const SkPath &a, const SkPath &b)
const SkPointsk_get_path_points (const SkPath &, int index)

Detailed Description

The SkPath class encapsulates compound (multiple contour) geometric paths consisting of straight line segments, quadratic curves, and cubic curves.

Definition at line 33 of file SkPath.h.


Member Enumeration Documentation

Enumerator:
kCW_Direction 

clockwise direction for adding closed contours

kCCW_Direction 

counter-clockwise direction for adding closed contours

Definition at line 341 of file SkPath.h.

Enumerator:
kWinding_FillType 

Specifies that "inside" is computed by a non-zero sum of signed edge crossings

kEvenOdd_FillType 

Specifies that "inside" is computed by an odd number of edge crossings

kInverseWinding_FillType 

Same as Winding, but draws outside of the path, rather than inside

kInverseEvenOdd_FillType 

Same as EvenOdd, but draws outside of the path, rather than inside

Definition at line 46 of file SkPath.h.

Enumerator:
kMove_Verb 

iter.next returns 1 point

kLine_Verb 

iter.next returns 2 points

kQuad_Verb 

iter.next returns 3 points

kCubic_Verb 

iter.next returns 4 points

kClose_Verb 

iter.next returns 1 point (the last point)

kDone_Verb 

iter.next returns 0 points

Definition at line 493 of file SkPath.h.


Constructor & Destructor Documentation

SkPath::SkPath (  ) 
SkPath::SkPath ( const SkPath  ) 
SkPath::~SkPath (  ) 

Member Function Documentation

void SkPath::addArc ( const SkRect oval,
SkScalar  startAngle,
SkScalar  sweepAngle 
)

Add the specified arc to the path as a new contour.

Parameters:
oval The bounds of oval used to define the size of the arc
startAngle Starting angle (in degrees) where the arc begins
sweepAngle Sweep angle (in degrees) measured clockwise
void SkPath::addCircle ( SkScalar  x,
SkScalar  y,
SkScalar  radius,
Direction  dir = kCW_Direction 
)

Add a closed circle contour to the path

Parameters:
x The x-coordinate of the center of a circle to add as a closed contour to the path
y The y-coordinate of the center of a circle to add as a closed contour to the path
radius The radius of a circle to add as a closed contour to the path
dir The direction to wind the circle's contour
void SkPath::addOval ( const SkRect oval,
Direction  dir = kCW_Direction 
)

Add a closed oval contour to the path

Parameters:
oval The bounding oval to add as a closed contour to the path
dir The direction to wind the oval's contour
void SkPath::addPath ( const SkPath src,
const SkMatrix matrix 
)

Add a copy of src to the path, transformed by matrix

Parameters:
src The path to add as a new contour
void SkPath::addPath ( const SkPath src  )  [inline]

Add a copy of src to the path

Definition at line 425 of file SkPath.h.

void SkPath::addPath ( const SkPath src,
SkScalar  dx,
SkScalar  dy 
)

Add a copy of src to the path, offset by (dx,dy)

Parameters:
src The path to add as a new contour
dx The amount to translate the path in X as it is added
dx The amount to translate the path in Y as it is added
void SkPath::addRect ( SkScalar  left,
SkScalar  top,
SkScalar  right,
SkScalar  bottom,
Direction  dir = kCW_Direction 
)

Add a closed rectangle contour to the path

Parameters:
left The left side of a rectangle to add as a closed contour to the path
top The top of a rectangle to add as a closed contour to the path
right The right side of a rectangle to add as a closed contour to the path
bottom The bottom of a rectangle to add as a closed contour to the path
dir The direction to wind the rectangle's contour
void SkPath::addRect ( const SkRect rect,
Direction  dir = kCW_Direction 
)

Add a closed rectangle contour to the path

Parameters:
rect The rectangle to add as a closed contour to the path
dir The direction to wind the rectangle's contour
void SkPath::addRoundRect ( const SkRect rect,
const SkScalar  radii[],
Direction  dir = kCW_Direction 
)

Add a closed round-rectangle contour to the path. Each corner receives two radius values [X, Y]. The corners are ordered top-left, top-right, bottom-right, bottom-left.

Parameters:
rect The bounds of a round-rectangle to add as a closed contour
radii Array of 8 scalars, 4 [X,Y] pairs for each corner
dir The direction to wind the round-rectangle's contour
void SkPath::addRoundRect ( const SkRect rect,
SkScalar  rx,
SkScalar  ry,
Direction  dir = kCW_Direction 
)

Add a closed round-rectangle contour to the path

Parameters:
rect The bounds of a round-rectangle to add as a closed contour
rx The x-radius of the rounded corners on the round-rectangle
ry The y-radius of the rounded corners on the round-rectangle
dir The direction to wind the round-rectangle's contour
void SkPath::arcTo ( const SkPoint  p1,
const SkPoint  p2,
SkScalar  radius 
) [inline]

Append a line and arc to the current path. This is the same as the PostScript call "arct".

Definition at line 332 of file SkPath.h.

void SkPath::arcTo ( SkScalar  x1,
SkScalar  y1,
SkScalar  x2,
SkScalar  y2,
SkScalar  radius 
)

Append a line and arc to the current path. This is the same as the PostScript call "arct".

void SkPath::arcTo ( const SkRect oval,
SkScalar  startAngle,
SkScalar  sweepAngle,
bool  forceMoveTo 
)

Append the specified arc to the path as a new contour. If the start of the path is different from the path's current last point, then an automatic lineTo() is added to connect the current contour to the start of the arc. However, if the path is empty, then we call moveTo() with the first point of the arc. The sweep angle is treated mod 360.

Parameters:
oval The bounding oval defining the shape and size of the arc
startAngle Starting angle (in degrees) where the arc begins
sweepAngle Sweep angle (in degrees) measured clockwise. This is treated mod 360.
forceMoveTo If true, always begin a new contour with the arc
void SkPath::close (  ) 

Close the current contour. If the current point is not equal to the first point of the contour, a line segment is automatically added.

void SkPath::computeBounds (  )  const
void SkPath::cons_moveto (  ) 
void SkPath::cubicTo ( const SkPoint p1,
const SkPoint p2,
const SkPoint p3 
) [inline]

Add a cubic bezier from the last point, approaching control points p1 and p2, and ending at p3. If no moveTo() call has been made for this contour, the first point is automatically set to (0,0).

Parameters:
p1 The 1st control point on a cubic curve
p2 The 2nd control point on a cubic curve
p3 The end point on a cubic curve

Definition at line 284 of file SkPath.h.

void SkPath::cubicTo ( SkScalar  x1,
SkScalar  y1,
SkScalar  x2,
SkScalar  y2,
SkScalar  x3,
SkScalar  y3 
)

Add a cubic bezier from the last point, approaching control points (x1,y1) and (x2,y2), and ending at (x3,y3). If no moveTo() call has been made for this contour, the first point is automatically set to (0,0).

Parameters:
x1 The x-coordinate of the 1st control point on a cubic curve
y1 The y-coordinate of the 1st control point on a cubic curve
x2 The x-coordinate of the 2nd control point on a cubic curve
y2 The y-coordinate of the 2nd control point on a cubic curve
x3 The x-coordinate of the end point on a cubic curve
y3 The y-coordinate of the end point on a cubic curve
void SkPath::flatten ( SkFlattenableWriteBuffer  )  const
const SkRect& SkPath::getBounds (  )  const [inline]

Returns the bounds of the path's points. If the path contains 0 or 1 points, the bounds is set to (0,0,0,0), and isEmpty() will return true. Note: this bounds may be larger than the actual shape, since curves do not extend as far as their control points.

Definition at line 142 of file SkPath.h.

FillType SkPath::getFillType (  )  const [inline]

Return the path's fill type. This is used to define how "inside" is computed. The default value is kWinding_FillType.

Returns:
the path's fill type

Definition at line 68 of file SkPath.h.

void SkPath::getLastPt ( SkPoint lastPt  )  const

Return the last point on the path. If no points have been added, (0,0) is returned.

Parameters:
lastPt The last point on the path is returned here
int SkPath::getPoints ( SkPoint  points[],
int  max 
) const

Returns the number of points in the path. Up to max points are copied.

Parameters:
points If not null, receives up to max points
max The maximum number of points to copy into points
Returns:
the actual number of points in the path
void SkPath::incReserve ( unsigned  extraPtCount  ) 

Hint to the path to prepare for adding more points. This can allow the path to more efficiently grow its storage.

Parameters:
extraPtCount The number of extra points the path should preallocate for.
bool SkPath::isConvex (  )  const [inline]

Returns true if the path is flagged as being convex. This is not a confirmed by any analysis, it is just the value set earlier.

Definition at line 88 of file SkPath.h.

bool SkPath::isEmpty (  )  const

Returns true if the path is empty (contains no lines or curves)

Returns:
true if the path is empty (contains no lines or curves)
bool SkPath::isInverseFillType (  )  const [inline]

Returns true if the filltype is one of the Inverse variants

Definition at line 78 of file SkPath.h.

bool SkPath::isRect ( SkRect rect  )  const

Returns true if the path specifies a rectangle. If so, and if rect is not null, set rect to the bounds of the path. If the path does not specify a rectangle, return false and ignore rect.

Parameters:
rect If not null, returns the bounds of the path if it specifies a rectangle
Returns:
true if the path specifies a rectangle
void SkPath::lineTo ( const SkPoint p  )  [inline]

Add a line from the last point to the specified point. If no moveTo() call has been made for this contour, the first point is automatically set to (0,0).

Parameters:
p The end of a line

Definition at line 210 of file SkPath.h.

void SkPath::lineTo ( SkScalar  x,
SkScalar  y 
)

Add a line from the last point to the specified point (x,y). If no moveTo() call has been made for this contour, the first point is automatically set to (0,0).

Parameters:
x The x-coordinate of the end of a line
y The y-coordinate of the end of a line
void SkPath::moveTo ( const SkPoint p  )  [inline]

Set the beginning of the next contour to the point

Parameters:
p The start of a new contour

Definition at line 180 of file SkPath.h.

void SkPath::moveTo ( SkScalar  x,
SkScalar  y 
)

Set the beginning of the next contour to the point (x,y).

Parameters:
x The x-coordinate of the start of a new contour
y The y-coordinate of the start of a new contour
void SkPath::offset ( SkScalar  dx,
SkScalar  dy 
) [inline]

Offset the path by (dx,dy), returning true on success

Parameters:
dx The amount in the X direction to offset the entire path
dy The amount in the Y direction to offset the entire path

Definition at line 449 of file SkPath.h.

void SkPath::offset ( SkScalar  dx,
SkScalar  dy,
SkPath dst 
) const

Offset the path by (dx,dy), returning true on success

Parameters:
dx The amount in the X direction to offset the entire path
dy The amount in the Y direction to offset the entire path
dst The translated path is written here
SkPath& SkPath::operator= ( const SkPath  ) 
void SkPath::pathTo ( const SkPath path  ) 
void SkPath::quadTo ( const SkPoint p1,
const SkPoint p2 
) [inline]

Add a quadratic bezier from the last point, approaching control point p1, and ending at p2. If no moveTo() call has been made for this contour, the first point is automatically set to (0,0).

Parameters:
p1 The control point on a quadratic curve
p2 The end point on a quadratic curve

Definition at line 243 of file SkPath.h.

void SkPath::quadTo ( SkScalar  x1,
SkScalar  y1,
SkScalar  x2,
SkScalar  y2 
)

Add a quadratic bezier from the last point, approaching control point (x1,y1), and ending at (x2,y2). If no moveTo() call has been made for this contour, the first point is automatically set to (0,0).

Parameters:
x1 The x-coordinate of the control point on a quadratic curve
y1 The y-coordinate of the control point on a quadratic curve
x2 The x-coordinate of the end point on a quadratic curve
y2 The y-coordinate of the end point on a quadratic curve
void SkPath::rCubicTo ( SkScalar  x1,
SkScalar  y1,
SkScalar  x2,
SkScalar  y2,
SkScalar  x3,
SkScalar  y3 
)

Same as cubicTo, but the coordinates are considered relative to the current point on this contour. If there is no previous point, then a moveTo(0,0) is inserted automatically.

Parameters:
dx1 The amount to add to the x-coordinate of the last point on this contour, to specify the 1st control point of a cubic curve
dy1 The amount to add to the y-coordinate of the last point on this contour, to specify the 1st control point of a cubic curve
dx2 The amount to add to the x-coordinate of the last point on this contour, to specify the 2nd control point of a cubic curve
dy2 The amount to add to the y-coordinate of the last point on this contour, to specify the 2nd control point of a cubic curve
dx3 The amount to add to the x-coordinate of the last point on this contour, to specify the end point of a cubic curve
dy3 The amount to add to the y-coordinate of the last point on this contour, to specify the end point of a cubic curve
void SkPath::reset (  ) 

Clear any lines and curves from the path, making it empty. This frees up internal storage associated with those segments. This does NOT change the fill-type setting nor isConvex

void SkPath::reversePathTo ( const SkPath  ) 
void SkPath::rewind (  ) 

Similar to reset(), in that all lines and curves are removed from the path. However, any internal storage for those lines/curves is retained, making reuse of the path potentially faster. This does NOT change the fill-type setting nor isConvex

void SkPath::rLineTo ( SkScalar  dx,
SkScalar  dy 
)

Same as lineTo, but the coordinates are considered relative to the last point on this contour. If there is no previous point, then a moveTo(0,0) is inserted automatically.

Parameters:
dx The amount to add to the x-coordinate of the previous point on this contour, to specify a line
dy The amount to add to the y-coordinate of the previous point on this contour, to specify a line
void SkPath::rMoveTo ( SkScalar  dx,
SkScalar  dy 
)

Set the beginning of the next contour relative to the last point on the previous contour. If there is no previous contour, this is treated the same as moveTo().

Parameters:
dx The amount to add to the x-coordinate of the end of the previous contour, to specify the start of a new contour
dy The amount to add to the y-coordinate of the end of the previous contour, to specify the start of a new contour
void SkPath::rQuadTo ( SkScalar  dx1,
SkScalar  dy1,
SkScalar  dx2,
SkScalar  dy2 
)

Same as quadTo, but the coordinates are considered relative to the last point on this contour. If there is no previous point, then a moveTo(0,0) is inserted automatically.

Parameters:
dx1 The amount to add to the x-coordinate of the last point on this contour, to specify the control point of a quadratic curve
dy1 The amount to add to the y-coordinate of the last point on this contour, to specify the control point of a quadratic curve
dx2 The amount to add to the x-coordinate of the last point on this contour, to specify the end point of a quadratic curve
dy2 The amount to add to the y-coordinate of the last point on this contour, to specify the end point of a quadratic curve
void SkPath::setFillType ( FillType  ft  )  [inline]

Set the path's fill type. This is used to define how "inside" is computed. The default value is kWinding_FillType.

Parameters:
ft The new fill type for this path

Definition at line 75 of file SkPath.h.

void SkPath::setIsConvex ( bool  isConvex  )  [inline]

Set the isConvex flag to true or false. Convex paths may draw faster if this flag is set, though setting this to true on a path that is in fact not convex can give undefined results when drawn. Paths default to isConvex == false

Definition at line 95 of file SkPath.h.

void SkPath::setLastPt ( const SkPoint p  )  [inline]

Set the last point on the path. If no points have been added, moveTo(p) is automatically called.

Parameters:
p The new location for the last point

Definition at line 489 of file SkPath.h.

void SkPath::setLastPt ( SkScalar  x,
SkScalar  y 
)

Set the last point on the path. If no points have been added, moveTo(x,y) is automatically called.

Parameters:
x The new x-coordinate for the last point
y The new y-coordinate for the last point
void SkPath::subdivide ( SkScalar  dist,
bool  bendLines,
SkPath dst = NULL 
) const

Subdivide the path so that no segment is longer that dist. If bendLines is true, then turn all line segments into curves. If dst == null, then the original path itself is modified (not const!)

void SkPath::swap ( SkPath other  ) 

Swap contents of this and other. Guaranteed not to throw.

void SkPath::toggleInverseFillType (  )  [inline]

Toggle between inverse and normal filltypes. This reverse the return value of isInverseFillType()

Definition at line 83 of file SkPath.h.

void SkPath::transform ( const SkMatrix matrix  )  [inline]

Transform the points in this path by matrix

Parameters:
matrix The matrix to apply to the path

Definition at line 465 of file SkPath.h.

void SkPath::transform ( const SkMatrix matrix,
SkPath dst 
) const

Transform the points in this path by matrix, and write the answer into dst.

Parameters:
matrix The matrix to apply to the path
dst The transformed path is written here
void SkPath::unflatten ( SkFlattenableReadBuffer  ) 
void SkPath::updateBoundsCache (  )  const [inline]

Calling this will, if the internal cache of the bounds is out of date, update it so that subsequent calls to getBounds will be instanteous. This also means that any copies or simple transformations of the path will inherit the cached bounds.

Definition at line 154 of file SkPath.h.


Friends And Related Function Documentation

friend class Iter [friend]

Definition at line 578 of file SkPath.h.

bool operator!= ( const SkPath a,
const SkPath b 
) [friend]

Definition at line 42 of file SkPath.h.

bool operator== ( const SkPath ,
const SkPath  
) [friend]
const SkPoint* sk_get_path_points ( const SkPath ,
int  index 
) [friend]
friend class SkAutoPathBoundsUpdate [friend]

Definition at line 595 of file SkPath.h.

friend class SkPathStroker [friend]

Definition at line 581 of file SkPath.h.


Member Data Documentation

Definition at line 570 of file SkPath.h.

uint8_t SkPath::fBoundsIsDirty [mutable]

Definition at line 571 of file SkPath.h.

Definition at line 572 of file SkPath.h.

Definition at line 573 of file SkPath.h.

SkDEBUGCODE (void validate() const;) private SkTDArray<uint8_t> SkPath::fVerbs

Definition at line 565 of file SkPath.h.


The documentation for this class was generated from the following file:

Generated on Tue Oct 20 11:03:42 2009 for Skia by  doxygen 1.6.1