androidx.ink.strokes


Classes

ImmutableStrokeInputBatch

An immutable implementation of StrokeInputBatch.

Cmn
InProgressStroke

Use an InProgressStroke to efficiently build a stroke over multiple rendering frames with incremental inputs.

Cmn
MutableStrokeInputBatch

A mutable implementation of StrokeInputBatch.

Cmn
Stroke

An immutable object comprised of a StrokeInputBatch that represents a user-drawn (or sometimes synthetic) path, a Brush that contains information on how that path should be converted into a geometric shape and rendered on screen, and a PartitionedMesh which is the geometric shape calculated from the combination of the StrokeInputBatch and the Brush.

Cmn
StrokeInput

A single input specifying position, time since the start of the stream, and optionally pressure, tiltRadians, and orientationRadians.

Cmn
StrokeInputBatch

A read-only view of an object that stores multiple StrokeInput values together in a more memory-efficient manner than just List<StrokeInput>.

Cmn

Objects

Extension functions summary

PartitionedMesh

Creates a PartitionedMesh of the shape enclosed by the given StrokeInputBatch input points.

Cmn

Extension functions

StrokeInputBatch.createClosedShape

fun StrokeInputBatch.createClosedShape(): PartitionedMesh

Creates a PartitionedMesh of the shape enclosed by the given StrokeInputBatch input points. A typical use case is selecting a region of the scene and performing hit testing with the resulting PartitionedMesh.

For a given stroke this algorithm aims to:

  1. Identify and create any connections that the user may have intended to make but did not fully connect.

  2. Trim any extra end points that the user did not intend to be part of the selected area.

Example usage:

fun onStrokeFinished(stroke: Stroke) {
val selectionRegion = stroke.inputs.createClosedShape()
for (stroke in myScene.strokes) {
if (stroke.shape.intersects(selectionRegion)) {
myScene.setSelected(stroke, true)
}
}
}
Parameters
StrokeInputBatch

The StrokeInputBatch to create a closed shape from.

Returns
PartitionedMesh

The PartitionedMesh of the closed shape. If there are fewer than 3 input points, or if there are fewer than 3 points remaining after removing points with the same (x,y) coordinates as the previous point, this function will return a PartitionedMesh that is point-like (1 point remaining) or segment-like (2 points remaining). The resulting mesh will have an area of 0 but can still be used for hit testing via intersection.