mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Finished copy / cut /paste
Also fixed a minor bug that caused the preview rectangle for the selection tool to not be aligned to the actual selection.
This commit is contained in:
22
js/_move.js
22
js/_move.js
@ -7,7 +7,6 @@ var firstTimeMove = true;
|
||||
|
||||
// TODO: move with arrows
|
||||
function updateMovePreview(mousePosition) {
|
||||
// ISSUE
|
||||
selectionCanceled = false;
|
||||
|
||||
if (firstTimeMove) {
|
||||
@ -22,8 +21,8 @@ function updateMovePreview(mousePosition) {
|
||||
// put the image data with offset
|
||||
TMPLayer.context.putImageData(
|
||||
imageDataToMove,
|
||||
Math.round(lastMousePos[0] / zoom - imageDataToMove.width / 2),
|
||||
Math.round(lastMousePos[1] / zoom - imageDataToMove.height / 2));
|
||||
Math.round(lastMousePos[0] / zoom) - imageDataToMove.width / 2,
|
||||
Math.round(lastMousePos[1] / zoom) - imageDataToMove.height / 2);
|
||||
|
||||
lastMovePos = lastMousePos;
|
||||
moveSelection(lastMousePos[0] / zoom, lastMousePos[1] / zoom, imageDataToMove.width, imageDataToMove.height);
|
||||
@ -32,8 +31,12 @@ function updateMovePreview(mousePosition) {
|
||||
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 cleanImageData = new ImageData(endX - startX, endY - startY);
|
||||
|
||||
if (imageDataToMove !== undefined) {
|
||||
// Saving the current clipboard before editing it in order to merge it with the current layer
|
||||
cleanImageData.data.set(imageDataToMove.data);
|
||||
|
||||
let underlyingImageData = currentLayer.context.getImageData(startX, startY, endX - startX, endY - startY);
|
||||
|
||||
for (let i=0; i<underlyingImageData.data.length; i+=4) {
|
||||
@ -60,12 +63,18 @@ function endSelection() {
|
||||
if (lastMovePos !== undefined) {
|
||||
currentLayer.context.putImageData(
|
||||
imageDataToMove,
|
||||
Math.round(lastMovePos[0] / zoom - imageDataToMove.width / 2),
|
||||
Math.round(lastMovePos[1] / zoom - imageDataToMove.height / 2));
|
||||
Math.round(lastMovePos[0] / zoom) - imageDataToMove.width / 2,
|
||||
Math.round(lastMovePos[1] / zoom) - imageDataToMove.height / 2);
|
||||
}
|
||||
else {
|
||||
undo();
|
||||
console.log("yo");
|
||||
currentLayer.context.putImageData(
|
||||
imageDataToMove,
|
||||
copiedStartX,
|
||||
copiedStartY);
|
||||
}
|
||||
|
||||
imageDataToMove.data.set(cleanImageData.data);
|
||||
}
|
||||
|
||||
selectionCanceled = true;
|
||||
@ -73,4 +82,5 @@ function endSelection() {
|
||||
firstTimeMove = true;
|
||||
imageDataToMove = undefined;
|
||||
isPasting = false;
|
||||
isCutting = false;
|
||||
}
|
Reference in New Issue
Block a user