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:
parent
9324a6a57e
commit
378e0f0cd0
@ -1,6 +1,6 @@
|
|||||||
function changeTool (selectedTool) {
|
function changeTool (selectedTool) {
|
||||||
// Ending any selection in progress
|
// Ending any selection in progress
|
||||||
if (currentTool.includes("select") && !selectedTool.includes("select")) {
|
if (currentTool.includes("select") && !selectedTool.includes("select") && !selectionCanceled) {
|
||||||
endSelection();
|
endSelection();
|
||||||
}
|
}
|
||||||
//set tool and temp tje tje tpp;
|
//set tool and temp tje tje tpp;
|
||||||
|
28
js/_move.js
28
js/_move.js
@ -1,6 +1,7 @@
|
|||||||
var imageDataToMove;
|
var imageDataToMove;
|
||||||
var canMoveSelection = false;
|
var canMoveSelection = false;
|
||||||
var lastMovePos;
|
var lastMovePos;
|
||||||
|
var selectionCanceled = false;
|
||||||
|
|
||||||
// TODO: move with arrows
|
// TODO: move with arrows
|
||||||
function updateMovePreview(mouseEvent) {
|
function updateMovePreview(mouseEvent) {
|
||||||
@ -24,12 +25,37 @@ function endSelection() {
|
|||||||
// for every element in the selected data
|
// for every element in the selected data
|
||||||
// if the current pixel is empty
|
// if the current pixel is empty
|
||||||
// copy the pixel in the selected data
|
// copy the pixel in the selected data
|
||||||
|
|
||||||
TMPLayer.context.clearRect(0, 0, TMPLayer.canvas.width, TMPLayer.canvas.height);
|
TMPLayer.context.clearRect(0, 0, TMPLayer.canvas.width, TMPLayer.canvas.height);
|
||||||
VFXLayer.context.clearRect(0, 0, VFXLayer.canvas.width, VFXLayer.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(
|
currentLayer.context.putImageData(
|
||||||
imageDataToMove,
|
imageDataToMove,
|
||||||
Math.round(lastMovePos[0] / zoom - imageDataToMove.width / 2),
|
Math.round(lastMovePos[0] / zoom - imageDataToMove.width / 2),
|
||||||
Math.round(lastMovePos[1] / zoom - imageDataToMove.height / 2));
|
Math.round(lastMovePos[1] / zoom - imageDataToMove.height / 2));
|
||||||
|
|
||||||
|
selectionCanceled = true;
|
||||||
}
|
}
|
7
js/_pixelEditorUtility.js
Normal file
7
js/_pixelEditorUtility.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
function isPixelEmpty(pixel) {
|
||||||
|
if ((pixel[0] == 0 && pixel[1] == 0 && pixel[2] == 0) || pixel[3] == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
@ -30,6 +30,7 @@ function startRectSelection(mouseEvent) {
|
|||||||
|
|
||||||
// Drawing the rect
|
// Drawing the rect
|
||||||
drawRect(startX, startY);
|
drawRect(startX, startY);
|
||||||
|
selectionCanceled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateRectSelection(mouseEvent) {
|
function updateRectSelection(mouseEvent) {
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
//=include utilities/rgbToHsl.js
|
//=include utilities/rgbToHsl.js
|
||||||
//=include utilities/hslToRgb.js
|
//=include utilities/hslToRgb.js
|
||||||
//=include libraries/cookies.js
|
//=include libraries/cookies.js
|
||||||
|
//=include _pixelEditorUtility.js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user