Class RasterPath

java.lang.Object
com.codename1.backend.image.RasterPath

public final class RasterPath extends Object

A shape made of straight lines and quadratic and cubic Bezier curves, for RasterGraphics.fill(RasterPath) and RasterGraphics.draw(RasterPath).

A path is a list of subpaths, each started by moveTo(double, double). Filling closes every subpath implicitly; stroking draws a subpath closed only after closePath().

The static factories build the common shapes. Angles are in degrees, counterclockwise from three o'clock, as on screen with y pointing down (so a positive extent turns toward the top).

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    An arc closed by the straight line between its ends.
    static final int
    An arc drawn alone, both ends open.
    static final int
    An arc closed through the center, a pie slice.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Appends every subpath of another path to this one.
    static RasterPath
    arc(double x, double y, double w, double h, double startDeg, double extentDeg, int type)
    Creates an arc of the ellipse inscribed in a rectangle.
    Closes the current subpath with a line back to its start.
    curveTo(double c1x, double c1y, double c2x, double c2y, double x, double y)
    Adds a cubic Bezier curve.
    static RasterPath
    ellipse(double x, double y, double w, double h)
    Creates the ellipse inscribed in a rectangle.
    boolean
    Returns true when the path has no segments.
    lineTo(double x, double y)
    Adds a straight line to a point.
    moveTo(double x, double y)
    Starts a new subpath at a point.
    static RasterPath
    polygon(double[] xs, double[] ys, int n)
    Creates a closed polygon.
    static RasterPath
    polyline(double[] xs, double[] ys, int n)
    Creates an open chain of lines.
    quadTo(double cx, double cy, double x, double y)
    Adds a quadratic Bezier curve.
    static RasterPath
    rect(double x, double y, double w, double h)
    Creates a rectangle.
    static RasterPath
    roundRect(double x, double y, double w, double h, double arcW, double arcH)
    Creates a rectangle with elliptical corners.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ARC_OPEN

      public static final int ARC_OPEN
      An arc drawn alone, both ends open.
      See Also:
    • ARC_CHORD

      public static final int ARC_CHORD
      An arc closed by the straight line between its ends.
      See Also:
    • ARC_PIE

      public static final int ARC_PIE
      An arc closed through the center, a pie slice.
      See Also:
  • Constructor Details

    • RasterPath

      public RasterPath()
  • Method Details

    • moveTo

      public RasterPath moveTo(double x, double y)

      Starts a new subpath at a point.

      Parameters
      • x: x
      • y: y
      Returns

      this path

    • lineTo

      public RasterPath lineTo(double x, double y)

      Adds a straight line to a point.

      Parameters
      • x: x
      • y: y
      Returns

      this path

    • quadTo

      public RasterPath quadTo(double cx, double cy, double x, double y)

      Adds a quadratic Bezier curve.

      Parameters
      • cx: control point x
      • cy: control point y
      • x: end x
      • y: end y
      Returns

      this path

    • curveTo

      public RasterPath curveTo(double c1x, double c1y, double c2x, double c2y, double x, double y)

      Adds a cubic Bezier curve.

      Parameters
      • c1x: first control point x
      • c1y: first control point y
      • c2x: second control point x
      • c2y: second control point y
      • x: end x
      • y: end y
      Returns

      this path

    • closePath

      public RasterPath closePath()

      Closes the current subpath with a line back to its start.

      Returns

      this path

    • isEmpty

      public boolean isEmpty()
      Returns true when the path has no segments.
    • polygon

      public static RasterPath polygon(double[] xs, double[] ys, int n)

      Creates a closed polygon.

      Parameters
      • xs: x of each vertex
      • ys: y of each vertex
      • n: number of vertices to use
      Returns

      the path

    • polyline

      public static RasterPath polyline(double[] xs, double[] ys, int n)

      Creates an open chain of lines.

      Parameters
      • xs: x of each vertex
      • ys: y of each vertex
      • n: number of vertices to use
      Returns

      the path

    • rect

      public static RasterPath rect(double x, double y, double w, double h)

      Creates a rectangle.

      Parameters
      • x: left
      • y: top
      • w: width
      • h: height
      Returns

      the path

    • roundRect

      public static RasterPath roundRect(double x, double y, double w, double h, double arcW, double arcH)

      Creates a rectangle with elliptical corners.

      Parameters
      • x: left
      • y: top
      • w: width
      • h: height
      • arcW: horizontal diameter of a corner
      • arcH: vertical diameter of a corner
      Returns

      the path

    • ellipse

      public static RasterPath ellipse(double x, double y, double w, double h)

      Creates the ellipse inscribed in a rectangle.

      Parameters
      • x: left
      • y: top
      • w: width
      • h: height
      Returns

      the path

    • arc

      public static RasterPath arc(double x, double y, double w, double h, double startDeg, double extentDeg, int type)

      Creates an arc of the ellipse inscribed in a rectangle.

      Parameters
      • x: left of the ellipse's bounds
      • y: top of the ellipse's bounds
      • w: width of the ellipse
      • h: height of the ellipse
      • startDeg: start angle in degrees
      • extentDeg: angular extent in degrees, negative for clockwise
      • type: ARC_OPEN, ARC_CHORD or ARC_PIE
      Returns

      the path

    • append

      public RasterPath append(RasterPath other)

      Appends every subpath of another path to this one.

      Parameters
      • other: the path to append
      Returns

      this path