FileDocCategorySizeDatePackage
Path.javaAPI DocAndroid 1.5 API23241Wed May 06 22:42:00 BST 2009android.graphics

Path

public class Path extends Object
The Path class encapsulates compound (multiple contour) geometric paths consisting of straight line segments, quadratic curves, and cubic curves. It can be drawn with canvas.drawPath(path, paint), either filled or stroked (based on the paint's Style), or it can be used for clipping or to draw text on a path.

Fields Summary
private static final FillType[]
sFillTypeArray
private final int
mNativePath
Constructors Summary
public Path()
Create an empty path

        mNativePath = init1();
    
public Path(Path src)
Create a new path, copying the contents from the src path.

param
src The path to copy from when initializing the new path

        int valNative = 0;
        if (src != null) {
            valNative = src.mNativePath;
        }
        mNativePath = init2(valNative);
    
Methods Summary
public voidaddArc(RectF oval, float startAngle, float sweepAngle)
Add the specified arc to the path as a new contour.

param
oval The bounds of oval defining the shape and size of the arc
param
startAngle Starting angle (in degrees) where the arc begins
param
sweepAngle Sweep angle (in degrees) measured clockwise

        if (oval == null) {
            throw new NullPointerException("need oval parameter");
        }
        native_addArc(mNativePath, oval, startAngle, sweepAngle);
    
public voidaddCircle(float x, float y, float radius, android.graphics.Path$Direction dir)
Add a closed circle contour to the path

param
x The x-coordinate of the center of a circle to add to the path
param
y The y-coordinate of the center of a circle to add to the path
param
radius The radius of a circle to add to the path
param
dir The direction to wind the circle's contour

        native_addCircle(mNativePath, x, y, radius, dir.nativeInt);
    
public voidaddOval(RectF oval, android.graphics.Path$Direction dir)
Add a closed oval contour to the path

param
oval The bounds of the oval to add as a closed contour to the path
param
dir The direction to wind the oval's contour

        if (oval == null) {
            throw new NullPointerException("need oval parameter");
        }
        native_addOval(mNativePath, oval, dir.nativeInt);
    
public voidaddPath(android.graphics.Path src, float dx, float dy)
Add a copy of src to the path, offset by (dx,dy)

param
src The path to add as a new contour
param
dx The amount to translate the path in X as it is added

        native_addPath(mNativePath, src.mNativePath, dx, dy);
    
public voidaddPath(android.graphics.Path src)
Add a copy of src to the path

param
src The path that is appended to the current path

        native_addPath(mNativePath, src.mNativePath);
    
public voidaddPath(android.graphics.Path src, Matrix matrix)
Add a copy of src to the path, transformed by matrix

param
src The path to add as a new contour

        native_addPath(mNativePath, src.mNativePath, matrix.native_instance);
    
public voidaddRect(RectF rect, android.graphics.Path$Direction dir)
Add a closed rectangle contour to the path

param
rect The rectangle to add as a closed contour to the path
param
dir The direction to wind the rectangle's contour

        if (rect == null) {
            throw new NullPointerException("need rect parameter");
        }
        native_addRect(mNativePath, rect, dir.nativeInt);
    
public voidaddRect(float left, float top, float right, float bottom, android.graphics.Path$Direction dir)
Add a closed rectangle contour to the path

param
left The left side of a rectangle to add to the path
param
top The top of a rectangle to add to the path
param
right The right side of a rectangle to add to the path
param
bottom The bottom of a rectangle to add to the path
param
dir The direction to wind the rectangle's contour

        native_addRect(mNativePath, left, top, right, bottom, dir.nativeInt);
    
public voidaddRoundRect(RectF rect, float rx, float ry, android.graphics.Path$Direction dir)
Add a closed round-rectangle contour to the path

param
rect The bounds of a round-rectangle to add to the path
param
rx The x-radius of the rounded corners on the round-rectangle
param
ry The y-radius of the rounded corners on the round-rectangle
param
dir The direction to wind the round-rectangle's contour

        if (rect == null) {
            throw new NullPointerException("need rect parameter");
        }
        native_addRoundRect(mNativePath, rect, rx, ry, dir.nativeInt);
    
public voidaddRoundRect(RectF rect, float[] radii, android.graphics.Path$Direction dir)
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

param
rect The bounds of a round-rectangle to add to the path
param
radii Array of 8 values, 4 pairs of [X,Y] radii
param
dir The direction to wind the round-rectangle's contour

        if (rect == null) {
            throw new NullPointerException("need rect parameter");
        }
        if (radii.length < 8) {
            throw new ArrayIndexOutOfBoundsException("radii[] needs 8 values");
        }
        native_addRoundRect(mNativePath, rect, radii, dir.nativeInt);
    
public voidarcTo(RectF oval, float startAngle, float sweepAngle, boolean 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 tread mod 360.

param
oval The bounds of oval defining shape and size of the arc
param
startAngle Starting angle (in degrees) where the arc begins
param
sweepAngle Sweep angle (in degrees) measured clockwise, treated mod 360.
param
forceMoveTo If true, always begin a new contour with the arc

        native_arcTo(mNativePath, oval, startAngle, sweepAngle, forceMoveTo);
    
public voidarcTo(RectF oval, float startAngle, float sweepAngle)
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.

param
oval The bounds of oval defining shape and size of the arc
param
startAngle Starting angle (in degrees) where the arc begins
param
sweepAngle Sweep angle (in degrees) measured clockwise

        native_arcTo(mNativePath, oval, startAngle, sweepAngle, false);
    
public voidclose()
Close the current contour. If the current point is not equal to the first point of the contour, a line segment is automatically added.

        native_close(mNativePath);
    
public voidcomputeBounds(RectF bounds, boolean exact)
Compute the bounds of the path, and write the answer into bounds. If the path contains 0 or 1 points, the bounds is set to (0,0,0,0)

param
bounds Returns the computed bounds of the path
param
exact If true, return the exact (but slower) bounds, else return just the bounds of all control points

        // 1-exact, 0-fast correspond to the values in SkPath.h
        native_computeBounds(mNativePath, bounds, exact ? 1 : 0);
    
public voidcubicTo(float x1, float y1, float x2, float y2, float x3, float 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).

param
x1 The x-coordinate of the 1st control point on a cubic curve
param
y1 The y-coordinate of the 1st control point on a cubic curve
param
x2 The x-coordinate of the 2nd control point on a cubic curve
param
y2 The y-coordinate of the 2nd control point on a cubic curve
param
x3 The x-coordinate of the end point on a cubic curve
param
y3 The y-coordinate of the end point on a cubic curve

        native_cubicTo(mNativePath, x1, y1, x2, y2, x3, y3);
    
protected voidfinalize()

        try {
            finalizer(mNativePath);
        } finally {
            super.finalize();
        }
    
private static native voidfinalizer(int nPath)

public android.graphics.Path$FillTypegetFillType()
Return the path's fill type. This defines how "inside" is computed. The default value is WINDING.

return
the path's fill type


                              
       
        return sFillTypeArray[native_getFillType(mNativePath)];
    
public voidincReserve(int extraPtCount)
Hint to the path to prepare for adding more points. This can allow the path to more efficiently allocate its storage.

param
extraPtCount The number of extra points that may be added to this path

        native_incReserve(mNativePath, extraPtCount);
    
private static native intinit1()

private static native intinit2(int nPath)

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

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

        return native_isEmpty(mNativePath);
    
public booleanisInverseFillType()
Returns true if the filltype is one of the INVERSE variants

return
true if the filltype is one of the INVERSE variants

        final int ft = native_getFillType(mNativePath);
        return (ft & 2) != 0;
    
public booleanisRect(RectF rect)
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.

param
rect If not null, returns the bounds of the path if it specifies a rectangle
return
true if the path specifies a rectangle

        return native_isRect(mNativePath, rect);
    
public voidlineTo(float x, float 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).

param
x The x-coordinate of the end of a line
param
y The y-coordinate of the end of a line

        native_lineTo(mNativePath, x, y);
    
public voidmoveTo(float x, float y)
Set the beginning of the next contour to the point (x,y).

param
x The x-coordinate of the start of a new contour
param
y The y-coordinate of the start of a new contour

        native_moveTo(mNativePath, x, y);
    
private static native voidnative_addArc(int nPath, RectF oval, float startAngle, float sweepAngle)

private static native voidnative_addCircle(int nPath, float x, float y, float radius, int dir)

private static native voidnative_addOval(int nPath, RectF oval, int dir)

private static native voidnative_addPath(int nPath, int src, float dx, float dy)

private static native voidnative_addPath(int nPath, int src)

private static native voidnative_addPath(int nPath, int src, int matrix)

private static native voidnative_addRect(int nPath, RectF rect, int dir)

private static native voidnative_addRect(int nPath, float left, float top, float right, float bottom, int dir)

private static native voidnative_addRoundRect(int nPath, RectF rect, float rx, float ry, int dir)

private static native voidnative_addRoundRect(int nPath, RectF r, float[] radii, int dir)

private static native voidnative_arcTo(int nPath, RectF oval, float startAngle, float sweepAngle, boolean forceMoveTo)

private static native voidnative_close(int nPath)

private static native voidnative_computeBounds(int nPath, RectF bounds, int btype)

private static native voidnative_cubicTo(int nPath, float x1, float y1, float x2, float y2, float x3, float y3)

private static native intnative_getFillType(int nPath)

private static native voidnative_incReserve(int nPath, int extraPtCount)

private static native booleannative_isEmpty(int nPath)

private static native booleannative_isRect(int nPath, RectF rect)

private static native voidnative_lineTo(int nPath, float x, float y)

private static native voidnative_moveTo(int nPath, float x, float y)

private static native voidnative_offset(int nPath, float dx, float dy, int dst_path)

private static native voidnative_offset(int nPath, float dx, float dy)

private static native voidnative_quadTo(int nPath, float x1, float y1, float x2, float y2)

private static native voidnative_rCubicTo(int nPath, float x1, float y1, float x2, float y2, float x3, float y3)

private static native voidnative_rLineTo(int nPath, float dx, float dy)

private static native voidnative_rMoveTo(int nPath, float dx, float dy)

private static native voidnative_rQuadTo(int nPath, float dx1, float dy1, float dx2, float dy2)

private static native voidnative_reset(int nPath)

private static native voidnative_rewind(int nPath)

private static native voidnative_set(int native_dst, int native_src)

private static native voidnative_setFillType(int nPath, int ft)

private static native voidnative_setLastPoint(int nPath, float dx, float dy)

private static native voidnative_transform(int nPath, int matrix, int dst_path)

private static native voidnative_transform(int nPath, int matrix)

final intni()

        return mNativePath;
    
public voidoffset(float dx, float dy, android.graphics.Path dst)
Offset the path by (dx,dy), returning true on success

param
dx The amount in the X direction to offset the entire path
param
dy The amount in the Y direction to offset the entire path
param
dst The translated path is written here. If this is null, then the original path is modified.

        int dstNative = 0;
        if (dst != null) {
            dstNative = dst.mNativePath;
        }
        native_offset(mNativePath, dx, dy, dstNative);
    
public voidoffset(float dx, float dy)
Offset the path by (dx,dy), returning true on success

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

        native_offset(mNativePath, dx, dy);
    
public voidquadTo(float x1, float y1, float x2, float 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).

param
x1 The x-coordinate of the control point on a quadratic curve
param
y1 The y-coordinate of the control point on a quadratic curve
param
x2 The x-coordinate of the end point on a quadratic curve
param
y2 The y-coordinate of the end point on a quadratic curve

        native_quadTo(mNativePath, x1, y1, x2, y2);
    
public voidrCubicTo(float x1, float y1, float x2, float y2, float x3, float 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.

        native_rCubicTo(mNativePath, x1, y1, x2, y2, x3, y3);
    
public voidrLineTo(float dx, float 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.

param
dx The amount to add to the x-coordinate of the previous point on this contour, to specify a line
param
dy The amount to add to the y-coordinate of the previous point on this contour, to specify a line

        native_rLineTo(mNativePath, dx, dy);
    
public voidrMoveTo(float dx, float 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().

param
dx The amount to add to the x-coordinate of the end of the previous contour, to specify the start of a new contour
param
dy The amount to add to the y-coordinate of the end of the previous contour, to specify the start of a new contour

        native_rMoveTo(mNativePath, dx, dy);
    
public voidrQuadTo(float dx1, float dy1, float dx2, float 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.

param
dx1 The amount to add to the x-coordinate of the last point on this contour, for the control point of a quadratic curve
param
dy1 The amount to add to the y-coordinate of the last point on this contour, for the control point of a quadratic curve
param
dx2 The amount to add to the x-coordinate of the last point on this contour, for the end point of a quadratic curve
param
dy2 The amount to add to the y-coordinate of the last point on this contour, for the end point of a quadratic curve

        native_rQuadTo(mNativePath, dx1, dy1, dx2, dy2);
    
public voidreset()
Clear any lines and curves from the path, making it empty. This does NOT change the fill-type setting.

        native_reset(mNativePath);
    
public voidrewind()
Rewinds the path: clears any lines and curves from the path but keeps the internal data structure for faster reuse.

        native_rewind(mNativePath);
    
public voidset(android.graphics.Path src)
Replace the contents of this with the contents of src.

        if (this != src) {
            native_set(mNativePath, src.mNativePath);
        }
    
public voidsetFillType(android.graphics.Path$FillType ft)
Set the path's fill type. This defines how "inside" is computed.

param
ft The new fill type for this path

        native_setFillType(mNativePath, ft.nativeInt);
    
public voidsetLastPoint(float dx, float dy)
Sets the last point of the path.

param
dx The new X coordinate for the last point
param
dy The new Y coordinate for the last point

        native_setLastPoint(mNativePath, dx, dy);
    
public voidtoggleInverseFillType()
Toggles the INVERSE state of the filltype

        int ft = native_getFillType(mNativePath);
        ft ^= 2;
        native_setFillType(mNativePath, ft);
    
public voidtransform(Matrix matrix, android.graphics.Path dst)
Transform the points in this path by matrix, and write the answer into dst. If dst is null, then the the original path is modified.

param
matrix The matrix to apply to the path
param
dst The transformed path is written here. If dst is null, then the the original path is modified

        int dstNative = 0;
        if (dst != null) {
            dstNative = dst.mNativePath;
        }
        native_transform(mNativePath, matrix.native_instance, dstNative);
    
public voidtransform(Matrix matrix)
Transform the points in this path by matrix.

param
matrix The matrix to apply to the path

        native_transform(mNativePath, matrix.native_instance);