Skip to main content

Class: default

Defined in: src/lib/brushes/StrokeEngine/index.ts:152

Draws brush and eraser strokes.

Stamps are drawn at full strength into a stroke buffer, so overlapping stamps within one stroke do not build up opacity. The buffer is merged into the layer with the stroke's opacity (the preset's alpha):

  • Brush: painted over the layer (or only onto existing pixels when the layer's alpha lock is on).
  • Eraser: removes the buffer's shape from the layer (or paints its colour onto existing pixels when alpha lock is on).
  • With a mask, the buffer is first cut to the mask, so the stroke only applies inside it.

While drawing, preview provides the layer with the stroke merged in, to draw instead of the layer. The stroke is written into the layer when it ends.

Dispatches a change event whenever the preview changes, and when a stroke is committed or cancelled. Dispatches a beforecommit event (with StrokeCommitDetail) just before a stroke that changes its layer is written into it, so the area can be recorded for undo. Dispatches strokebegin when a stroke starts and strokeend when it's committed or cancelled.

Example​

engine.begin(options, { x: 10, y: 10, pressure: 0.5 }, event.timeStamp);
engine.move({ x: 20, y: 12 }, event.timeStamp);
engine.end({ x: 25, y: 15 }, event.timeStamp);

Extends​

  • EventTarget

Constructors​

Constructor​

new default(width, height, createCanvas?): StrokeEngine

Defined in: src/lib/brushes/StrokeEngine/index.ts:181

Parameters​

width​

number

height​

number

createCanvas?​

CanvasFactory = createOffscreenCanvas

Returns​

StrokeEngine

Overrides​

EventTarget.constructor

Properties​

debugEnabled​

debugEnabled: boolean = false

Defined in: src/lib/brushes/StrokeEngine/index.ts:173

Whether strokes record their points and stamps for the debug overlay


debugTrace​

readonly debugTrace: object

Defined in: src/lib/brushes/StrokeEngine/index.ts:176

Points recorded and stamps placed by the current or last stroke (only while debugEnabled)

points​

points: BrushStrokePoint[]

stamps​

stamps: BrushStrokePoint[]


height​

readonly height: number

Defined in: src/lib/brushes/StrokeEngine/index.ts:157

Canvas height in pixels


width​

readonly width: number

Defined in: src/lib/brushes/StrokeEngine/index.ts:154

Canvas width in pixels

Accessors​

drawing​

Get Signature​

get drawing(): boolean

Defined in: src/lib/brushes/StrokeEngine/index.ts:203

Whether a stroke is in progress

Returns​

boolean


preview​

Get Signature​

get preview(): LayerOverride | undefined

Defined in: src/lib/brushes/StrokeEngine/index.ts:208

The layer with the stroke in progress merged in, to draw in its place; undefined when not drawing

Returns​

LayerOverride | undefined

Methods​

addEventListener()​

addEventListener(type, callback, options?): void

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14380

The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

MDN Reference

Parameters​

type​

string

callback​

EventListenerOrEventListenerObject | null

options?​

boolean | AddEventListenerOptions

Returns​

void

Inherited from​

EventTarget.addEventListener


begin()​

begin(options, point, time): void

Defined in: src/lib/brushes/StrokeEngine/index.ts:249

Start a stroke at the pointer-down point. Cancels any stroke already in progress.

Parameters​

options​

StrokeOptions

point​

BrushStrokePoint

time​

number

Returns​

void


cancel()​

cancel(): void

Defined in: src/lib/brushes/StrokeEngine/index.ts:306

Abandon the stroke in progress without changing the layer.

Returns​

void


dispatchEvent()​

dispatchEvent(event): boolean

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14386

The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

MDN Reference

Parameters​

event​

Event

Returns​

boolean

Inherited from​

EventTarget.dispatchEvent


end()​

end(point, time): void

Defined in: src/lib/brushes/StrokeEngine/index.ts:293

Finish the stroke at the pointer-up point and write it into the layer.

Parameters​

point​

BrushStrokePoint

time​

number

Returns​

void


move()​

move(point, time): void

Defined in: src/lib/brushes/StrokeEngine/index.ts:282

Continue the stroke as the pointer moves. Points are recorded at the preset's sample rate.

Parameters​

point​

BrushStrokePoint

time​

number

Returns​

void


removeEventListener()​

removeEventListener(type, callback, options?): void

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14392

The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

MDN Reference

Parameters​

type​

string

callback​

EventListenerOrEventListenerObject | null

options?​

boolean | EventListenerOptions

Returns​

void

Inherited from​

EventTarget.removeEventListener


setDebug()​

setDebug(enabled): void

Defined in: src/lib/brushes/StrokeEngine/index.ts:229

Turn recording of stroke points and stamps (for the debug overlay) on or off.

Parameters​

enabled​

boolean

Returns​

void


takeChangedArea()​

takeChangedArea(): Rect | undefined

Defined in: src/lib/brushes/StrokeEngine/index.ts:196

The area of the canvas whose preview changed since this was last called (stamps placed, or a stroke cancelled or written into its layer), to redraw only that area; undefined if nothing changed.

Returns​

Rect | undefined