Move setOutputAreaSize

This commit is contained in:
Dariusz L
2025-07-30 11:37:26 +02:00
parent fcb5565a28
commit 3d60c6aafa
4 changed files with 71 additions and 56 deletions

View File

@@ -330,33 +330,10 @@ export class Canvas {
}
/**
* Ustawia nowy rozmiar output area zgodnie z nowym systemem (resetuje rozszerzenia, pozycję, rozmiar)
* (Fasada: deleguje do CanvasLayers)
*/
setOutputAreaSize(width, height) {
// Reset rozszerzeń
this.outputAreaExtensions = { top: 0, bottom: 0, left: 0, right: 0 };
this.outputAreaExtensionEnabled = false;
this.lastOutputAreaExtensions = { top: 0, bottom: 0, left: 0, right: 0 };
// Oblicz środek obecnego output area
const prevBounds = this.outputAreaBounds;
const centerX = prevBounds.x + prevBounds.width / 2;
const centerY = prevBounds.y + prevBounds.height / 2;
// Nowa pozycja lewego górnego rogu, by środek pozostał w miejscu
const newX = centerX - width / 2;
const newY = centerY - height / 2;
// Ustaw nowy rozmiar bazowy i pozycję
this.originalCanvasSize = { width, height };
this.originalOutputAreaPosition = { x: newX, y: newY };
// Ustaw outputAreaBounds na nowy rozmiar i pozycję
this.outputAreaBounds = {
x: newX,
y: newY,
width,
height
};
// Zaktualizuj rozmiar przez istniejącą metodę (ustawia maskę, itp.)
this.updateOutputAreaSize(width, height, true);
this.render();
this.saveState();
this.canvasLayers.setOutputAreaSize(width, height);
}
/**
* Eksportuje spłaszczony canvas jako blob

View File

@@ -492,6 +492,36 @@ export class CanvasLayers {
this.canvas.canvasState.saveStateToDB();
}
}
/**
* Ustawia nowy rozmiar output area względem środka, resetuje rozszerzenia.
*/
setOutputAreaSize(width, height) {
// Reset rozszerzeń
this.canvas.outputAreaExtensions = { top: 0, bottom: 0, left: 0, right: 0 };
this.canvas.outputAreaExtensionEnabled = false;
this.canvas.lastOutputAreaExtensions = { top: 0, bottom: 0, left: 0, right: 0 };
// Oblicz środek obecnego output area
const prevBounds = this.canvas.outputAreaBounds;
const centerX = prevBounds.x + prevBounds.width / 2;
const centerY = prevBounds.y + prevBounds.height / 2;
// Nowa pozycja lewego górnego rogu, by środek pozostał w miejscu
const newX = centerX - width / 2;
const newY = centerY - height / 2;
// Ustaw nowy rozmiar bazowy i pozycję
this.canvas.originalCanvasSize = { width, height };
this.canvas.originalOutputAreaPosition = { x: newX, y: newY };
// Ustaw outputAreaBounds na nowy rozmiar i pozycję
this.canvas.outputAreaBounds = {
x: newX,
y: newY,
width,
height
};
// Zaktualizuj rozmiar przez istniejącą metodę (ustawia maskę, itp.)
this.updateOutputAreaSize(width, height, true);
this.canvas.render();
this.canvas.saveState();
}
getHandles(layer) {
const centerX = layer.x + layer.width / 2;
const centerY = layer.y + layer.height / 2;

View File

@@ -430,39 +430,10 @@ export class Canvas {
/**
* Ustawia nowy rozmiar output area zgodnie z nowym systemem (resetuje rozszerzenia, pozycję, rozmiar)
* (Fasada: deleguje do CanvasLayers)
*/
setOutputAreaSize(width: number, height: number) {
// Reset rozszerzeń
this.outputAreaExtensions = { top: 0, bottom: 0, left: 0, right: 0 };
this.outputAreaExtensionEnabled = false;
this.lastOutputAreaExtensions = { top: 0, bottom: 0, left: 0, right: 0 };
// Oblicz środek obecnego output area
const prevBounds = this.outputAreaBounds;
const centerX = prevBounds.x + prevBounds.width / 2;
const centerY = prevBounds.y + prevBounds.height / 2;
// Nowa pozycja lewego górnego rogu, by środek pozostał w miejscu
const newX = centerX - width / 2;
const newY = centerY - height / 2;
// Ustaw nowy rozmiar bazowy i pozycję
this.originalCanvasSize = { width, height };
this.originalOutputAreaPosition = { x: newX, y: newY };
// Ustaw outputAreaBounds na nowy rozmiar i pozycję
this.outputAreaBounds = {
x: newX,
y: newY,
width,
height
};
// Zaktualizuj rozmiar przez istniejącą metodę (ustawia maskę, itp.)
this.updateOutputAreaSize(width, height, true);
this.render();
this.saveState();
this.canvasLayers.setOutputAreaSize(width, height);
}
/**

View File

@@ -565,6 +565,43 @@ export class CanvasLayers {
}
}
/**
* Ustawia nowy rozmiar output area względem środka, resetuje rozszerzenia.
*/
setOutputAreaSize(width: number, height: number): void {
// Reset rozszerzeń
this.canvas.outputAreaExtensions = { top: 0, bottom: 0, left: 0, right: 0 };
this.canvas.outputAreaExtensionEnabled = false;
this.canvas.lastOutputAreaExtensions = { top: 0, bottom: 0, left: 0, right: 0 };
// Oblicz środek obecnego output area
const prevBounds = this.canvas.outputAreaBounds;
const centerX = prevBounds.x + prevBounds.width / 2;
const centerY = prevBounds.y + prevBounds.height / 2;
// Nowa pozycja lewego górnego rogu, by środek pozostał w miejscu
const newX = centerX - width / 2;
const newY = centerY - height / 2;
// Ustaw nowy rozmiar bazowy i pozycję
this.canvas.originalCanvasSize = { width, height };
this.canvas.originalOutputAreaPosition = { x: newX, y: newY };
// Ustaw outputAreaBounds na nowy rozmiar i pozycję
this.canvas.outputAreaBounds = {
x: newX,
y: newY,
width,
height
};
// Zaktualizuj rozmiar przez istniejącą metodę (ustawia maskę, itp.)
this.updateOutputAreaSize(width, height, true);
this.canvas.render();
this.canvas.saveState();
}
getHandles(layer: Layer): Record<string, Point> {
const centerX = layer.x + layer.width / 2;
const centerY = layer.y + layer.height / 2;