DrawTransform


Defines transformations that can be applied to a drawing environment

Summary

Public functions

Unit
clipPath(path: Path, clipOp: ClipOp)

Reduces the clip region to the intersection of the current clip and the given rounded rectangle.

Cmn
Unit
clipRect(left: Float, top: Float, right: Float, bottom: Float, clipOp: ClipOp)

Reduces the clip region to the intersection of the current clip and the given rectangle indicated by the given left, top, right and bottom bounds.

Cmn
Unit
inset(left: Float, top: Float, right: Float, bottom: Float)

Simultaneously translate the coordinate space by left and top as well as modify the dimensions of the current painting area.

Cmn
Unit
rotate(degrees: Float, pivot: Offset)

Add a rotation (in degrees clockwise) to the current transform at the given pivot point.

Cmn
Unit
scale(scaleX: Float, scaleY: Float, pivot: Offset)

Add an axis-aligned scale to the current transform, scaling by the first argument in the horizontal direction and the second in the vertical direction at the given pivot coordinate.

Cmn
Unit
transform(matrix: Matrix)

Transform the drawing environment by the given matrix

Cmn
Unit
translate(left: Float, top: Float)

Translate the coordinate space by the given delta in pixels in both the x and y coordinates respectively

Cmn

Public properties

open Offset

Convenience method to obtain the current position of the current transformation

Cmn
Size

Get the current size of the CanvasTransform

Cmn

Extension functions

inline Unit

Convenience method modifies the DrawScope bounds to inset both left, top, right and bottom bounds by inset.

Cmn
inline Unit
DrawTransform.inset(horizontal: Float, vertical: Float)

Convenience method modifies the DrawTransform bounds to inset both left and right bounds by horizontal as well as the top and bottom by vertical.

Cmn
inline Unit
DrawTransform.rotateRad(radians: Float, pivot: Offset)

Add a rotation (in radians clockwise) to the current transform at the given pivot point.

Cmn
inline Unit
DrawTransform.scale(scale: Float, pivot: Offset)

Add an axis-aligned scale to the current transform, scaling uniformly in both directions by the provided scale factor at the pivot coordinate.

Cmn

Public functions

clipPath

fun clipPath(path: Path, clipOp: ClipOp = ClipOp.Intersect): Unit

Reduces the clip region to the intersection of the current clip and the given rounded rectangle. After this method is invoked, this clip is no longer applied

Parameters
path: Path

Shape to clip drawing content within

clipOp: ClipOp = ClipOp.Intersect

Clipping operation to conduct on the given bounds, defaults to ClipOp.Intersect

clipRect

fun clipRect(
    left: Float = 0.0f,
    top: Float = 0.0f,
    right: Float = size.width,
    bottom: Float = size.height,
    clipOp: ClipOp = ClipOp.Intersect
): Unit

Reduces the clip region to the intersection of the current clip and the given rectangle indicated by the given left, top, right and bottom bounds. After this method is invoked, this clip is no longer applied.

Use ClipOp.Difference to subtract the provided rectangle from the current clip.

Parameters
left: Float = 0.0f

Left bound of the rectangle to clip

top: Float = 0.0f

Top bound of the rectangle to clip

right: Float = size.width

Right bound ofthe rectangle to clip

bottom: Float = size.height

Bottom bound of the rectangle to clip

clipOp: ClipOp = ClipOp.Intersect

Clipping operation to perform on the given bounds

inset

fun inset(left: Float, top: Float, right: Float, bottom: Float): Unit

Simultaneously translate the coordinate space by left and top as well as modify the dimensions of the current painting area. This provides a callback to issue more drawing instructions within the modified coordinate space. This method modifies the width to be equivalent to width - (left + right) as well as height to height - (top + bottom)

Parameters
left: Float

number of pixels to inset the left drawing bound

top: Float

number of pixels to inset the top drawing bound

right: Float

number of pixels to inset the right drawing bound

bottom: Float

number of pixels to inset the bottom drawing bound

rotate

fun rotate(degrees: Float, pivot: Offset = center): Unit

Add a rotation (in degrees clockwise) to the current transform at the given pivot point. The pivot coordinate remains unchanged by the rotation transformation.

Parameters
degrees: Float

to rotate clockwise

pivot: Offset = center

The coordinates for the pivot point, defaults to the center of the coordinate space

scale

fun scale(scaleX: Float, scaleY: Float, pivot: Offset = center): Unit

Add an axis-aligned scale to the current transform, scaling by the first argument in the horizontal direction and the second in the vertical direction at the given pivot coordinate. The pivot coordinate remains unchanged by the scale transformation.

Parameters
scaleX: Float

The amount to scale in X

scaleY: Float

The amount to scale in Y

pivot: Offset = center

The coordinate for the pivot point, defaults to the center of the coordinate space

transform

fun transform(matrix: Matrix): Unit

Transform the drawing environment by the given matrix

Parameters
matrix: Matrix

transformation matrix used to transform the drawing environment

translate

fun translate(left: Float = 0.0f, top: Float = 0.0f): Unit

Translate the coordinate space by the given delta in pixels in both the x and y coordinates respectively

Parameters
left: Float = 0.0f

Pixels to translate the coordinate space in the x-axis

top: Float = 0.0f

Pixels to translate the coordinate space in the y-axis

Public properties

center

open val centerOffset

Convenience method to obtain the current position of the current transformation

size

val sizeSize

Get the current size of the CanvasTransform

Extension functions

inline fun DrawTransform.inset(inset: Float): Unit

Convenience method modifies the DrawScope bounds to inset both left, top, right and bottom bounds by inset. After this method is invoked, the coordinate space is returned to the state before this inset was applied.

Parameters
inset: Float

number of pixels to inset left, top, right, and bottom bounds.

inline fun DrawTransform.inset(horizontal: Float = 0.0f, vertical: Float = 0.0f): Unit

Convenience method modifies the DrawTransform bounds to inset both left and right bounds by horizontal as well as the top and bottom by vertical. After this method is invoked, the coordinate space is returned to the state before the inset was applied

Parameters
horizontal: Float = 0.0f

number of pixels to inset both left and right bounds. Zero by default.

vertical: Float = 0.0f

number of pixels to inset both top and bottom bounds. Zero by default.

inline fun DrawTransform.rotateRad(radians: Float, pivot: Offset = center): Unit

Add a rotation (in radians clockwise) to the current transform at the given pivot point. The pivot coordinate remains unchanged by the rotation transformation

Parameters
radians: Float

to rotate clockwise

pivot: Offset = center

The coordinate for the pivot point, defaults to the center of the coordinate space

inline fun DrawTransform.scale(scale: Float, pivot: Offset = center): Unit

Add an axis-aligned scale to the current transform, scaling uniformly in both directions by the provided scale factor at the pivot coordinate. The pivot coordinate remains unchanged by the scale transformation.

Parameters
scale: Float

The amount to scale

pivot: Offset = center

The coordinate for the pivot point, defaults to the center of the coordinate space