mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Fixed history for canvas edits
This commit is contained in:
parent
927be7c310
commit
8201099ad5
@ -33,23 +33,31 @@ function HistoryStateAddLayer() {
|
|||||||
|
|
||||||
//prototype for undoing canvas changes
|
//prototype for undoing canvas changes
|
||||||
function HistoryStateEditCanvas () {
|
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 () {
|
this.undo = function () {
|
||||||
var currentCanvas = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]);
|
console.log("id: " + this.layerID);
|
||||||
currentLayer.context.putImageData(this.canvas, 0, 0);
|
|
||||||
|
|
||||||
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);
|
redoStates.push(this);
|
||||||
|
|
||||||
currentLayer.updateLayerPreview();
|
stateLayer.updateLayerPreview();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.redo = function () {
|
this.redo = function () {
|
||||||
var currentCanvas = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]);
|
console.log("id: " + this.layerID);
|
||||||
currentLayer.context.putImageData(this.canvas, 0, 0);
|
|
||||||
|
|
||||||
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);
|
undoStates.push(this);
|
||||||
|
|
||||||
currentLayer.updateLayerPreview();
|
currentLayer.updateLayerPreview();
|
||||||
|
@ -30,7 +30,6 @@ function KeyPress(e) {
|
|||||||
break;
|
break;
|
||||||
// copy tool c
|
// copy tool c
|
||||||
case 67: case 99:
|
case 67: case 99:
|
||||||
console.log("Copying");
|
|
||||||
if (keyboardEvent.ctrlKey && !dragging && currentTool.name == 'moveselection') {
|
if (keyboardEvent.ctrlKey && !dragging && currentTool.name == 'moveselection') {
|
||||||
copySelection();
|
copySelection();
|
||||||
}
|
}
|
||||||
@ -53,7 +52,6 @@ function KeyPress(e) {
|
|||||||
break;
|
break;
|
||||||
// eraser -6, r
|
// eraser -6, r
|
||||||
case 54: case 82:
|
case 54: case 82:
|
||||||
console.log("Pressed r");
|
|
||||||
tool.eraser.switchTo()
|
tool.eraser.switchTo()
|
||||||
break;
|
break;
|
||||||
// Rectangular selection
|
// Rectangular selection
|
||||||
@ -62,13 +60,11 @@ function KeyPress(e) {
|
|||||||
break;
|
break;
|
||||||
// Paste tool
|
// Paste tool
|
||||||
case 86: case 118:
|
case 86: case 118:
|
||||||
console.log("Pasting");
|
|
||||||
if (keyboardEvent.ctrlKey && !dragging) {
|
if (keyboardEvent.ctrlKey && !dragging) {
|
||||||
pasteSelection();
|
pasteSelection();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 88: case 120:
|
case 88: case 120:
|
||||||
console.log("Cutting");
|
|
||||||
if (keyboardEvent.ctrlKey && !dragging && currentTool.name == 'moveselection') {
|
if (keyboardEvent.ctrlKey && !dragging && currentTool.name == 'moveselection') {
|
||||||
cutSelectionTool();
|
cutSelectionTool();
|
||||||
tool.pencil.switchTo();
|
tool.pencil.switchTo();
|
||||||
@ -76,7 +72,6 @@ function KeyPress(e) {
|
|||||||
break;
|
break;
|
||||||
//Z
|
//Z
|
||||||
case 90:
|
case 90:
|
||||||
console.log('PRESSED Z ', keyboardEvent.ctrlKey)
|
|
||||||
//CTRL+ALT+Z redo
|
//CTRL+ALT+Z redo
|
||||||
if (keyboardEvent.altKey && keyboardEvent.ctrlKey)
|
if (keyboardEvent.altKey && keyboardEvent.ctrlKey)
|
||||||
redo();
|
redo();
|
||||||
|
@ -81,7 +81,7 @@ class Layer {
|
|||||||
currentID++;
|
currentID++;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.id = id;
|
this.id = "layer" + id;
|
||||||
|
|
||||||
if (menuEntry != null) {
|
if (menuEntry != null) {
|
||||||
menuEntry.id = "layer" + id;
|
menuEntry.id = "layer" + id;
|
||||||
|
Loading…
Reference in New Issue
Block a user