mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Started commenting code
This commit is contained in:
@ -1,11 +1,17 @@
|
||||
// Data saved when copying or cutting
|
||||
let clipboardData;
|
||||
// Tells if the user is pasting something or not
|
||||
let isPasting = false;
|
||||
|
||||
// Coordinates of the copied (or cut) selection
|
||||
let copiedStartX;
|
||||
let copiedStartY;
|
||||
let copiedEndX;
|
||||
let copiedEndY;
|
||||
|
||||
/** Copies the current selection to the clipboard
|
||||
*
|
||||
*/
|
||||
function copySelection() {
|
||||
copiedEndX = endX;
|
||||
copiedEndY = endY;
|
||||
@ -16,13 +22,19 @@ function copySelection() {
|
||||
clipboardData = currentLayer.context.getImageData(startX, startY, endX - startX + 1, endY - startY + 1);
|
||||
}
|
||||
|
||||
/** Pastes the clipboard data onto the current layer
|
||||
*
|
||||
*/
|
||||
function pasteSelection() {
|
||||
// Can't paste if the layer is locked
|
||||
if (currentLayer.isLocked) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Cancel the current selection
|
||||
endSelection();
|
||||
|
||||
// I'm pasting
|
||||
isPasting = true;
|
||||
// Putting the image data on the tmp layer
|
||||
TMPLayer.context.putImageData(clipboardData, copiedStartX, copiedStartY);
|
||||
@ -43,9 +55,11 @@ function pasteSelection() {
|
||||
//drawRect(copiedStartX, copiedEndX, copiedStartY, copiedEndY);
|
||||
}
|
||||
|
||||
/** Cuts the current selection and copies it to the clipboard
|
||||
*
|
||||
*/
|
||||
function cutSelectionTool() {
|
||||
console.log("Taglio");
|
||||
|
||||
// Saving the coordinates
|
||||
copiedEndX = endX;
|
||||
copiedEndY = endY;
|
||||
|
||||
@ -53,13 +67,19 @@ function cutSelectionTool() {
|
||||
copiedStartY = startY;
|
||||
|
||||
// Getting the selected pixels
|
||||
// If I'm already moving a selection
|
||||
if (imageDataToMove !== undefined) {
|
||||
// I just save that selection in the clipboard
|
||||
clipboardData = imageDataToMove;
|
||||
// And clear the underlying space
|
||||
TMPLayer.context.clearRect(0, 0, TMPLayer.canvas.width, TMPLayer.canvas.height);
|
||||
// The image has been cleared, so I don't have anything to move anymore
|
||||
imageDataToMove = undefined;
|
||||
}
|
||||
else {
|
||||
clipboardData = currentLayer.context.getImageData(startX, startY, endX - startX + 1, endY - startY + 1);
|
||||
// Otherwise, I copy the current selection into the clipboard
|
||||
copySelection();
|
||||
// And clear the selection
|
||||
currentLayer.context.clearRect(startX - 0.5, startY - 0.5, endX - startX + 1, endY - startY + 1);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user