BrushTip


public final class 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

public final class BrushTip.Builder

Builder for BrushTip.

Public constructors

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

Constructs a new BrushTip with the given attributes.

Public methods

static final @NonNull BrushTip.Builder

Returns a new BrushTip.Builder.

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

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

boolean
equals(Object other)
final @NonNull List<@NonNull BrushBehavior>

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

final @FloatRange(from = 0.0, to = 1.0) float

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

final @FloatRange(from = 0.0, toInclusive = false) float

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

final @IntRange(from = 0) long

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

final @FloatRange(from = 0.0, to = 1.0) float

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

final @AngleDegreesFloat float

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

final @FloatRange(from = 0.0, toInclusive = false) 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.

final @FloatRange(from = 0.0, toInclusive = false) 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.

final @FloatRange(from = -90.0, to = 90.0) @AngleDegreesFloat float

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

int
final @NonNull BrushTip.Builder

Returns a Builder with values set equivalent to this.

@NonNull String

Public constructors

BrushTip

Added in 1.1.0-alpha03
public BrushTip(
    @FloatRange(from = 0.0, toInclusive = false) float scaleX,
    @FloatRange(from = 0.0, toInclusive = false) float scaleY,
    @FloatRange(from = 0.0, to = 1.0) float cornerRounding,
    @FloatRange(from = -90.0, to = 90.0) @AngleDegreesFloat float slantDegrees,
    @FloatRange(from = 0.0, to = 1.0) float pinch,
    @AngleDegreesFloat float rotationDegrees,
    @FloatRange(from = 0.0, toInclusive = false) float particleGapDistanceScale,
    @IntRange(from = 0) long particleGapDurationMillis,
    @NonNull List<@NonNull BrushBehavior> behaviors
)

Constructs a new BrushTip with the given attributes.

Public methods

builder

Added in 1.1.0-alpha03
public static final @NonNull BrushTip.Builder builder()

Returns a new BrushTip.Builder.

copy

Added in 1.1.0-alpha03
public final @NonNull BrushTip copy(
    @FloatRange(from = 0.0, toInclusive = false) float scaleX,
    @FloatRange(from = 0.0, toInclusive = false) float scaleY,
    @FloatRange(from = 0.0, to = 1.0) float cornerRounding,
    @FloatRange(from = -90.0, to = 90.0) @AngleDegreesFloat float slantDegrees,
    @FloatRange(from = 0.0, to = 1.0) float pinch,
    @AngleDegreesFloat float rotationDegrees,
    @FloatRange(from = 0.0, toInclusive = false) float particleGapDistanceScale,
    @IntRange(from = 0) long particleGapDurationMillis,
    @NonNull List<@NonNull BrushBehavior> behaviors
)

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

Java callers should use Builder instead.

equals

public boolean equals(Object other)

getBehaviors

Added in 1.1.0-alpha03
public final @NonNull List<@NonNull BrushBehaviorgetBehaviors()

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

getCornerRounding

Added in 1.1.0-alpha03
public final @FloatRange(from = 0.0, to = 1.0) float getCornerRounding()

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.

getParticleGapDistanceScale

Added in 1.1.0-alpha03
public final @FloatRange(from = 0.0, toInclusive = false) float getParticleGapDistanceScale()

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.

getParticleGapDurationMillis

Added in 1.1.0-alpha03
public final @IntRange(from = 0) long getParticleGapDurationMillis()

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.

getPinch

Added in 1.1.0-alpha03
public final @FloatRange(from = 0.0, to = 1.0) float getPinch()

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.

getRotationDegrees

Added in 1.1.0-alpha03
public final @AngleDegreesFloat float getRotationDegrees()

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.

getScaleX

Added in 1.1.0-alpha03
public final @FloatRange(from = 0.0, toInclusive = false) float getScaleX()

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.

getScaleY

Added in 1.1.0-alpha03
public final @FloatRange(from = 0.0, toInclusive = false) float getScaleY()

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.

getSlantDegrees

Added in 1.1.0-alpha03
public final @FloatRange(from = -90.0, to = 90.0) @AngleDegreesFloat float getSlantDegrees()

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.

hashCode

public int hashCode()

toBuilder

Added in 1.1.0-alpha03
public final @NonNull BrushTip.Builder toBuilder()

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

public @NonNull String toString()