2021-12-27 21:11:59 +03:00
|
|
|
class LassoSelectionTool extends SelectionTool {
|
2021-12-30 01:16:16 +03:00
|
|
|
currentPixels = [];
|
2021-12-29 00:51:18 +03:00
|
|
|
|
2021-12-27 21:11:59 +03:00
|
|
|
constructor (name, options, switchFunc, moveTool) {
|
2021-12-27 21:40:23 +03:00
|
|
|
super(name, options, switchFunc, moveTool);
|
2021-12-29 00:51:18 +03:00
|
|
|
Events.on('click', this.mainButton, switchFunc, this);
|
2022-01-30 02:09:43 +03:00
|
|
|
|
|
|
|
this.resetTutorial();
|
|
|
|
this.addTutorialTitle("Lasso selection tool");
|
|
|
|
this.addTutorialKey("Q", " to select the lasso selection tool");
|
|
|
|
this.addTutorialKey("Left drag", " to select an area");
|
|
|
|
this.addTutorialKey("Left drag", " to move a selection");
|
|
|
|
this.addTutorialKey("Esc", " to cancel a selection")
|
|
|
|
this.addTutorialKey("Click", " outside the selection to cancel it")
|
|
|
|
this.addTutorialKey("CTRL+C", " to copy a selection")
|
|
|
|
this.addTutorialKey("CTRL+V", " to paste a selection")
|
|
|
|
this.addTutorialKey("CTRL+X", " to cut a selection")
|
2022-02-25 17:49:30 +03:00
|
|
|
this.addTutorialImg("/lassoselect-tutorial.gif");
|
2021-12-27 21:11:59 +03:00
|
|
|
}
|
|
|
|
|
2022-01-22 14:18:10 +03:00
|
|
|
onStart(mousePos, mouseTarget) {
|
|
|
|
super.onStart(mousePos, mouseTarget);
|
|
|
|
|
|
|
|
if (Util.isChildOfByClass(mouseTarget, "editor-top-menu") ||
|
|
|
|
!Util.cursorInCanvas(currFile.canvasSize, [mousePos[0]/currFile.zoom, mousePos[1]/currFile.zoom]))
|
|
|
|
return;
|
2022-01-06 01:54:29 +03:00
|
|
|
|
2021-12-29 00:51:18 +03:00
|
|
|
this.currentPixels = [];
|
|
|
|
this.drawSelection();
|
2022-01-02 23:57:35 +03:00
|
|
|
this.currentPixels.push([mousePos[0] / currFile.zoom, mousePos[1] / currFile.zoom]);
|
2021-12-27 21:11:59 +03:00
|
|
|
}
|
|
|
|
|
2022-01-22 14:18:10 +03:00
|
|
|
onDrag(mousePos, mouseTarget) {
|
|
|
|
super.onDrag(mousePos, mouseTarget);
|
|
|
|
|
2022-02-05 00:13:11 +03:00
|
|
|
if (!Util.cursorInCanvas(currFile.canvasSize, [mousePos[0]/currFile.zoom, mousePos[1]/currFile.zoom]))
|
2022-01-22 14:18:10 +03:00
|
|
|
return;
|
2021-12-30 01:16:16 +03:00
|
|
|
|
2021-12-29 00:51:18 +03:00
|
|
|
if (this.currentPixels[this.currentPixels.length - 1] != mousePos)
|
2022-01-02 23:57:35 +03:00
|
|
|
this.currentPixels.push([mousePos[0] / currFile.zoom, mousePos[1] / currFile.zoom]);
|
2022-01-06 01:54:29 +03:00
|
|
|
|
2021-12-29 00:51:18 +03:00
|
|
|
this.drawSelection();
|
2021-12-27 21:11:59 +03:00
|
|
|
}
|
|
|
|
|
2022-01-22 14:18:10 +03:00
|
|
|
onEnd(mousePos, mouseTarget) {
|
|
|
|
super.onEnd(mousePos, mouseTarget);
|
2021-12-29 01:14:37 +03:00
|
|
|
new HistoryState().EditCanvas();
|
|
|
|
|
2022-02-05 00:13:11 +03:00
|
|
|
if (Util.isChildOfByClass(mouseTarget, "editor-top-menu"))
|
2022-01-22 14:18:10 +03:00
|
|
|
return;
|
|
|
|
|
2022-01-02 23:57:35 +03:00
|
|
|
this.currentPixels.push([this.startMousePos[0] / currFile.zoom, this.startMousePos[1] / currFile.zoom]);
|
2021-12-29 01:14:37 +03:00
|
|
|
|
2022-01-08 21:16:15 +03:00
|
|
|
// Include extreme borders
|
|
|
|
this.boundingBox.maxX++;
|
|
|
|
this.boundingBox.maxY++;
|
|
|
|
|
|
|
|
// Switch to the move tool so that the user can move the selection
|
2021-12-29 01:14:37 +03:00
|
|
|
this.switchFunc(this.moveTool);
|
2022-01-08 21:16:15 +03:00
|
|
|
this.moveTool.setSelectionData(this.getSelection(), this);
|
2021-12-27 21:11:59 +03:00
|
|
|
}
|
|
|
|
|
2021-12-29 00:51:18 +03:00
|
|
|
onSelect() {
|
|
|
|
super.onSelect();
|
2021-12-27 21:11:59 +03:00
|
|
|
}
|
|
|
|
|
2021-12-29 00:51:18 +03:00
|
|
|
onDeselect() {
|
|
|
|
super.onDeselect();
|
2021-12-27 21:11:59 +03:00
|
|
|
}
|
|
|
|
|
2021-12-29 00:51:18 +03:00
|
|
|
drawSelection() {
|
|
|
|
if (this.currentPixels.length <= 1)
|
|
|
|
return;
|
|
|
|
let point = [];
|
2022-01-02 23:57:35 +03:00
|
|
|
let prevPoint = [];
|
2021-12-29 00:51:18 +03:00
|
|
|
|
|
|
|
currFile.VFXLayer.context.clearRect(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]);
|
|
|
|
currFile.VFXLayer.context.fillStyle = 'rgba(0,0,0,1)';
|
2021-12-27 21:11:59 +03:00
|
|
|
|
2021-12-29 00:51:18 +03:00
|
|
|
for (var index = 0; index < this.currentPixels.length; index ++) {
|
|
|
|
point = this.currentPixels[index];
|
|
|
|
|
|
|
|
if (index == 0)
|
|
|
|
currFile.VFXLayer.context.moveTo(point[0], point[1]);
|
|
|
|
else {
|
2022-01-02 23:57:35 +03:00
|
|
|
prevPoint = this.currentPixels[index- 1];
|
|
|
|
currFile.VFXLayer.drawLine(Math.floor(prevPoint[0]), Math.floor(prevPoint[1]),
|
|
|
|
Math.floor(point[0]), Math.floor(point[1]), 1);
|
2021-12-29 00:51:18 +03:00
|
|
|
}
|
|
|
|
}
|
2022-01-02 23:57:35 +03:00
|
|
|
|
2022-01-06 01:54:29 +03:00
|
|
|
currFile.VFXLayer.drawLine(Math.floor(point[0]), Math.floor(point[1]),
|
|
|
|
Math.floor(this.currentPixels[0][0]), Math.floor(this.currentPixels[0][1]), 1);
|
2021-12-29 01:38:28 +03:00
|
|
|
}
|
2021-12-27 21:11:59 +03:00
|
|
|
}
|