Skip to content

Commit

Permalink
async
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 committed Apr 26, 2022
1 parent a8c1818 commit fddbae7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
28 changes: 16 additions & 12 deletions src/brushes/circle_brush.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ fabric.CircleBrush = fabric.util.createClass(fabric.BaseBrush, /** @lends fabric
/**
* Invoked on mouse up
*/
onMouseUp: function() {
onMouseUp: function () {
this._finalizeAndAddPath();
},

/**
* @private
*/
_finalizeAndAddPath: async function () {
var originalRenderOnAddRemove = this.canvas.renderOnAddRemove, i, len;
this.canvas.renderOnAddRemove = false;

Expand All @@ -102,21 +109,18 @@ fabric.CircleBrush = fabric.util.createClass(fabric.BaseBrush, /** @lends fabric
});

this.shadow && (circle.shadow = new fabric.Shadow(this.shadow));

circles.push(circle);
}
var canvas = this.canvas, ctx = canvas.contextTop;
var group = new fabric.Group(circles, { canvas: canvas });
this._addClipPathToResult(group)
.then(function () {
canvas.fire('before:path:created', { path: group });
canvas.add(group);
canvas.fire('path:created', { path: group });
canvas.clearContext(ctx);
this._resetShadow(ctx);
canvas.renderOnAddRemove = originalRenderOnAddRemove;
canvas.requestRenderAll();
}.bind(this));
await this._addClipPathToResult(group);
canvas.fire('before:path:created', { path: group });
canvas.add(group);
canvas.fire('path:created', { path: group });
canvas.clearContext(ctx);
this._resetShadow(ctx);
canvas.renderOnAddRemove = originalRenderOnAddRemove;
canvas.requestRenderAll();
},

/**
Expand Down
22 changes: 12 additions & 10 deletions src/brushes/spray_brush.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ fabric.SprayBrush = fabric.util.createClass( fabric.BaseBrush, /** @lends fabric
* Invoked on mouse up
*/
onMouseUp: function () {
this._finalizeAndAddPath();
},

_finalizeAndAddPath: async function () {
var canvas = this.canvas, ctx = canvas.contextTop;
var originalRenderOnAddRemove = canvas.renderOnAddRemove;
canvas.renderOnAddRemove = false;
Expand Down Expand Up @@ -115,16 +119,14 @@ fabric.SprayBrush = fabric.util.createClass( fabric.BaseBrush, /** @lends fabric

var group = new fabric.Group(rects);
this.shadow && group.set('shadow', new fabric.Shadow(this.shadow));
this._addClipPathToResult(group)
.then(function () {
canvas.fire('before:path:created', { path: group });
canvas.add(group);
canvas.fire('path:created', { path: group });
canvas.clearContext(ctx);
this._resetShadow(ctx);
canvas.renderOnAddRemove = originalRenderOnAddRemove;
canvas.requestRenderAll();
}.bind(this));
await this._addClipPathToResult(group);
canvas.fire('before:path:created', { path: group });
canvas.add(group);
canvas.fire('path:created', { path: group });
canvas.clearContext(ctx);
this._resetShadow(ctx);
canvas.renderOnAddRemove = originalRenderOnAddRemove;
canvas.requestRenderAll();
},

/**
Expand Down

0 comments on commit fddbae7

Please sign in to comment.