Skip to content

Commit 779ad4b

Browse files
committed
feat: Add resize and reposition support for remaining shapes
1 parent 8da86d8 commit 779ad4b

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

apps/collabydraw/components/canvas/StandaloneCanvas.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,6 @@ export function StandaloneCanvas() {
290290
}
291291
};
292292

293-
useEffect(() => {
294-
//
295-
296-
}, []);
297-
298293
return (
299294
<div data-isloading={isLoading} data-matches={matches} className={`collabydraw h-screen overflow-hidden ${(activeTool === "grab" && !sidebarOpen) ? (grabbing ? "cursor-grabbing" : "cursor-grab") : "cursor-crosshair"} `}>
300295
{!isLoading && (

apps/collabydraw/draw/Game.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -960,10 +960,10 @@ export class Game {
960960
}
961961

962962
eraser(x: number, y: number) {
963-
const transformedPoint = this.transformPanScale(x, y);
964-
963+
// We don't need to transform the coordinates here again since they're already transformed
964+
// in the mouseDownHandler and mouseMoveHandler
965965
const shapeIndex = this.existingShape.findIndex((shape) =>
966-
this.isPointInShape(transformedPoint.x, transformedPoint.y, shape)
966+
this.isPointInShape(x, y, shape)
967967
);
968968

969969
if (shapeIndex !== -1) {

apps/collabydraw/draw/SelectionManager.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class SelectionManager {
3232
}
3333

3434
private resetCursor() {
35-
this.canvas.style.cursor = "auto";
35+
this.canvas.style.cursor = "";
3636
}
3737

3838
private onUpdateCallback: () => void = () => {};
@@ -110,18 +110,21 @@ export class SelectionManager {
110110
case "diamond":
111111
bounds.width = shape.width;
112112
bounds.height = shape.height;
113-
// bounds.x = shape.x - shape.width / 2 - 10;
114-
// bounds.y = shape.y - shape.height / 2 - 10;
115-
bounds.x = shape.x;
116-
bounds.y = shape.y;
113+
bounds.x = shape.x - shape.width / 2;
114+
bounds.y = shape.y - shape.height / 2;
117115
break;
118116

119117
case "line":
120118
// case "arrow":
121-
bounds.width = Math.abs(shape.x - shape.toX) + 20;
122-
bounds.height = Math.abs(shape.y - shape.toY) + 20;
123-
bounds.x = Math.min(shape.x, shape.toX) - 10;
124-
bounds.y = Math.min(shape.y, shape.toY) - 10;
119+
const minX = Math.min(shape.x, shape.toX);
120+
const minY = Math.min(shape.y, shape.toY);
121+
const maxX = Math.max(shape.x, shape.toX);
122+
const maxY = Math.max(shape.y, shape.toY);
123+
124+
bounds.x = minX - shape.strokeWidth;
125+
bounds.y = minY - shape.strokeWidth;
126+
bounds.width = maxX - minX + shape.strokeWidth * 2;
127+
bounds.height = maxY - minY + shape.strokeWidth * 2;
125128
break;
126129

127130
// case "text":
@@ -201,7 +204,7 @@ export class SelectionManager {
201204
this.ctx.roundRect(
202205
handle.x - handleSize / 2,
203206
handle.y - handleSize / 2,
204-
handleSize,
207+
handleSize,
205208
handleSize,
206209
3
207210
);
@@ -259,6 +262,11 @@ export class SelectionManager {
259262
x: x - this.selectedShape.x,
260263
y: y - this.selectedShape.y,
261264
};
265+
} else if (this.selectedShape.type === "diamond") {
266+
this.dragOffset = {
267+
x: x - this.selectedShape.x,
268+
y: y - this.selectedShape.y,
269+
};
262270
} else if (this.selectedShape.type !== "pen") {
263271
this.dragOffset = {
264272
x: x - this.selectedShape.x,
@@ -389,8 +397,12 @@ export class SelectionManager {
389397
this.selectedShape.radX = newBounds.width / 2;
390398
this.selectedShape.radY = newBounds.height / 2;
391399
} else if (this.selectedShape.type === "diamond") {
392-
this.selectedShape.width =
393-
Math.max(Math.abs(newBounds.width), Math.abs(newBounds.height)) / 2;
400+
const centerX = newBounds.x + newBounds.width / 2;
401+
const centerY = newBounds.y + newBounds.height / 2;
402+
this.selectedShape.x = centerX;
403+
this.selectedShape.y = centerY;
404+
this.selectedShape.width = newBounds.width;
405+
this.selectedShape.height = newBounds.height;
394406
} else if (this.selectedShape.type === "line") {
395407
// || this.selectedShape.type === "arrow") {
396408
// Update line/arrow endpoints based on the resize handle

0 commit comments

Comments
 (0)