{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

DrawTransform

@DrawScopeMarker
public interface DrawTransform


Defines transformations that can be applied to a drawing environment

Summary

Public methods

abstract void
clipPath(@NonNull Path path, @NonNull ClipOp clipOp)

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

abstract void
clipRect(
    float left,
    float top,
    float right,
    float bottom,
    @NonNull 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.

default @NonNull Offset

Convenience method to obtain the current position of the current transformation

abstract @NonNull Size

Get the current size of the CanvasTransform

abstract void
inset(float left, float top, float right, float bottom)

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

abstract void
rotate(float degrees, @NonNull Offset pivot)

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

abstract void
scale(float scaleX, float scaleY, @NonNull Offset pivot)

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.

abstract void

Transform the drawing environment by the given matrix

abstract void
translate(float left, float top)

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

Extension functions

default final void
DrawTransformKt.inset(@NonNull DrawTransform receiver, float inset)

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

default final void
DrawTransformKt.inset(
    @NonNull DrawTransform receiver,
    float horizontal,
    float vertical
)

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

default final void
DrawTransformKt.rotateRad(
    @NonNull DrawTransform receiver,
    float radians,
    @NonNull Offset pivot
)

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

default final void
DrawTransformKt.scale(
    @NonNull DrawTransform receiver,
    float scale,
    @NonNull Offset pivot
)

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

Public methods

clipPath

abstract void clipPath(@NonNull Path path, @NonNull ClipOp clipOp)

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
@NonNull Path path

Shape to clip drawing content within

@NonNull ClipOp clipOp

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

clipRect

abstract void clipRect(
    float left,
    float top,
    float right,
    float bottom,
    @NonNull 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. After this method is invoked, this clip is no longer applied.

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

Parameters
float left

Left bound of the rectangle to clip

float top

Top bound of the rectangle to clip

float right

Right bound ofthe rectangle to clip

float bottom

Bottom bound of the rectangle to clip

@NonNull ClipOp clipOp

Clipping operation to perform on the given bounds

getCenter

default @NonNull Offset getCenter()

Convenience method to obtain the current position of the current transformation

getSize

abstract @NonNull Size getSize()

Get the current size of the CanvasTransform

inset

abstract void inset(float left, float top, float right, float bottom)

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
float left

number of pixels to inset the left drawing bound

float top

number of pixels to inset the top drawing bound

float right

number of pixels to inset the right drawing bound

float bottom

number of pixels to inset the bottom drawing bound

rotate

abstract void rotate(float degrees, @NonNull Offset pivot)

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
float degrees

to rotate clockwise

@NonNull Offset pivot

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

scale

abstract void scale(float scaleX, float scaleY, @NonNull Offset pivot)

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
float scaleX

The amount to scale in X

float scaleY

The amount to scale in Y

@NonNull Offset pivot

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

transform

abstract void transform(@NonNull Matrix matrix)

Transform the drawing environment by the given matrix

Parameters
@NonNull Matrix matrix

transformation matrix used to transform the drawing environment

translate

abstract void translate(float left, float top)

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

Parameters
float left

Pixels to translate the coordinate space in the x-axis

float top

Pixels to translate the coordinate space in the y-axis

Extension functions

DrawTransformKt.inset

default final void DrawTransformKt.inset(@NonNull DrawTransform receiver, float inset)

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
float inset

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

DrawTransformKt.inset

default final void DrawTransformKt.inset(
    @NonNull DrawTransform receiver,
    float horizontal,
    float vertical
)

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
float horizontal

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

float vertical

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

DrawTransformKt.rotateRad

default final void DrawTransformKt.rotateRad(
    @NonNull DrawTransform receiver,
    float radians,
    @NonNull Offset pivot
)

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
float radians

to rotate clockwise

@NonNull Offset pivot

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

DrawTransformKt.scale

default final void DrawTransformKt.scale(
    @NonNull DrawTransform receiver,
    float scale,
    @NonNull Offset pivot
)

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
float scale

The amount to scale

@NonNull Offset pivot

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