mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-21 20:52:12 -03:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user