fix(ui): always use current brush width when making straight lines

This commit is contained in:
psychedelicious 2024-06-16 20:50:57 +10:00
parent 890e6a95ed
commit e937aa831f

View File

@ -188,15 +188,24 @@ export const setStageEventHandlers = ({
if (toolState.selected === 'brush') { if (toolState.selected === 'brush') {
if (e.evt.shiftKey) { if (e.evt.shiftKey) {
// Extend the last line straight to the new point const lastAddedPoint = getLastAddedPoint();
setLastAddedPoint(pos); // Create a straight line if holding shift
onPointAddedToLine( if (lastAddedPoint) {
onBrushLineAdded(
{ {
id: selectedEntity.id, id: selectedEntity.id,
point: [pos.x - selectedEntity.x, pos.y - selectedEntity.y], points: [
lastAddedPoint.x - selectedEntity.x,
lastAddedPoint.y - selectedEntity.y,
pos.x - selectedEntity.x,
pos.y - selectedEntity.y,
],
color: getCurrentFill(),
width: toolState.brush.width,
}, },
selectedEntity.type selectedEntity.type
); );
}
} else { } else {
onBrushLineAdded( onBrushLineAdded(
{ {
@ -213,19 +222,28 @@ export const setStageEventHandlers = ({
selectedEntity.type selectedEntity.type
); );
} }
setLastAddedPoint(pos);
} }
if (toolState.selected === 'eraser') { if (toolState.selected === 'eraser') {
if (e.evt.shiftKey) { if (e.evt.shiftKey) {
// Extend the last line straight to the new point // Create a straight line if holding shift
setLastAddedPoint(pos); const lastAddedPoint = getLastAddedPoint();
onPointAddedToLine( if (lastAddedPoint) {
onEraserLineAdded(
{ {
id: selectedEntity.id, id: selectedEntity.id,
point: [pos.x - selectedEntity.x, pos.y - selectedEntity.y], points: [
lastAddedPoint.x - selectedEntity.x,
lastAddedPoint.y - selectedEntity.y,
pos.x - selectedEntity.x,
pos.y - selectedEntity.y,
],
width: toolState.eraser.width,
}, },
selectedEntity.type selectedEntity.type
); );
}
} else { } else {
onEraserLineAdded( onEraserLineAdded(
{ {
@ -241,6 +259,7 @@ export const setStageEventHandlers = ({
selectedEntity.type selectedEntity.type
); );
} }
setLastAddedPoint(pos);
} }
}); });
@ -341,6 +360,7 @@ export const setStageEventHandlers = ({
}, },
selectedEntity.type selectedEntity.type
); );
setLastAddedPoint(pos);
setIsDrawing(true); setIsDrawing(true);
} }
} }
@ -364,6 +384,7 @@ export const setStageEventHandlers = ({
}, },
selectedEntity.type selectedEntity.type
); );
setLastAddedPoint(pos);
setIsDrawing(true); setIsDrawing(true);
} }
} }