diff --git a/js/_hotkeyListener.js b/js/_hotkeyListener.js index 6bdd922..13021d4 100644 --- a/js/_hotkeyListener.js +++ b/js/_hotkeyListener.js @@ -13,8 +13,10 @@ function KeyPress(e) { // if (e.key === "Escape") { - endSelection(); - changeTool('pencil'); + if (!selectionCanceled) { + endSelection(); + changeTool('pencil'); + } } else { switch (keyboardEvent.keyCode) { @@ -53,9 +55,18 @@ function KeyPress(e) { //CTRL+ALT+Z redo if (keyboardEvent.altKey && keyboardEvent.ctrlKey) redo(); + if (!selectionCanceled) { + endSelection(); + changeTool('pencil'); + } //CTRL+Z undo - else if (keyboardEvent.ctrlKey) - undo(); + else if (keyboardEvent.ctrlKey) { + undo(); + if (!selectionCanceled) { + endSelection(); + changeTool('pencil'); + } + } //Z switch to zoom tool else changeTool('zoom'); diff --git a/js/_mouseEvents.js b/js/_mouseEvents.js index 262d78c..a590d36 100644 --- a/js/_mouseEvents.js +++ b/js/_mouseEvents.js @@ -127,7 +127,7 @@ window.addEventListener("mouseup", function (mouseEvent) { layers[i].copyData(layers[0]); } } - else if (currentTool == 'rectselect') { + else if (currentTool == 'rectselect' && isRectSelecting) { endRectSelection(mouseEvent); } else if (currentTool == 'rectangle') { @@ -143,6 +143,8 @@ window.addEventListener("mouseup", function (mouseEvent) { }, false); +// OPTIMIZABLE: redundant || mouseEvent.target.className in currentTool ifs + //mouse is moving on canvas window.addEventListener("mousemove", draw, false); function draw (mouseEvent) { @@ -300,13 +302,17 @@ function draw (mouseEvent) { updateCursor(); } else if (currentTool == 'rectselect') { - if (dragging && !isRectSelecting) { + if (dragging && !isRectSelecting && mouseEvent.target.className == 'drawingCanvas') { isRectSelecting = true; + console.log("cominciata selezione su " + mouseEvent.target.className); startRectSelection(mouseEvent); } else if (dragging && isRectSelecting) { updateRectSelection(mouseEvent); } + else if (isRectSelecting) { + endRectSelection(); + } } else if (currentTool == 'moveselection') { // Updating the cursor (move if inside rect, cross if not) diff --git a/js/_move.js b/js/_move.js index cca209a..4b182ca 100644 --- a/js/_move.js +++ b/js/_move.js @@ -2,10 +2,20 @@ var imageDataToMove; var originalDataPosition; var canMoveSelection = false; var lastMovePos; -var selectionCanceled = false; +var selectionCanceled = true; +var firstTimeMove = true; // TODO: move with arrows function updateMovePreview(mouseEvent) { + // ISSUE + selectionCanceled = false; + + if (firstTimeMove) { + cutSelection(mouseEvent); + } + + firstTimeMove = false; + lastMousePos = getCursorPosition(mouseEvent); // clear the entire tmp layer TMPLayer.context.clearRect(0, 0, TMPLayer.canvas.width, TMPLayer.canvas.height); @@ -23,42 +33,40 @@ function endSelection() { TMPLayer.context.clearRect(0, 0, TMPLayer.canvas.width, TMPLayer.canvas.height); VFXLayer.context.clearRect(0, 0, VFXLayer.canvas.width, VFXLayer.canvas.height); - let underlyingImageData = currentLayer.context.getImageData(startX, startY, endX - startX, endY - startY); + if (imageDataToMove !== undefined) { + let underlyingImageData = currentLayer.context.getImageData(startX, startY, endX - startX, endY - startY); + + for (let i=0; i