mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Added back copy cut paste
This commit is contained in:
parent
afff386e5f
commit
fa1da7ca4c
@ -63,7 +63,25 @@ class SelectionTool extends Tool {
|
|||||||
this.boundingBox.minY + (this.boundingBox.maxY - this.boundingBox.minY) / 2];
|
this.boundingBox.minY + (this.boundingBox.maxY - this.boundingBox.minY) / 2];
|
||||||
}
|
}
|
||||||
|
|
||||||
cutSelection() {}
|
cutSelection() {
|
||||||
|
let currLayerData = currFile.currentLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]).data;
|
||||||
|
|
||||||
|
// Save the selected pixels so that they can be moved and pasted back in the right place
|
||||||
|
for (const key in this.currSelection) {
|
||||||
|
let x = parseInt(key.split(",")[0]);
|
||||||
|
let y = parseInt(key.split(",")[1]);
|
||||||
|
let index = (y * currFile.canvasSize[1] + x) * 4;
|
||||||
|
|
||||||
|
for (let i=0; i<4; i++) {
|
||||||
|
// Save the pixel
|
||||||
|
this.previewData.data[index + i] = currLayerData[index + i];
|
||||||
|
// Delete the data below
|
||||||
|
currLayerData[index + i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currFile.currentLayer.context.putImageData(new ImageData(currLayerData, currFile.canvasSize[0]), 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
pasteSelection(){
|
pasteSelection(){
|
||||||
if (this.currSelection == undefined)
|
if (this.currSelection == undefined)
|
||||||
@ -106,7 +124,9 @@ class SelectionTool extends Tool {
|
|||||||
currFile.VFXLayer.canvas.style.zIndex = MIN_Z_INDEX;
|
currFile.VFXLayer.canvas.style.zIndex = MIN_Z_INDEX;
|
||||||
}
|
}
|
||||||
|
|
||||||
copySelection(){}
|
copySelection() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
cursorInSelectedArea(mousePos) {
|
cursorInSelectedArea(mousePos) {
|
||||||
let floored = [Math.floor(mousePos[0] / currFile.zoom) - this.moveOffset[0],
|
let floored = [Math.floor(mousePos[0] / currFile.zoom) - this.moveOffset[0],
|
||||||
@ -175,7 +195,6 @@ class SelectionTool extends Tool {
|
|||||||
let selected = [];
|
let selected = [];
|
||||||
let visited = {};
|
let visited = {};
|
||||||
let data = currFile.VFXLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]).data;
|
let data = currFile.VFXLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]).data;
|
||||||
let currLayerData = currFile.currentLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]).data;
|
|
||||||
|
|
||||||
// BFS: a pixel that causes the algorithm to visit a pixel of the bounding box is outside the
|
// BFS: a pixel that causes the algorithm to visit a pixel of the bounding box is outside the
|
||||||
// selection. Otherwise, since the algorithm stops visiting when it reaches the outline,
|
// selection. Otherwise, since the algorithm stops visiting when it reaches the outline,
|
||||||
@ -200,23 +219,10 @@ class SelectionTool extends Tool {
|
|||||||
// Create the image data containing the selected pixels
|
// Create the image data containing the selected pixels
|
||||||
this.previewData = new ImageData(currFile.canvasSize[0], currFile.canvasSize[1]);
|
this.previewData = new ImageData(currFile.canvasSize[0], currFile.canvasSize[1]);
|
||||||
|
|
||||||
// Save the selected pixels so that they can be moved and pasted back in the right place
|
// Cut the selection
|
||||||
for (const key in this.currSelection) {
|
this.cutSelection();
|
||||||
let x = parseInt(key.split(",")[0]);
|
// Put it on the TMP layer
|
||||||
let y = parseInt(key.split(",")[1]);
|
|
||||||
let index = (y * currFile.canvasSize[1] + x) * 4;
|
|
||||||
|
|
||||||
for (let i=0; i<4; i++) {
|
|
||||||
// Save the pixel
|
|
||||||
this.previewData.data[index + i] = currLayerData[index + i];
|
|
||||||
// Delete the data below
|
|
||||||
currLayerData[index + i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
currFile.currentLayer.context.putImageData(new ImageData(currLayerData, currFile.canvasSize[0]), 0, 0);
|
|
||||||
currFile.TMPLayer.context.putImageData(this.previewData, 0, 0);
|
currFile.TMPLayer.context.putImageData(this.previewData, 0, 0);
|
||||||
|
|
||||||
this.drawSelectedArea();
|
this.drawSelectedArea();
|
||||||
|
|
||||||
return this.previewData;
|
return this.previewData;
|
||||||
|
Loading…
Reference in New Issue
Block a user