Skip to content

DrawShape

final class DrawShape
Package: dev.joid.lib.draw.shape · Module: core · Source: DrawShape.java

Draws filled and outlined shapes, lines and curves with a Color, sharp at every scale.

Reach it through DrawUtils.SHAPE. Positions and sizes are in design pixels, in the coordinates you draw in; every method accepts a gradient or an animated Color. Edges stay sharp by themselves: on the pixel grid they snap to whole pixels, and under a rotation or a fractional scale they are smoothed, so no method has a thin or smooth variant. A rectangle without width or height draws nothing.

ReturnsSignatureSummary
DrawShapeinst() factoryReturns the shared instance, the one in DrawUtils.SHAPE.

ReturnsSignatureSummary
voiddrawRect(double x, double y, double width, double height, Color color)Fills the rectangle at x, y of width × height.
voiddrawRoundedRect(double x, double y, double width, double height, Color color, float radius)Fills the rectangle with its four corners rounded by radius.
voiddrawRoundedRect(double x, double y, double width, double height, Color color, float radius, boolean roundedLeft, boolean roundedTop, boolean roundedRight, boolean roundedBottom)Fills the rectangle and rounds only some corners, with one boolean per side: roundedLeft, roundedTop, roundedRight and roundedBottom.
voiddrawRoundedBorder(double x, double y, double width, double height, Color color, float radius)Strokes the outline of the rounded rectangle, 1 design pixel wide, inside its edge.
voiddrawRoundedBorder(double x, double y, double width, double height, Color color, float radius, double stroke)Strokes the outline of the rounded rectangle, stroke design pixels wide, inside its edge.
voiddrawShadow(double x, double y, double width, double height, Color color, float radius, float blur)Draws the soft shadow of a rounded box: the box at x, y of width × height with corner radius, blurred by blur design pixels.
voiddrawShadow(double x, double y, double width, double height, Color color, float radius, boolean roundedLeft, boolean roundedTop, boolean roundedRight, boolean roundedBottom, float blur)Draws the soft shadow of a box whose corners are rounded only on the chosen sides, as in drawRoundedRect, blurred by blur design pixels.
voiddrawCircle(double x, double y, Color color, double radius)Fills the disc centered on x, y with the given radius.
voiddrawBorder(double x, double y, double width, double height, Color color)Strokes a border 1 design pixel wide inside the rectangle at x, y of width × height.
voiddrawBorder(double x, double y, double width, double height, Color color, double stroke)Strokes a border stroke design pixels wide inside the rectangle.
voiddrawPolygon(Color color, Point… points)Fills the polygon through points, in order; a convex polygon gets smoothed edges.
voiddrawLine(Color color, Point… points)Draws a smoothed line through points, in order, with the line width of the render state, in design pixels.
voiddrawLine(Color color, float stroke, Point… points)Draws a smoothed line through points, stroke design pixels wide.
voiddrawDashedLine(Color color, int pattern, float stroke, Point… points)Draws a dashed line through points, stroke design pixels wide: dashes of pattern design pixels separated by gaps of the same length, restarted at each point.
voiddrawCurvedLine(Color color, Point start, Point control, Point end)Draws a quadratic Bézier curve from start to end, pulled toward control, in about one segment per design pixel of its length.
voiddrawCurvedLine(Color color, float stroke, Point start, Point control, Point end)Draws the quadratic Bézier curve stroke design pixels wide.
voiddrawCurvedLine(Color color, Point start, Point startControl, Point endControl, Point end)Draws a cubic Bézier curve from start to end, shaped by startControl and endControl.
voiddrawCurvedLine(Color color, float stroke, Point start, Point startControl, Point endControl, Point end)Draws the cubic Bézier curve stroke design pixels wide.
voiddrawShape(DrawMode mode, Color color, Point… points)Draws points as the primitive that mode names, such as DrawMode.LINES or DrawMode.POLYGON.
voiddrawRawRect(double x, double y, double width, double height)Fills the rectangle with the current color of the render state, without a texture and without edge smoothing.

DrawShape inst() factory

Returns the shared instance, the one in DrawUtils.SHAPE.

void drawRect(double x, double y, double width, double height, Color color)

Fills the rectangle at x, y of width × height. A rectangle thinner than one screen pixel draws with its coverage as opacity, so a hairline stays visible.

void drawRoundedRect(double x, double y, double width, double height, Color color, float radius)

Fills the rectangle with its four corners rounded by radius. The radius is capped at half the shorter side, so 999F draws a pill.

void drawRoundedRect(double x, double y, double width, double height, Color color, float radius, boolean roundedLeft, boolean roundedTop, boolean roundedRight, boolean roundedBottom)

Fills the rectangle and rounds only some corners, with one boolean per side: roundedLeft, roundedTop, roundedRight and roundedBottom. A corner is rounded when both of its sides are: true, true, true, false keeps the bottom corners square.

void drawRoundedBorder(double x, double y, double width, double height, Color color, float radius)

Strokes the outline of the rounded rectangle, 1 design pixel wide, inside its edge.

void drawRoundedBorder(double x, double y, double width, double height, Color color, float radius, double stroke)

Strokes the outline of the rounded rectangle, stroke design pixels wide, inside its edge.

void drawShadow(double x, double y, double width, double height, Color color, float radius, float blur)

Draws the soft shadow of a rounded box: the box at x, y of width × height with corner radius, blurred by blur design pixels. The shadow spreads 1.5 times the blur beyond the box; a blur of 0F or less draws a plain rounded rectangle. A gradient color uses its start color.

void drawShadow(double x, double y, double width, double height, Color color, float radius, boolean roundedLeft, boolean roundedTop, boolean roundedRight, boolean roundedBottom, float blur)

Draws the soft shadow of a box whose corners are rounded only on the chosen sides, as in drawRoundedRect, blurred by blur design pixels.

void drawCircle(double x, double y, Color color, double radius)

Fills the disc centered on x, y with the given radius.

void drawBorder(double x, double y, double width, double height, Color color)

Strokes a border 1 design pixel wide inside the rectangle at x, y of width × height. It covers the same pixels as drawRoundedBorder with a radius of 0F.

void drawBorder(double x, double y, double width, double height, Color color, double stroke)

Strokes a border stroke design pixels wide inside the rectangle.

void drawPolygon(Color color, Point... points)

Fills the polygon through points, in order; a convex polygon gets smoothed edges.

void drawLine(Color color, Point... points)

Draws a smoothed line through points, in order, with the line width of the render state, in design pixels.

void drawLine(Color color, float stroke, Point... points)

Draws a smoothed line through points, stroke design pixels wide.

void drawDashedLine(Color color, int pattern, float stroke, Point... points)

Throws:

  • IllegalArgumentException: The dash pattern … is not positive, pass a length above 0

Draws a dashed line through points, stroke design pixels wide: dashes of pattern design pixels separated by gaps of the same length, restarted at each point. Throws IllegalArgumentException when pattern is 0 or less.

void drawCurvedLine(Color color, Point start, Point control, Point end)

Draws a quadratic Bézier curve from start to end, pulled toward control, in about one segment per design pixel of its length.

void drawCurvedLine(Color color, float stroke, Point start, Point control, Point end)

Draws the quadratic Bézier curve stroke design pixels wide.

void drawCurvedLine(Color color, Point start, Point startControl, Point endControl, Point end)

Draws a cubic Bézier curve from start to end, shaped by startControl and endControl.

void drawCurvedLine(Color color, float stroke, Point start, Point startControl, Point endControl, Point end)

Draws the cubic Bézier curve stroke design pixels wide.

void drawShape(DrawMode mode, Color color, Point... points)

Draws points as the primitive that mode names, such as DrawMode.LINES or DrawMode.POLYGON.

void drawRawRect(double x, double y, double width, double height)

Fills the rectangle with the current color of the render state, without a texture and without edge smoothing. Use it inside a shader pass or a mask, where the color comes from elsewhere.


fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses

Report a problem with this page