Skip to content

@fabwcie/free-drawing / components/toolbar/widgets/Brush

components/toolbar/widgets/Brush ​

Classes ​

BrushWidget ​

Defined in: packages/free-drawing/src/components/toolbar/widgets/Brush/Brush.ts:17

Brush: freehand strokes of stroke color, width and opacity, thinner when drawn fast (settings of perfect-freehand from brush widget options)

Extends

Constructors ​

Constructor ​

new BrushWidget(drawer): BrushWidget

Defined in: packages/free-drawing/src/components/toolbar/widgets/Brush/Brush.ts:25

Create the brush tool, shortcut B, with its overlay

Parameters
drawer ​

Drawer

Drawer of this widget

Returns

BrushWidget

Overrides

FreehandWidget.constructor

Properties ​

$button ​

$button: HTMLButtonElement

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:29

Button activating the widget, pressed while it is active, named by the title of the tool

Inherited from

FreehandWidget.$button

$container ​

protected readonly $container: HTMLElement

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:21

Container of the button in toolbar (or menu of its group), with a class from widget id

Inherited from

FreehandWidget.$container

actionOnly ​

readonly actionOnly: boolean = false

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:27

Button runs an action (setActive(true)), the widget never becomes the active tool (e.g. image tool)

Inherited from

FreehandWidget.actionOnly

cursor ​

protected cursor: string = crosshairCursor

Defined in: packages/free-drawing/src/components/toolbar/widgets/FreehandWidget.ts:35

Stage cursor while widget is active

Inherited from

FreehandWidget.cursor

drawer ​

protected drawer: Drawer

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:61

Drawer of this widget

Inherited from

FreehandWidget.drawer

id ​

id: AvailableTools

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:31

Id of the tool, key of the widget in toolbar (drawer.getWidget(id)) and namespace of its stage events

Inherited from

FreehandWidget.id

inAction ​

inAction: boolean = false

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:39

Pointer action in progress (drawing, erasing, selecting...), see startAction / endAction

Inherited from

FreehandWidget.inAction

options ​

readonly options: BrushWidgetOptions

Defined in: packages/free-drawing/src/components/toolbar/widgets/Brush/Brush.ts:19

Widget options given with drawer widgets option

Overrides

FreehandWidget.options

overlay ​

overlay: BrushOverlay

Defined in: packages/free-drawing/src/components/toolbar/widgets/Brush/Brush.ts:18

Options of the tool (color, width...), shown while widget is active (see showOverlayOnActive)

Overrides

FreehandWidget.overlay

shortcut ​

shortcut: string | undefined

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:33

Key activating the tool, lower case (shortcut widget option, else default of the widget), none if undefined

Inherited from

FreehandWidget.shortcut

showOverlayOnActive ​

protected showOverlayOnActive: boolean = true

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:47

Show overlay while widget is active (false when overlay depends on something else, e.g. selection)

Inherited from

FreehandWidget.showOverlayOnActive

Accessors ​

isDisabled ​
Get Signature

get isDisabled(): boolean

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:138

Widget can not be activated (see setDisabled)

Returns

boolean

Inherited from

FreehandWidget.isDisabled

isPaint ​
Get Signature

get isPaint(): boolean

Defined in: packages/free-drawing/src/components/toolbar/widgets/FreehandWidget.ts:67

Stroke being drawn (pointer action in progress)

Deprecated

use inAction

Returns

boolean

Inherited from

FreehandWidget.isPaint

Methods ​

addTo() ​

addTo(parent): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:96

Internal

Adds the button of this widget (icon, shortcut letter) in its container, at the end of parent

Parameters
parent ​

HTMLElement

Element receiving the button container: toolbar root or menu of a group

Returns

void

Inherited from

FreehandWidget.addTo

afterDraw() ​

protected afterDraw(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:320

Shape drawn with this tool: selection tool activated, nothing selected, unless tool is kept (keepTool preference)

Returns

void

Inherited from

FreehandWidget.afterDraw

cancelAction() ​

cancelAction(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:241

Pointer action cancelled (two finger gesture of the drawer: zoom and move of the view): its result is discarded (onCancel: shape being drawn removed...), then it ends without change

Returns

void

Inherited from

FreehandWidget.cancelAction

clearSelection() ​

clearSelection(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:313

Unselect shapes, with selection widget (implemented by it)

Returns

void

Inherited from

FreehandWidget.clearSelection

endAction() ​

protected endAction(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:254

Pointer action ends (pointer up)

Returns

void

Inherited from

FreehandWidget.endAction

freehandSettings() ​

protected freehandSettings(): object

Defined in: packages/free-drawing/src/components/toolbar/widgets/Brush/Brush.ts:74

Settings of perfect-freehand from brush widget options

Returns

Given settings, defaults for missing ones

smoothing ​

smoothing: number

Softness of stroke edges (smoothing option, 1 by default)

streamline ​

streamline: number

Stabilization of stroke (streamline option, 0.5 by default)

thinning ​

thinning: number

Effect of drawing speed on stroke width (thinning option, 0.6 by default)

Overrides

FreehandWidget.freehandSettings

initEvents() ​

protected initEvents(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/FreehandWidget.ts:85

Draw by drag: closed line added on pointer down, its outline follows the pointer (shared live), finished on pointer up

Returns

void

Inherited from

FreehandWidget.initEvents

lineStyle() ​

protected lineStyle(): object

Defined in: packages/free-drawing/src/components/toolbar/widgets/Brush/Brush.ts:35

Style of brush strokes, from drawer options

Returns

Color, opacity and width of options, normal blending, name of brush strokes

fill ​

fill: ColorLike = strokeColor

Outline of the stroke filled with stroke color

globalCompositeOperation ​

globalCompositeOperation: "source-over"

Drawn over the drawing (normal blending)

name ​

name: string = shapeName.line

Shape name of brush strokes

opacity ​

opacity: number

Opacity (opacity option)

stroke ​

stroke: ColorLike = strokeColor

Stroke color (strokeColor option)

strokeWidth ​

strokeWidth: number

Stroke width (strokeWidth option)

Overrides

FreehandWidget.lineStyle

onActive() ​

protected onActive(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:199

Called on activation, after events, cursor and overlay setup

Returns

void

Inherited from

FreehandWidget.onActive

onCancel() ​

protected onCancel(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/FreehandWidget.ts:74

Stroke being drawn removed (two finger gesture), also for collaborators who got its preview

Returns

void

Inherited from

FreehandWidget.onCancel

onConstrainChange() ​

protected onConstrainChange(constrain): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/FreehandWidget.ts:168

Shift pressed or released while drawing: stroke straight from its start, or back to the pointer path

Parameters
constrain ​

boolean

Shift pressed

Returns

void

Inherited from

FreehandWidget.onConstrainChange

onDesactive() ​

protected onDesactive(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:204

Called on deactivation, after events removal and overlay hidden

Returns

void

Inherited from

FreehandWidget.onDesactive

onStage() ​

protected onStage(events, handler): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:150

Listen stage events while widget is active. Events are namespaced with widget id, so they are removed on deactivation without removing other listeners. One pointer at a time: during a pointer action, another press (second finger, other button) is ignored, and a touch action ends when its finger is lifted, where it is lifted. Touches of a two finger gesture are ignored.

Parameters
events ​

string

Space separated event names

handler ​

KonvaEventListener<Stage, any>

Konva listener called with the stage event

Returns

void

Inherited from

FreehandWidget.onStage

recognizesShapes() ​

protected recognizesShapes(): boolean

Defined in: packages/free-drawing/src/components/toolbar/widgets/Brush/Brush.ts:58

Brush strokes recognized as shapes with the shapeRecognition preference

Returns

boolean

shapeRecognition option

Overrides

FreehandWidget.recognizesShapes

removeEvents() ​

protected removeEvents(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:192

Remove widget events, called on deactivation

Returns

void

Inherited from

FreehandWidget.removeEvents

setActive() ​

setActive(active): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:353

Activate widget (nothing if disabled): previous widget deactivated, button pressed, then initEvents, updateCursor, overlay shown (if showOverlayOnActive), onActive and drawer focused. Deactivate it: pointer action ended, removeEvents, overlay hidden, onDesactive, button released.

Parameters
active ​

boolean

Activate (true) or deactivate (false) widget

Returns

void

Inherited from

FreehandWidget.setActive

setDisabled() ​

setDisabled(disabled): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:123

Disable or enable widget: a disabled widget can not be activated and its button is disabled (also its group when all its widgets are). Drawing tools are disabled in read only.

Parameters
disabled ​

boolean

Disable widget

Returns

void

Inherited from

FreehandWidget.setDisabled

shareLive() ​

protected shareLive(...shapes): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:306

Shapes being drawn shown to collaborators while drawing (final state is sent on change)

Parameters
shapes ​

...DrawingShape[]

Shapes in their current state, sent as a live change of the collaboration session

Returns

void

Inherited from

FreehandWidget.shareLive

showToolOverlay() ​

showToolOverlay(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:210

Overlay shown again (selection cleared), only for a tool showing it while active (not the frame tool, sharing the overlay of shape tools: it would stay shown once the tool is changed)

Returns

void

Inherited from

FreehandWidget.showToolOverlay

startAction() ​

protected startAction(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:231

Pointer action starts (pointer down): shortcuts are disabled and UI (toolbar, overlays...) ignores pointer, pointer followed out of the canvas until it is released

Returns

void

Inherited from

FreehandWidget.startAction

strokeSize() ​

protected strokeSize(): number

Defined in: packages/free-drawing/src/components/toolbar/widgets/Brush/Brush.ts:66

Width of brush strokes

Returns

number

strokeWidth option

Overrides

FreehandWidget.strokeSize

toggleDisable() ​

toggleDisable(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:114

Disable / enable widget, a disabled widget can not be activated

Returns

void

Inherited from

FreehandWidget.toggleDisable

updateCursor() ​

updateCursor(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:223

Set stage cursor to the cursor of widget: on activation, and to restore it after a temporary one (pan grabbing)

Returns

void

Inherited from

FreehandWidget.updateCursor