DrawTransform

Interface

Common
@DrawScopeMarker
@JvmDefaultWithCompatibility
interface DrawTransform

Defines transformations that can be applied to a drawing environment

Properties

Common
val size: Size

Get the current size of the CanvasTransform

Common
val center: Offset

Convenience method to obtain the current position of the current transformation

Functions

fun 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. 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

leftnumber of pixels to inset the left drawing bound
topnumber of pixels to inset the top drawing bound
rightnumber of pixels to inset the right drawing bound
bottomnumber of pixels to inset the bottom drawing bound
fun clipRect(
        left: Float = 0.0f,
        top: Float = 0.0f,
        right: Float = size.width,
        bottom: Float = size.height,
        clipOp: ClipOp = ClipOp.Intersect,
    )

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

leftLeft bound of the rectangle to clip
topTop bound of the rectangle to clip
rightRight bound ofthe rectangle to clip
bottomBottom bound of the rectangle to clip
clipOpClipping operation to perform on the given bounds
fun clipPath(path: Path, clipOp: ClipOp = ClipOp.Intersect)

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

pathShape to clip drawing content within
clipOpClipping operation to conduct on the given bounds, defaults to ClipOp.Intersect
fun translate(left: Float = 0.0f, top: Float = 0.0f)

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

Parameters

leftPixels to translate the coordinate space in the x-axis
topPixels to translate the coordinate space in the y-axis
fun rotate(degrees: Float, pivot: Offset = center)

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

degreesto rotate clockwise
pivotThe coordinates for the pivot point, defaults to the center of the coordinate space
fun scale(scaleX: Float, scaleY: Float, pivot: Offset = center)

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

scaleXThe amount to scale in X
scaleYThe amount to scale in Y
pivotThe coordinate for the pivot point, defaults to the center of the coordinate space
fun transform(matrix: Matrix)

Transform the drawing environment by the given matrix

Parameters

matrixtransformation matrix used to transform the drawing environment