Add mask editor integration to canvas workflow

Introduces the ability to open the current canvas in a mask editor, upload and retrieve mask edits, and apply them to the mask layer. Adds utility functions for mask editor state detection and control, a new 'Edit Mask' button in the UI, and methods for handling mask updates and preview refresh. Also adds a setMask method to MaskTool for precise mask placement.
This commit is contained in:
Dariusz L
2025-06-29 04:15:45 +02:00
parent fc8ebedb1e
commit 7a7c8f2295
5 changed files with 245 additions and 0 deletions

View File

@@ -279,4 +279,26 @@ export class MaskTool {
this.y += dy;
log.info(`Mask position updated to (${this.x}, ${this.y})`);
}
setMask(image) {
// `this.x` i `this.y` przechowują pozycję lewego górnego rogu płótna maski
// względem lewego górnego rogu widoku. Zatem (-this.x, -this.y) to pozycja
// lewego górnego rogu widoku na płótnie maski.
const destX = -this.x;
const destY = -this.y;
// Wyczyść tylko ten obszar na dużym płótnie maski, który odpowiada
// widocznemu obszarowi wyjściowemu.
this.maskCtx.clearRect(destX, destY, this.canvasInstance.width, this.canvasInstance.height);
// Narysuj nowy obraz maski (który ma rozmiar obszaru wyjściowego)
// dokładnie w tym wyczyszczonym miejscu.
this.maskCtx.drawImage(image, destX, destY);
if (this.onStateChange) {
this.onStateChange();
}
this.canvasInstance.render(); // Wymuś odświeżenie, aby zobaczyć zmianę
log.info(`MaskTool updated with a new mask image at correct canvas position (${destX}, ${destY}).`);
}
}