Allow dragging transparent elements when selected (#508)

* Allow dragging transparent elements when selected

Addresses #339

* Update package.json
This commit is contained in:
Dvir Azulay 2020-01-22 00:10:49 -05:00 committed by Christopher Chedeau
parent d30498a289
commit a856ce06e9

View File

@ -8,6 +8,10 @@ import {
getLinePoints getLinePoints
} from "./bounds"; } from "./bounds";
function isElementDraggableFromInside(element: ExcalidrawElement): boolean {
return element.backgroundColor !== "transparent" || element.isSelected;
}
export function hitTest( export function hitTest(
element: ExcalidrawElement, element: ExcalidrawElement,
x: number, x: number,
@ -51,7 +55,7 @@ export function hitTest(
ty /= t; ty /= t;
}); });
if (element.backgroundColor !== "transparent") { if (isElementDraggableFromInside(element)) {
return ( return (
a * tx - (px - lineThreshold) >= 0 && b * ty - (py - lineThreshold) >= 0 a * tx - (px - lineThreshold) >= 0 && b * ty - (py - lineThreshold) >= 0
); );
@ -61,7 +65,7 @@ export function hitTest(
} else if (element.type === "rectangle") { } else if (element.type === "rectangle") {
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element); const [x1, y1, x2, y2] = getElementAbsoluteCoords(element);
if (element.backgroundColor !== "transparent") { if (isElementDraggableFromInside(element)) {
return ( return (
x > x1 - lineThreshold && x > x1 - lineThreshold &&
x < x2 + lineThreshold && x < x2 + lineThreshold &&
@ -94,7 +98,7 @@ export function hitTest(
leftY leftY
] = getDiamondPoints(element); ] = getDiamondPoints(element);
if (element.backgroundColor !== "transparent") { if (isElementDraggableFromInside(element)) {
// TODO: remove this when we normalize coordinates globally // TODO: remove this when we normalize coordinates globally
if (topY > bottomY) [bottomY, topY] = [topY, bottomY]; if (topY > bottomY) [bottomY, topY] = [topY, bottomY];
if (rightX < leftX) [leftX, rightX] = [rightX, leftX]; if (rightX < leftX) [leftX, rightX] = [rightX, leftX];