Use cursor delta to resize shape (#341)

This commit is contained in:
Guillermo Peralta Scura 2020-01-12 14:05:08 -03:00 committed by Christopher Chedeau
parent abf2aaa102
commit c67435719f

View File

@ -636,36 +636,42 @@ export class App extends React.Component<{}, AppState> {
if (selectedElements.length === 1) { if (selectedElements.length === 1) {
const { x, y } = viewportCoordsToSceneCoords(e, this.state); const { x, y } = viewportCoordsToSceneCoords(e, this.state);
let deltaX = 0;
let deltaY = 0;
selectedElements.forEach(element => { selectedElements.forEach(element => {
switch (resizeHandle) { switch (resizeHandle) {
case "nw": case "nw":
element.width += element.x - lastX; deltaX = lastX - x;
element.x = lastX; element.width += deltaX;
element.x -= deltaX;
if (e.shiftKey) { if (e.shiftKey) {
element.y += element.height - element.width; element.y += element.height - element.width;
element.height = element.width; element.height = element.width;
} else { } else {
element.height += element.y - lastY; const deltaY = lastY - y;
element.y = lastY; element.height += deltaY;
element.y -= deltaY;
} }
break; break;
case "ne": case "ne":
element.width = lastX - element.x; element.width += x - lastX;
if (e.shiftKey) { if (e.shiftKey) {
element.y += element.height - element.width; element.y += element.height - element.width;
element.height = element.width; element.height = element.width;
} else { } else {
element.height += element.y - lastY; deltaY = lastY - y;
element.y = lastY; element.height += deltaY;
element.y -= deltaY;
} }
break; break;
case "sw": case "sw":
element.width += element.x - lastX; deltaX = lastX - x;
element.x = lastX; element.width += deltaX;
element.x -= deltaX;
if (e.shiftKey) { if (e.shiftKey) {
element.height = element.width; element.height = element.width;
} else { } else {
element.height = lastY - element.y; element.height += y - lastY;
} }
break; break;
case "se": case "se":
@ -677,18 +683,20 @@ export class App extends React.Component<{}, AppState> {
} }
break; break;
case "n": case "n":
element.height += element.y - lastY; deltaY = lastY - y;
element.y = lastY; element.height += deltaY;
element.y -= deltaY;
break; break;
case "w": case "w":
element.width += element.x - lastX; deltaX = lastX - x;
element.x = lastX; element.width += deltaX;
element.x -= deltaX;
break; break;
case "s": case "s":
element.height = lastY - element.y; element.height += y - lastY;
break; break;
case "e": case "e":
element.width = lastX - element.x; element.width += x - lastX;
break; break;
} }