Skip to content

Commit d4edca7

Browse files
author
Yan Heng
committed
feat: 增加顶点控制器
1 parent f5e7c47 commit d4edca7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

packages/core/src/customs/polyline.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@ import { fabric } from 'fabric';
22

33
export class Polyline extends fabric.Polyline {
44
public onSelect(options: { e?: Event | undefined }): boolean {
5+
const points = this.points ?? [];
6+
this.controls = points.reduce<Record<string, fabric.Control>>(
7+
(controls, point, index) => {
8+
controls[`p${index}`] = new fabric.Control({
9+
actionName: 'modifyPolyline',
10+
positionHandler(dim, finalMatrix, fabricObject: Polyline) {
11+
const x = point.x - fabricObject.pathOffset.x;
12+
const y = point.y - fabricObject.pathOffset.y;
13+
return fabric.util.transformPoint(
14+
new fabric.Point(x, y),
15+
fabric.util.multiplyTransformMatrices(
16+
fabricObject.canvas?.viewportTransform ?? [],
17+
fabricObject.calcTransformMatrix()
18+
)
19+
);
20+
},
21+
});
22+
return controls;
23+
},
24+
{ ...this.controls }
25+
);
526
return super.onSelect(options);
627
}
728

0 commit comments

Comments
 (0)