From b5b5126bea0e95e116a2789313c320133483fe74 Mon Sep 17 00:00:00 2001 From: ShaMan123 Date: Mon, 7 Nov 2022 14:06:47 +0200 Subject: [PATCH 1/5] abstract methods + tidyup --- src/brushes/base_brush.class.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/brushes/base_brush.class.ts b/src/brushes/base_brush.class.ts index 39eae1d1cff..7131d5e9c5b 100644 --- a/src/brushes/base_brush.class.ts +++ b/src/brushes/base_brush.class.ts @@ -1,7 +1,7 @@ import { fabric } from '../../HEADER'; import { Color } from '../color'; -import { Point } from '../point.class'; -import { Canvas, Shadow } from '../__types__'; +import type { Point } from '../point.class'; +import type { Canvas, Shadow } from '../__types__'; /** * @see {@link http://fabricjs.com/freedrawing|Freedrawing demo} @@ -75,6 +75,11 @@ export abstract class BaseBrush { this.canvas = canvas; } + abstract _render(): void; + abstract onMouseDown(pointer: Point): void; + abstract onMouseMove(pointer: Point): void; + abstract onMouseUp(pointer: Point): void; + /** * Sets brush styles * @private @@ -100,6 +105,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 @@ -120,11 +130,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 From c536ecb53fcf50c7d8deed62faec0cf227ab4ffb Mon Sep 17 00:00:00 2001 From: ShaMan123 Date: Mon, 7 Nov 2022 14:13:07 +0200 Subject: [PATCH 2/5] Update base_brush.class.ts --- src/brushes/base_brush.class.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/brushes/base_brush.class.ts b/src/brushes/base_brush.class.ts index 7131d5e9c5b..6268f4164d6 100644 --- a/src/brushes/base_brush.class.ts +++ b/src/brushes/base_brush.class.ts @@ -1,8 +1,11 @@ import { fabric } from '../../HEADER'; import { Color } from '../color'; import type { Point } from '../point.class'; +import { TEvent } from '../typedefs'; import type { Canvas, Shadow } from '../__types__'; +type TBrushEventData = TEvent & { pointer: Point }; + /** * @see {@link http://fabricjs.com/freedrawing|Freedrawing demo} */ @@ -76,9 +79,9 @@ export abstract class BaseBrush { } abstract _render(): void; - abstract onMouseDown(pointer: Point): void; - abstract onMouseMove(pointer: Point): void; - abstract onMouseUp(pointer: Point): void; + abstract onMouseDown(pointer: Point, ev: TBrushEventData): void; + abstract onMouseMove(pointer: Point, ev: TBrushEventData): void; + abstract onMouseUp(ev: TBrushEventData): void; /** * Sets brush styles From faf374ebf32e2450621652a9a34a3eaf214dbe1b Mon Sep 17 00:00:00 2001 From: ShaMan123 Date: Mon, 7 Nov 2022 14:14:29 +0200 Subject: [PATCH 3/5] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 228c17d831c..06013527c09 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) - chore(TS): migrate Rect [#8411](https://github.com/fabricjs/fabric.js/pull/8411) - chore(TS): migrate Ellipse [#8408](https://github.com/fabricjs/fabric.js/pull/8408) - chore(TS): migrate Triangle to TS [#8410](https://github.com/fabricjs/fabric.js/pull/8410) From 2558035a155887fc40eb3ca133c865abed817f8b Mon Sep 17 00:00:00 2001 From: ShaMan123 Date: Mon, 7 Nov 2022 14:23:45 +0200 Subject: [PATCH 4/5] Update base_brush.class.ts --- src/brushes/base_brush.class.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/brushes/base_brush.class.ts b/src/brushes/base_brush.class.ts index 6268f4164d6..2601fbe4ae1 100644 --- a/src/brushes/base_brush.class.ts +++ b/src/brushes/base_brush.class.ts @@ -81,7 +81,10 @@ export abstract class BaseBrush { abstract _render(): void; abstract onMouseDown(pointer: Point, ev: TBrushEventData): void; abstract onMouseMove(pointer: Point, ev: TBrushEventData): void; - abstract onMouseUp(ev: TBrushEventData): void; + /** + * @returns true if brush should continue blocking interaction + */ + abstract onMouseUp(ev: TBrushEventData): boolean | void; /** * Sets brush styles From a43e7aadb294394474d0a5df279d4678f5073c67 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sun, 27 Nov 2022 00:13:40 +0100 Subject: [PATCH 5/5] fix merge --- src/brushes/base_brush.class.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/brushes/base_brush.class.ts b/src/brushes/base_brush.class.ts index 6fe4b9f641e..a7c224e1583 100644 --- a/src/brushes/base_brush.class.ts +++ b/src/brushes/base_brush.class.ts @@ -1,7 +1,7 @@ import { fabric } from '../../HEADER'; import { Color } from '../color'; import type { Point } from '../point.class'; -import { TEvent } from '../typedefs'; +import { TEvent } from '../EventTypeDefs'; import type { Shadow } from '../shadow.class'; import { Canvas } from '../__types__';