Fixed history for canvas edits

This commit is contained in:
unsettledgames 2020-06-23 23:29:13 +02:00
parent 927be7c310
commit 8201099ad5
3 changed files with 17 additions and 14 deletions

View File

@ -33,23 +33,31 @@ function HistoryStateAddLayer() {
//prototype for undoing canvas changes
function HistoryStateEditCanvas () {
this.canvas = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]);
this.canvasState = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]);
this.layerID = currentLayer.id;
this.undo = function () {
var currentCanvas = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]);
currentLayer.context.putImageData(this.canvas, 0, 0);
console.log("id: " + this.layerID);
this.canvas = currentCanvas;
var stateLayer = getLayerByID(this.layerID);
var currentCanvas = stateLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]);
stateLayer.context.putImageData(this.canvasState, 0, 0);
this.canvasState = currentCanvas;
redoStates.push(this);
currentLayer.updateLayerPreview();
stateLayer.updateLayerPreview();
};
this.redo = function () {
var currentCanvas = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]);
currentLayer.context.putImageData(this.canvas, 0, 0);
console.log("id: " + this.layerID);
this.canvas = currentCanvas;
var stateLayer = getLayerByID(this.layerID);
var currentCanvas = stateLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]);
stateLayer.context.putImageData(this.canvasState, 0, 0);
this.canvasState = currentCanvas;
undoStates.push(this);
currentLayer.updateLayerPreview();

View File

@ -30,7 +30,6 @@ function KeyPress(e) {
break;
// copy tool c
case 67: case 99:
console.log("Copying");
if (keyboardEvent.ctrlKey && !dragging && currentTool.name == 'moveselection') {
copySelection();
}
@ -53,7 +52,6 @@ function KeyPress(e) {
break;
// eraser -6, r
case 54: case 82:
console.log("Pressed r");
tool.eraser.switchTo()
break;
// Rectangular selection
@ -62,13 +60,11 @@ function KeyPress(e) {
break;
// Paste tool
case 86: case 118:
console.log("Pasting");
if (keyboardEvent.ctrlKey && !dragging) {
pasteSelection();
}
break;
case 88: case 120:
console.log("Cutting");
if (keyboardEvent.ctrlKey && !dragging && currentTool.name == 'moveselection') {
cutSelectionTool();
tool.pencil.switchTo();
@ -76,7 +72,6 @@ function KeyPress(e) {
break;
//Z
case 90:
console.log('PRESSED Z ', keyboardEvent.ctrlKey)
//CTRL+ALT+Z redo
if (keyboardEvent.altKey && keyboardEvent.ctrlKey)
redo();

View File

@ -81,7 +81,7 @@ class Layer {
currentID++;
}
this.id = id;
this.id = "layer" + id;
if (menuEntry != null) {
menuEntry.id = "layer" + id;