mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
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:
@ -64,14 +64,21 @@ function changedSize(event) {
|
||||
borders.bottom = bottom;
|
||||
}
|
||||
|
||||
function resizeCanvas(event) {
|
||||
function resizeCanvas(event, size) {
|
||||
let imageDatas = [];
|
||||
let leftOffset = 0;
|
||||
let topOffset = 0;
|
||||
let copiedDataIndex = 0;
|
||||
|
||||
// If I'm undoing, I manually put the values in the window
|
||||
if (size !== undefined) {
|
||||
document.getElementById("rc-width").value = size.x;
|
||||
document.getElementById("rc-height").value = size.y;
|
||||
|
||||
changedSize();
|
||||
}
|
||||
|
||||
rcUpdateBorders();
|
||||
changedSize();
|
||||
|
||||
// Save all imageDatas
|
||||
for (let i=0; i<layers.length; i++) {
|
||||
@ -80,6 +87,19 @@ function resizeCanvas(event) {
|
||||
}
|
||||
}
|
||||
|
||||
// Saving the history only if I'm not already undoing or redoing
|
||||
if (size == undefined) {
|
||||
// Saving history
|
||||
new HistoryStateResizeCanvas(
|
||||
{x: parseInt(layers[0].canvasSize[0]) + borders.left + borders.right,
|
||||
y: parseInt(layers[0].canvasSize[1]) + borders.top + borders.bottom},
|
||||
|
||||
{x: layers[0].canvasSize[0],
|
||||
y: layers[0].canvasSize[1]},
|
||||
imageDatas
|
||||
);
|
||||
}
|
||||
|
||||
// Resize the canvases
|
||||
for (let i=0; i<layers.length; i++) {
|
||||
layers[i].canvasSize[0] = parseInt(layers[i].canvasSize[0]) + borders.left + borders.right;
|
||||
@ -135,13 +155,14 @@ function resizeCanvas(event) {
|
||||
topOffset = borders.top + borders.bottom;
|
||||
break;
|
||||
default:
|
||||
console.log('now thats a very weird pivot');
|
||||
console.log('Pivot does not exist, please report an issue at https://github.com/lospec/pixel-editor');
|
||||
break;
|
||||
}
|
||||
|
||||
for (let i=0; i<layers.length; i++) {
|
||||
if (layers[i].menuEntry != null) {
|
||||
layers[i].context.putImageData(imageDatas[copiedDataIndex], leftOffset, topOffset);
|
||||
layers[i].updateLayerPreview();
|
||||
copiedDataIndex++;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user