public class GeneralPath extends Object implements IPath
After you create the GeneralPath you can convert it to a Polygon for drawing on a Graphics context, or to a sequence of floating point co-ordinates for other purposes.
You create the path by starting with an initial moveTo(xstart,ystart) to start at that point. You then do sequences of lineTo(), quadTo() or curveTo() calls to add segments to the path. You can call closePath() at the end (optionally) to create a closed path.
Modifier and Type | Field and Description |
---|---|
static int |
GET_LINES_AS_INTS
This is an option for getLines().
|
static int |
TRANSFORM_HORIZONTAL_MIRROR
A Transform operation.
|
static int |
TRANSFORM_HORIZONTAL_STRETCH
A Transform operation.
|
static int |
TRANSFORM_ROTATE
A Transform operation.
|
static int |
TRANSFORM_SCALE
A Transform operation.
|
static int |
TRANSFORM_TRANSLATE
A Transform operation.
|
static int |
TRANSFORM_VERTICAL_MIRROR
A Transform operation.
|
static int |
TRANSFORM_VERTICAL_STRETCH
A Transform operation.
|
Constructor and Description |
---|
GeneralPath()
Create an empty GeneralPath with a default pre-allocated capacity.
|
GeneralPath(int capacity)
Create an empty GeneralPath with a pre-allocated capacity.
|
Modifier and Type | Method and Description |
---|---|
void |
addToPath(double x,
double y)
Add a straight line segment to the path.
|
void |
addToPath(double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
Add a Cubic Bezier curve segment from the current point to (x3,y3) using
(x1, y1) and (x2, y2) as the control points.
|
void |
append(GeneralPath path,
boolean connect)
Append another path to this path.
|
void |
append(GeneralPath path,
boolean connect,
boolean relative)
Append another path to this path.
|
void |
closePath()
This method indicates that a line should be drawn from the most recent added point to the most
recent moveTo() point.
|
int |
countPoints()
This returns the number of points that has been added to the GeneralPath so far.
|
void |
curveTo(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
Draw a Bezier curve from the last point to the co-ordinates (x3,y3) using
(x1,y1) and (x2,y2) as the curve's control points.
|
float[] |
getBoundingRect(float[] dest)
Get the bounding Rectangle for the GeneralPath.
|
Rect |
getBounds(Rect dest)
Get the bounds of the path as a Rect - which holds only integer values.
|
GeneralPath |
getCopy()
Get a copy of this GeneralPath.
|
Object[] |
getLines(boolean includeLastPoint,
int options)
This returns the lines as integer or floating point values.
|
int |
getLines(Object destx,
Object desty,
int offset,
boolean includeLastPoint,
int options)
Convert the GeneralPath to an sequence of lines that fit the path.
|
float[] |
getXPoints()
This returns the array of x co-ordinates of the points added to the GeneralPath.
|
float[] |
getYPoints()
This returns the array of y co-ordinates of the points added to the GeneralPath.
|
boolean |
isClosed()
Returns if the path was closed.
|
void |
lineTo(float x,
float y)
Draw a line from the last point to the co-ordinates (x,y).
|
void |
moveTo(float x,
float y)
Move the current point to the specified x,y location.
|
boolean |
openPath()
If the last operation in this GeneralPath is a closePath(), this will remove it, thereby
opening the path again.
|
void |
quadTo(float x1,
float y1,
float x2,
float y2)
Draw a quadratic curve from the last point to the co-ordinates (x2,y2) using
(x1,y1) as the curve's control point.
|
GeneralPath |
reverse()
This reverses the sub-path direction.
|
void |
startPath(double x,
double y)
Start a new sub path at x and y.
|
Polygon |
toPolygon()
Convert the GeneralPath to a Polygon object - which stores all co-ordinates
as integer values.
|
GeneralPath |
transform(double m00,
double m10,
double m01,
double m11,
double m02,
double m12)
This does an Affine Transform on the GeneralPath to produce a new GeneralPath.
|
GeneralPath |
transform(int transformOperation,
float x,
float y,
double factor) |
public static final int GET_LINES_AS_INTS
public static final int TRANSFORM_TRANSLATE
public static final int TRANSFORM_ROTATE
public static final int TRANSFORM_HORIZONTAL_MIRROR
public static final int TRANSFORM_VERTICAL_MIRROR
public static final int TRANSFORM_HORIZONTAL_STRETCH
public static final int TRANSFORM_VERTICAL_STRETCH
public static final int TRANSFORM_SCALE
public GeneralPath(int capacity)
capacity
- The initial capacity of the GeneralPath.public GeneralPath()
public int countPoints()
public float[] getXPoints()
public float[] getYPoints()
public void closePath()
public boolean isClosed()
public boolean openPath()
public void moveTo(float x, float y)
x
- The x-coordinate of the new point.y
- The y-coordinate of the new point.public void lineTo(float x, float y)
x
- The x-coordinate of the end point.y
- The y-coordinate of the end point.public void quadTo(float x1, float y1, float x2, float y2)
x1
- The x-coordinate of the control point.y1
- The y-coordinate of the control point.x2
- The x-coordinate of the end point.y2
- The y-coordinate of the end point.public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3)
x1
- The x-coordinate of the first control point.y1
- The y-coordinate of the first control point.x2
- The x-coordinate of the second control point.y2
- The y-coordinate of the second control point.x3
- The x-coordinate of the end point.y3
- The y-coordinate of the end point.public int getLines(Object destx, Object desty, int offset, boolean includeLastPoint, int options)
destx
- The destination for the x-coordinates. This should be an array of int or array of float values and must match the type of desty.
This can be null to indicate that you want a count of the maximum number of points that will be generated.desty
- The destination for the y-coordinates. This should be an array of int or array of float values and must match the type of destx.
This can be null to indicate that you want a count of the maximum number of points that will be generated.offset
- The start point in the destination arrays for the points.includeLastPoint
- If this is true then the last point (which will be the same as the
start point for a closed polygon) will be included, otherwise it will be omitted. If you are
going to be using this data in Graphics.drawPolygon() then set this to false, since that method
will automatically close the polygon by drawing back to the first point.options
- No options are defined as yet.public void append(GeneralPath path, boolean connect)
path
- The other path to add to this path.connect
- If this is true then a line segment will be placed from the last point
of this path to the first point of the other path IF the first operation of the other GeneralPath
is a moveTo().public void append(GeneralPath path, boolean connect, boolean relative)
path
- The other path to add to this path.connect
- If this is true then a line segment will be placed from the last point
of this path to the first point of the other path IF the first operation of the other GeneralPath
is a moveTo().relative
- If this is true then all co-ordinates of the other path will be considered
relative to the first point of this path.public float[] getBoundingRect(float[] dest)
dest
- An array of 4 floats - if it is null a new array will be created and returned. dest[0] will hold the leftmost x value, dest[1] the topmost y value,
dest[2] the width (distance from the leftmost to the rightmost x value) and dest[3] the height (distance
from the topmost to the bottommost y value).public Rect getBounds(Rect dest)
public Object[] getLines(boolean includeLastPoint, int options)
includeLastPoint
- If this is true then the last point (which will be the same as the
start point for a closed polygon) will be included, otherwise it will be omitted. If you are
going to be using this data in Graphics.drawPolygon() then set this to false, since that method
will automatically close the polygon by drawing back to the first point.options
- GET_LINES_AS_INTS to return the lines as int values, otherwise it will be returned as floats.public Polygon toPolygon()
public GeneralPath getCopy()
public GeneralPath reverse()
public GeneralPath transform(int transformOperation, float x, float y, double factor)
transformOperation
- The selected operation - should be one of the TRANSFORM_XXX values.x
- The x-coordinate to be used by the transform. Its use depends on the transform selected.y
- The y-coordinate to be used by the transform. Its use depends on the transform selected.factor
- A value representing some paramter used for the transform. For example for TRANSFORM_ROTATE
it will be the number of degrees to rotate the path.public GeneralPath transform(double m00, double m10, double m01, double m11, double m02, double m12)
For each x and y point in the GeneralPath, the corresponding x' and y' points in the new GeneralPath will be given by:
x' = m00*x + m01*y + m02; y' = m10*x + m11*y + m12;
public void addToPath(double x, double y)
IPath
public void addToPath(double x1, double y1, double x2, double y2, double x3, double y3)
IPath