mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-04-16 20:30:58 +00:00
Add a new event and fixed the free drawing point displacement (#4311)
* things * fixed drawing paths * added jsdocs
This commit is contained in:
parent
124da9ca26
commit
87f4fc905b
3 changed files with 25 additions and 15 deletions
|
|
@ -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,23 +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);
|
||||
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);
|
||||
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 = points[i];
|
||||
if ((i + 1) < points.length) {
|
||||
p2 = new fabric.Point(points[i + 1].x, points[i + 1].y);
|
||||
p2 = points[i + 1];
|
||||
}
|
||||
}
|
||||
path.push('L ', p1.x, ' ', p1.y, ' ');
|
||||
path.push('L ', p1.x + width, ' ', p1.y, ' ');
|
||||
return path;
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@
|
|||
*
|
||||
* @fires before:selection:cleared
|
||||
* @fires selection:cleared
|
||||
* @fires selection:updated
|
||||
* @fires selection:created
|
||||
*
|
||||
* @fires path:created
|
||||
* @fires mouse:down
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue