public class Path extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Path.Direction
Specifies how closed shapes (e.g. rects, ovals) are oriented when they
are added to a path.
|
static class |
Path.FillType
Enum for the ways a path may be filled.
|
static class |
Path.Op
The logical operations that can be performed when combining two paths.
|
Modifier and Type | Field and Description |
---|---|
boolean |
isSimplePath |
long |
mNativePath |
Region |
rects |
Constructor and Description |
---|
Path()
Create an empty path
|
Path(Path src)
Create a new path, copying the contents from the src path.
|
Modifier and Type | Method and Description |
---|---|
void |
addArc(float left,
float top,
float right,
float bottom,
float startAngle,
float sweepAngle)
Add the specified arc to the path as a new contour.
|
void |
addArc(RectF oval,
float startAngle,
float sweepAngle)
Add the specified arc to the path as a new contour.
|
void |
addCircle(float x,
float y,
float radius,
Path.Direction dir)
Add a closed circle contour to the path
|
void |
addOval(float left,
float top,
float right,
float bottom,
Path.Direction dir)
Add a closed oval contour to the path
|
void |
addOval(RectF oval,
Path.Direction dir)
Add a closed oval contour to the path
|
void |
addPath(Path src)
Add a copy of src to the path
|
void |
addPath(Path src,
float dx,
float dy)
Add a copy of src to the path, offset by (dx,dy)
|
void |
addPath(Path src,
Matrix matrix)
Add a copy of src to the path, transformed by matrix
|
void |
addRect(float left,
float top,
float right,
float bottom,
Path.Direction dir)
Add a closed rectangle contour to the path
|
void |
addRect(RectF rect,
Path.Direction dir)
Add a closed rectangle contour to the path
|
void |
addRoundRect(float left,
float top,
float right,
float bottom,
float[] radii,
Path.Direction dir)
Add a closed round-rectangle contour to the path.
|
void |
addRoundRect(float left,
float top,
float right,
float bottom,
float rx,
float ry,
Path.Direction dir)
Add a closed round-rectangle contour to the path
|
void |
addRoundRect(RectF rect,
float[] radii,
Path.Direction dir)
Add a closed round-rectangle contour to the path.
|
void |
addRoundRect(RectF rect,
float rx,
float ry,
Path.Direction dir)
Add a closed round-rectangle contour to the path
|
float[] |
approximate(float acceptableError)
Approximate the
Path with a series of line segments. |
void |
arcTo(float left,
float top,
float right,
float bottom,
float startAngle,
float sweepAngle,
boolean forceMoveTo)
Append the specified arc to the path as a new contour.
|
void |
arcTo(RectF oval,
float startAngle,
float sweepAngle)
Append the specified arc to the path as a new contour.
|
void |
arcTo(RectF oval,
float startAngle,
float sweepAngle,
boolean forceMoveTo)
Append the specified arc to the path as a new contour.
|
void |
close()
Close the current contour.
|
void |
computeBounds(RectF bounds,
boolean exact)
Compute the bounds of the control points of the path, and write the
answer into bounds.
|
void |
cubicTo(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).
|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
Path.FillType |
getFillType()
Return the path's fill type.
|
void |
incReserve(int extraPtCount)
Hint to the path to prepare for adding more points.
|
boolean |
isConvex()
Returns the path's convexity, as defined by the content of the path.
|
boolean |
isEmpty()
Returns true if the path is empty (contains no lines or curves)
|
boolean |
isInverseFillType()
Returns true if the filltype is one of the INVERSE variants
|
boolean |
isRect(RectF rect)
Returns true if the path specifies a rectangle.
|
void |
lineTo(float x,
float y)
Add a line from the last point to the specified point (x,y).
|
void |
moveTo(float x,
float y)
Set the beginning of the next contour to the point (x,y).
|
void |
offset(float dx,
float dy)
Offset the path by (dx,dy)
|
void |
offset(float dx,
float dy,
Path dst)
Offset the path by (dx,dy)
|
boolean |
op(Path path,
Path.Op op)
Set this path to the result of applying the Op to this path and the specified path.
|
boolean |
op(Path path1,
Path path2,
Path.Op op)
Set this path to the result of applying the Op to the two specified paths.
|
void |
quadTo(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).
|
void |
rCubicTo(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.
|
void |
reset()
Clear any lines and curves from the path, making it empty.
|
void |
rewind()
Rewinds the path: clears any lines and curves from the path but
keeps the internal data structure for faster reuse.
|
void |
rLineTo(float dx,
float dy)
Same as lineTo, but the coordinates are considered relative to the last
point on this contour.
|
void |
rMoveTo(float dx,
float dy)
Set the beginning of the next contour relative to the last point on the
previous contour.
|
void |
rQuadTo(float dx1,
float dy1,
float dx2,
float dy2)
Same as quadTo, but the coordinates are considered relative to the last
point on this contour.
|
void |
set(Path src)
Replace the contents of this with the contents of src.
|
void |
setFillType(Path.FillType ft)
Set the path's fill type.
|
void |
setLastPoint(float dx,
float dy)
Sets the last point of the path.
|
void |
toggleInverseFillType()
Toggles the INVERSE state of the filltype
|
void |
transform(Matrix matrix)
Transform the points in this path by matrix.
|
void |
transform(Matrix matrix,
Path dst)
Transform the points in this path by matrix, and write the answer
into dst.
|
public long mNativePath
public boolean isSimplePath
public Region rects
public Path()
public Path(Path src)
src
- The path to copy from when initializing the new pathpublic void reset()
public void rewind()
public void set(Path src)
public boolean op(Path path, Path.Op op)
path
- The second operand (for difference, the subtrahend)Path.Op
,
op(Path, Path, android.graphics.Path.Op)
public boolean op(Path path1, Path path2, Path.Op op)
path1
- The first operand (for difference, the minuend)path2
- The second operand (for difference, the subtrahend)Path.Op
,
op(Path, android.graphics.Path.Op)
public boolean isConvex()
A path is convex if it has a single contour, and only ever curves in a single direction.
This function will calculate the convexity of the path from its control points, and cache the result.
public Path.FillType getFillType()
public void setFillType(Path.FillType ft)
ft
- The new fill type for this pathpublic boolean isInverseFillType()
public void toggleInverseFillType()
public boolean isEmpty()
public boolean isRect(RectF rect)
rect
- If not null, returns the bounds of the path if it specifies
a rectanglepublic void computeBounds(RectF bounds, boolean exact)
bounds
- Returns the computed bounds of the path's control points.exact
- This parameter is no longer used.public void incReserve(int extraPtCount)
extraPtCount
- The number of extra points that may be added to this
pathpublic void moveTo(float x, float y)
x
- The x-coordinate of the start of a new contoury
- The y-coordinate of the start of a new contourpublic void rMoveTo(float dx, float dy)
dx
- The amount to add to the x-coordinate of the end of the
previous contour, to specify the start of a new contourdy
- The amount to add to the y-coordinate of the end of the
previous contour, to specify the start of a new contourpublic void lineTo(float x, float y)
x
- The x-coordinate of the end of a liney
- The y-coordinate of the end of a linepublic void rLineTo(float dx, float dy)
dx
- The amount to add to the x-coordinate of the previous point on
this contour, to specify a linedy
- The amount to add to the y-coordinate of the previous point on
this contour, to specify a linepublic void quadTo(float x1, float y1, float x2, float y2)
x1
- The x-coordinate of the control point on a quadratic curvey1
- The y-coordinate of the control point on a quadratic curvex2
- The x-coordinate of the end point on a quadratic curvey2
- The y-coordinate of the end point on a quadratic curvepublic void rQuadTo(float dx1, float dy1, float dx2, float dy2)
dx1
- The amount to add to the x-coordinate of the last point on
this contour, for the control point of a quadratic curvedy1
- The amount to add to the y-coordinate of the last point on
this contour, for the control point of a quadratic curvedx2
- The amount to add to the x-coordinate of the last point on
this contour, for the end point of a quadratic curvedy2
- The amount to add to the y-coordinate of the last point on
this contour, for the end point of a quadratic curvepublic void cubicTo(float x1, float y1, float x2, float y2, float x3, float y3)
x1
- The x-coordinate of the 1st control point on a cubic curvey1
- The y-coordinate of the 1st control point on a cubic curvex2
- The x-coordinate of the 2nd control point on a cubic curvey2
- The y-coordinate of the 2nd control point on a cubic curvex3
- The x-coordinate of the end point on a cubic curvey3
- The y-coordinate of the end point on a cubic curvepublic void rCubicTo(float x1, float y1, float x2, float y2, float x3, float y3)
public void arcTo(RectF oval, float startAngle, float sweepAngle, boolean forceMoveTo)
oval
- The bounds of oval defining shape and size of the arcstartAngle
- Starting angle (in degrees) where the arc beginssweepAngle
- Sweep angle (in degrees) measured clockwise, treated
mod 360.forceMoveTo
- If true, always begin a new contour with the arcpublic void arcTo(RectF oval, float startAngle, float sweepAngle)
oval
- The bounds of oval defining shape and size of the arcstartAngle
- Starting angle (in degrees) where the arc beginssweepAngle
- Sweep angle (in degrees) measured clockwisepublic void arcTo(float left, float top, float right, float bottom, float startAngle, float sweepAngle, boolean forceMoveTo)
startAngle
- Starting angle (in degrees) where the arc beginssweepAngle
- Sweep angle (in degrees) measured clockwise, treated
mod 360.forceMoveTo
- If true, always begin a new contour with the arcpublic void close()
public void addRect(RectF rect, Path.Direction dir)
rect
- The rectangle to add as a closed contour to the pathdir
- The direction to wind the rectangle's contourpublic void addRect(float left, float top, float right, float bottom, Path.Direction dir)
left
- The left side of a rectangle to add to the pathtop
- The top of a rectangle to add to the pathright
- The right side of a rectangle to add to the pathbottom
- The bottom of a rectangle to add to the pathdir
- The direction to wind the rectangle's contourpublic void addOval(RectF oval, Path.Direction dir)
oval
- The bounds of the oval to add as a closed contour to the pathdir
- The direction to wind the oval's contourpublic void addOval(float left, float top, float right, float bottom, Path.Direction dir)
dir
- The direction to wind the oval's contourpublic void addCircle(float x, float y, float radius, Path.Direction dir)
x
- The x-coordinate of the center of a circle to add to the pathy
- The y-coordinate of the center of a circle to add to the pathradius
- The radius of a circle to add to the pathdir
- The direction to wind the circle's contourpublic void addArc(RectF oval, float startAngle, float sweepAngle)
oval
- The bounds of oval defining the shape and size of the arcstartAngle
- Starting angle (in degrees) where the arc beginssweepAngle
- Sweep angle (in degrees) measured clockwisepublic void addArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle)
startAngle
- Starting angle (in degrees) where the arc beginssweepAngle
- Sweep angle (in degrees) measured clockwisepublic void addRoundRect(RectF rect, float rx, float ry, Path.Direction dir)
rect
- The bounds of a round-rectangle to add to the pathrx
- The x-radius of the rounded corners on the round-rectanglery
- The y-radius of the rounded corners on the round-rectangledir
- The direction to wind the round-rectangle's contourpublic void addRoundRect(float left, float top, float right, float bottom, float rx, float ry, Path.Direction dir)
rx
- The x-radius of the rounded corners on the round-rectanglery
- The y-radius of the rounded corners on the round-rectangledir
- The direction to wind the round-rectangle's contourpublic void addRoundRect(RectF rect, float[] radii, Path.Direction dir)
rect
- The bounds of a round-rectangle to add to the pathradii
- Array of 8 values, 4 pairs of [X,Y] radiidir
- The direction to wind the round-rectangle's contourpublic void addRoundRect(float left, float top, float right, float bottom, float[] radii, Path.Direction dir)
radii
- Array of 8 values, 4 pairs of [X,Y] radiidir
- The direction to wind the round-rectangle's contourpublic void addPath(Path src, float dx, float dy)
src
- The path to add as a new contourdx
- The amount to translate the path in X as it is addedpublic void addPath(Path src)
src
- The path that is appended to the current pathpublic void addPath(Path src, Matrix matrix)
src
- The path to add as a new contourpublic void offset(float dx, float dy, Path dst)
dx
- The amount in the X direction to offset the entire pathdy
- The amount in the Y direction to offset the entire pathdst
- The translated path is written here. If this is null, then
the original path is modified.public void offset(float dx, float dy)
dx
- The amount in the X direction to offset the entire pathdy
- The amount in the Y direction to offset the entire pathpublic void setLastPoint(float dx, float dy)
dx
- The new X coordinate for the last pointdy
- The new Y coordinate for the last pointpublic void transform(Matrix matrix, Path dst)
matrix
- The matrix to apply to the pathdst
- The transformed path is written here. If dst is null,
then the the original path is modifiedpublic void transform(Matrix matrix)
matrix
- The matrix to apply to the pathprotected void finalize() throws Throwable
Object
finalize
method to dispose of
system resources or to perform other cleanup.
The general contract of finalize
is that it is invoked
if and when the JavaTM virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The finalize
method may take any action, including
making this object available again to other threads; the usual purpose
of finalize
, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.
The finalize
method of class Object
performs no
special action; it simply returns normally. Subclasses of
Object
may override this definition.
The Java programming language does not guarantee which thread will
invoke the finalize
method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.
After the finalize
method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.
The finalize
method is never invoked more than once by a Java
virtual machine for any given object.
Any exception thrown by the finalize
method causes
the finalization of this object to be halted, but is otherwise
ignored.
public float[] approximate(float acceptableError)
Path
with a series of line segments.
This returns float[] with the array containing point components.
There are three components for each point, in order:
Two points may share the same fraction along its length when there is a move action within the Path.
acceptableError
- The acceptable error for a line on the
Path. Typically this would be 0.5 so that
the error is less than half a pixel.