Skip to content

Commit

Permalink
feat(EraserBrush): V2 (fabricjs#7470)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 authored and rockerBOO committed Jan 28, 2022
1 parent a0ced20 commit f9411e9
Show file tree
Hide file tree
Showing 10 changed files with 482 additions and 459 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog


## [5.0.0]

- feat(fabric.EraserBrush): added `eraser` property to Object instead of attaching to `clipPath`, remove hacky `getClipPath`/`setClipPath` [#7470](https://github.com/fabricjs/fabric.js/pull/7470), see **BREAKING** comments.
- feat(fabric.EraserBrush): support `inverted` option to undo erasing [#7470](https://github.com/fabricjs/fabric.js/pull/7470)
- fix(fabric.EraserBrush): fix doubling opaic objects while erasing [#7445](https://github.com/fabricjs/fabric.js/issues/7445) [#7470](https://github.com/fabricjs/fabric.js/pull/7470)

**BREAKING**:

- fabric.EraserBrush: The Eraser object is now a subclass of Group. This means that loading from JSON will break between versions.
Use this [code](https://gist.github.com/ShaMan123/6c5c4ca2cc720a2700848a2deb6addcd) to transform your json payload to the new version.


## [next]
- feat(fabric.Canvas): fire an extra mouse up for the original control of the initial target [`#7612`](https://github.com/fabricjs/fabric.js/pull/7612)
- fix(fabric.Object) bounding box display with skewY when outside group [`#7611`](https://github.com/fabricjs/fabric.js/pull/7611)
Expand Down Expand Up @@ -28,6 +41,7 @@
- docs(): specify default value and docs for enablePointerEvents [`#7386`](https://github.com/fabricjs/fabric.js/pull/7386)
- feat(fabric.PencilBrush): add an option to draw a straight line while pressing a key [`#7034`](https://github.com/fabricjs/fabric.js/pull/7034)


## [4.6.0]

- feat(fabric.util): added fabric.util.transformPath to add transformations to path points [#7300](https://github.com/fabricjs/fabric.js/pull/7300)
Expand Down
4 changes: 2 additions & 2 deletions src/brushes/base_brush.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ fabric.BaseBrush = fabric.util.createClass(/** @lends fabric.BaseBrush.prototype
/**
* Sets brush styles
* @private
* @param {CanvasRenderingContext2D} ctx
*/
_setBrushStyles: function() {
var ctx = this.canvas.contextTop;
_setBrushStyles: function (ctx) {
ctx.strokeStyle = this.color;
ctx.lineWidth = this.width;
ctx.lineCap = this.strokeLineCap;
Expand Down
12 changes: 7 additions & 5 deletions src/brushes/pattern_brush.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab

/**
* Creates "pattern" instance property
* @param {CanvasRenderingContext2D} ctx
*/
getPattern: function() {
return this.canvas.contextTop.createPattern(this.source || this.getPatternSrc(), 'repeat');
getPattern: function(ctx) {
return ctx.createPattern(this.source || this.getPatternSrc(), 'repeat');
},

/**
* Sets brush styles
* @param {CanvasRenderingContext2D} ctx
*/
_setBrushStyles: function() {
this.callSuper('_setBrushStyles');
this.canvas.contextTop.strokeStyle = this.getPattern();
_setBrushStyles: function(ctx) {
this.callSuper('_setBrushStyles', ctx);
ctx.strokeStyle = this.getPattern(ctx);
},

/**
Expand Down
9 changes: 5 additions & 4 deletions src/brushes/pencil_brush.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
*/
_reset: function() {
this._points = [];
this._setBrushStyles();
this._setBrushStyles(this.canvas.contextTop);
this._setShadow();
this._hasStraightLine = false;
},
Expand All @@ -168,12 +168,13 @@
/**
* Draw a smooth path on the topCanvas using quadraticCurveTo
* @private
* @param {CanvasRenderingContext2D} [ctx]
*/
_render: function() {
var ctx = this.canvas.contextTop, i, len,
_render: function(ctx) {
var i, len,
p1 = this._points[0],
p2 = this._points[1];

ctx = ctx || this.canvas.contextTop;
this._saveAndTransform(ctx);
ctx.beginPath();
//if we only have 2 points in the path and they are the same
Expand Down
Loading

0 comments on commit f9411e9

Please sign in to comment.