Update to clipping context while drawing

This commit is contained in:
Igor Zinken
2025-03-16 12:17:59 +01:00
parent dbafae9984
commit b765404704
3 changed files with 6 additions and 5 deletions

View File

@@ -728,7 +728,7 @@ export default class LayerRenderer extends ZoomableSprite {
if ( clipContext ) {
// when the layer if offset/transformed and there is no active selection, clip the out of bounds content
documentContext.save();
clipLayer( documentContext, this.layer, this._bounds, viewport, this._invertSelection );
clipLayer( documentContext, this.layer, this._bounds, viewport, false );
}
renderDrawableCanvas(
isDrawingOnMask ? drawContext : documentContext, this.getPaintSize(), this.canvas, this._brush.options.opacity,

View File

@@ -80,8 +80,9 @@ export const createInverseClipping = ( ctx: CanvasRenderingContext2D, shape: Sha
/**
* Clip the output of a LayerRenderer to not exceed the Layers bounds (in case it is offset or transformed).
* This is not necessary as zCanvas will automatically crop the bitmaps, however during live preview while
* drawing on the Layer, it helps to clip the contents of the overlaid drawable Canvas.
* This is not necessary as zCanvas will automatically crop the bitmaps on render, however during live preview while
* drawing on the Layer, we should clip the contents of the overlaid drawable Canvas to hide content that will
* be clipped after committing the drawing.
*/
export const clipLayer = ( ctx: CanvasRenderingContext2D, layer: Layer, rendererBounds: Rectangle, viewport: Viewport, invert = false ): void => {
const { scale, rotation, mirrorY } = layer.effects;

View File

@@ -366,7 +366,7 @@ describe( "LayerRenderer", () => {
renderer.draw( ctx, viewport );
expect( mockRenderOperation ).toHaveBeenCalledWith(
"clipLayer", ctx, renderer.layer, renderer.getBounds(), viewport, undefined
"clipLayer", ctx, renderer.layer, renderer.getBounds(), viewport, false
);
});
@@ -376,7 +376,7 @@ describe( "LayerRenderer", () => {
renderer.draw( ctx, viewport );
expect( mockRenderOperation ).toHaveBeenCalledWith(
"clipLayer", ctx, renderer.layer, renderer.getBounds(), viewport, undefined
"clipLayer", ctx, renderer.layer, renderer.getBounds(), viewport, false
);
});
});