Skip to content

Commit 045abb9

Browse files
feat(ui): bbox aspect ratio lock is always inverted by shift
1 parent 2496ac1 commit 045abb9

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

invokeai/frontend/web/src/features/controlLayers/konva/CanvasTool/CanvasBboxToolModule.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const ALL_ANCHORS: string[] = [
3030
'bottom-center',
3131
'bottom-right',
3232
];
33-
const CORNER_ANCHORS: string[] = ['top-left', 'top-right', 'bottom-left', 'bottom-right'];
3433
const NO_ANCHORS: string[] = [];
3534

3635
/**
@@ -344,9 +343,23 @@ export class CanvasBboxToolModule extends CanvasModuleBase {
344343
let width = roundToMultipleMin(this.konva.proxyRect.width() * this.konva.proxyRect.scaleX(), gridSize);
345344
let height = roundToMultipleMin(this.konva.proxyRect.height() * this.konva.proxyRect.scaleY(), gridSize);
346345

347-
// If ratio is locked OR shift is held and we are resizing from a corner, retain aspect ratio - needs special
348-
// handling. We skip this if alt/opt is held - this requires math too big for my brain.
349-
if ((this.manager.stateApi.getBbox().aspectRatio.isLocked || (shift && CORNER_ANCHORS.includes(anchor))) && !alt) {
346+
// When resizing the bbox using the transformer, we may need to do some extra math to maintain the current aspect
347+
// ratio. Need to check a few things to determine if we should be maintaining the aspect ratio or not.
348+
let shouldMaintainAspectRatio = false;
349+
350+
if (alt) {
351+
// If alt is held, we are doing center-anchored transforming. In this case, maintaining aspect ratio is rather
352+
// complicated.
353+
shouldMaintainAspectRatio = false;
354+
} else if (this.manager.stateApi.getBbox().aspectRatio.isLocked) {
355+
// When the aspect ratio is locked, holding shift means we SHOULD NOT maintain the aspect ratio
356+
shouldMaintainAspectRatio = !shift;
357+
} else {
358+
// When the aspect ratio is not locked, holding shift means we SHOULD maintain aspect ratio
359+
shouldMaintainAspectRatio = shift;
360+
}
361+
362+
if (shouldMaintainAspectRatio) {
350363
// Fit the bbox to the last aspect ratio
351364
let fittedWidth = Math.sqrt(width * height * this.$aspectRatioBuffer.get());
352365
let fittedHeight = fittedWidth / this.$aspectRatioBuffer.get();

0 commit comments

Comments
 (0)