diff --git a/js/Canvas.js b/js/Canvas.js index 7f4c847..466b3bd 100644 --- a/js/Canvas.js +++ b/js/Canvas.js @@ -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 diff --git a/js/CanvasLayers.js b/js/CanvasLayers.js index 537a3a4..8d91ffa 100644 --- a/js/CanvasLayers.js +++ b/js/CanvasLayers.js @@ -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; diff --git a/src/Canvas.ts b/src/Canvas.ts index 405b483..0336382 100644 --- a/src/Canvas.ts +++ b/src/Canvas.ts @@ -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); } /** diff --git a/src/CanvasLayers.ts b/src/CanvasLayers.ts index 0e3e1a6..7aa7b97 100644 --- a/src/CanvasLayers.ts +++ b/src/CanvasLayers.ts @@ -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 { const centerX = layer.x + layer.width / 2; const centerY = layer.y + layer.height / 2;