Added history states for canvas resizing

Must fix bug that happens when creating a new layer after resizing the canvas
This commit is contained in:
unsettledgames
2020-09-15 13:06:31 +02:00
parent 663b714b46
commit b7d5f603b1
6 changed files with 71 additions and 12 deletions

View File

@@ -3,6 +3,35 @@ var redoStates = [];
const undoLogStyle = 'background: #87ff1c; color: black; padding: 5px;';
function HistoryStateResizeCanvas(newSize, oldSize, imageDatas) {
this.oldSize = oldSize;
this.newSize = newSize;
this.imageDatas = imageDatas;
this.undo = function() {
let dataIndex = 0;
console.log("breakpoint");
// Resizing the canvas
resizeCanvas(null, oldSize);
// Putting the image datas
for (let i=0; i<imageDatas.length; i++) {
if (layers[i].menuEntry != null) {
layers[i].context.putImageData(imageDatas[dataIndex], 0, 0);
dataIndex++;
}
}
redoStates.push(this);
};
this.redo = function() {
resizeCanvas(null, newSize);
undoStates.push(this);
};
saveHistoryState(this);
}
function HistoryStateFlattenVisible(flattened) {
this.nFlattened = flattened;