mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Fixed bug that deleted the underlying pixels when confirming a selection
This commit is contained in:
28
js/_move.js
28
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<underlyingImageData.data.length; i+=4) {
|
||||
let currentMovePixel = [
|
||||
imageDataToMove.data[i], imageDataToMove.data[i+1],
|
||||
imageDataToMove.data[i+2], imageDataToMove.data[i+3]
|
||||
];
|
||||
|
||||
let currentUnderlyingPixel = [
|
||||
underlyingImageData.data[i], underlyingImageData.data[i+1],
|
||||
underlyingImageData.data[i+2], underlyingImageData.data[i+3]
|
||||
];
|
||||
|
||||
if (isPixelEmpty(currentMovePixel)) {
|
||||
if (!isPixelEmpty(underlyingImageData)) {
|
||||
imageDataToMove.data[i] = currentUnderlyingPixel[0];
|
||||
imageDataToMove.data[i+1] = currentUnderlyingPixel[1];
|
||||
imageDataToMove.data[i+2] = currentUnderlyingPixel[2];
|
||||
imageDataToMove.data[i+3] = currentUnderlyingPixel[3];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentLayer.context.putImageData(
|
||||
imageDataToMove,
|
||||
Math.round(lastMovePos[0] / zoom - imageDataToMove.width / 2),
|
||||
Math.round(lastMovePos[1] / zoom - imageDataToMove.height / 2));
|
||||
|
||||
selectionCanceled = true;
|
||||
}
|
Reference in New Issue
Block a user