feat(ui): rotation snap to nearest 45deg when holding shift

This commit is contained in:
psychedelicious 2024-08-01 15:08:42 +10:00
parent 81bf52ef37
commit 402f5a4717

View File

@ -126,6 +126,15 @@ export class CanvasLayer extends CanvasEntity {
return { x: scaledTargetX, y: scaledTargetY }; 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.konva.transformer.on('transformstart', () => {
this._log.trace( this._log.trace(
{ {
@ -249,6 +258,11 @@ export class CanvasLayer extends CanvasEntity {
this.isTransforming = false; this.isTransforming = false;
this._isFirstRender = true; this._isFirstRender = true;
this.isPendingBboxCalculation = false; 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 { destroy(): void {