Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

handles to stretch the shape #15

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
handles to stretch the shape
  • Loading branch information
vera0005 committed Nov 18, 2021
commit 0d364c5314d3c40e94e02715cc2d28b9c2ab62df
24 changes: 24 additions & 0 deletions src/freehand/EditableFreehand.js
Original file line number Diff line number Diff line change
@@ -173,6 +173,30 @@ export default class EditableFreehand extends EditableShape {

this.emit('update', toSVGTarget(this.shape, this.env.image));
}*/
else {
const { naturalWidth, naturalHeight } = this.env.image;
const dx = constrain(x, pos.x - this.grabbedAt.x, naturalWidth - width);
const dy = constrain(y, pos.y - this.grabbedAt.y, naturalHeight - height);

const handleIdx = this.handles.indexOf(this.grabbedElem);
let updatedPoints = [];
getPoints(this.shape).forEach((pt, idx) => {
if (idx === handleIdx) {
updatedPoints.push(pos);
} else if (idx + 1 === handleIdx || idx - 1 === handleIdx) {
let f = 0.5;
this.setHandleXY(this.handles[idx], pt.x + f * dx, pt.y + f * dy);
updatedPoints.push({ x: pt.x + f * dx, y: pt.y + f * dy }); //{ x: pt.x + 0.5*dx, y: pt.y + 0.5*dy };
} else {
updatedPoints.push(pt);
}
});

this.grabbedAt = pos;
this.setPoints(updatedPoints);
this.setHandleXY(this.handles[handleIdx], pos.x, pos.y);
this.emit('update', toSVGTarget(this.shape, this.env.image));
}
}
}