pixel-editor/js/_move.js

35 lines
1.3 KiB
JavaScript
Raw Normal View History

var imageDataToMove;
2020-03-05 18:13:23 +03:00
var canMoveSelection = false;
var lastMovePos;
2020-03-05 18:13:23 +03:00
// TODO: move with arrows
function updateMovePreview(mouseEvent) {
lastMousePos = getCursorPosition(mouseEvent);
// clear the entire tmp layer
TMPLayer.context.clearRect(0, 0, TMPLayer.canvas.width, TMPLayer.canvas.height);
// 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));
lastMovePos = lastMousePos;
2020-03-05 18:13:23 +03:00
moveSelection(lastMousePos[0] / zoom, lastMousePos[1] / zoom, imageDataToMove.width, imageDataToMove.height)
}
function endSelection() {
2020-03-08 00:40:05 +03:00
// We have to make something smarter:
// Take the selected data
// Take the data underlying the selected data
// for every element in the selected data
// if the current pixel is empty
// copy the pixel in the selected data
2020-03-05 18:13:23 +03:00
TMPLayer.context.clearRect(0, 0, TMPLayer.canvas.width, TMPLayer.canvas.height);
VFXLayer.context.clearRect(0, 0, VFXLayer.canvas.width, VFXLayer.canvas.height);
currentLayer.context.putImageData(
imageDataToMove,
Math.round(lastMovePos[0] / zoom - imageDataToMove.width / 2),
Math.round(lastMovePos[1] / zoom - imageDataToMove.height / 2));
}