Kar 2025-07-08 13:55:47 +05:30
parent 520099b31d
commit a907f2781c
1 changed files with 17 additions and 3 deletions

View File

@ -169,9 +169,23 @@ const DrawingCanvas = () => {
setShapes(prev => { setShapes(prev => {
const updated = [...prev]; const updated = [...prev];
const shape = { ...updated[selectedIndex] }; const shape = { ...updated[selectedIndex] };
// Move shape based on offset if (shape.type === 'pencil') {
shape.x = x - offset.x; // Calculate movement delta
shape.y = y - offset.y; const dx = x - offset.x - shape.points[0].x;
const dy = y - offset.y - shape.points[0].y;
shape.points = shape.points.map(pt => ({
x: pt.x + dx,
y: pt.y + dy
}));
// Update offset so dragging is smooth
setOffset({
x: x - shape.points[0].x,
y: y - shape.points[0].y
});
} else {
shape.x = x - offset.x;
shape.y = y - offset.y;
}
updated[selectedIndex] = shape; updated[selectedIndex] = shape;
return updated; return updated;
}); });