mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-21 20:52:12 -03:00
Keep Proportion with shift
This commit is contained in:
25
js/Canvas.js
25
js/Canvas.js
@@ -560,7 +560,7 @@ export class Canvas {
|
||||
|
||||
startCanvasMove(worldCoords) {
|
||||
this.interaction.mode = 'movingCanvas';
|
||||
this.interaction.dragStart = { ...worldCoords };
|
||||
this.interaction.dragStart = {...worldCoords};
|
||||
const initialX = this.snapToGrid(worldCoords.x - this.width / 2);
|
||||
const initialY = this.snapToGrid(worldCoords.y - this.height / 2);
|
||||
|
||||
@@ -701,6 +701,29 @@ export class Canvas {
|
||||
let newWidth = vecX * cos + vecY * sin;
|
||||
let newHeight = vecY * cos - vecX * sin;
|
||||
|
||||
if (isShiftPressed) {
|
||||
const originalAspectRatio = o.width / o.height;
|
||||
if (handle.length === 2) {
|
||||
|
||||
const potentialWidth = Math.abs(newWidth);
|
||||
const potentialHeight = Math.abs(newHeight);
|
||||
|
||||
if (potentialWidth / originalAspectRatio > potentialHeight) {
|
||||
newHeight = newWidth / originalAspectRatio;
|
||||
} else {
|
||||
newWidth = newHeight * originalAspectRatio;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (signX !== 0) {
|
||||
newHeight = newWidth / originalAspectRatio;
|
||||
} else {
|
||||
newWidth = newHeight * originalAspectRatio;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let signX = handle.includes('e') ? 1 : (handle.includes('w') ? -1 : 0);
|
||||
let signY = handle.includes('s') ? 1 : (handle.includes('n') ? -1 : 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user