diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f08751010d..c7c62363419 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [next] +- chore(TS): BaseBrush abstract methods [#8428](https://github.com/fabricjs/fabric.js/pull/8428) - feat(): Add `createObjectDefaultControls` and `createTextboxDefaultControls` to create copies of control sets. [#8415](https://github.com/fabricjs/fabric.js/pull/8415) - fix(PatternBrush): `getPatternSrc`, rm `getPatternSrcFunction` [#8468](https://github.com/fabricjs/fabric.js/pull/8468) - chore(TS): more FabricObject typing [#8405](https://github.com/fabricjs/fabric.js/pull/8405) diff --git a/src/brushes/base_brush.class.ts b/src/brushes/base_brush.class.ts index 203a4a8a265..a7c224e1583 100644 --- a/src/brushes/base_brush.class.ts +++ b/src/brushes/base_brush.class.ts @@ -1,9 +1,12 @@ import { fabric } from '../../HEADER'; import { Color } from '../color'; -import { Point } from '../point.class'; +import type { Point } from '../point.class'; +import { TEvent } from '../EventTypeDefs'; import type { Shadow } from '../shadow.class'; import { Canvas } from '../__types__'; +type TBrushEventData = TEvent & { pointer: Point }; + /** * @see {@link http://fabricjs.com/freedrawing|Freedrawing demo} */ @@ -76,6 +79,14 @@ export abstract class BaseBrush { this.canvas = canvas; } + abstract _render(): void; + abstract onMouseDown(pointer: Point, ev: TBrushEventData): void; + abstract onMouseMove(pointer: Point, ev: TBrushEventData): void; + /** + * @returns true if brush should continue blocking interaction + */ + abstract onMouseUp(ev: TBrushEventData): boolean | void; + /** * Sets brush styles * @private @@ -101,6 +112,11 @@ export abstract class BaseBrush { ctx.transform(v[0], v[1], v[2], v[3], v[4], v[5]); } + protected needsFullRender() { + const color = new Color(this.color); + return color.getAlpha() < 1 || !!this.shadow; + } + /** * Sets brush shadow styles * @private @@ -121,11 +137,6 @@ export abstract class BaseBrush { ctx.shadowOffsetY = shadow.offsetY * zoom; } - protected needsFullRender() { - const color = new Color(this.color); - return color.getAlpha() < 1 || !!this.shadow; - } - /** * Removes brush shadow styles * @private