Skip to content

Commit

Permalink
Revert "add drawDot func to pencilbrush (fabricjs#4743)"
Browse files Browse the repository at this point in the history
This reverts commit f855bbc.
  • Loading branch information
AndrewJDR committed May 4, 2018
1 parent a267b76 commit 8e48229
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions src/brushes/pencil_brush.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@
this._points = [];
},

/**
* Invoked inside on mouse down and mouse move
* @param {Object} pointer
*/
_drawSegment: function (ctx, p1, p2) {
var midPoint = p1.midPointFrom(p2);
ctx.quadraticCurveTo(p1.x, p1.y, midPoint.x, midPoint.y);
return midPoint;
},

/**
* Inovoked on mouse down
* @param {Object} pointer
Expand All @@ -44,25 +34,17 @@
* @param {Object} pointer
*/
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);
}
this.oldEnd = this._drawSegment(ctx, points[length - 2], points[length - 1], true);
ctx.stroke();
ctx.restore();
}
this._captureDrawingPath(pointer);
// redraw curve
// clear top canvas
this.canvas.clearContext(this.canvas.contextTop);
this._render();
},

/**
* Invoked on mouse up
*/
onMouseUp: function() {
this.oldEnd = undefined;
this._finalizeAndAddPath();
},

Expand All @@ -76,6 +58,7 @@

this._reset();
this._addPoint(p);

this.canvas.contextTop.moveTo(p.x, p.y);
},

Expand All @@ -85,10 +68,9 @@
*/
_addPoint: function(point) {
if (this._points.length > 1 && point.eq(this._points[this._points.length - 1])) {
return false;
return;
}
this._points.push(point);
return true;
},

/**
Expand All @@ -97,6 +79,7 @@
*/
_reset: function() {
this._points.length = 0;

this._setBrushStyles();
this._setShadow();
},
Expand All @@ -107,7 +90,7 @@
*/
_captureDrawingPath: function(pointer) {
var pointerPoint = new fabric.Point(pointer.x, pointer.y);
return this._addPoint(pointerPoint);
this._addPoint(pointerPoint);
},

/**
Expand Down Expand Up @@ -137,7 +120,9 @@
for (i = 1, len = this._points.length; i < len; i++) {
// we pick the point between pi + 1 & pi + 2 as the
// end point and p1 as our control point.
this._drawSegment(ctx, p1, p2);
var midPoint = p1.midPointFrom(p2);
ctx.quadraticCurveTo(p1.x, p1.y, midPoint.x, midPoint.y);

p1 = this._points[i];
p2 = this._points[i + 1];
}
Expand Down

0 comments on commit 8e48229

Please sign in to comment.