Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(TS): BaseBrush abstract methods #8428

Merged
merged 8 commits into from
Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to make all signature the same

Suggested change
abstract onMouseUp(ev: TBrushEventData): boolean | void;
abstract onMouseUp(pointer: Point, ev: TBrushEventData): boolean | void;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's plan the new api directly.


/**
* 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() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved it because it was in between shadow methods

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