mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Fixed bugs in new selection system
This commit is contained in:
@@ -20,9 +20,13 @@ class SelectionTool extends Tool {
|
||||
this.switchFunc = switchFunc;
|
||||
}
|
||||
|
||||
onStart(mousePos) {
|
||||
onStart(mousePos, mouseTarget) {
|
||||
super.onStart(mousePos);
|
||||
|
||||
if (mouseTarget == undefined || Util.isChildOfByClass(mouseTarget, "editor-top-menu") ||
|
||||
!Util.cursorInCanvas(currFile.canvasSize, [mousePos[0]/currFile.zoom, mousePos[1]/currFile.zoom]))
|
||||
return;
|
||||
|
||||
// Putting the vfx layer on top of everything
|
||||
currFile.VFXLayer.canvas.style.zIndex = MAX_Z_INDEX;
|
||||
currFile.VFXLayer.context.fillStyle = "rgba(0,0,0,1)";
|
||||
@@ -47,6 +51,7 @@ class SelectionTool extends Tool {
|
||||
onDrag(mousePos) {
|
||||
super.onDrag(mousePos);
|
||||
|
||||
console.log("drag");
|
||||
let mouseX = mousePos[0] / currFile.zoom;
|
||||
let mouseY = mousePos[1] / currFile.zoom;
|
||||
|
||||
@@ -65,9 +70,13 @@ class SelectionTool extends Tool {
|
||||
Math.min(Math.max(mouseY, 0), currFile.canvasSize[1]-1));
|
||||
}
|
||||
|
||||
onEnd(mousePos) {
|
||||
onEnd(mousePos, mouseTarget) {
|
||||
super.onEnd(mousePos);
|
||||
|
||||
if (mouseTarget == undefined || Util.isChildOfByClass(mouseTarget, "editor-top-menu") ||
|
||||
!Util.cursorInCanvas(currFile.canvasSize, [mousePos[0]/currFile.zoom, mousePos[1]/currFile.zoom]))
|
||||
return;
|
||||
|
||||
let mouseX = mousePos[0] / currFile.zoom;
|
||||
let mouseY = mousePos[1] / currFile.zoom;
|
||||
|
||||
@@ -232,10 +241,12 @@ class SelectionTool extends Tool {
|
||||
this.previewData = new ImageData(currFile.canvasSize[0], currFile.canvasSize[1]);
|
||||
|
||||
// Cut the selection
|
||||
this.cutSelection();
|
||||
this.cutSelection();
|
||||
// Put it on the TMP layer
|
||||
currFile.TMPLayer.context.putImageData(this.previewData, 0, 0);
|
||||
// Draw the selected area and the bounding box
|
||||
this.drawSelectedArea();
|
||||
this.drawBoundingBox();
|
||||
|
||||
return this.previewData;
|
||||
}
|
||||
@@ -359,6 +370,18 @@ class SelectionTool extends Tool {
|
||||
this.boundingBox.minY + this.moveOffset[1]);
|
||||
}
|
||||
|
||||
drawBoundingBox() {
|
||||
currFile.VFXLayer.context.fillStyle = "red";
|
||||
currFile.VFXLayer.context.fillRect(this.boundingBox.minX + this.moveOffset[0],
|
||||
this.boundingBox.minY + this.moveOffset[1], 1, 1);
|
||||
currFile.VFXLayer.context.fillRect(this.boundingBox.minX+ this.moveOffset[0],
|
||||
this.boundingBox.maxY + this.moveOffset[1], 1, 1);
|
||||
currFile.VFXLayer.context.fillRect(this.boundingBox.maxX+ this.moveOffset[0],
|
||||
this.boundingBox.minY + this.moveOffset[1], 1, 1);
|
||||
currFile.VFXLayer.context.fillRect(this.boundingBox.maxX+ this.moveOffset[0],
|
||||
this.boundingBox.maxY + this.moveOffset[1], 1, 1);
|
||||
}
|
||||
|
||||
isBorderOfBox(pixel) {
|
||||
return pixel[0] == this.boundingBox.minX || pixel[0] == this.boundingBox.maxX ||
|
||||
pixel[1] == this.boundingBox.minY || pixel[1] == this.boundingBox.maxY;
|
||||
|
||||
Reference in New Issue
Block a user