feat: hold shift to create square selection in rectangle-select tool
This commit is contained in:
parent
ff55954a75
commit
8dd7fa684e
1 changed files with 15 additions and 4 deletions
|
|
@ -265,14 +265,25 @@ function Canvas() {
|
||||||
const newSelection: CoordinateArray = [];
|
const newSelection: CoordinateArray = [];
|
||||||
|
|
||||||
const startX = Math.min(dragStartCoords.x, mouseCoords.x);
|
const startX = Math.min(dragStartCoords.x, mouseCoords.x);
|
||||||
const endX = Math.max(dragStartCoords.x, mouseCoords.x);
|
let endX = Math.max(dragStartCoords.x, mouseCoords.x);
|
||||||
const startY = Math.min(dragStartCoords.y, mouseCoords.y);
|
const startY = Math.min(dragStartCoords.y, mouseCoords.y);
|
||||||
const endY = Math.max(dragStartCoords.y, mouseCoords.y);
|
let endY = Math.max(dragStartCoords.y, mouseCoords.y);
|
||||||
|
|
||||||
const isRadiusEven = radius == 1 || radius % 2 == 0;
|
const isRadiusEven = radius == 1 || radius % 2 == 0;
|
||||||
|
const radiusOffset = isRadiusEven ? radius : radius - 1;
|
||||||
|
|
||||||
for (let x = startX; x < endX + (isRadiusEven ? radius : radius - 1); x++) {
|
// If holding shift, create a square selection
|
||||||
for (let y = startY; y < endY + (isRadiusEven ? radius : radius - 1); y++) {
|
if (holdingShiftRef.current) {
|
||||||
|
const width = Math.abs(endX - startX);
|
||||||
|
const height = Math.abs(endY - startY);
|
||||||
|
const size = Math.max(width, height);
|
||||||
|
|
||||||
|
endX = startX + (endX < startX ? -size : size);
|
||||||
|
endY = startY + (endY < startY ? -size : size);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let x = startX; x < endX + radiusOffset; x++) {
|
||||||
|
for (let y = startY; y < endY + radiusOffset; y++) {
|
||||||
newSelection.push([x, y]);
|
newSelection.push([x, y]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue