Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: GraphicsContext

[14:7] extends: FxObj

Wraps the JavaFX GraphicsContext and provides 2D drawing operations for a Canvas. Obtain an instance by calling getGraphicsContext() on a Canvas object. The GraphicsContext maintains a state stack that can be saved and restored. State includes fill paint, stroke paint, line width, font, transforms, and clip.

Methods

  • setFill (object PaintObj)

    Sets the fill paint. Accepts a Color, LinearGradient, or RadialGradient object.

    • @p PaintObj is a paint object (Color, LinearGradient, or RadialGradient).
    • @r this object for chaining
  • setStroke (object PaintObj)

    Sets the stroke paint. Accepts a Color, LinearGradient, or RadialGradient object.

    • @p PaintObj is a paint object (Color, LinearGradient, or RadialGradient).
    • @r this object for chaining
  • setLineWidth (double Width)

    Sets the stroke line width.

    • @p Width is a double with the line width.
    • @r this object for chaining
  • setLineCap (string Cap)

    Sets the line cap style.

    • @p Cap is a string: BUTT, ROUND, or SQUARE.
    • @r this object for chaining
  • setLineJoin (string Join)

    Sets the line join style.

    • @p Join is a string: MITER, BEVEL, or ROUND.
    • @r this object for chaining
  • setMiterLimit (double Limit)

    Sets the miter limit for MITER line joins.

    • @p Limit is a double with the miter limit.
    • @r this object for chaining
  • setGlobalAlpha (double Alpha)

    Sets the global opacity for all drawing operations.

    • @p Alpha is a double from 0.0 (transparent) to 1.0 (opaque).
    • @r this object for chaining
  • setGlobalBlendMode (string Mode)

    Sets the global blend mode for compositing.

    • @p Mode is a string with the blend mode (e.g. SRC_OVER, MULTIPLY, SCREEN, ADD, OVERLAY, DARKEN, LIGHTEN, COLOR_DODGE, COLOR_BURN, HARD_LIGHT, SOFT_LIGHT, DIFFERENCE, EXCLUSION, RED, GREEN, BLUE).
    • @r this object for chaining
  • fillRect (double X, double Y, double W, double H)

    Fills a rectangle.

    • @p X is a double with the X position.
    • @p Y is a double with the Y position.
    • @p W is a double with the width.
    • @p H is a double with the height.
    • @r this object for chaining
  • strokeRect (double X, double Y, double W, double H)

    Strokes a rectangle outline.

    • @p X is a double with the X position.
    • @p Y is a double with the Y position.
    • @p W is a double with the width.
    • @p H is a double with the height.
    • @r this object for chaining
  • fillOval (double X, double Y, double W, double H)

    Fills an oval.

    • @p X is a double with the X position of the bounding box.
    • @p Y is a double with the Y position of the bounding box.
    • @p W is a double with the width.
    • @p H is a double with the height.
    • @r this object for chaining
  • strokeOval (double X, double Y, double W, double H)

    Strokes an oval outline.

    • @p X is a double with the X position of the bounding box.
    • @p Y is a double with the Y position of the bounding box.
    • @p W is a double with the width.
    • @p H is a double with the height.
    • @r this object for chaining
  • fillArc (double X, double Y, double W, double H, double Start, double Extent, string Type)

    Fills an arc.

    • @p X is a double with the X position.
    • @p Y is a double with the Y position.
    • @p W is a double with the width.
    • @p H is a double with the height.
    • @p Start is a double with the start angle in degrees.
    • @p Extent is a double with the angular extent in degrees.
    • @p Type is a string with the arc type: OPEN, CHORD, or ROUND.
    • @r this object for chaining
  • strokeArc (double X, double Y, double W, double H, double Start, double Extent, string Type)

    Strokes an arc outline.

    • @p X is a double with the X position.
    • @p Y is a double with the Y position.
    • @p W is a double with the width.
    • @p H is a double with the height.
    • @p Start is a double with the start angle in degrees.
    • @p Extent is a double with the angular extent in degrees.
    • @p Type is a string with the arc type: OPEN, CHORD, or ROUND.
    • @r this object for chaining
  • fillRoundRect (double X, double Y, double W, double H, double ArcW, double ArcH)

    Fills a rounded rectangle.

    • @p X is a double with the X position.
    • @p Y is a double with the Y position.
    • @p W is a double with the width.
    • @p H is a double with the height.
    • @p ArcW is a double with the arc width for corners.
    • @p ArcH is a double with the arc height for corners.
    • @r this object for chaining
  • strokeRoundRect (double X, double Y, double W, double H, double ArcW, double ArcH)

    Strokes a rounded rectangle outline.

    • @p X is a double with the X position.
    • @p Y is a double with the Y position.
    • @p W is a double with the width.
    • @p H is a double with the height.
    • @p ArcW is a double with the arc width for corners.
    • @p ArcH is a double with the arc height for corners.
    • @r this object for chaining
  • strokeLine (double X1, double Y1, double X2, double Y2)

    Draws a line between two points.

    • @p X1 is a double with the start X.
    • @p Y1 is a double with the start Y.
    • @p X2 is a double with the end X.
    • @p Y2 is a double with the end Y.
    • @r this object for chaining
  • beginPath ()

    Begins a new path.

    • @r this object for chaining
  • moveTo (double X, double Y)

    Moves the path cursor to the specified position without drawing.

    • @p X is a double with the X position.
    • @p Y is a double with the Y position.
    • @r this object for chaining
  • lineTo (double X, double Y)

    Adds a line segment from the current position to the specified position.

    • @p X is a double with the end X.
    • @p Y is a double with the end Y.
    • @r this object for chaining
  • quadraticCurveTo (double CX, double CY, double X, double Y)

    Adds a quadratic Bezier curve to the path.

    • @p CX is a double with the control point X.
    • @p CY is a double with the control point Y.
    • @p X is a double with the end point X.
    • @p Y is a double with the end point Y.
    • @r this object for chaining
  • bezierCurveTo (double CX1, double CY1, double CX2, double CY2, double X, double Y)

    Adds a cubic Bezier curve to the path.

    • @p CX1 is a double with the first control point X.
    • @p CY1 is a double with the first control point Y.
    • @p CX2 is a double with the second control point X.
    • @p CY2 is a double with the second control point Y.
    • @p X is a double with the end point X.
    • @p Y is a double with the end point Y.
    • @r this object for chaining
  • arcTo (double X1, double Y1, double X2, double Y2, double Radius)

    Adds an arc to the path defined by two tangent lines and a radius.

    • @p X1 is a double with the first tangent point X.
    • @p Y1 is a double with the first tangent point Y.
    • @p X2 is a double with the second tangent point X.
    • @p Y2 is a double with the second tangent point Y.
    • @p Radius is a double with the arc radius.
    • @r this object for chaining
  • closePath ()

    Closes the current path by drawing a line back to the starting point.

    • @r this object for chaining
  • stroke ()

    Strokes the current path with the current stroke paint and line settings.

    • @r this object for chaining
  • fill ()

    Fills the current path with the current fill paint.

    • @r this object for chaining
  • setLineDashes (list Dashes = null)

    Sets the dash pattern for stroked lines. Pass null or an empty list to clear the dash pattern and use solid lines.

    • @p Dashes is a list of doubles defining the dash pattern (e.g. [10.0, 5.0]), or null for solid.
    • @r this object for chaining
  • setLineDashOffset (double Offset)

    Sets the offset into the dash pattern.

    • @p Offset is a double with the dash offset.
    • @r this object for chaining
  • fillText (string Text, double X, double Y)

    Fills text at the specified position using the current fill paint and font.

    • @p Text is a string with the text to draw.
    • @p X is a double with the X position.
    • @p Y is a double with the Y position.
    • @r this object for chaining
  • strokeText (string Text, double X, double Y)

    Strokes text outline at the specified position using the current stroke paint and font.

    • @p Text is a string with the text to draw.
    • @p X is a double with the X position.
    • @p Y is a double with the Y position.
    • @r this object for chaining
  • setFont (object FontObj)

    Sets the font for text drawing.

    • @p FontObj is a FxObj with a JavaFX Font (from Font.get() or Font.load()).
    • @r this object for chaining
  • setTextAlign (string Align)

    Sets the horizontal text alignment.

    • @p Align is a string: LEFT, CENTER, RIGHT, or JUSTIFY.
    • @r this object for chaining
  • setTextBaseline (string Baseline)

    Sets the vertical text baseline.

    • @p Baseline is a string: TOP, CENTER, BASELINE, or BOTTOM.
    • @r this object for chaining
  • drawImage (object Img, double X, double Y)

    Draws an image at the specified position.

    • @p Img is an Image object to draw.
    • @p X is a double with the X position.
    • @p Y is a double with the Y position.
    • @r this object for chaining
  • drawImageScaled (object Img, double X, double Y, double W, double H)

    Draws an image scaled to the specified size.

    • @p Img is an Image object to draw.
    • @p X is a double with the X position.
    • @p Y is a double with the Y position.
    • @p W is a double with the target width.
    • @p H is a double with the target height.
    • @r this object for chaining
  • clearRect (double X, double Y, double W, double H)

    Clears a rectangular area, making it transparent.

    • @p X is a double with the X position.
    • @p Y is a double with the Y position.
    • @p W is a double with the width.
    • @p H is a double with the height.
    • @r this object for chaining
  • save ()

    Pushes the current state onto the state stack. The state includes fill, stroke, line width, line cap, line join, miter limit, font, text align, text baseline, transforms, clip, and global alpha.

    • @r this object for chaining
  • restore ()

    Pops the state from the state stack, restoring all saved state properties.

    • @r this object for chaining
  • clip ()

    Intersects the current clip with the current path. Drawing operations after this call will only affect pixels inside the clipped area.

    • @r this object for chaining
  • translate (double X, double Y)

    Translates the origin by the specified amounts.

    • @p X is a double with the horizontal translation.
    • @p Y is a double with the vertical translation.
    • @r this object for chaining
  • rotate (double Angle)

    Rotates the canvas around the current origin.

    • @p Angle is a double with the rotation angle in degrees.
    • @r this object for chaining
  • scale (double X, double Y)

    Scales the canvas axes.

    • @p X is a double with the horizontal scale factor.
    • @p Y is a double with the vertical scale factor.
    • @r this object for chaining
  • getPixelWriter ()

    Returns the PixelWriter for this canvas as an AussomJavaObject. Use AJI invoke() to call methods on it (e.g. setColor).

    • @r An AussomJavaObject wrapping the PixelWriter.