BrushTip



A BrushTip consists of parameters that control how stroke inputs are used to model the tip shape and color, and create vertices for the stroke mesh.

The specification can be considered in two parts:

  1. Parameters for the base shape of the tip as a function of Brush size.

  2. An array of BrushBehaviors that allow dynamic properties of each input to augment the tip shape and color.

The base tip shape is controlled by various parameters: scaleX and scaleY control the size and aspect ratio; cornerRounding controls the roundness (going from square to rounded-rect to circle); slantDegrees controls the slantedness (going from rectangle to parallelogram); pinch controls the triangularity (going from rectangle to trapezoid to triangle). By combining these parameters, the tip shape can be circular, or pill-shaped, or a rounded triangle, or a rounded convex quadrilateral.

Through BrushBehaviors, the tip can also produce a per-vertex HSLA color shift that can be used to augment the Brush color when drawing.

The default parameters produce a static circular tip shape, with diameter equal to the Brush size and no color shift.

Summary

Nested types

Builder for BrushTip.

Public companion functions

BrushTip.Builder

Returns a new BrushTip.Builder.

Cmn

Public constructors

BrushTip(
    scaleX: @FloatRange(from = 0.0, toInclusive = false) Float,
    scaleY: @FloatRange(from = 0.0, toInclusive = false) Float,
    cornerRounding: @FloatRange(from = 0.0, to = 1.0) Float,
    slantDegrees: @FloatRange(from = -90.0, to = 90.0) @AngleDegreesFloat Float,
    pinch: @FloatRange(from = 0.0, to = 1.0) Float,
    rotationDegrees: @AngleDegreesFloat Float,
    particleGapDistanceScale: @FloatRange(from = 0.0, toInclusive = false) Float,
    particleGapDurationMillis: @IntRange(from = 0) Long,
    behaviors: List<BrushBehavior>
)

Constructs a new BrushTip with the given attributes.

Cmn

Public functions

BrushTip
copy(
    scaleX: @FloatRange(from = 0.0, toInclusive = false) Float,
    scaleY: @FloatRange(from = 0.0, toInclusive = false) Float,
    cornerRounding: @FloatRange(from = 0.0, to = 1.0) Float,
    slantDegrees: @FloatRange(from = -90.0, to = 90.0) @AngleDegreesFloat Float,
    pinch: @FloatRange(from = 0.0, to = 1.0) Float,
    rotationDegrees: @AngleDegreesFloat Float,
    particleGapDistanceScale: @FloatRange(from = 0.0, toInclusive = false) Float,
    particleGapDurationMillis: @IntRange(from = 0) Long,
    behaviors: List<BrushBehavior>
)

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

Cmn
open operator Boolean
equals(other: Any?)
Cmn
open Int
Cmn
BrushTip.Builder

Returns a Builder with values set equivalent to this.

Cmn
open String
Cmn

Public properties

List<BrushBehavior>

An immutable list of BrushBehaviors that allow dynamic properties of each input to augment the tip shape and color.

Cmn
Float

A normalized value in the range 0, 1 that is used to calculate the initial radius of curvature for the tip's corners.

Cmn
Float

Parameter controlling emission of particles as a function of distance traveled by the stroke inputs.

Cmn
Long

Parameter controlling emission of particles as a function of time elapsed along the stroke.

Cmn
Float

A unitless parameter in the range 0, 1 that controls the separation between two of the shape's corners prior to applying rotationDegrees.

Cmn
Float

Angle in degrees specifying the initial rotation of the tip shape after applying scaleX, scaleY, pinch, and slantDegrees.

Cmn
Float

2D scale used to calculate the initial width and height of the tip shape relative to the brush size prior to applying slantDegrees and rotationDegrees.

Cmn
Float

2D scale used to calculate the initial width and height of the tip shape relative to the brush size prior to applying slantDegrees and rotationDegrees.

Cmn
Float

Angle in degrees used to calculate the initial slant of the tip shape prior to applying rotationDegrees.

Cmn

Public companion functions

builder

fun builder(): BrushTip.Builder

Returns a new BrushTip.Builder.

Public constructors

BrushTip

BrushTip(
    scaleX: @FloatRange(from = 0.0, toInclusive = false) Float = 1.0f,
    scaleY: @FloatRange(from = 0.0, toInclusive = false) Float = 1.0f,
    cornerRounding: @FloatRange(from = 0.0, to = 1.0) Float = 1.0f,
    slantDegrees: @FloatRange(from = -90.0, to = 90.0) @AngleDegreesFloat Float = 0.0f,
    pinch: @FloatRange(from = 0.0, to = 1.0) Float = 0.0f,
    rotationDegrees: @AngleDegreesFloat Float = 0.0f,
    particleGapDistanceScale: @FloatRange(from = 0.0, toInclusive = false) Float = 0.0f,
    particleGapDurationMillis: @IntRange(from = 0) Long = 0,
    behaviors: List<BrushBehavior> = emptyList()
)

Constructs a new BrushTip with the given attributes.

Public functions

copy

fun copy(
    scaleX: @FloatRange(from = 0.0, toInclusive = false) Float = this.scaleX,
    scaleY: @FloatRange(from = 0.0, toInclusive = false) Float = this.scaleY,
    cornerRounding: @FloatRange(from = 0.0, to = 1.0) Float = this.cornerRounding,
    slantDegrees: @FloatRange(from = -90.0, to = 90.0) @AngleDegreesFloat Float = this.slantDegrees,
    pinch: @FloatRange(from = 0.0, to = 1.0) Float = this.pinch,
    rotationDegrees: @AngleDegreesFloat Float = this.rotationDegrees,
    particleGapDistanceScale: @FloatRange(from = 0.0, toInclusive = false) Float = this.particleGapDistanceScale,
    particleGapDurationMillis: @IntRange(from = 0) Long = this.particleGapDurationMillis,
    behaviors: List<BrushBehavior> = this.behaviors
): BrushTip

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

Java callers should use Builder instead.

equals

open operator fun equals(other: Any?): Boolean

hashCode

open fun hashCode(): Int

toBuilder

fun toBuilder(): BrushTip.Builder

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

toString

open fun toString(): String

Public properties

behaviors

val behaviorsList<BrushBehavior>

An immutable list of BrushBehaviors that allow dynamic properties of each input to augment the tip shape and color.

cornerRounding

val cornerRoundingFloat

A normalized value in the range 0, 1 that is used to calculate the initial radius of curvature for the tip's corners. A value of 0 results in sharp corners and a value of 1 results in the maximum radius of curvature given the current tip dimensions.

particleGapDistanceScale

val particleGapDistanceScaleFloat

Parameter controlling emission of particles as a function of distance traveled by the stroke inputs.

When this and particleGapDurationMillis are both zero, the stroke will be continuous, unless gaps are introduced dynamically by BrushBehaviors. Otherwise, the stroke will be made up of particles. A new particle will be emitted after at least particleGapDistanceScale * Brush.size distance has been traveled by the stoke inputs.

particleGapDurationMillis

val particleGapDurationMillisLong

Parameter controlling emission of particles as a function of time elapsed along the stroke.

When this and particleGapDistanceScale are both zero, the stroke will be continuous, unless gaps are introduced dynamically by BrushBehaviors. Otherwise, the stroke will be made up of particles. Particles will be emitted at most once every particleGapDurationMillis.

pinch

val pinchFloat

A unitless parameter in the range 0, 1 that controls the separation between two of the shape's corners prior to applying rotationDegrees.

The two corners affected lie toward the negative y-axis relative to the center of the tip shape. I.e. the "upper edge" of the shape if positive y is chosen to point "down" in stroke coordinates.

If scaleX is not 0, different values of pinch produce the following shapes: A value of 0 will leave the corners unaffected as a rectangle or parallelogram. Values between 0 and 1 will bring the corners closer together to result in a (possibly slanted) trapezoidal shape. A value of 1 will make the two corners coincide and result in a triangular shape.

rotationDegrees

val rotationDegreesFloat

Angle in degrees specifying the initial rotation of the tip shape after applying scaleX, scaleY, pinch, and slantDegrees. The rotation is in the direction from the positive x-axis towards the positive y-axis.

scaleX

val scaleXFloat

2D scale used to calculate the initial width and height of the tip shape relative to the brush size prior to applying slantDegrees and rotationDegrees.

The base width and height of the tip will be equal to the brush size multiplied by scaleX and scaleY respectively. Valid values must be finite and non-negative, with at least one value greater than zero.

scaleY

val scaleYFloat

2D scale used to calculate the initial width and height of the tip shape relative to the brush size prior to applying slantDegrees and rotationDegrees.

The base width and height of the tip will be equal to the brush size multiplied by scaleX and scaleY respectively. Valid values must be finite and non-negative, with at least one value greater than zero.

slantDegrees

val slantDegreesFloat

Angle in degrees used to calculate the initial slant of the tip shape prior to applying rotationDegrees.

The value should be in the range -90, 90 degrees, and represents the angle by which "vertical" lines of the tip shape will appear rotated about their intersection with the x-axis. A positive value will rotate from the positive x-axis towards the positive y-axis.

More info: This property is similar to the single-arg CSS skew() transformation. Unlike skew, slant tries to preserve the perimeter of the tip shape as opposed to its area. This is akin to "pressing" a rectangle into a parallelogram with non-right angles while preserving the side lengths.