From 378e0f0cd0477c6f40de5d91139c9dcea19fd29f Mon Sep 17 00:00:00 2001 From: unsettledgames <47360416+unsettledgames@users.noreply.github.com> Date: Sat, 7 Mar 2020 23:13:35 +0100 Subject: [PATCH] Fixed bug that deleted the underlying pixels when confirming a selection --- js/_changeTool.js | 2 +- js/_move.js | 28 +++++++++++++++++++++++++++- js/_pixelEditorUtility.js | 7 +++++++ js/_rectSelect.js | 1 + js/pixel-editor.js | 1 + 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 js/_pixelEditorUtility.js diff --git a/js/_changeTool.js b/js/_changeTool.js index 9b59317..25ebcf3 100644 --- a/js/_changeTool.js +++ b/js/_changeTool.js @@ -1,6 +1,6 @@ function changeTool (selectedTool) { // Ending any selection in progress - if (currentTool.includes("select") && !selectedTool.includes("select")) { + if (currentTool.includes("select") && !selectedTool.includes("select") && !selectionCanceled) { endSelection(); } //set tool and temp tje tje tpp; diff --git a/js/_move.js b/js/_move.js index 33ada6d..d3eef89 100644 --- a/js/_move.js +++ b/js/_move.js @@ -1,6 +1,7 @@ var imageDataToMove; var canMoveSelection = false; var lastMovePos; +var selectionCanceled = false; // TODO: move with arrows function updateMovePreview(mouseEvent) { @@ -24,12 +25,37 @@ function endSelection() { // for every element in the selected data // if the current pixel is empty // copy the pixel in the selected data - + 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); + + for (let i=0; i