From 402f5a4717fe110e4d87e453e5025f79260c943b Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:08:42 +1000 Subject: [PATCH] feat(ui): rotation snap to nearest 45deg when holding shift --- .../features/controlLayers/konva/CanvasLayer.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasLayer.ts b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasLayer.ts index da6480981e..fb48c18434 100644 --- a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasLayer.ts +++ b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasLayer.ts @@ -126,6 +126,15 @@ export class CanvasLayer extends CanvasEntity { return { x: scaledTargetX, y: scaledTargetY }; }); + this.konva.transformer.boundBoxFunc((oldBoundBox, newBoundBox) => { + if (this._manager.stateApi.getShiftKey()) { + if (Math.abs(newBoundBox.rotation % (Math.PI / 4)) > 0) { + return oldBoundBox; + } + } + return newBoundBox; + }); + this.konva.transformer.on('transformstart', () => { this._log.trace( { @@ -249,6 +258,11 @@ export class CanvasLayer extends CanvasEntity { this.isTransforming = false; this._isFirstRender = true; this.isPendingBboxCalculation = false; + + this._manager.stateApi.onShiftChanged((isPressed) => { + // Use shift enable/disable rotation snaps + this.konva.transformer.rotationSnaps(isPressed ? [0, 45, 90, 135, 180, 225, 270, 315] : []); + }); } destroy(): void {