Add world-space positioning and resizing for mask tool

Introduces x/y coordinates to MaskTool for world-space positioning, allowing the mask to extend beyond the output area. Updates mask drawing, export, and rendering logic to account for mask position. Ensures mask position is updated when moving or resizing the canvas, and preserves mask content during canvas resizing. Improves mask extraction and rendering accuracy.
This commit is contained in:
Dariusz L
2025-06-26 22:09:28 +02:00
parent f2998f0f08
commit daf3abeea7
4 changed files with 162 additions and 38 deletions

View File

@@ -82,16 +82,24 @@ export class CanvasRenderer {
this.drawCanvasOutline(ctx);
const maskImage = this.canvas.maskTool.getMask();
if (this.canvas.maskTool.isActive) {
ctx.globalCompositeOperation = 'source-over';
ctx.globalAlpha = 0.5;
ctx.drawImage(maskImage, 0, 0);
ctx.globalAlpha = 1.0;
} else if (maskImage) {
ctx.globalCompositeOperation = 'source-over';
ctx.globalAlpha = 1.0;
ctx.drawImage(maskImage, 0, 0);
if (maskImage) {
// Create a clipping region to only show mask content that overlaps with the output area
ctx.save();
// Only show what's visible inside the output area
if (this.canvas.maskTool.isActive) {
ctx.globalCompositeOperation = 'source-over';
ctx.globalAlpha = 0.5;
} else {
ctx.globalCompositeOperation = 'source-over';
ctx.globalAlpha = 1.0;
}
// Draw the mask at its world space position
ctx.drawImage(maskImage, this.canvas.maskTool.x, this.canvas.maskTool.y);
ctx.globalAlpha = 1.0;
ctx.restore();
}
this.renderInteractionElements(ctx);