Class ShapePainter
- java.lang.Object
-
- ej.drawing.ShapePainter
-
public class ShapePainter extends Object
TheShapePainterclass offers a set of static methods to render thick shapes (with or without anti-aliasing) and polygons.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classShapePainter.CapDefines the cap representation when drawing a line or a circle arc.
-
Constructor Summary
Constructors Constructor Description ShapePainter()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voiddrawPolygon(GraphicsContext gc, int[] xys)Draws the closed polygon which is defined by the array of integer coordinates, using the current color.static voiddrawPolygon(GraphicsContext gc, int[] xys, int offset, int length)Draws the closed polygon which is defined by the array of integer coordinates, using the current color.static voiddrawThickCircle(GraphicsContext gc, int x, int y, int diameter, int thickness)Draws the outline of a circle covering the square specified by its diameter, using theGraphicsContext's current color.
The center of the circle is defined as the center of the square whose origin is at(x,y)(upper-left corner) and whose dimension is given bydiameter.
Ifdiameteris negative, nothing is drawn.static voiddrawThickCircleArc(GraphicsContext gc, int x, int y, int diameter, float startAngle, float arcAngle, int thickness)Draws the outline of a circular arc covering the specified square, using theGraphicsContext's current color.
The arc is drawn fromstartAngleup toarcAngledegrees.static voiddrawThickEllipse(GraphicsContext gc, int x, int y, int width, int height, int thickness)Draws the outline of a ellipse covering the specified rectangle, using theGraphicsContext's current color.
The center of the ellipse is defined as the center of the rectangle whose origin is at(x,y)(upper-left corner) and whose dimension is given bywidthandheight.
If eitherwidthorheightis negative or zero, nothing is drawn.static voiddrawThickFadedCircle(GraphicsContext gc, int x, int y, int diameter, int thickness, int fade)Draws the faded outline of a circle covering the square specified by its diameter, using theGraphicsContext's current color.
The center of the circle is defined as the center of the square whose origin is at(x,y)(upper-left corner) and whose dimension is given bydiameter.
Ifdiameteris negative or zero, nothing is drawn.static voiddrawThickFadedCircleArc(GraphicsContext gc, int x, int y, int diameter, float startAngle, float arcAngle, int thickness, int fade, ShapePainter.Cap startCap, ShapePainter.Cap endCap)Draws the faded outline of a circular arc covering the specified square, using the current color and caps.static voiddrawThickFadedEllipse(GraphicsContext gc, int x, int y, int width, int height, int thickness, int fade)Draws the outline of a ellipse covering the specified rectangle, using theGraphicsContext's current color.
The center of the ellipse is defined as the center of the rectangle whose origin is at(x,y)(upper-left corner) and whose dimension is given bywidthandheight.
If eitherwidthorheightis negative or zero, nothing is drawn.static voiddrawThickFadedLine(GraphicsContext gc, int startX, int startY, int endX, int endY, int thickness, int fade, ShapePainter.Cap startCap, ShapePainter.Cap endCap)static voiddrawThickFadedPoint(GraphicsContext gc, int x, int y, int thickness, int fade)Draws a faded point at(x,y)using theGraphicsContext's current color.static voiddrawThickLine(GraphicsContext gc, int startX, int startY, int endX, int endY, int thickness)static voidfillPolygon(GraphicsContext gc, int[] xys)Fills the closed polygon which is defined by the array of integer coordinates, using the current color.static voidfillPolygon(GraphicsContext gc, int[] xys, int offset, int length)Fills the closed polygon which is defined by the array of integer coordinates, using the current color.
-
-
-
Method Detail
-
drawThickFadedPoint
public static void drawThickFadedPoint(GraphicsContext gc, int x, int y, int thickness, int fade)
Draws a faded point at(x,y)using theGraphicsContext's current color.The shape's bounding box is
(x - thickness / 2 - fade, y - thickness / 2 - fade) to (x + thickness / 2 + fade, y + thickness / 2 + fade).- Parameters:
gc- the graphics context where render the drawing.x- the x coordinate of the pointy- the y coordinate of the pointthickness- the thickness to apply.fade- the fade to apply.- Throws:
IllegalArgumentException- when given thickness is negative
-
drawThickLine
public static void drawThickLine(GraphicsContext gc, int startX, int startY, int endX, int endY, int thickness)
Draws a line from(x1,y1)to(x2,y2)using theGraphicsContext's current color.The rendering is aliased but the rendering time is often faster than
drawThickFadedLine(GraphicsContext, int, int, int, int, int, int, Cap, Cap).Equivalent to calling
drawThickFadedLine(GraphicsContext, int, int, int, int, int, int, Cap, Cap)with a fade equals to 0 andShapePainter.Cap.NONEfor caps.The shape's bounding box is
(min(startX, endX) - thickness / 2, min(startY, endY) - thickness / 2) to (max(startX, endX) + thickness / 2, max(startY, endY) + thickness / 2).- Parameters:
gc- the graphics context where render the drawing.startX- the x coordinate of the start of the line.startY- the y coordinate of the start of the line.endX- the x coordinate of the end of the line.endY- the y coordinate of the end of the line.thickness- the thickness to apply.- Throws:
IllegalArgumentException- when given thickness is negative
-
drawThickFadedLine
public static void drawThickFadedLine(GraphicsContext gc, int startX, int startY, int endX, int endY, int thickness, int fade, ShapePainter.Cap startCap, ShapePainter.Cap endCap)
Draws a faded line from(x1,y1)to(x2,y2)using theGraphicsContext's current color and caps.The shape's bounding box is
(min(startX, endX) - thickness / 2 - fade, min(startY, endY) - thickness / 2 - fade) to (max(startX, endX) + thickness / 2 + fade, max(startY, endY) + thickness / 2 + fade).- Parameters:
gc- the graphics context where render the drawing.startX- the x coordinate of the start of the linestartY- the y coordinate of the start of the lineendX- the x coordinate of the end of the lineendY- the y coordinate of the end of the linethickness- the thickness to apply.fade- the fade to apply.startCap- the cap to draw on (x1,y1).endCap- the cap to draw on (x2,y2).- Throws:
IllegalArgumentException- when given thickness or fade is negative
-
drawThickCircleArc
public static void drawThickCircleArc(GraphicsContext gc, int x, int y, int diameter, float startAngle, float arcAngle, int thickness)
Draws the outline of a circular arc covering the specified square, using theGraphicsContext's current color.
The arc is drawn fromstartAngleup toarcAngledegrees. The center of the arc is defined as the center of the square whose origin is at(x,y)(upper-left corner) and whose dimension is given bydiameter.
Angles are interpreted such that 0 degrees is at the 3 o'clock position. A positive value indicates a counter-clockwise rotation while a negative value indicates a clockwise rotation.
Ifdiameteris negative, nothing is drawn.The rendering is aliased but the rendering time is often faster than
drawThickFadedCircleArc(GraphicsContext, int, int, int, float, float, int, int, Cap, Cap).Equivalent to calling
drawThickFadedCircleArc(GraphicsContext, int, int, int, float, float, int, int, Cap, Cap)with a fade equals to 0 andShapePainter.Cap.NONEfor caps.The shape's bounding box is (when arcAngle is 360°):
(x - thickness / 2, y - thickness / 2) to (x + diameter + thickness / 2, y + diameter + thickness / 2).- Parameters:
gc- the graphics context where render the drawing.x- the x coordinate of the upper-left corner of the square where the arc is drawn.y- the y coordinate of the upper-left corner of the square where the arc is drawn.diameter- the diameter of the arc to draw.startAngle- the beginning angle of the arc to draw.arcAngle- the angular extent of the arc fromstartAngle.thickness- the thickness to apply.- Throws:
IllegalArgumentException- when given thickness is negative
-
drawThickFadedCircleArc
public static void drawThickFadedCircleArc(GraphicsContext gc, int x, int y, int diameter, float startAngle, float arcAngle, int thickness, int fade, ShapePainter.Cap startCap, ShapePainter.Cap endCap)
Draws the faded outline of a circular arc covering the specified square, using the current color and caps.
The arc is drawn fromstartAngleup toarcAngledegrees. The center of the arc is defined as the center of the square whose origin is at(x,y)(upper-left corner) and whose dimension is given bydiameter.
Angles are interpreted such that 0 degrees is at the 3 o'clock position. A positive value indicates a counter-clockwise rotation while a negative value indicates a clockwise rotation.
Ifdiameteris negative or zero, nothing is drawn.
The angles are given relative to the square. For instance an angle of 45 degrees is always defined by the line from the center of the square to the upper right corner of the square. Thus for a non squared square angles are skewed along either height or width.The shape's bounding box is (when arcAngle is 360°):
(x - thickness / 2 - fade, y - thickness / 2 - fade) to (x + diameter + thickness / 2 + fade, y + diameter + thickness / 2 + fade).- Parameters:
gc- the graphics context where render the drawing.x- the x coordinate of the upper-left corner of the square where the arc is drawny- the y coordinate of the upper-left corner of the square where the arc is drawndiameter- the diameter of the arc to drawstartAngle- the beginning angle of the arc to drawarcAngle- the angular extent of the arc fromstartAnglethickness- the thickness to apply.fade- the fade to apply.startCap- the cap to draw at startAngle.endCap- the cap to draw at startAngle + arcAngle.- Throws:
IllegalArgumentException- when given thickness or fade is negative
-
drawThickCircle
public static void drawThickCircle(GraphicsContext gc, int x, int y, int diameter, int thickness)
Draws the outline of a circle covering the square specified by its diameter, using theGraphicsContext's current color.
The center of the circle is defined as the center of the square whose origin is at(x,y)(upper-left corner) and whose dimension is given bydiameter.
Ifdiameteris negative, nothing is drawn.
The rendering is aliased but the rendering time is often faster than
drawThickFadedCircle(GraphicsContext, int, int, int, int, int).Equivalent to calling
drawThickFadedCircle(GraphicsContext, int, int, int, int, int)with a fade equals to 0.The shape's bounding box is
(x - thickness / 2, y - thickness / 2) to (x + diameter + thickness / 2, y + diameter + thickness / 2).- Parameters:
gc- the graphics context where render the drawing.x- the x coordinate of the upper-left corner of the square where the circle is drawn.y- the y coordinate of the upper-left corner of the square where the circle is drawn.diameter- the diameter of the circle to draw.thickness- the thickness to apply.- Throws:
IllegalArgumentException- when given thickness is negative
-
drawThickFadedCircle
public static void drawThickFadedCircle(GraphicsContext gc, int x, int y, int diameter, int thickness, int fade)
Draws the faded outline of a circle covering the square specified by its diameter, using theGraphicsContext's current color.
The center of the circle is defined as the center of the square whose origin is at(x,y)(upper-left corner) and whose dimension is given bydiameter.
Ifdiameteris negative or zero, nothing is drawn.
The shape's bounding box is
(x - thickness / 2 - fade, y - thickness / 2 - fade) to (x + diameter + thickness / 2 + fade, y + diameter + thickness / 2 + fade).- Parameters:
gc- the graphics context where render the drawing.x- the x coordinate of the upper-left corner of the square where the circle is drawny- the y coordinate of the upper-left corner of the square where the circle is drawndiameter- the diameter of the circle to drawthickness- the thickness to apply.fade- the fade to apply.- Throws:
IllegalArgumentException- when given thickness or fade is negative
-
drawThickEllipse
public static void drawThickEllipse(GraphicsContext gc, int x, int y, int width, int height, int thickness)
Draws the outline of a ellipse covering the specified rectangle, using theGraphicsContext's current color.
The center of the ellipse is defined as the center of the rectangle whose origin is at(x,y)(upper-left corner) and whose dimension is given bywidthandheight.
If eitherwidthorheightis negative or zero, nothing is drawn.
The rendering is aliased but the rendering time is often faster than
drawThickFadedEllipse(GraphicsContext, int, int, int, int, int, int).Equivalent to calling
drawThickFadedEllipse(GraphicsContext, int, int, int, int, int, int)with a fade equals to 0.The shape's bounding box is
(x - thickness / 2, y - thickness / 2) to (x + width + thickness / 2, y + height + thickness / 2).- Parameters:
gc- the graphics context where render the drawing.x- the x coordinate of the upper-left corner of the rectangle where the ellipse is drawny- the y coordinate of the upper-left corner of the rectangle where the ellipse is drawnwidth- the width of the ellipse to drawheight- the height of the ellipse to drawthickness- the thickness to apply.- Throws:
IllegalArgumentException- when given thickness is negative
-
drawThickFadedEllipse
public static void drawThickFadedEllipse(GraphicsContext gc, int x, int y, int width, int height, int thickness, int fade)
Draws the outline of a ellipse covering the specified rectangle, using theGraphicsContext's current color.
The center of the ellipse is defined as the center of the rectangle whose origin is at(x,y)(upper-left corner) and whose dimension is given bywidthandheight.
If eitherwidthorheightis negative or zero, nothing is drawn.
The shape's bounding box is
(x - thickness / 2 - fade, y - thickness / 2 - fade) to (x + width + thickness / 2 + fade, y + height + thickness / 2 + fade).- Parameters:
gc- the graphics context where render the drawing.x- the x coordinate of the upper-left corner of the rectangle where the ellipse is drawny- the y coordinate of the upper-left corner of the rectangle where the ellipse is drawnwidth- the width of the ellipse to drawheight- the height of the ellipse to drawthickness- the thickness to apply.fade- the fade to apply.- Throws:
IllegalArgumentException- when given thickness or fade is negative
-
drawPolygon
public static void drawPolygon(GraphicsContext gc, int[] xys)
Draws the closed polygon which is defined by the array of integer coordinates, using the current color. Lines are drawn between each consecutive pair, and between the first pair and last pair in the array. The effect is identical to
draw(xys,0,xys.length);- Parameters:
gc- the graphics context where render the drawing.xys- the array of coordinates : x1,y1,......xn,yn.- Throws:
IllegalArgumentException- if the given array length is odd.
-
drawPolygon
public static void drawPolygon(GraphicsContext gc, int[] xys, int offset, int length)
Draws the closed polygon which is defined by the array of integer coordinates, using the current color. Lines are drawn between each consecutive pair, and between the first pair and last pair in the array.- Parameters:
gc- the graphics context where render the drawing.xys- the array of coordinates : x1,y1,......xn,yn.offset- thex1index inxys.length- the number of coordinates, must be even.- Throws:
IllegalArgumentException- if the given array length is odd.ArrayIndexOutOfBoundsException- the wanted data is outside the array bounds.
-
fillPolygon
public static void fillPolygon(GraphicsContext gc, int[] xys)
Fills the closed polygon which is defined by the array of integer coordinates, using the current color. Lines are drawn between each consecutive pair, and between the first pair and last pair in the array. The lines connecting each pair of points are included in the filled polygon. The effect is identical to
fill(xys,0,xys.length);- Parameters:
gc- the graphics context where render the drawing.xys- the array of coordinates : x1,y1,......xn,yn.- Throws:
IllegalArgumentException- if the given array length is odd.
-
fillPolygon
public static void fillPolygon(GraphicsContext gc, int[] xys, int offset, int length)
Fills the closed polygon which is defined by the array of integer coordinates, using the current color. Lines are drawn between each consecutive pair, and between the first pair and last pair in the array. The lines connecting each pair of points are included in the filled polygon.- Parameters:
gc- the graphics context where render the drawing.xys- the array of coordinates : x1,y1,......xn,yn.offset- thex1index inxys.length- the number of coordinates, must be even.- Throws:
ArrayIndexOutOfBoundsException- ifoffsetandlengthdo not specify a valid range withinxys.IllegalArgumentException- if thexyslength is odd.
-
-