Canvas

interface Canvas : CommonCanvas

All rendering operations are done using Canvases. A canvas represents an "infinite", 2-D surface that can be "drawn" onto. Despite this, there is a size associated with each Canvas that indicates its clipping region. The framework manages Canvases and makes them available to Views during View.render.

Canvases are intended to be efficient and reuse previous content when they are re-rendered.

Author

Nicholas Eddy

Inherited properties

Link copied to clipboard

The height to which the Canvas will clip by default.

Link copied to clipboard
abstract var size: Size

The size to which the Canvas will clip to by default. A View's Canvas won't clip if View.clipCanvasToBounds == false

Link copied to clipboard

The width to which the Canvas will clip by default.

Functions

Link copied to clipboard
abstract fun clip(ellipse: Ellipse, block: Canvas.() -> Unit)

Clips the operations within block within the given ellipse.

abstract fun clip(path: Path, block: Canvas.() -> Unit)

Clips the operations within block within the given path.

abstract fun clip(polygon: Polygon, block: Canvas.() -> Unit)

Clips the operations within block within the given polygon.

abstract fun clip(rectangle: Rectangle, radius: Double = 0.0, block: Canvas.() -> Unit)

Clips the operations within block within the given rectangle.

Link copied to clipboard
open fun flipHorizontally(block: Canvas.() -> Unit)

Flips the operations within block horizontally around the center of the Canvas.

open fun flipHorizontally(around: Double, block: Canvas.() -> Unit)

Flips the operations within block horizontally around the given x-coordinate.

Link copied to clipboard
open fun flipVertically(block: Canvas.() -> Unit)

Flips the operations within block vertically around the center of the Canvas.

open fun flipVertically(around: Double, block: Canvas.() -> Unit)

Flips the operations within block vertically around the given y-coordinate.

Link copied to clipboard
open fun innerShadow(horizontal: Double = 0.0, vertical: Double = 0.0, blurRadius: Double = 1.0, color: Color = Black, block: Canvas.() -> Unit)

Adds an inner shadow to the operations within block.

Link copied to clipboard
open fun outerShadow(horizontal: Double = 0.0, vertical: Double = 0.0, blurRadius: Double = 1.0, color: Color = Black, block: Canvas.() -> Unit)

Adds an outer shadow to the operations within block.

Link copied to clipboard
open fun rotate(by: Measure<Angle>, block: Canvas.() -> Unit)

Rotates the operations within block around 0,0 by the given angle.

open fun rotate(around: Point, by: Measure<Angle>, block: Canvas.() -> Unit)

Rotates the operations within block around the given point by the given angle.

Link copied to clipboard
open fun scale(x: Double = 1.0, y: Double = 1.0, block: Canvas.() -> Unit)

Linearly scales the operations within block.

open fun scale(around: Point, x: Double = 1.0, y: Double = 1.0, block: Canvas.() -> Unit)

Linearly scales the operations within block around the given point.

Link copied to clipboard
abstract fun shadow(shadow: Shadow, block: Canvas.() -> Unit)

Adds a shadow to the operations within block.

Link copied to clipboard
abstract fun transform(transform: AffineTransform, block: Canvas.() -> Unit)

Transforms the operations within block.

abstract fun transform(transform: AffineTransform, camera: Camera, block: Canvas.() -> Unit)

Applies a perspective transform to the operations within block.

Link copied to clipboard
open fun translate(by: Point, block: Canvas.() -> Unit)

Translates the operations within block by the given x, y.

Inherited functions

Link copied to clipboard
abstract fun arc(center: Point, radius: Double, sweep: Measure<Angle>, rotation: Measure<Angle>, fill: Paint)

Fills an arc centered at the given point and swept by the given angle.

abstract fun arc(center: Point, radius: Double, sweep: Measure<Angle>, rotation: Measure<Angle>, stroke: Stroke, fill: Paint? = null)

Fills and outlines an arc centered at the given point and swept by the given angle.

Link copied to clipboard
inline fun Renderer.arc(center: Point, radius: Double, sweep: Measure<Angle>, rotation: Measure<Angle>, color: Color)

Fills an arc centered at the given point and swept by the given angle.

inline fun Renderer.arc(center: Point, radius: Double, sweep: Measure<Angle>, rotation: Measure<Angle>, stroke: Stroke, color: Color)

Fills and outlines an arc centered at the given point and swept by the given angle.

Link copied to clipboard
abstract fun circle(circle: Circle, fill: Paint)

Fills a circle.

abstract fun circle(circle: Circle, stroke: Stroke, fill: Paint? = null)

Fills and outlines a circle.

Link copied to clipboard
inline fun CommonCanvas.circle(circle: Circle, color: Color)

Fills a circle.

inline fun CommonCanvas.circle(circle: Circle, stroke: Stroke, color: Color)

Fills and outlines a circle.

Link copied to clipboard
abstract fun clear()

Clear contents

Link copied to clipboard
abstract fun ellipse(ellipse: Ellipse, fill: Paint)

Fills an ellipse.

abstract fun ellipse(ellipse: Ellipse, stroke: Stroke, fill: Paint? = null)

Fills and outlines an ellipse.

Link copied to clipboard
inline fun CommonCanvas.ellipse(ellipse: Ellipse, color: Color)

Fills an ellipse.

inline fun CommonCanvas.ellipse(ellipse: Ellipse, stroke: Stroke, color: Color)

Fills and outlines an ellipse.

Link copied to clipboard
abstract fun flush()

Cleans up commits rendering

Link copied to clipboard
open fun image(image: Image, at: Point, opacity: Float = 1.0f, radius: Double = 0.0, source: Rectangle = Rectangle(size = image.size))
abstract fun image(image: Image, destination: Rectangle = Rectangle(size = image.size), opacity: Float = 1.0f, radius: Double = 0.0, source: Rectangle = Rectangle(size = image.size))

Draws an image.

Link copied to clipboard
abstract fun line(start: Point, end: Point, stroke: Stroke)

Draws a line between the given points.

Link copied to clipboard
abstract fun path(path: Path, stroke: Stroke)
abstract fun path(points: List<Point>, stroke: Stroke)

Draws a line path connecting the given points.

abstract fun path(path: Path, fill: Paint, fillRule: Renderer.FillRule? = null)
abstract fun path(points: List<Point>, fill: Paint, fillRule: Renderer.FillRule? = null)

Fills a line path connecting the given points.

abstract fun path(path: Path, stroke: Stroke, fill: Paint, fillRule: Renderer.FillRule? = null)
abstract fun path(points: List<Point>, stroke: Stroke, fill: Paint, fillRule: Renderer.FillRule? = null)

Fills and outlines a line path connecting the given points.

Link copied to clipboard
inline fun Renderer.path(path: Path, color: Color, fillRule: Renderer.FillRule? = null)
inline fun Renderer.path(points: List<Point>, color: Color, fillRule: Renderer.FillRule? = null)

Fills a line path connecting the given points.

fun Renderer.path(path: Path, stroke: Stroke, color: Color, fillRule: Renderer.FillRule? = null)
inline fun Renderer.path(points: List<Point>, stroke: Stroke, color: Color, fillRule: Renderer.FillRule? = null)

Fills and outlines a line path connecting the given points.

Link copied to clipboard
abstract fun poly(polygon: Polygon, fill: Paint)

Fills a polygon.

abstract fun poly(polygon: Polygon, stroke: Stroke, fill: Paint? = null)

Fills and outlines a polygon.

Link copied to clipboard
inline fun Renderer.poly(polygon: Polygon, color: Color)

Fills a polygon.

inline fun Renderer.poly(polygon: Polygon, stroke: Stroke, color: Color)

Fills and outlines a polygon.

Link copied to clipboard
abstract fun rect(rectangle: Rectangle, fill: Paint)

Fills a rectangle.

abstract fun rect(rectangle: Rectangle, stroke: Stroke, fill: Paint? = null)

Fills and outlines a rectangle.

abstract fun rect(rectangle: Rectangle, radius: Double, fill: Paint)

Fills a rounded rectangle.

abstract fun rect(rectangle: Rectangle, radius: Double, stroke: Stroke, fill: Paint? = null)

Fills and outlines a rounded rectangle.

Link copied to clipboard
inline fun CommonCanvas.rect(rectangle: Rectangle, color: Color)

Fills a rectangle.

inline fun CommonCanvas.rect(rectangle: Rectangle, stroke: Stroke, color: Color)

Fills and outlines a rectangle.

inline fun CommonCanvas.rect(rectangle: Rectangle, radius: Double, color: Color)

Fills a rounded rectangle.

inline fun CommonCanvas.rect(rectangle: Rectangle, radius: Double, stroke: Stroke, color: Color)

Fills and outlines a rounded rectangle.

Link copied to clipboard
abstract fun text(text: StyledText, at: Point = Origin, textSpacing: TextSpacing = default)

Draws styled text.

open fun text(text: String, at: Point = Origin, fill: Paint, textSpacing: TextSpacing = default)

Draws unwrapped plain text in the default Font.

abstract fun text(text: String, font: Font?, at: Point, fill: Paint, textSpacing: TextSpacing = default)

Draws unwrapped plain text.

Link copied to clipboard
inline fun CommonCanvas.text(text: String, at: Point = Origin, color: Color)

Draws unwrapped plain text in the default Font.

inline fun CommonCanvas.text(text: String, font: Font?, at: Point = Origin, color: Color)

Draws unwrapped plain text.

Link copied to clipboard
abstract fun wedge(center: Point, radius: Double, sweep: Measure<Angle>, rotation: Measure<Angle>, fill: Paint)

Fills a width centered at the given point and swept by the given angle. Wedges are like arcs with their paths closed at the center point.

abstract fun wedge(center: Point, radius: Double, sweep: Measure<Angle>, rotation: Measure<Angle>, stroke: Stroke, fill: Paint? = null)

Fills and outlines a width centered at the given point and swept by the given angle. Wedges are like arcs with their paths closed at the center point.

Link copied to clipboard
inline fun Renderer.wedge(center: Point, radius: Double, sweep: Measure<Angle>, rotation: Measure<Angle>, color: Color)

Fills a width centered at the given point and swept by the given angle. Wedges are like arcs with their paths closed at the center point.

inline fun Renderer.wedge(center: Point, radius: Double, sweep: Measure<Angle>, rotation: Measure<Angle>, stroke: Stroke, color: Color)

Fills and outlines a width centered at the given point and swept by the given angle. Wedges are like arcs with their paths closed at the center point.

Link copied to clipboard
abstract fun wrapped(text: StyledText, at: Point = Origin, width: Double, indent: Double = 0.0, alignment: TextAlignment = Start, lineSpacing: Float = 1.0f, textSpacing: TextSpacing = default)

Draws wrapped styled text.

abstract fun wrapped(text: String, at: Point = Origin, width: Double, fill: Paint, font: Font? = null, indent: Double = 0.0, alignment: TextAlignment = Start, lineSpacing: Float = 1.0f, textSpacing: TextSpacing = default)

Draws wrapped plain text.

Link copied to clipboard
inline fun CommonCanvas.wrapped(text: String, font: Font? = null, at: Point, width: Double, color: Color)

Draws wrapped plain text.