From 908cc1b17c02f705820b08aa39d6574ed9a2f2f1 Mon Sep 17 00:00:00 2001 From: Nicola <47360416+unsettledgames@users.noreply.github.com> Date: Wed, 29 Dec 2021 23:16:16 +0100 Subject: [PATCH] Started lasso selection computing --- js/tools/BrushTool.js | 4 +- js/tools/LassoSelectionTool.js | 86 ++++++++++++++++++++++++++-- js/tools/RectangularSelectionTool.js | 1 - 3 files changed, 83 insertions(+), 8 deletions(-) diff --git a/js/tools/BrushTool.js b/js/tools/BrushTool.js index 70776b9..4ba6508 100644 --- a/js/tools/BrushTool.js +++ b/js/tools/BrushTool.js @@ -22,11 +22,11 @@ class BrushTool extends ResizableTool { currFile.currentLayer.drawLine(Math.floor(this.prevMousePos[0]/currFile.zoom), Math.floor(this.prevMousePos[1]/currFile.zoom), Math.floor(this.currMousePos[0]/currFile.zoom), - Math.floor(this.currMousePos[1]/currFile.zoom), + Math.floor(this.currMousePos[1]/currFile.zoom), this.currSize ); } - + currFile.currentLayer.updateLayerPreview(); } diff --git a/js/tools/LassoSelectionTool.js b/js/tools/LassoSelectionTool.js index 02ade4b..f98b181 100644 --- a/js/tools/LassoSelectionTool.js +++ b/js/tools/LassoSelectionTool.js @@ -1,6 +1,7 @@ class LassoSelectionTool extends SelectionTool { - currentPixels = [] - currSelection = {} + currentPixels = []; + currSelection = {}; + boundingBox = {minX: 9999999, maxX: -1, minY: 9999999, maxY: -1}; constructor (name, options, switchFunc, moveTool) { super(name, options, switchFunc, moveTool); @@ -21,21 +22,33 @@ class LassoSelectionTool extends SelectionTool { onDrag(mousePos) { super.onDrag(mousePos); + let mouseX = mousePos[0] / currFile.zoom; + let mouseY = mousePos[1] / currFile.zoom; + if (this.currentPixels[this.currentPixels.length - 1] != mousePos) this.currentPixels.push([mousePos[0] / currFile.zoom, mousePos[1] / currFile.zoom]); this.drawSelection(); - console.log("here selection"); + + if (mouseX > this.boundingBox.maxX) + this.boundingBox.maxX = Math.floor(mouseX); + if (mouseX < this.boundingBox.minX) + this.boundingBox.minX = Math.floor(mouseX); + if (mouseY < this.boundingBox.minY) + this.boundingBox.minY = Math.floor(mouseY); + if (mouseY > this.boundingBox.maxY) + this.boundingBox.maxY = Math.floor(mouseY); } onEnd(mousePos) { super.onEnd(mousePos); new HistoryState().EditCanvas(); - this.currentPixels.push[this.startMousePos[0] / currFile.zoom, this.startMousePos[1] / currFile.zoom]; + this.currentPixels.push([this.startMousePos[0] / currFile.zoom, this.startMousePos[1] / currFile.zoom]); this.getSelection(); // Switch to the move tool so that the user can move the selection this.switchFunc(this.moveTool); + this.moveTool.setSelectionData(null, this); } onSelect() { @@ -80,7 +93,70 @@ class LassoSelectionTool extends SelectionTool { currFile.VFXLayer.context.closePath(); } - getSelection() { + cursorInSelectedArea(mousePos) { } + + getSelection() { + let selected = []; + if (this.currentPixels.length <= 1){ + return; + } + + for (let x=this.boundingBox.minX; x 1) { + continue; + } + if (isNaN(T1)) { + continue; + } + + intersectionCount++; + } + + if (intersectionCount & 1) + selected.push(toCheck); + } + } + } + + for (let i=0; i