Skip to content

Commit

Permalink
chore(TS): BaseBrush abstract methods (#8428)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 committed Nov 27, 2022
1 parent 0de984c commit 72c3add
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 17 additions & 6 deletions src/brushes/base_brush.class.ts
Original file line number Diff line number Diff line change
@@ -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}
*/
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 72c3add

Please sign in to comment.