Skip to content

Commit

Permalink
Brush problems (fabricjs#4938)
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored May 8, 2018
1 parent d91b34c commit 88e33c0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
28 changes: 19 additions & 9 deletions src/brushes/pencil_brush.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,24 @@
*/
onMouseMove: function(pointer) {
if (this._captureDrawingPath(pointer) && this._points.length > 1) {
var points = this._points, length = points.length, ctx = this.canvas.contextTop;
// draw the curve update
this._saveAndTransform(ctx);
if (this.oldEnd) {
ctx.beginPath();
ctx.moveTo(this.oldEnd.x, this.oldEnd.y);
if (this.needsFullRender) {
// redraw curve
// clear top canvas
this.canvas.clearContext(this.canvas.contextTop);
this._render();
}
else {
var points = this._points, length = points.length, ctx = this.canvas.contextTop;
// draw the curve update
this._saveAndTransform(ctx);
if (this.oldEnd) {
ctx.beginPath();
ctx.moveTo(this.oldEnd.x, this.oldEnd.y);
}
this.oldEnd = this._drawSegment(ctx, points[length - 2], points[length - 1], true);
ctx.stroke();
ctx.restore();
}
this.oldEnd = this._drawSegment(ctx, points[length - 2], points[length - 1], true);
ctx.stroke();
ctx.restore();
}
},

Expand Down Expand Up @@ -98,6 +106,8 @@
_reset: function() {
this._points.length = 0;
this._setBrushStyles();
var color = new fabric.Color(this.color);
this.needsFullRender = (color.getAlpha() < 1);
this._setShadow();
},

Expand Down
4 changes: 3 additions & 1 deletion src/canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@
this.clearContext(this.contextTop);
this.contextTopDirty = false;
}
this.renderTopLayer(this.contextTop);
if (this.hasLostContext) {
this.renderTopLayer(this.contextTop);
}
var canvasToDrawOn = this.contextContainer;
this.renderCanvas(canvasToDrawOn, this._chooseObjectsToRender());
return this;
Expand Down
1 change: 1 addition & 0 deletions src/static_canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@
if (!options.cssOnly) {
this._setBackstoreDimension(prop, dimensions[prop]);
cssValue += 'px';
this.hasLostContext = true;
}

if (!options.backstoreOnly) {
Expand Down

0 comments on commit 88e33c0

Please sign in to comment.