public final class Brush


Defines how stroke inputs are interpreted to create the visual representation of a stroke.

The type completely describes how inputs are used to create stroke meshes, and how those meshes should be drawn by stroke renderers. In an analogous way to "font" and "font family", a Brush can be considered an instance of a BrushFamily with a particular color, size, and an extra parameter controlling visual fidelity, called epsilon.

Summary

Nested types

public final class Brush.Builder

Builder for Brush.

public static class Brush.Companion

Public constructors

Brush(@NonNull BrushFamily family, float size, float epsilon)

The default color of a Brush is pure black.

Public methods

static final @NonNull Brush.Builder

Returns a new Brush.Builder.

final @NonNull Brush
copy(@NonNull BrushFamily family, float size, float epsilon)

Creates a copy of this and allows named properties to be altered while keeping the rest unchanged.

final @NonNull Brush
copyWithColorIntArgb(
    @ColorInt int colorIntArgb,
    @NonNull BrushFamily family,
    float size,
    float epsilon
)

Creates a copy of this and allows named properties to be altered while keeping the rest unchanged.

final @NonNull Brush
copyWithColorLong(
    @ColorLong long colorLong,
    @NonNull BrushFamily family,
    float size,
    float epsilon
)

Creates a copy of this and allows named properties to be altered while keeping the rest unchanged.

static final @NonNull Brush
createWithColorIntArgb(
    @NonNull BrushFamily family,
    @ColorInt int colorIntArgb,
    float size,
    float epsilon
)

Returns a new Brush with the color specified by a ColorInt, which is in the sRGB color space by definition.

static final @NonNull Brush
createWithColorLong(
    @NonNull BrushFamily family,
    @ColorLong long colorLong,
    float size,
    float epsilon
)

Returns a new Brush with the color specified by a ColorLong, which can encode several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

boolean
equals(Object other)
final @ColorInt int

The brush color as a ColorInt, which can only express colors in the sRGB color space.

final @ColorLong long

The brush color as a ColorLong, which can express colors in several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

final float

The smallest distance for which two points should be considered visually distinct for stroke generation geometry purposes.

final @NonNull BrushFamily

The BrushFamily for this brush.

final float

The overall thickness of strokes created with a given brush, in the same units as the stroke coordinate system.

int
final @NonNull Brush.Builder

Returns a Builder with values set equivalent to this.

@NonNull String

Protected methods

final void

Delete native Brush memory.

Extension functions

final @NonNull Brush
@RequiresApi(value = 26)
BrushUtil.copyWithAndroidColor(
    @NonNull Brush receiver,
    @NonNull Color color,
    @NonNull BrushFamily family,
    float size,
    float epsilon
)

Creates a copy of this Brush and allows named properties to be altered while keeping the rest unchanged.

final @NonNull Color

The brush color as an android.graphics.Color instance, which can express colors in several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

final @NonNull Brush.Builder
@RequiresApi(value = 26)
BrushUtil.toBuilderWithAndroidColor(
    @NonNull Brush receiver,
    @NonNull Color color
)

Returns a Brush.Builder with values set equivalent to the Brush and the color specified by an android.graphics.Color instance, which can encode several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

Public constructors

Brush

Added in 1.0.0-alpha01
public Brush(@NonNull BrushFamily family, float size, float epsilon)

The default color of a Brush is pure black. To set a custom color, use createWithColorLong or createWithColorIntArgb.

Public methods

builder

Added in 1.0.0-alpha01
public static final @NonNull Brush.Builder builder()

Returns a new Brush.Builder.

copy

Added in 1.0.0-alpha01
public final @NonNull Brush copy(@NonNull BrushFamily family, float size, float epsilon)

Creates a copy of this and allows named properties to be altered while keeping the rest unchanged. To change the color, use copyWithColorLong or copyWithColorIntArgb.

copyWithColorIntArgb

Added in 1.0.0-alpha01
public final @NonNull Brush copyWithColorIntArgb(
    @ColorInt int colorIntArgb,
    @NonNull BrushFamily family,
    float size,
    float epsilon
)

Creates a copy of this and allows named properties to be altered while keeping the rest unchanged. The color is specified as a ColorInt, which is in the sRGB color space by definition. Note that the ColorInt channel order puts alpha first (in the most significant byte).

Kotlin interprets integer literals greater than 0x7fffffff as Longs, so callers that want to specify a literal ColorInt with alpha >= 0x80 must call Long.toInt on the literal.

copyWithColorLong

Added in 1.0.0-alpha01
public final @NonNull Brush copyWithColorLong(
    @ColorLong long colorLong,
    @NonNull BrushFamily family,
    float size,
    float epsilon
)

Creates a copy of this and allows named properties to be altered while keeping the rest unchanged. The color is specified as a ColorLong, which can encode several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

Some libraries (notably Jetpack UI Graphics) use ULong for ColorLongs, so the caller must call ULong.toLong on such a value before passing it to this method.

createWithColorIntArgb

Added in 1.0.0-alpha01
public static final @NonNull Brush createWithColorIntArgb(
    @NonNull BrushFamily family,
    @ColorInt int colorIntArgb,
    float size,
    float epsilon
)

Returns a new Brush with the color specified by a ColorInt, which is in the sRGB color space by definition. Note that the ColorInt channel order puts alpha first (in the most significant byte).

Kotlin interprets integer literals greater than 0x7fffffff as Longs, so callers that want to specify a literal ColorInt with alpha >= 0x80 must call Long.toInt on the literal.

createWithColorLong

Added in 1.0.0-alpha01
public static final @NonNull Brush createWithColorLong(
    @NonNull BrushFamily family,
    @ColorLong long colorLong,
    float size,
    float epsilon
)

Returns a new Brush with the color specified by a ColorLong, which can encode several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

Some libraries (notably Jetpack UI Graphics) use ULong for ColorLongs, so the caller must call ULong.toLong on such a value before passing it to this method.

equals

public boolean equals(Object other)

getColorIntArgb

Added in 1.0.0-alpha01
public final @ColorInt int getColorIntArgb()

The brush color as a ColorInt, which can only express colors in the sRGB color space. For clients that want to support wide-gamut colors, use colorLong.

getColorLong

Added in 1.0.0-alpha01
public final @ColorLong long getColorLong()

The brush color as a ColorLong, which can express colors in several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

getEpsilon

Added in 1.0.0-alpha01
public final float getEpsilon()

The smallest distance for which two points should be considered visually distinct for stroke generation geometry purposes. Effectively, it is the visual fidelity of strokes created with this brush, where any (lack of) visual fidelity can be observed by a user the further zoomed in they are on the stroke. Lower values of epsilon result in higher fidelity strokes at the cost of somewhat higher memory usage. This value, like size, is in the same units as the stroke coordinate system. A size of 0.1 physical pixels at the default zoom level is a good starting point that can tolerate a reasonable amount of zooming in with high quality visual results.

getFamily

Added in 1.0.0-alpha01
public final @NonNull BrushFamily getFamily()

The BrushFamily for this brush. See StockBrushes for available BrushFamily values.

getSize

Added in 1.0.0-alpha01
public final float getSize()

The overall thickness of strokes created with a given brush, in the same units as the stroke coordinate system. This must be at least as big as epsilon.

hashCode

public int hashCode()

toBuilder

Added in 1.0.0-alpha01
public final @NonNull Brush.Builder toBuilder()

Returns a Builder with values set equivalent to this. Java developers, use the returned builder to build a copy of a Brush. Kotlin developers, see copy method.

toString

public @NonNull String toString()

Protected methods

finalize

Added in 1.0.0-alpha01
protected final void finalize()

Delete native Brush memory.

Extension functions

BrushUtil.copyWithAndroidColor

@RequiresApi(value = 26)
public final @NonNull Brush BrushUtil.copyWithAndroidColor(
    @NonNull Brush receiver,
    @NonNull Color color,
    @NonNull BrushFamily family,
    float size,
    float epsilon
)

Creates a copy of this Brush and allows named properties to be altered while keeping the rest unchanged. The color is specified as an android.graphics.Color instance, which can encode several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

BrushUtil.createAndroidColor

@RequiresApi(value = 26)
public final @NonNull Color BrushUtil.createAndroidColor(@NonNull Brush receiver)

The brush color as an android.graphics.Color instance, which can express colors in several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

Unless an instance of android.graphics.Color is actually needed, prefer to use Brush.colorLong to get the color without causing an allocation, especially in performance-sensitive code. Brush.colorLong is fully compatible with the Long representation of android.graphics.Color.

BrushUtil.toBuilderWithAndroidColor

@RequiresApi(value = 26)
public final @NonNull Brush.Builder BrushUtil.toBuilderWithAndroidColor(
    @NonNull Brush receiver,
    @NonNull Color color
)

Returns a Brush.Builder with values set equivalent to the Brush and the color specified by an android.graphics.Color instance, which can encode several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3. Java developers, use the returned builder to build a copy of a Brush. Kotlin developers, see copyWithAndroidColor method.

In Kotlin, calling this is equivalent to calling Brush.toBuilder followed by Brush.Builder.setAndroidColor. For Java callers, this function allows more fluent call chaining.