feat: 裁剪组裁剪跟随选择组移动
This commit is contained in:
@@ -97,9 +97,7 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
}
|
||||
if (color.indexOf("rgb") === -1) {
|
||||
// convert named colors
|
||||
var tempElem = document.body.appendChild(
|
||||
document.createElement("fictum")
|
||||
); // intentionally use unknown tag to lower chances of css rule override with !important
|
||||
var tempElem = document.body.appendChild(document.createElement("fictum")); // intentionally use unknown tag to lower chances of css rule override with !important
|
||||
var flag = "rgb(1, 2, 3)"; // this flag tested on chrome 59, ff 53, ie9, ie10, ie11, edge 14
|
||||
tempElem.style.color = flag;
|
||||
if (tempElem.style.color !== flag) {
|
||||
@@ -116,7 +114,7 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
if (color.indexOf("rgba") === -1) {
|
||||
color += ",1"; // convert 'rgb(R,G,B)' to 'rgb(R,G,B)A' which looks awful but will pass the regxep below
|
||||
}
|
||||
return color.match(/[\.\d]+/g).map(function (a) {
|
||||
return color.match(/[.\d]+/g).map(function (a) {
|
||||
return +a;
|
||||
});
|
||||
}
|
||||
@@ -269,13 +267,7 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
draw: function () {
|
||||
var ctx = this.ctx;
|
||||
ctx.save();
|
||||
this.line(
|
||||
ctx,
|
||||
this._lastPoint,
|
||||
this._point,
|
||||
this.color,
|
||||
this._currentLineWidth
|
||||
);
|
||||
this.line(ctx, this._lastPoint, this._point, this.color, this._currentLineWidth);
|
||||
ctx.restore();
|
||||
},
|
||||
|
||||
@@ -319,10 +311,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
},
|
||||
|
||||
onMouseDown: function (pointer) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this.canvas.contextTop.globalAlpha = this.opacity;
|
||||
this._size = this.width / 2 + this._baseWidth;
|
||||
this._drawn = false;
|
||||
@@ -330,10 +320,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
},
|
||||
|
||||
onMouseMove: function (pointer) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this.update(pointer);
|
||||
this.draw(this.canvas.contextTop);
|
||||
},
|
||||
@@ -358,9 +346,7 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
|
||||
update: function (p) {
|
||||
this.set(p);
|
||||
this._latestStrokeLength = this._point
|
||||
.subtract(this._latest)
|
||||
.distanceFrom({ x: 0, y: 0 });
|
||||
this._latestStrokeLength = this._point.subtract(this._latest).distanceFrom({ x: 0, y: 0 });
|
||||
},
|
||||
|
||||
draw: function (ctx) {
|
||||
@@ -372,12 +358,7 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
v.normalize(s);
|
||||
|
||||
dotSize =
|
||||
this._sep *
|
||||
fabric.util.clamp(
|
||||
(this._inkAmount / this._latestStrokeLength) * 3,
|
||||
1,
|
||||
0.5
|
||||
);
|
||||
this._sep * fabric.util.clamp((this._inkAmount / this._latestStrokeLength) * 3, 1, 0.5);
|
||||
dotNum = Math.ceil(this._size * this._sep);
|
||||
|
||||
range = this._size / 2;
|
||||
@@ -428,10 +409,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
|
||||
onMouseDown: function (pointer) {
|
||||
// 添加坐标转换处理画布缩放和偏移
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
|
||||
this._points = [pointer];
|
||||
this._count = 0;
|
||||
@@ -440,15 +419,7 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
color = fabric.util.colorValues(this.color);
|
||||
|
||||
ctx.strokeStyle =
|
||||
"rgba(" +
|
||||
color[0] +
|
||||
"," +
|
||||
color[1] +
|
||||
"," +
|
||||
color[2] +
|
||||
"," +
|
||||
0.1 * this.opacity +
|
||||
")";
|
||||
"rgba(" + color[0] + "," + color[1] + "," + color[2] + "," + 0.1 * this.opacity + ")";
|
||||
ctx.lineWidth = this.width;
|
||||
|
||||
this._points.push(pointer);
|
||||
@@ -456,10 +427,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
|
||||
onMouseMove: function (pointer) {
|
||||
// 添加坐标转换处理画布缩放和偏移
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
|
||||
this._points.push(pointer);
|
||||
|
||||
@@ -528,10 +497,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
},
|
||||
|
||||
_render: function (pointer) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
var len,
|
||||
i,
|
||||
point = this.setPointer(pointer),
|
||||
@@ -579,21 +546,11 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
for (i = 0; i < num; i++) {
|
||||
r = fabric.util.getRandom(range, 1);
|
||||
c = fabric.util.getRandom(Math.PI * 2);
|
||||
point = new fabric.Point(
|
||||
pointer.x + r * Math.sin(c),
|
||||
pointer.y + r * Math.cos(c)
|
||||
);
|
||||
point = new fabric.Point(pointer.x + r * Math.sin(c), pointer.y + r * Math.cos(c));
|
||||
|
||||
ctx.fillStyle = color;
|
||||
ctx.beginPath();
|
||||
ctx.arc(
|
||||
point.x,
|
||||
point.y,
|
||||
fabric.util.getRandom(maxSize) / 2,
|
||||
0,
|
||||
Math.PI * 2,
|
||||
false
|
||||
);
|
||||
ctx.arc(point.x, point.y, fabric.util.getRandom(maxSize) / 2, 0, Math.PI * 2, false);
|
||||
ctx.fill();
|
||||
}
|
||||
ctx.restore();
|
||||
@@ -609,10 +566,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
},
|
||||
|
||||
_resetTip: function (pointer) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
var len,
|
||||
i,
|
||||
point = this.setPointer(pointer);
|
||||
@@ -655,10 +610,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
},
|
||||
|
||||
onMouseDown: function (pointer) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._points = [pointer];
|
||||
this._count = 0;
|
||||
|
||||
@@ -667,23 +620,13 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
|
||||
//ctx.globalCompositeOperation = 'source-over';
|
||||
ctx.strokeStyle =
|
||||
"rgba(" +
|
||||
color[0] +
|
||||
"," +
|
||||
color[1] +
|
||||
"," +
|
||||
color[2] +
|
||||
"," +
|
||||
0.05 * this.opacity +
|
||||
")";
|
||||
"rgba(" + color[0] + "," + color[1] + "," + color[2] + "," + 0.05 * this.opacity + ")";
|
||||
ctx.lineWidth = this.width;
|
||||
},
|
||||
|
||||
onMouseMove: function (pointer) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._points.push(pointer);
|
||||
|
||||
var i,
|
||||
@@ -772,10 +715,7 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
this._lastPoint.x - lineWidthDiff + num,
|
||||
this._lastPoint.y + lineWidthDiff - num
|
||||
);
|
||||
ctx.lineTo(
|
||||
pointer.x - lineWidthDiff + num,
|
||||
pointer.y + lineWidthDiff - num
|
||||
);
|
||||
ctx.lineTo(pointer.x - lineWidthDiff + num, pointer.y + lineWidthDiff - num);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
@@ -783,10 +723,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
},
|
||||
|
||||
onMouseDown: function (pointer) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._lastPoint = pointer;
|
||||
this.canvas.contextTop.strokeStyle = this.color;
|
||||
this.canvas.contextTop.lineWidth = this._lineWidth;
|
||||
@@ -795,10 +733,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
|
||||
onMouseMove: function (pointer) {
|
||||
if (this.canvas._isCurrentlyDrawing) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._render(pointer);
|
||||
}
|
||||
},
|
||||
@@ -852,10 +788,7 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
this._lastPoint.x + lineWidthDiff - num,
|
||||
this._lastPoint.y + lineWidthDiff - num
|
||||
);
|
||||
ctx.lineTo(
|
||||
pointer.x + lineWidthDiff - num,
|
||||
pointer.y + lineWidthDiff - num
|
||||
);
|
||||
ctx.lineTo(pointer.x + lineWidthDiff - num, pointer.y + lineWidthDiff - num);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
@@ -863,10 +796,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
},
|
||||
|
||||
onMouseDown: function (pointer) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._lastPoint = pointer;
|
||||
this.canvas.contextTop.strokeStyle = this.color;
|
||||
this.canvas.contextTop.lineWidth = this._lineWidth;
|
||||
@@ -875,10 +806,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
|
||||
onMouseMove: function (pointer) {
|
||||
if (this.canvas._isCurrentlyDrawing) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._render(pointer);
|
||||
}
|
||||
},
|
||||
@@ -923,10 +852,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
},
|
||||
|
||||
onMouseDown: function (pointer) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._points = [];
|
||||
this._points.push(["M", pointer.x, pointer.y]);
|
||||
|
||||
@@ -938,10 +865,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
|
||||
onMouseMove: function (pointer) {
|
||||
if (this.canvas._isCurrentlyDrawing) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._render(pointer);
|
||||
}
|
||||
},
|
||||
@@ -1010,10 +935,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
|
||||
onMouseDown: function (pointer) {
|
||||
// 添加坐标转换处理画布缩放和偏移
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
|
||||
this._lastPoint = pointer;
|
||||
this.canvas.contextTop.strokeStyle = this.color;
|
||||
@@ -1024,10 +947,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
onMouseMove: function (pointer) {
|
||||
if (this.canvas._isCurrentlyDrawing) {
|
||||
// 添加坐标转换处理画布缩放和偏移
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
|
||||
this._render(pointer);
|
||||
}
|
||||
@@ -1093,10 +1014,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
},
|
||||
|
||||
onMouseDown: function (pointer) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._lastPoint = pointer;
|
||||
this.canvas.contextTop.lineWidth = this._lineWidth;
|
||||
this._size = this.width + this._baseWidth;
|
||||
@@ -1104,10 +1023,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
|
||||
onMouseMove: function (pointer) {
|
||||
if (this.canvas._isCurrentlyDrawing) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._render(pointer);
|
||||
}
|
||||
},
|
||||
@@ -1158,12 +1075,10 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(painters[i].dx, painters[i].dy);
|
||||
painters[i].dx -= painters[i].ax =
|
||||
(painters[i].ax +
|
||||
(painters[i].dx - this._lastPoint.x) * painters[i].div) *
|
||||
(painters[i].ax + (painters[i].dx - this._lastPoint.x) * painters[i].div) *
|
||||
painters[i].ease;
|
||||
painters[i].dy -= painters[i].ay =
|
||||
(painters[i].ay +
|
||||
(painters[i].dy - this._lastPoint.y) * painters[i].div) *
|
||||
(painters[i].ay + (painters[i].dy - this._lastPoint.y) * painters[i].div) *
|
||||
painters[i].ease;
|
||||
ctx.lineTo(painters[i].dx, painters[i].dy);
|
||||
ctx.stroke();
|
||||
@@ -1185,26 +1100,16 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
ease: Math.random() * 0.2 + 0.6,
|
||||
});
|
||||
}
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._lastPoint = pointer;
|
||||
|
||||
//ctx.globalCompositeOperation = 'source-over';
|
||||
ctx.strokeStyle =
|
||||
"rgba(" +
|
||||
color[0] +
|
||||
"," +
|
||||
color[1] +
|
||||
"," +
|
||||
color[2] +
|
||||
"," +
|
||||
0.05 * this.opacity +
|
||||
")";
|
||||
"rgba(" + color[0] + "," + color[1] + "," + color[2] + "," + 0.05 * this.opacity + ")";
|
||||
ctx.lineWidth = this.width;
|
||||
|
||||
for (var i = 0; i < this._nrPainters; i++) {
|
||||
for (let i = 0; i < this._nrPainters; i++) {
|
||||
this._painters[i].dx = pointer.x;
|
||||
this._painters[i].dy = pointer.y;
|
||||
}
|
||||
@@ -1216,10 +1121,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
},
|
||||
|
||||
onMouseMove: function (pointer) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._lastPoint = pointer;
|
||||
},
|
||||
|
||||
@@ -1254,34 +1157,22 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
},
|
||||
|
||||
onMouseDown: function (pointer) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._points = [pointer];
|
||||
|
||||
var ctx = this.canvas.contextTop,
|
||||
color = fabric.util.colorValues(this.color);
|
||||
|
||||
ctx.strokeStyle =
|
||||
"rgba(" +
|
||||
color[0] +
|
||||
"," +
|
||||
color[1] +
|
||||
"," +
|
||||
color[2] +
|
||||
"," +
|
||||
this.opacity +
|
||||
")";
|
||||
"rgba(" + color[0] + "," + color[1] + "," + color[2] + "," + this.opacity + ")";
|
||||
ctx.lineWidth = this.width;
|
||||
ctx.lineJoin = ctx.lineCap = "round";
|
||||
},
|
||||
|
||||
onMouseMove: function (pointer) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._points.push(pointer);
|
||||
|
||||
var ctx = this.canvas.contextTop,
|
||||
@@ -1346,10 +1237,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
this.canvas.contextTop.globalAlpha = this.opacity;
|
||||
|
||||
// 坐标转换
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
|
||||
this._points = [pointer];
|
||||
this._count = 0;
|
||||
@@ -1361,23 +1250,13 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
|
||||
ctx.lineWidth = this.width;
|
||||
ctx.strokeStyle =
|
||||
"rgba(" +
|
||||
color[0] +
|
||||
"," +
|
||||
color[1] +
|
||||
"," +
|
||||
color[2] +
|
||||
"," +
|
||||
0.3 * this.opacity +
|
||||
")";
|
||||
"rgba(" + color[0] + "," + color[1] + "," + color[2] + "," + 0.3 * this.opacity + ")";
|
||||
},
|
||||
|
||||
onMouseMove: function (pointer) {
|
||||
// 坐标转换
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
|
||||
this._points.push(pointer);
|
||||
|
||||
@@ -1396,15 +1275,7 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
// 增加透明度设置
|
||||
var color = fabric.util.colorValues(this.color);
|
||||
ctx.strokeStyle =
|
||||
"rgba(" +
|
||||
color[0] +
|
||||
"," +
|
||||
color[1] +
|
||||
"," +
|
||||
color[2] +
|
||||
"," +
|
||||
0.2 * this.opacity +
|
||||
")";
|
||||
"rgba(" + color[0] + "," + color[1] + "," + color[2] + "," + 0.2 * this.opacity + ")";
|
||||
|
||||
// 修改循环逻辑,确保在有点时能画出效果
|
||||
if (this._count > 0) {
|
||||
@@ -1416,10 +1287,7 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
|
||||
if (d < 4000 && Math.random() > d / 2000) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(
|
||||
points[this._count].x + dx * factor,
|
||||
points[this._count].y + dy * factor
|
||||
);
|
||||
ctx.moveTo(points[this._count].x + dx * factor, points[this._count].y + dy * factor);
|
||||
ctx.lineTo(points[i].x - dx * factor, points[i].y - dy * factor);
|
||||
ctx.stroke();
|
||||
this._drawn = true;
|
||||
@@ -1494,10 +1362,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
|
||||
onMouseDown: function (pointer) {
|
||||
this.canvas.contextTop.globalAlpha = this.opacity;
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._point = new fabric.Point(pointer.x, pointer.y);
|
||||
this._lastPoint = this._point;
|
||||
|
||||
@@ -1510,10 +1376,8 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
},
|
||||
|
||||
onMouseMove: function (pointer) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._lastPoint = this._point;
|
||||
this._point = new fabric.Point(pointer.x, pointer.y);
|
||||
},
|
||||
@@ -1542,13 +1406,7 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
|
||||
x = self._lastPoint.x + Math.sin(angle) - self.size / 2;
|
||||
y = self._lastPoint.y + Math.cos(angle) - self.size / 2;
|
||||
self.canvas.contextTop.drawImage(
|
||||
self.brush._element,
|
||||
x,
|
||||
y,
|
||||
self.size,
|
||||
self.size
|
||||
);
|
||||
self.canvas.contextTop.drawImage(self.brush._element, x, y, self.size, self.size);
|
||||
|
||||
if (self.canvas._isCurrentlyDrawing) {
|
||||
setTimeout(draw, self._interval);
|
||||
@@ -1594,43 +1452,22 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
var ctx = this.canvas.contextTop,
|
||||
color = fabric.util.colorValues(this.color),
|
||||
bgColor = fabric.util.colorValues(this.bgColor);
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._lastPoint = pointer;
|
||||
this._drawn = false;
|
||||
|
||||
//ctx.globalCompositeOperation = 'source-over';
|
||||
this.canvas.contextTop.globalAlpha = this.opacity;
|
||||
ctx.fillStyle =
|
||||
"rgba(" +
|
||||
bgColor[0] +
|
||||
"," +
|
||||
bgColor[1] +
|
||||
"," +
|
||||
bgColor[2] +
|
||||
"," +
|
||||
bgColor[3] +
|
||||
")";
|
||||
ctx.strokeStyle =
|
||||
"rgba(" +
|
||||
color[0] +
|
||||
"," +
|
||||
color[1] +
|
||||
"," +
|
||||
color[2] +
|
||||
"," +
|
||||
color[3] +
|
||||
")";
|
||||
"rgba(" + bgColor[0] + "," + bgColor[1] + "," + bgColor[2] + "," + bgColor[3] + ")";
|
||||
ctx.strokeStyle = "rgba(" + color[0] + "," + color[1] + "," + color[2] + "," + color[3] + ")";
|
||||
ctx.lineWidth = this.width;
|
||||
},
|
||||
|
||||
onMouseMove: function (pointer) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
var ctx = this.canvas.contextTop,
|
||||
dx = pointer.x - this._lastPoint.x,
|
||||
dy = pointer.y - this._lastPoint.y,
|
||||
@@ -1683,20 +1520,16 @@ import { sprayBrushDataUrl } from "./data/sprayBrushData.js";
|
||||
},
|
||||
|
||||
onMouseDown: function (pointer) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._points = [pointer];
|
||||
this._count = 0;
|
||||
this._colorValues = fabric.util.colorValues(this.color);
|
||||
},
|
||||
|
||||
onMouseMove: function (pointer) {
|
||||
pointer.x =
|
||||
pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y =
|
||||
pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
pointer.x = pointer.x * this.canvas.getZoom() + this.canvas.viewportTransform[4];
|
||||
pointer.y = pointer.y * this.canvas.getZoom() + this.canvas.viewportTransform[5];
|
||||
this._points.push(pointer);
|
||||
|
||||
var ctx = this.canvas.contextTop,
|
||||
|
||||
Reference in New Issue
Block a user