public final class GeneralPath
- Object
- GeneralPath
ImplementsShape
A general geometric path, consisting of any number of subpaths constructed
out of straight lines and cubic or quadratic Bezier curves. The inside of the
curve is defined for drawing purposes by a winding rule. Either the
#WIND_EVEN_ODD or #WIND_NON_ZERO winding rule can be chosen.
A drawing of a GeneralPath
The #WIND_EVEN_ODD winding rule defines a point as inside a path if:
A ray from the point towards infinity in an arbitrary direction intersects
the path an odd number of times. Points A and C in the
image are considered to be outside the path. (both intersect twice) Point
B intersects once, and is inside.
The #WIND_NON_ZERO winding rule defines a point as inside a path if:
The path intersects the ray in an equal number of opposite directions. Point
A in the image is outside (one intersection in the ‘up’ direction,
one in the ‘down’ direction) Point B in the image is inside (one
intersection ‘down’) Point C in the image is inside (two intersections in the
‘down’ direction)
Form hi = new Form("Shape");
// We create a 50 x 100 shape, this is arbitrary since we can scale it easily
GeneralPath path = new GeneralPath();
path.moveTo(20,0);
path.lineTo(30, 0);
path.lineTo(30, 100);
path.lineTo(20, 100);
path.lineTo(20, 15);
path.lineTo(5, 40);
path.lineTo(5, 25);
path.lineTo(20,0);
hi.getContentPane().getUnselectedStyle().setBgPainter(new Painter() {
public void paint(Graphics g, Rectangle rect) {
g.setColor(0xff);
float widthRatio = ((float) rect.getWidth()) / 50f;
float heightRatio = ((float) rect.getHeight()) / 100f;
g.scale(widthRatio, heightRatio);
g.translate((int) (((float) rect.getX()) / widthRatio), (int) (((float) rect.getY()) / heightRatio));
g.fillShape(path);
g.resetAffine();
}
});
hi.show();
Note: This description and image were copied from the GNU classpath docs). License here http://www.gnu.org/licenses/licenses.html#FDL
Fields
public static final int WIND_EVEN_ODD = 0 | Same constant as PathIterator#WIND_EVEN_ODD |
public static final int WIND_NON_ZERO = 1 | Same constant as PathIterator#WIND_NON_ZERO |
Constructors
public GeneralPath() | Constructs a GeneralPath with the default (#WIND_NON_ZERO) winding rule and initial capacity (10). |
public GeneralPath(int rule) | Constructs a GeneralPath with a specific winding rule and the default initial capacity (10). |
public GeneralPath(int rule, int initialCapacity) | Constructs a GeneralPath with a specific winding rule and the initial capacity. |
public GeneralPath(Shape shape) | Constructs a GeneralPath from an arbitrary shape object. |
Methods
Inherited methods
Field details
WIND_EVEN_ODD
public static final int WIND_EVEN_ODD = 0PathIterator#WIND_EVEN_ODDWIND_NON_ZERO
public static final int WIND_NON_ZERO = 1PathIterator#WIND_NON_ZEROConstructor details
GeneralPath
public GeneralPath()#WIND_NON_ZERO)
winding rule and initial capacity (10).GeneralPath
public GeneralPath(int rule)Parameters
ruleint- The winding rule. One of
#WIND_NON_ZEROand#WIND_EVEN_ODD
See also
GeneralPath
public GeneralPath(int rule, int initialCapacity)Parameters
ruleint- The winding rule. (
#WIND_NON_ZEROor#WIND_EVEN_ODD). initialCapacityint- the inital capacity, in path segments
GeneralPath
public GeneralPath(Shape shape)Method details
recycle
public static synchronized void recycle(GeneralPath p)Parameters
pGeneralPath- The path to recycle.
See also
createFromPool
public static GeneralPath createFromPool()Creates a new GeneralPath from an object Pool. This is useful if you need to create a temporary General path that you wish to dispose of after using.
You should return this object back to the pool when you are done
using the #recycle(com.codename1.ui.geom.GeneralPath) method.
isConvexPolygon
public static boolean isConvexPolygon(float[] xPoints, float[] yPoints)Parameters
xPointsfloat[]- The x coordinates of the polygon.
yPointsfloat[]- The y coordinates of the polygon.
Returns
isConvexPolygon
public static boolean isConvexPolygon(int[] xPoints, int[] yPoints)isPolygon
public boolean isPolygon()Returns
getTypesSize
public int getTypesSize()Returns
getPointsSize
public int getPointsSize()Returns
getTypes
public void getTypes(byte[] out)Parameters
outbyte[]- An array to copy the path commands into.
getPoints
public void getPoints(float[] out)Parameters
outfloat[]- An array to copy the points into.
toString
public String toString()equals
public boolean equals(Shape shape, Transform t)getWindingRule
public int getWindingRule()Returns
#WIND_NON_ZERO or #WIND_EVEN_ODDsetWindingRule
public void setWindingRule(int rule)#WIND_EVEN_ODD for an even-odd winding rule, or
#WIND_NON_ZERO for a non-zero winding rule.Parameters
ruleint- the rule. (
#WIND_NON_ZEROor#WIND_EVEN_ODD).
moveTo
public void moveTo(double x, double y)moveTo
public void moveTo(float x, float y)Parameters
xfloat- the x-coordinate.
yfloat- the y-coordinate.
lineTo
public void lineTo(double x, double y)lineTo
public void lineTo(float x, float y)Parameters
xfloat- x coordinate of the line endpoint.
yfloat- y coordinate of the line endpoint.
quadTo
public void quadTo(double x1, double y1, double x2, double y2)quadTo
public void quadTo(float x1, float y1, float x2, float y2)Parameters
x1float- x coordinate of the control point
y1float- y coordinate of the control point
x2float- x coordinate of the curve endpoint.
y2float- y coordinate of the curve endpoint.
curveTo
public void curveTo(double x1, double y1, double x2, double y2, double x3, double y3)curveTo
public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3)Parameters
x1float- x coordinate of the first control point
y1float- y coordinate of the first control point
x2float- x coordinate of the second control point
y2float- y coordinate of the second control point
x3float- x coordinate of the curve endpoint.
y3float- y coordinate of the curve endpoint.
arc
public void arc(float x, float y, float w, float h, float startAngle, float sweepAngle)Parameters
xfloat- Left x coord of bounding rect.
yfloat- Top y coordof bounding rect.
wfloat- Width of bounding rect.
hfloat- Height of bounding rect.
startAnglefloat- Start angle on ellipse in radians. Counter-clockwise from 3-o’clock.
sweepAnglefloat- Sweep angle in radians. Counter-clockwise.
arc
public void arc(float x, float y, float w, float h, float startAngle, float sweepAngle, boolean joinPath)Parameters
xfloat- Left x coord of bounding rect.
yfloat- Top y coordof bounding rect.
wfloat- Width of bounding rect.
hfloat- Height of bounding rect.
startAnglefloat- Start angle on ellipse in radians. Counter-clockwise from 3-o’clock.
sweepAnglefloat- Sweep angle in radians. Counter-clockwise.
joinPathboolean- If true, then this will join the arc to the existing path with a line.
arc
public void arc(double x, double y, double w, double h, double startAngle, double sweepAngle)Parameters
xdouble- Left x coord of bounding rect.
ydouble- Top y coordof bounding rect.
wdouble- Width of bounding rect.
hdouble- Height of bounding rect.
startAngledouble- Start angle on ellipse in radians. Counter-clockwise from 3-o’clock.
sweepAngledouble- Sweep angle in radians. Counter-clockwise.
arc
public void arc(double x, double y, double w, double h, double startAngle, double sweepAngle, boolean joinPath)Parameters
xdouble- Left x coord of bounding rect.
ydouble- Top y coordof bounding rect.
wdouble- Width of bounding rect.
hdouble- Height of bounding rect.
startAngledouble- Start angle on ellipse in radians. Counter-clockwise from 3-o’clock.
sweepAngledouble- Sweep angle in radians. Counter-clockwise.
joinPathboolean- If true then this will join the arc to the existing path with a line.
arcTo
public void arcTo(float cX, float cY, float endX, float endY)Adds an arc to the path. This method uses an approximation of an arc using a cubic path. It is not a precise arc.
Note: The arc is drawn counter-clockwise around the center point. See double, double, double, boolean)
to draw clockwise.
Parameters
cXfloat- The x-coordinate of the oval center.
cYfloat- The y-coordinate of the oval center.
endXfloat- The end X coordinate.
endYfloat- The end Y coordinate.
arcTo
public void arcTo(float cX, float cY, float endX, float endY, boolean clockwise)Parameters
cXfloat- The x-coordinate of the oval center.
cYfloat- The y-coordinate of the oval center.
endXfloat- The end X coordinate.
endYfloat- The end Y coordinate.
clockwiseboolean- If true, the arc is drawn clockwise around the center point.
arcTo
public void arcTo(double cX, double cY, double endX, double endY)Adds an arc to the path. This method uses an approximation of an arc using a cubic path. It is not a precise arc.
Note: The arc is drawn counter-clockwise around the center point. See double, double, double, boolean)
to draw clockwise.
Parameters
cXdouble- The x-coordinate of the oval center.
cYdouble- The y-coordinate of the oval center.
endXdouble- The end X coordinate.
endYdouble- The end Y coordinate.
arcTo
public void arcTo(double cX, double cY, double endX, double endY, boolean clockwise)Parameters
cXdouble- The x-coordinate of the oval center.
cYdouble- The y-coordinate of the oval center.
endXdouble- The end X coordinate.
endYdouble- The end Y coordinate.
clockwiseboolean- If true, the arc is drawn clockwise around the center point.
closePath
public void closePath()append
public void append(Shape shape, boolean connect)Parameters
shapeShape- the shape (null not permitted).
connectboolean- whether to connect the new shape to the existing path.
append
public void append(PathIterator path, boolean connect)PathIterator#SEG_MOVETO segment of the appended path
is changed into a PathIterator#SEG_LINETO segment.Parameters
pathPathIterator- the PathIterator specifying which segments shall be appended (null not permitted).
connectboolean- true for substituting the initial
PathIterator#SEG_MOVETOsegment by aPathIterator#SEG_LINETO, or false for not performing any substitution. If thisGeneralPathis currently empty, connect is assumed to be false, thus leaving the initialPathIterator#SEG_MOVETOunchanged.
getCurrentPoint
public float[] getCurrentPoint()Returns
[x,y] representing x
and y coordinate of the current appending point of the path..getCurrentPoint
public void getCurrentPoint(float[] point)Parameters
pointfloat[]- Out parameter. Will be filled with the coords of the current point.
reset
public void reset()getBounds2D
public float[] getBounds2D()Returns
[x, y, width, height].getBounds2D
public void getBounds2D(float[] out)Parameters
outfloat[]- 4-element float[] array.
getBounds
public Rectangle getBounds()Returns
getBounds
public void getBounds(Rectangle out)isRectangle
public boolean isRectangle()Returns
getPathIterator
public PathIterator getPathIterator()Returns
getPathIterator
public PathIterator getPathIterator(Transform m){Gets an iterator where all points are transformed by the provided transform.
Note: If com.codename1.ui.Transform#isSupported() is false, then using this iterator will throw a Runtime Exception.}
Returns
createTransformedShape
public Shape createTransformedShape(Transform m)Returns a shape formed by transforming the current shape with the provided transform.
Note: If com.codename1.ui.Transform#isSupported is false, this may throw a RuntimeException.
Parameters
mTransform- The transform to be used to transform the shape.
Returns
setPath
public void setPath(GeneralPath p, Transform t)p with the given
Transform t applied to it.Parameters
pGeneralPath- The path to copy.
tTransform- The transform to apply to all points in the path.
setRect
public void setRect(Rectangle r, Transform t)Parameters
rRectangle- Rectangle to copy.
tTransform- The transform to apply to the points in in
r.
setShape
public void setShape(Shape s, Transform t)Parameters
sShape- The shape to copy.
tTransform- The transform to apply to all points in the shape.
intersect
public boolean intersect(Rectangle rect)Parameters
rectRectangle- The rectangle to intersect with this path.
Returns
rect intersects the current path. False otherwise. If there is no intersection, the
path will be reset to be empty.intersect
public boolean intersect(int x, int y, int w, int h)transform
public void transform(Transform m)Parameters
mTransform- The transform to apply to the path.
intersect
public void intersect(Shape shape)Resets this path to be the intersection of itself with the given shape. Note that only
com.codename1.ui.geom.Rectangles are current supported. If you pass any other
shape, it will throw a RuntimeException.
Note: If com.codename1.ui.TransformisSupported is false, this will throw a Runtime Exception
Parameters
shapeShape- The shape to intersect with the current shape.
intersection
public Shape intersection(Rectangle rect)Parameters
rectRectangle- A rectangle with which to form an intersection.
Returns
contains
public boolean contains(float x, float y)Parameters
xfloat- The x coordinate to check
yfloat- The y coordinate to check
Returns
contains
public boolean contains(int x, int y)Parameters
xint- The x-coordinate of the point to test.
yint- The y-coordinate of the point to test.