mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Added back copy / paste
This commit is contained in:
parent
73f7c980eb
commit
cd6d959d35
@ -75,11 +75,9 @@ const Input = (() => {
|
|||||||
//if no document has been created yet or there is a dialog box open ignore hotkeys
|
//if no document has been created yet or there is a dialog box open ignore hotkeys
|
||||||
if (!Startup.documentCreated() || Dialogue.isOpen()) return;
|
if (!Startup.documentCreated() || Dialogue.isOpen()) return;
|
||||||
|
|
||||||
//
|
|
||||||
if (e.key === "Escape") {
|
if (e.key === "Escape") {
|
||||||
if (!selectionCanceled) {
|
console.log("esc");
|
||||||
tool.pencil.switchTo();
|
Events.emit("esc-pressed");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
switch (keyboardEvent.keyCode) {
|
switch (keyboardEvent.keyCode) {
|
||||||
|
@ -3,12 +3,47 @@ class MoveSelectionTool extends Tool {
|
|||||||
selectionTool = undefined;
|
selectionTool = undefined;
|
||||||
endTool = undefined;
|
endTool = undefined;
|
||||||
switchFunc = undefined;
|
switchFunc = undefined;
|
||||||
|
lastCopiedSelection = undefined;
|
||||||
|
|
||||||
constructor (name, options, switchFunc, endTool) {
|
constructor (name, options, switchFunc, endTool) {
|
||||||
super(name, options, switchFunc);
|
super(name, options, switchFunc);
|
||||||
|
|
||||||
this.switchFunc = switchFunc;
|
this.switchFunc = switchFunc;
|
||||||
this.endTool = endTool;
|
this.endTool = endTool;
|
||||||
|
|
||||||
|
Events.onCustom("esc-pressed", this.endSelection.bind(this));
|
||||||
|
|
||||||
|
Events.onCustom("ctrl+c", this.copySelection.bind(this));
|
||||||
|
Events.onCustom("ctrl+x", this.cutSelection.bind(this));
|
||||||
|
Events.onCustom("ctrl+v", this.pasteSelection.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
copySelection() {
|
||||||
|
this.lastCopiedSelection = this.currSelection;
|
||||||
|
}
|
||||||
|
|
||||||
|
cutSelection() {
|
||||||
|
this.lastCopiedSelection = this.currSelection;
|
||||||
|
this.endSelection();
|
||||||
|
this.currSelection = this.lastCopiedSelection;
|
||||||
|
// Cut the data
|
||||||
|
currentLayer.context.clearRect(this.currSelection.left, this.currSelection.top,
|
||||||
|
this.currSelection.width, this.currSelection.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
pasteSelection() {
|
||||||
|
if (this.lastCopiedSelection === undefined)
|
||||||
|
return;
|
||||||
|
// Finish the current selection and start a new one with the same data
|
||||||
|
this.endSelection();
|
||||||
|
this.switchFunc(this);
|
||||||
|
this.currSelection = this.lastCopiedSelection;
|
||||||
|
|
||||||
|
// Putting the vfx layer on top of everything
|
||||||
|
VFXLayer.canvas.style.zIndex = MAX_Z_INDEX;
|
||||||
|
this.onDrag(this.currMousePos);
|
||||||
|
|
||||||
|
new HistoryState().EditCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
onStart(mousePos) {
|
onStart(mousePos) {
|
||||||
@ -22,7 +57,6 @@ class MoveSelectionTool extends Tool {
|
|||||||
onDrag(mousePos) {
|
onDrag(mousePos) {
|
||||||
super.onDrag(mousePos);
|
super.onDrag(mousePos);
|
||||||
|
|
||||||
if (this.cursorInSelectedArea(mousePos)) {
|
|
||||||
this.currSelection = this.selectionTool.moveAnts(mousePos[0]/zoom,
|
this.currSelection = this.selectionTool.moveAnts(mousePos[0]/zoom,
|
||||||
mousePos[1]/zoom, this.currSelection.width, this.currSelection.height);
|
mousePos[1]/zoom, this.currSelection.width, this.currSelection.height);
|
||||||
|
|
||||||
@ -34,7 +68,6 @@ class MoveSelectionTool extends Tool {
|
|||||||
Math.round(mousePos[0] / zoom) - this.currSelection.width / 2,
|
Math.round(mousePos[0] / zoom) - this.currSelection.width / 2,
|
||||||
Math.round(mousePos[1] / zoom) - this.currSelection.height / 2);
|
Math.round(mousePos[1] / zoom) - this.currSelection.height / 2);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
onEnd(mousePos) {
|
onEnd(mousePos) {
|
||||||
super.onEnd(mousePos);
|
super.onEnd(mousePos);
|
||||||
@ -80,6 +113,8 @@ class MoveSelectionTool extends Tool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
endSelection() {
|
endSelection() {
|
||||||
|
if (this.currSelection == undefined)
|
||||||
|
return;
|
||||||
// Clearing the tmp (move preview) and vfx (ants) layers
|
// Clearing the tmp (move preview) and vfx (ants) layers
|
||||||
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);
|
||||||
@ -90,7 +125,7 @@ class MoveSelectionTool extends Tool {
|
|||||||
this.currSelection.left, this.currSelection.top,
|
this.currSelection.left, this.currSelection.top,
|
||||||
this.currSelection.width+1, this.currSelection.height+1
|
this.currSelection.width+1, this.currSelection.height+1
|
||||||
);
|
);
|
||||||
let pasteData = this.currSelection.data.data;
|
let pasteData = this.currSelection.data.data.slice();
|
||||||
|
|
||||||
for (let i=0; i<underlyingImageData.data.length; i+=4) {
|
for (let i=0; i<underlyingImageData.data.length; i+=4) {
|
||||||
let currentMovePixel = [
|
let currentMovePixel = [
|
||||||
@ -105,15 +140,19 @@ class MoveSelectionTool extends Tool {
|
|||||||
// If the pixel of the clipboard is empty, but the one below it isn't, I use the pixel below
|
// If the pixel of the clipboard is empty, but the one below it isn't, I use the pixel below
|
||||||
if (Util.isPixelEmpty(currentMovePixel)) {
|
if (Util.isPixelEmpty(currentMovePixel)) {
|
||||||
if (!Util.isPixelEmpty(currentUnderlyingPixel)) {
|
if (!Util.isPixelEmpty(currentUnderlyingPixel)) {
|
||||||
|
console.log("Original data: " + this.currSelection.data.data[i] + "," +
|
||||||
|
this.currSelection.data.data[i+1], this.currSelection.data.data[i+2]);
|
||||||
|
|
||||||
pasteData[i] = currentUnderlyingPixel[0];
|
pasteData[i] = currentUnderlyingPixel[0];
|
||||||
pasteData[i+1] = currentUnderlyingPixel[1];
|
pasteData[i+1] = currentUnderlyingPixel[1];
|
||||||
pasteData[i+2] = currentUnderlyingPixel[2];
|
pasteData[i+2] = currentUnderlyingPixel[2];
|
||||||
pasteData[i+3] = currentUnderlyingPixel[3];
|
pasteData[i+3] = currentUnderlyingPixel[3];
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Paste: " + pasteData.length + ", underlying: " + underlyingImageData.data.length);
|
console.log("After data: " + this.currSelection.data.data[i] + "," +
|
||||||
|
this.currSelection.data.data[i+1], this.currSelection.data.data[i+2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
currentLayer.context.putImageData(new ImageData(pasteData, this.currSelection.width+1),
|
currentLayer.context.putImageData(new ImageData(pasteData, this.currSelection.width+1),
|
||||||
this.currSelection.left, this.currSelection.top
|
this.currSelection.left, this.currSelection.top
|
||||||
|
@ -94,6 +94,7 @@ class RectangularSelectionTool extends SelectionTool {
|
|||||||
TMPLayer.context.putImageData(this.currSelection.data, this.startMousePos[0], this.startMousePos[1]);
|
TMPLayer.context.putImageData(this.currSelection.data, this.startMousePos[0], this.startMousePos[1]);
|
||||||
|
|
||||||
this.moveTool.setSelectionData(this.currSelection, this);
|
this.moveTool.setSelectionData(this.currSelection, this);
|
||||||
|
console.log("data set");
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelect() {
|
onSelect() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user