From 8d6cd783ec742ee5142b96eb59f93e0e9004bbf8 Mon Sep 17 00:00:00 2001 From: Dariusz L Date: Sun, 27 Jul 2025 21:17:52 +0200 Subject: [PATCH] Restore and save outputAreaBounds in CanvasState Adds logic to restore outputAreaBounds from saved state if available, or fallback to a default for legacy saves. Also ensures outputAreaBounds is included when saving state, improving consistency across sessions. --- js/CanvasState.js | 16 ++++++++++++++++ src/CanvasState.ts | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/js/CanvasState.js b/js/CanvasState.js index 93530a0..e717510 100644 --- a/js/CanvasState.js +++ b/js/CanvasState.js @@ -68,6 +68,21 @@ export class CanvasState { y: -(this.canvas.height / 4), zoom: 0.8 }; + // Restore outputAreaBounds if saved, otherwise use default + if (savedState.outputAreaBounds) { + this.canvas.outputAreaBounds = savedState.outputAreaBounds; + log.debug(`Output Area bounds restored: x=${this.canvas.outputAreaBounds.x}, y=${this.canvas.outputAreaBounds.y}, w=${this.canvas.outputAreaBounds.width}, h=${this.canvas.outputAreaBounds.height}`); + } + else { + // Fallback to default positioning for legacy saves + this.canvas.outputAreaBounds = { + x: -(this.canvas.width / 4), + y: -(this.canvas.height / 4), + width: this.canvas.width, + height: this.canvas.height + }; + log.debug(`Output Area bounds set to default: x=${this.canvas.outputAreaBounds.x}, y=${this.canvas.outputAreaBounds.y}, w=${this.canvas.outputAreaBounds.width}, h=${this.canvas.outputAreaBounds.height}`); + } this.canvas.canvasLayers.updateOutputAreaSize(this.canvas.width, this.canvas.height, false); log.debug(`Output Area resized to ${this.canvas.width}x${this.canvas.height} and viewport set.`); const loadedLayers = await this._loadLayers(savedState.layers); @@ -229,6 +244,7 @@ export class CanvasState { viewport: this.canvas.viewport, width: this.canvas.width, height: this.canvas.height, + outputAreaBounds: this.canvas.outputAreaBounds, }; if (state.layers.length === 0) { log.warn("No valid layers to save, skipping."); diff --git a/src/CanvasState.ts b/src/CanvasState.ts index c3477e7..c58f0e7 100644 --- a/src/CanvasState.ts +++ b/src/CanvasState.ts @@ -98,6 +98,21 @@ export class CanvasState { zoom: 0.8 }; + // Restore outputAreaBounds if saved, otherwise use default + if (savedState.outputAreaBounds) { + this.canvas.outputAreaBounds = savedState.outputAreaBounds; + log.debug(`Output Area bounds restored: x=${this.canvas.outputAreaBounds.x}, y=${this.canvas.outputAreaBounds.y}, w=${this.canvas.outputAreaBounds.width}, h=${this.canvas.outputAreaBounds.height}`); + } else { + // Fallback to default positioning for legacy saves + this.canvas.outputAreaBounds = { + x: -(this.canvas.width / 4), + y: -(this.canvas.height / 4), + width: this.canvas.width, + height: this.canvas.height + }; + log.debug(`Output Area bounds set to default: x=${this.canvas.outputAreaBounds.x}, y=${this.canvas.outputAreaBounds.y}, w=${this.canvas.outputAreaBounds.width}, h=${this.canvas.outputAreaBounds.height}`); + } + this.canvas.canvasLayers.updateOutputAreaSize(this.canvas.width, this.canvas.height, false); log.debug(`Output Area resized to ${this.canvas.width}x${this.canvas.height} and viewport set.`); const loadedLayers = await this._loadLayers(savedState.layers); @@ -264,6 +279,7 @@ export class CanvasState { viewport: this.canvas.viewport, width: this.canvas.width, height: this.canvas.height, + outputAreaBounds: this.canvas.outputAreaBounds, }; if (state.layers.length === 0) {