Improve mask editor integration and mask application logic

Replaces the mask editor's image preparation to use a new method that combines the full image with the current mask, ensuring the editor starts with the correct state. Updates mask application logic to fully replace the mask area instead of blending, and refactors mask extraction and application in CanvasLayers for consistency and correctness, including a new getFlattenedCanvasForMaskEditor method.
This commit is contained in:
Dariusz L
2025-06-29 23:16:22 +02:00
parent abb0f8ef53
commit 2eaa3d6620
2 changed files with 169 additions and 24 deletions

View File

@@ -219,8 +219,9 @@ export class Canvas {
* Uruchamia edytor masek
*/
async startMaskEditor() {
// Dla edytora masek używamy zwykłego spłaszczonego obrazu bez alpha
const blob = await this.canvasLayers.getFlattenedCanvasAsBlob();
// Używamy specjalnej metody która łączy pełny obraz z istniejącą maską
// Dzięki temu edytor masek dostanie pełny obraz z maską jako punkt startowy
const blob = await this.canvasLayers.getFlattenedCanvasForMaskEditor();
if (!blob) {
log.warn("Canvas is empty, cannot open mask editor.");
return;
@@ -446,9 +447,13 @@ export class Canvas {
const destX = -this.maskTool.x;
const destY = -this.maskTool.y;
maskCtx.globalCompositeOperation = 'screen';
maskCtx.drawImage(maskAsImage, destX, destY);
// Zamiast dodawać maskę (screen), zastąp całą maskę (source-over)
// Najpierw wyczyść obszar który będzie zastąpiony
maskCtx.globalCompositeOperation = 'source-over';
maskCtx.clearRect(destX, destY, this.width, this.height);
// Teraz narysuj nową maskę
maskCtx.drawImage(maskAsImage, destX, destY);
this.render();
this.saveState();