From bb4b409b70654c045c005134f401c6dea85a64e0 Mon Sep 17 00:00:00 2001 From: Asturur Date: Sat, 16 Sep 2017 11:24:59 +0200 Subject: [PATCH 1/3] things --- src/brushes/pencil_brush.class.js | 23 +++++++++++++---------- src/mixins/canvas_grouping.mixin.js | 4 +++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/brushes/pencil_brush.class.js b/src/brushes/pencil_brush.class.js index e82fcecf455..50eaa6c1b24 100644 --- a/src/brushes/pencil_brush.class.js +++ b/src/brushes/pencil_brush.class.js @@ -139,18 +139,21 @@ convertPointsToSVGPath: function(points) { var path = [], i, len, p1 = new fabric.Point(points[0].x, points[0].y), - p2 = new fabric.Point(points[1].x, points[1].y); + p2 = new fabric.Point(points[1].x, points[1].y), + len = points.length; path.push('M ', points[0].x, ' ', points[0].y, ' '); - for (i = 1, len = points.length; i < len; i++) { - var midPoint = p1.midPointFrom(p2); - // p1 is our bezier control point - // midpoint is our endpoint - // start point is p(i-1) value. - path.push('Q ', p1.x, ' ', p1.y, ' ', midPoint.x, ' ', midPoint.y, ' '); - p1 = new fabric.Point(points[i].x, points[i].y); - if ((i + 1) < points.length) { - p2 = new fabric.Point(points[i + 1].x, points[i + 1].y); + if (len > 2) { + for (i = 1; i < len; i++) { + var midPoint = p1.midPointFrom(p2); + // p1 is our bezier control point + // midpoint is our endpoint + // start point is p(i-1) value. + path.push('Q ', p1.x, ' ', p1.y, ' ', midPoint.x, ' ', midPoint.y, ' '); + p1 = new fabric.Point(points[i].x, points[i].y); + if ((i + 1) < points.length) { + p2 = new fabric.Point(points[i + 1].x, points[i + 1].y); + } } } path.push('L ', p1.x, ' ', p1.y, ' '); diff --git a/src/mixins/canvas_grouping.mixin.js b/src/mixins/canvas_grouping.mixin.js index 18961106738..0c7bef255a1 100644 --- a/src/mixins/canvas_grouping.mixin.js +++ b/src/mixins/canvas_grouping.mixin.js @@ -50,6 +50,7 @@ var activeSelection = this._activeObject; if (activeSelection.contains(target)) { activeSelection.removeWithUpdate(target); + target.fire('deselected', { e: e }); this._hoveredTarget = target; if (activeSelection.size() === 1) { // activate last remaining object @@ -59,9 +60,10 @@ } else { activeSelection.addWithUpdate(target); + target.fire('selected', { e: e }); this._hoveredTarget = activeSelection; } - this.fire('selection:created', { target: activeSelection, e: e }); + this.fire('selection:updated', { target: activeSelection, e: e, updated: target }); }, /** From c49ef2c60786eee042b8ee575cd774e05912329f Mon Sep 17 00:00:00 2001 From: Asturur Date: Sat, 16 Sep 2017 12:01:19 +0200 Subject: [PATCH 2/3] fixed drawing paths --- src/brushes/pencil_brush.class.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/brushes/pencil_brush.class.js b/src/brushes/pencil_brush.class.js index 50eaa6c1b24..897acc216f6 100644 --- a/src/brushes/pencil_brush.class.js +++ b/src/brushes/pencil_brush.class.js @@ -109,8 +109,11 @@ //then we should be drawing a dot. A path isn't drawn between two identical dots //that's why we set them apart a bit if (this._points.length === 2 && p1.x === p2.x && p1.y === p2.y) { - p1.x -= 0.5; - p2.x += 0.5; + var width = this.width / 1000; + p1 = new fabric.Point(p1.x, p1.y); + p2 = new fabric.Point(p2.x, p2.y); + p1.x -= width; + p2.x += width; } ctx.moveTo(p1.x, p1.y); @@ -137,26 +140,26 @@ * @return {String} SVG path */ convertPointsToSVGPath: function(points) { - var path = [], i, len, + var path = [], i, width = this.width / 1000, p1 = new fabric.Point(points[0].x, points[0].y), p2 = new fabric.Point(points[1].x, points[1].y), len = points.length; - path.push('M ', points[0].x, ' ', points[0].y, ' '); - if (len > 2) { - for (i = 1; i < len; i++) { + path.push('M ', p1.x - width, ' ', p1.y, ' '); + for (i = 1; i < len; i++) { + if (!p1.eq(p2)) { var midPoint = p1.midPointFrom(p2); // p1 is our bezier control point // midpoint is our endpoint // start point is p(i-1) value. path.push('Q ', p1.x, ' ', p1.y, ' ', midPoint.x, ' ', midPoint.y, ' '); - p1 = new fabric.Point(points[i].x, points[i].y); - if ((i + 1) < points.length) { - p2 = new fabric.Point(points[i + 1].x, points[i + 1].y); - } + } + p1 = points[i]; + if ((i + 1) < points.length) { + p2 = points[i + 1]; } } - path.push('L ', p1.x, ' ', p1.y, ' '); + path.push('L ', p1.x + width, ' ', p1.y, ' '); return path; }, From 5d5f217b8a8d9aa385281ae95d228664f53787c4 Mon Sep 17 00:00:00 2001 From: Asturur Date: Sat, 16 Sep 2017 12:52:00 +0200 Subject: [PATCH 3/3] added jsdocs --- src/canvas.class.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/canvas.class.js b/src/canvas.class.js index a07c33c401b..00299144b8e 100644 --- a/src/canvas.class.js +++ b/src/canvas.class.js @@ -25,6 +25,8 @@ * * @fires before:selection:cleared * @fires selection:cleared + * @fires selection:updated + * @fires selection:created * * @fires path:created * @fires mouse:down