Painter
class in package klyn.gui.windows

    public class Painter:

Painter

Immediate-mode drawing context for widgets.

The class intentionally combines the ergonomic surface of Java2D and the HTML canvas API: state stack, paths, transforms, text, images, gradients, antialiasing and convenience helpers such as `drawRect` and `fillText`.

    painter = Painter(320, 200)
    background = painter.createLinearGradient(0, 0, 320, 0)
    background.addStop(0.0, Color.white())
    background.addStop(1.0, Color(37, 99, 235, 1.0))
    painter.fillStyle = background
    painter.fillRect(0, 0, 320, 200)
    painter.strokeStyle = Color(15, 23, 42, 1.0)
    painter.lineWidth = 2.0
    painter.drawRect(20, 20, 120, 60)

Properties

Modifier and Type | Member | Description
--- | --- | ---
public property | antialiasingEnabled `antialiasingEnabled as Boolean` | Global vector antialiasing flag.
public property | commandCount `commandCount as Int` | Number of recorded drawing commands.
public property | fillRule `fillRule as String` | Current fill rule.
public property | fillStyle `fillStyle as Object` | Current fill paint source.
public property | font `font as String` | Current font description, canvas style.
public property | globalAlpha `globalAlpha as Double` | Current global alpha in `[0.0, 1.0]`.
public property | globalCompositeOperation `globalCompositeOperation as String` | Current global composite operation.
public property | height `height as Int` | Logical drawing height.
public property | imageSmoothingEnabled `imageSmoothingEnabled as Boolean` | Image smoothing flag.
public property | lastCommand `lastCommand as String` | Last recorded command.
public property | lineCap `lineCap as String` | Current line cap.
public property | lineDashOffset `lineDashOffset as Double` | Current dash offset.
public property | lineJoin `lineJoin as String` | Current line join.
public property | lineWidth `lineWidth as Double` | Current line width.
public property | miterLimit `miterLimit as Double` | Current miter limit.
public property | shadowBlur `shadowBlur as Double` | Shadow blur radius.
public property | shadowColor `shadowColor as Color` | Shadow color.
public property | shadowOffsetX `shadowOffsetX as Double` | Horizontal shadow offset.
public property | shadowOffsetY `shadowOffsetY as Double` | Vertical shadow offset.
public property | strokeStyle `strokeStyle as Object` | Current stroke paint source.
public property | textAlign `textAlign as String` | Current text alignment.
public property | textAntialiasingEnabled `textAntialiasingEnabled as Boolean` | Text antialiasing flag.
public property | textBaseline `textBaseline as String` | Current text baseline.
public property | transformA `transformA as Double` | Affine transform component `a`.
public property | transformB `transformB as Double` | Affine transform component `b`.
public property | transformC `transformC as Double` | Affine transform component `c`.
public property | transformD `transformD as Double` | Affine transform component `d`.
public property | transformE `transformE as Double` | Affine transform component `e`.
public property | transformF `transformF as Double` | Affine transform component `f`.
public property | width `width as Int` | Logical drawing width.

Constructors

Modifier and Type | Member | Description
--- | --- | ---
public | Painter `Painter(width as Int = 0, height as Int = 0):` | No summary.

Methods

Modifier and Type | Member | Description
--- | --- | ---
public | applyBrush `applyBrush(brush as Brush) as Void:` | Applies a `Brush` to the fill-related state.
public | applyPen `applyPen(pen as Pen) as Void:` | Applies a `Pen` to the stroke-related state.
public | arc `arc(x as Int, y as Int, radius as Int, startAngle as Double, endAngle as Double, counterClockwise as Boolean = false) as Void:` | Adds an arc segment.
public | arcTo `arcTo(x1 as Int, y1 as Int, x2 as Int, y2 as Int, radius as Int) as Void:` | Adds an `arcTo` segment.
public | beginPath `beginPath() as Void:` | Clears the current path and starts a new one.
public | bezierCurveTo `bezierCurveTo(cp1x as Int, cp1y as Int, cp2x as Int, cp2y as Int, x as Int, y as Int) as Void:` | Adds a cubic Bezier curve segment.
public | clearCommands `clearCommands() as Void:` | Clears the recorded commands without touching the state.
public | clearRect `clearRect(x as Int, y as Int, width as Int, height as Int) as Void:` | Clears a rectangular area.
public | clip `clip() as Void:` | Intersects the current clip with the current path.
public | closePath `closePath() as Void:` | Closes the current path.
public | commands `commands() as ArrayList<String>:` | Returns the command history recorded by this painter.
public | createLinearGradient `createLinearGradient(x0 as Int, y0 as Int, x1 as Int, y1 as Int) as LinearGradient:` | Creates a linear gradient.
public | createPattern `createPattern(image as Object, repetition as String = "repeat") as ImagePattern:` | Creates an image pattern.
public | createRadialGradient `createRadialGradient(x0 as Int, y0 as Int, r0 as Int, x1 as Int, y1 as Int, r1 as Int) as RadialGradient:` | Creates a radial gradient.
public | currentBrush `currentBrush() as Brush:` | Builds a `Brush` from the current fill-related state.
public | currentPath `currentPath() as String:` | Returns a textual description of the current path.
public | currentPen `currentPen() as Pen:` | Builds a `Pen` from the current stroke-related state.
public | drawEllipse `drawEllipse(x as Int, y as Int, width as Int, height as Int) as Void:` | Alias of `strokeOval`.
public | drawImage `drawImage(image as Object, dx as Int, dy as Int, dw as Int = -1, dh as Int = -1, sx as Int = 0, sy as Int = 0, sw as Int = -1, sh as Int = -1, tint as Color = null, hovered as Boolean = false, hoverTint as Color = null) as Void:` | Draws an image-like source.
public | drawLine `drawLine(x1 as Int, y1 as Int, x2 as Int, y2 as Int) as Void:` | Alias of `strokeLine`.
public | drawRect `drawRect(x as Int, y as Int, width as Int, height as Int) as Void:` | Alias of `strokeRect`.
public | drawText `drawText(text as String, x as Int, y as Int) as Void:` | Alias of `fillText`.
public | ellipse `ellipse(x as Int, y as Int, radiusX as Int, radiusY as Int, rotation as Double, startAngle as Double, endAngle as Double, counterClockwise as Boolean = false) as Void:` | Adds an ellipse segment.
public | fill `fill() as Void:` | Fills the current path.
public | fillEllipse `fillEllipse(x as Int, y as Int, width as Int, height as Int) as Void:` | Alias of `fillOval`.
public | fillOval `fillOval(x as Int, y as Int, width as Int, height as Int) as Void:` | Fills an oval or ellipse.
public | fillPolygon `fillPolygon(points as ArrayList<Int>) as Void:` | Fills a polygon described by alternating `x, y` coordinates.
public | fillRect `fillRect(x as Int, y as Int, width as Int, height as Int) as Void:` | Fills a rectangle.
public | fillRoundRect `fillRoundRect(x as Int, y as Int, width as Int, height as Int, radius as Int) as Void:` | Fills a rounded rectangle.
public | fillText `fillText(text as String, x as Int, y as Int) as Void:` | Draws filled text.
public | getLineDash `getLineDash() as ArrayList<Double>:` | Returns the current dash pattern.
public | lineTo `lineTo(x as Int, y as Int) as Void:` | Adds a `lineTo` segment to the current path.
public | measureText `measureText(text as String) as TextMetrics:` | Estimates text metrics for the current font.
public | measureTextWidth `measureTextWidth(text as String) as Double:` | Measures only the horizontal advance of a text run.
public | moveTo `moveTo(x as Int, y as Int) as Void:` | Adds a `moveTo` segment to the current path.
public | quadraticCurveTo `quadraticCurveTo(cpx as Int, cpy as Int, x as Int, y as Int) as Void:` | Adds a quadratic curve segment.
public | rect `rect(x as Int, y as Int, width as Int, height as Int) as Void:` | Adds a rectangle to the current path.
public | reset `reset() as Void:` | Resets the painter state to the default configuration.
public | resetClip `resetClip() as Void:` | Clears the clip information tracked by the painter.
public | resetTransform `resetTransform() as Void:` | Restores the identity transform.
public | restore `restore() as Void:` | Restores the last saved drawing state.
public | rotate `rotate(angle as Double) as Void:` | Applies a rotation in radians to the current transform.
public | roundRect `roundRect(x as Int, y as Int, width as Int, height as Int, radius as Int) as Void:` | Adds a rounded rectangle to the current path.
public | save `save() as Void:` | Saves the current drawing state on the internal stack.
public | scale `scale(x as Double, y as Double) as Void:` | Applies a scale to the current transform.
public | setLineDash `setLineDash(values as IList<Double>) as Void:` | Replaces the current dash pattern.
public | setTransform `setTransform(a as Double, b as Double, c as Double, d as Double, e as Double, f as Double) as Void:` | Replaces the current transform.
public | shear `shear(x as Double, y as Double) as Void:` | Applies a shear transform.
public | stroke `stroke() as Void:` | Strokes the current path.
public | strokeLine `strokeLine(x1 as Int, y1 as Int, x2 as Int, y2 as Int) as Void:` | Strokes a line segment.
public | strokeLines `strokeLines(points as ArrayList<Int>) as Void:` | Strokes several independent line segments with the current stroke style.
public | strokeOval `strokeOval(x as Int, y as Int, width as Int, height as Int) as Void:` | Strokes an oval or ellipse.
public | strokeRect `strokeRect(x as Int, y as Int, width as Int, height as Int) as Void:` | Strokes a rectangle.
public | strokeRoundRect `strokeRoundRect(x as Int, y as Int, width as Int, height as Int, radius as Int) as Void:` | Strokes a rounded rectangle.
public | strokeText `strokeText(text as String, x as Int, y as Int) as Void:` | Draws stroked text.
public | transform `transform(a as Double, b as Double, c as Double, d as Double, e as Double, f as Double) as Void:` | Applies an affine transform to the current matrix.
public | translate `translate(x as Double, y as Double) as Void:` | Applies a translation to the current transform.