@gedit/editor-2d 0.2.61 → 0.2.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/lib/browser/model/editor2d-model.d.ts +0 -2
- package/lib/browser/model/editor2d-model.d.ts.map +1 -1
- package/lib/browser/model/editor2d-model.js +0 -5
- package/lib/browser/model/editor2d-model.js.map +1 -1
- package/lib/browser/model/editor2d.d.ts +4 -4
- package/lib/browser/model/editor2d.d.ts.map +1 -1
- package/lib/browser/playground/path-edit/path-edit-layer-move-point.d.ts.map +1 -1
- package/lib/browser/playground/path-edit/path-edit-layer-move-point.js +4 -0
- package/lib/browser/playground/path-edit/path-edit-layer-move-point.js.map +1 -1
- package/lib/browser/playground/path-edit/path-edit-layer-svg-path.d.ts +4 -3
- package/lib/browser/playground/path-edit/path-edit-layer-svg-path.d.ts.map +1 -1
- package/lib/browser/playground/path-edit/path-edit-layer-svg-path.js +22 -10
- package/lib/browser/playground/path-edit/path-edit-layer-svg-path.js.map +1 -1
- package/lib/browser/playground/path-edit/utils.d.ts +18 -2
- package/lib/browser/playground/path-edit/utils.d.ts.map +1 -1
- package/lib/browser/playground/path-edit/utils.js +60 -10
- package/lib/browser/playground/path-edit/utils.js.map +1 -1
- package/lib/browser/playground/path-edit-layer.d.ts +6 -3
- package/lib/browser/playground/path-edit-layer.d.ts.map +1 -1
- package/lib/browser/playground/path-edit-layer.js +126 -36
- package/lib/browser/playground/path-edit-layer.js.map +1 -1
- package/lib/browser/playground/playground-context.d.ts +2 -3
- package/lib/browser/playground/playground-context.d.ts.map +1 -1
- package/lib/browser/playground/playground-context.js +4 -6
- package/lib/browser/playground/playground-context.js.map +1 -1
- package/lib/browser/playground/playground-contribution.d.ts +1 -2
- package/lib/browser/playground/playground-contribution.d.ts.map +1 -1
- package/lib/browser/playground/playground-contribution.js +0 -4
- package/lib/browser/playground/playground-contribution.js.map +1 -1
- package/lib/browser/playground/selection-entity-manager.d.ts +1 -1
- package/lib/browser/playground/selection-entity-manager.d.ts.map +1 -1
- package/lib/browser/playground/selection-entity-manager.js.map +1 -1
- package/package.json +9 -9
- package/src/browser/model/editor2d-model.ts +0 -2
- package/src/browser/model/editor2d.ts +4 -4
- package/src/browser/playground/path-edit/path-edit-layer-move-point.tsx +6 -0
- package/src/browser/playground/path-edit/path-edit-layer-svg-path.tsx +34 -17
- package/src/browser/playground/path-edit/utils.tsx +92 -11
- package/src/browser/playground/path-edit-layer.tsx +189 -55
- package/src/browser/playground/playground-context.ts +3 -3
- package/src/browser/playground/playground-contribution.ts +0 -2
- package/src/browser/playground/selection-entity-manager.tsx +1 -1
|
@@ -5,28 +5,25 @@ import {
|
|
|
5
5
|
entity,
|
|
6
6
|
Layer,
|
|
7
7
|
PathPointSelection,
|
|
8
|
+
PathPointSelectionEntity,
|
|
8
9
|
PathSelectMode,
|
|
10
|
+
PlaygroundLayer,
|
|
9
11
|
SelectorBoxConfigEntity,
|
|
10
12
|
} from '@gedit/playground';
|
|
11
13
|
import { DocumentEntity } from './entities/document-entity';
|
|
12
14
|
import { domUtils } from '@gedit/utils/lib/browser';
|
|
13
15
|
import { GameObjectBaseType } from '@gedit/render-engine';
|
|
14
|
-
import { Editor2dDocument, Editor2dPathNode } from '../model';
|
|
16
|
+
import type { Editor2dDocument, Editor2dPathNode } from '../model';
|
|
15
17
|
import { PlaygroundContext2d } from './playground-context';
|
|
16
18
|
import { SelectableTreeNode, TreeSelection } from '@gedit/tree';
|
|
17
19
|
import {
|
|
18
20
|
PathChild,
|
|
21
|
+
PathSchema,
|
|
19
22
|
PATH_FUNC_TYPE,
|
|
20
23
|
toFixedValue,
|
|
21
|
-
PathSchema,
|
|
22
24
|
} from '@gedit/canvas-draw';
|
|
23
25
|
|
|
24
|
-
import {
|
|
25
|
-
deepClone,
|
|
26
|
-
Disposable,
|
|
27
|
-
generateUuid,
|
|
28
|
-
PositionSchema,
|
|
29
|
-
} from '@gedit/utils';
|
|
26
|
+
import { deepClone, Disposable, generateUuid } from '@gedit/utils';
|
|
30
27
|
import {
|
|
31
28
|
PointSchema,
|
|
32
29
|
SvgPath,
|
|
@@ -34,6 +31,8 @@ import {
|
|
|
34
31
|
setBezierMovePoint,
|
|
35
32
|
PointSelection,
|
|
36
33
|
updatePathNodeData,
|
|
34
|
+
inverseTransformToData,
|
|
35
|
+
transformToData,
|
|
37
36
|
} from './path-edit';
|
|
38
37
|
|
|
39
38
|
export interface PathEditLayerEventContextProps {
|
|
@@ -60,11 +59,14 @@ export const PathEditLayerEventContext = React.createContext<PathEditLayerEventC
|
|
|
60
59
|
*/
|
|
61
60
|
export class PathEditLayer extends Layer<PlaygroundContext2d> {
|
|
62
61
|
node = domUtils.createDivWithClass('gedit-path-edit-layer');
|
|
62
|
+
id = 'pathEditLayer';
|
|
63
63
|
@entity(EditorStateConfigEntity)
|
|
64
64
|
protected editorState: EditorStateConfigEntity;
|
|
65
65
|
@entity(SelectorBoxConfigEntity)
|
|
66
66
|
protected selectorConfig!: SelectorBoxConfigEntity;
|
|
67
67
|
@entity(DocumentEntity) documentEntity: DocumentEntity;
|
|
68
|
+
@entity(PathPointSelectionEntity)
|
|
69
|
+
pathPointSelection: PathPointSelectionEntity;
|
|
68
70
|
|
|
69
71
|
currentPathNode?: Editor2dPathNode;
|
|
70
72
|
startPos?: PathChild;
|
|
@@ -103,6 +105,35 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
|
|
|
103
105
|
const nodeData = updatePathNodeData(this.currentPathNode!);
|
|
104
106
|
this.document?.updateNode(this.currentPathNode!, nodeData, true);
|
|
105
107
|
}
|
|
108
|
+
updateNodePathData(): void {
|
|
109
|
+
if (!this.currentPathNode) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const { origin = { x: 0.5, y: 0.5 }, size, path } = this.currentPathNode;
|
|
113
|
+
const { origin: oldOrigin = { x: 0.5, y: 0.5 }, paths } = path;
|
|
114
|
+
const diff = {
|
|
115
|
+
x: toFixedValue((oldOrigin.x - origin.x) * (size?.width || 0), 4),
|
|
116
|
+
y: toFixedValue((oldOrigin.y - origin.y) * (size?.height || 0), 4),
|
|
117
|
+
};
|
|
118
|
+
paths.forEach(item => {
|
|
119
|
+
item.x += diff.x;
|
|
120
|
+
item.y += diff.y;
|
|
121
|
+
if (typeof item.x1 === 'number') {
|
|
122
|
+
item.x1 += diff.x;
|
|
123
|
+
}
|
|
124
|
+
if (typeof item.x2 === 'number') {
|
|
125
|
+
item.x2 += diff.x;
|
|
126
|
+
}
|
|
127
|
+
if (typeof item.y1 === 'number') {
|
|
128
|
+
item.y1 += diff.y;
|
|
129
|
+
}
|
|
130
|
+
if (typeof item.y2 === 'number') {
|
|
131
|
+
item.y2 += diff.y;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
path.origin = origin;
|
|
135
|
+
this.document?.updateNode(this.currentPathNode, { path }, true);
|
|
136
|
+
}
|
|
106
137
|
|
|
107
138
|
// 选中的是第一个点
|
|
108
139
|
protected isOnePoint(point?: PathChild): boolean {
|
|
@@ -143,14 +174,14 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
|
|
|
143
174
|
}
|
|
144
175
|
|
|
145
176
|
onReady(): void {
|
|
146
|
-
this.
|
|
177
|
+
this.addDispose([
|
|
147
178
|
this.context.historyService.onHistoryBack(e => {
|
|
148
179
|
this.reNodeData();
|
|
149
180
|
this.pathPointSelection!.selectMode = PathSelectMode.ADD_PATH;
|
|
150
181
|
this.pathPointSelection!.clearSelection();
|
|
151
182
|
this.editorState.toDefaultState();
|
|
152
183
|
}),
|
|
153
|
-
this.editorState.onStateChange(
|
|
184
|
+
this.editorState.onStateChange(e => {
|
|
154
185
|
/**
|
|
155
186
|
* 1. 不是路径编辑状态时,清空数据
|
|
156
187
|
* 2. 是路径编辑状态时
|
|
@@ -182,6 +213,8 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
|
|
|
182
213
|
this.currentPathNode.path.closed
|
|
183
214
|
? this.pathPointSelection.enterSelectBezierMode(selectionNode)
|
|
184
215
|
: this.pathPointSelection.enterPathMode(selectionNode);
|
|
216
|
+
// 如果中心点不同,更新数据;
|
|
217
|
+
this.updateNodePathData();
|
|
185
218
|
} else if (!selectNodes.length) {
|
|
186
219
|
// 未选中时,清空数据
|
|
187
220
|
this.pathPointSelection.selectMode = PathSelectMode.ADD_PATH;
|
|
@@ -199,10 +232,18 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
|
|
|
199
232
|
);
|
|
200
233
|
const { paths = [], closed } = this.currentPathNode?.path || {};
|
|
201
234
|
const pathSelects: PathPointSelection[] = [];
|
|
235
|
+
const {
|
|
236
|
+
position = { x: 0, y: 1 },
|
|
237
|
+
scale = { x: 1, y: 1 },
|
|
238
|
+
rotation = 0,
|
|
239
|
+
} = this.currentPathNode!;
|
|
202
240
|
paths.forEach(p => {
|
|
203
241
|
const { x: $x, y: $y } = p;
|
|
204
|
-
|
|
205
|
-
|
|
242
|
+
let x = $x;
|
|
243
|
+
let y = $y;
|
|
244
|
+
const r = transformToData({ x, y }, { scale, rotation });
|
|
245
|
+
x = r.x + position.x;
|
|
246
|
+
y = r.y + position.y;
|
|
206
247
|
const wh = (4 / this.config.finalScale) * 2;
|
|
207
248
|
if (
|
|
208
249
|
x >= selectBound.x && // 左
|
|
@@ -265,20 +306,26 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
|
|
|
265
306
|
) {
|
|
266
307
|
return;
|
|
267
308
|
}
|
|
268
|
-
const {
|
|
309
|
+
const {
|
|
310
|
+
position = { x: 0, y: 0 },
|
|
311
|
+
scale = { x: 1, y: 1 },
|
|
312
|
+
rotation = 0,
|
|
313
|
+
} = this.currentPathNode || {};
|
|
314
|
+
let x = e.endPos.x / (this.config?.finalScale || 1) - position.x;
|
|
315
|
+
let y = e.endPos.y / (this.config?.finalScale || 1) - position.y;
|
|
316
|
+
const { x: rx, y: ry } = inverseTransformToData(
|
|
317
|
+
{ x, y },
|
|
318
|
+
{ scale, rotation }
|
|
319
|
+
);
|
|
320
|
+
x = rx;
|
|
321
|
+
y = ry;
|
|
269
322
|
this.startPos = {
|
|
270
|
-
x
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
),
|
|
274
|
-
y: toFixedValue(
|
|
275
|
-
e.endPos.y / (this.config?.finalScale || 1) - position.y,
|
|
276
|
-
4
|
|
277
|
-
),
|
|
278
|
-
}; // this.getPosFromMouseEvent(e);
|
|
323
|
+
x,
|
|
324
|
+
y,
|
|
325
|
+
};
|
|
279
326
|
this.startPos.id = generateUuid();
|
|
280
327
|
this.startPos.type = PATH_FUNC_TYPE.STRAIGHT;
|
|
281
|
-
this.
|
|
328
|
+
this.addPath(this.startPos);
|
|
282
329
|
this.pathPointSelection!.enterPathMode([
|
|
283
330
|
{
|
|
284
331
|
pointId: this.startPos.id,
|
|
@@ -291,10 +338,21 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
|
|
|
291
338
|
return;
|
|
292
339
|
}
|
|
293
340
|
// const pos = this.getPosFromMouseEvent(e);
|
|
294
|
-
const {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
341
|
+
const {
|
|
342
|
+
path,
|
|
343
|
+
position = { x: 0, y: 0 },
|
|
344
|
+
scale = { x: 1, y: 1 },
|
|
345
|
+
rotation = 0,
|
|
346
|
+
} = this.currentPathNode || {};
|
|
347
|
+
let x = e.endPos.x / (this.config?.finalScale || 1) - position.x;
|
|
348
|
+
let y = e.endPos.y / (this.config?.finalScale || 1) - position.y;
|
|
349
|
+
const { x: rx, y: ry } = inverseTransformToData(
|
|
350
|
+
{ x, y },
|
|
351
|
+
{ scale, rotation }
|
|
352
|
+
);
|
|
353
|
+
x = rx;
|
|
354
|
+
y = ry;
|
|
355
|
+
|
|
298
356
|
const pathNode = path?.paths.find(
|
|
299
357
|
c => c.id === this.startPos?.id
|
|
300
358
|
);
|
|
@@ -323,8 +381,24 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
|
|
|
323
381
|
},
|
|
324
382
|
});
|
|
325
383
|
}),
|
|
384
|
+
this.listenPlaygroundEvent('dblclick', (e: MouseEvent) => {
|
|
385
|
+
// 双击画布时,关闭路径
|
|
386
|
+
// 1. 在路径编辑状态时,不处理;
|
|
387
|
+
// 2. 选中的是 path 路径时,不处理,新增点;
|
|
388
|
+
// 3. 选中点时,不处理;
|
|
389
|
+
// 4. 右键时,不处理;
|
|
390
|
+
// 5. 不是路径编辑状态时,不处理;
|
|
391
|
+
const isExit =
|
|
392
|
+
this.editorState.is(EditorState.EDIT_PATH_STATE.id) &&
|
|
393
|
+
this.pathPointSelection.selectMode === PathSelectMode.SELECT_BEZIER;
|
|
394
|
+
if (isExit) {
|
|
395
|
+
const playgroundLayer = this.pipelineLayers.find(c => c.id === 'playgroundLayer') as PlaygroundLayer;
|
|
396
|
+
playgroundLayer?.keydownEvent?.({ key: 'Escape' } as KeyboardEvent);
|
|
397
|
+
}
|
|
398
|
+
}),
|
|
326
399
|
// 图层发生变化时退出模式
|
|
327
400
|
this.selectionService?.onSelectionChanged(e => {
|
|
401
|
+
// todo: pahtSelection 跟随 playground
|
|
328
402
|
const { isEnabled, pathPointSelection } = this;
|
|
329
403
|
if (isEnabled) {
|
|
330
404
|
if (!pathPointSelection) {
|
|
@@ -354,6 +428,7 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
|
|
|
354
428
|
this.currentPathNode.path.closed
|
|
355
429
|
? pathPointSelection.enterSelectBezierMode(selectionNode)
|
|
356
430
|
: pathPointSelection.enterPathMode(selectionNode);
|
|
431
|
+
this.updateNodePathData();
|
|
357
432
|
}
|
|
358
433
|
return;
|
|
359
434
|
}
|
|
@@ -380,7 +455,7 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
|
|
|
380
455
|
* 创建路径
|
|
381
456
|
* @param pos - 当前鼠标点击的位置
|
|
382
457
|
*/
|
|
383
|
-
|
|
458
|
+
addPath(pos: PointSchema): void {
|
|
384
459
|
if (!this.document) {
|
|
385
460
|
return;
|
|
386
461
|
}
|
|
@@ -448,14 +523,35 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
|
|
|
448
523
|
this.startDrag(e.clientX, e.clientY, {
|
|
449
524
|
onDrag: e => {
|
|
450
525
|
if (this.bezierStartPos) {
|
|
451
|
-
const {
|
|
452
|
-
|
|
453
|
-
|
|
526
|
+
const {
|
|
527
|
+
position = { x: 0, y: 0 },
|
|
528
|
+
scale = { x: 1, y: 1 },
|
|
529
|
+
rotation = 0,
|
|
530
|
+
} = this.currentPathNode || {};
|
|
531
|
+
let x = e.endPos.x / (this.config?.finalScale || 1) - position.x;
|
|
532
|
+
let y = e.endPos.y / (this.config?.finalScale || 1) - position.y;
|
|
533
|
+
const { x: currentX, y: currentY } = inverseTransformToData(
|
|
534
|
+
{ x, y },
|
|
535
|
+
{ scale, rotation }
|
|
536
|
+
);
|
|
537
|
+
x = currentX;
|
|
538
|
+
y = currentY;
|
|
454
539
|
this.onBezierPointMove({ x, y });
|
|
455
540
|
}
|
|
456
541
|
},
|
|
457
542
|
onDragEnd: () => {
|
|
458
543
|
this.bezierStartPos = undefined;
|
|
544
|
+
const { closed } = this.currentPathNode?.path || {};
|
|
545
|
+
if (!closed) {
|
|
546
|
+
const isStartOrEnd = this.getPointIsStartOrEnd(p);
|
|
547
|
+
if (isStartOrEnd) {
|
|
548
|
+
this.pathPointSelection!.enterPathMode([
|
|
549
|
+
{
|
|
550
|
+
pointId: p.id,
|
|
551
|
+
},
|
|
552
|
+
]);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
459
555
|
},
|
|
460
556
|
});
|
|
461
557
|
this.draw();
|
|
@@ -532,13 +628,14 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
|
|
|
532
628
|
// 拖动
|
|
533
629
|
onDrag: dragEvent => {
|
|
534
630
|
selection = pathPointSelection?.selection || [];
|
|
535
|
-
const { position = { x: 0, y: 0 } } = node;
|
|
536
631
|
const selectionNodes = selection
|
|
537
632
|
.map(s => node.path.paths.find(p => p.id === s.pointId))
|
|
538
633
|
.filter(c => c) as PathChild[];
|
|
539
634
|
const delta = selectionNodes.map(c => {
|
|
540
635
|
const point = node.path.paths.find(p => p.id === c.id)!;
|
|
541
|
-
const current = node.path.paths.find(
|
|
636
|
+
const current = node.path.paths.find(
|
|
637
|
+
p => p.id === currentPoint.id
|
|
638
|
+
)!;
|
|
542
639
|
if (point.id === currentPoint.id) {
|
|
543
640
|
return { x: 0, y: 0 };
|
|
544
641
|
}
|
|
@@ -550,10 +647,21 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
|
|
|
550
647
|
const startNode = selectionNodes.map((s: PathChild) =>
|
|
551
648
|
startNodeClone.find((c: PathChild) => c.id === s.id)
|
|
552
649
|
);
|
|
553
|
-
const
|
|
650
|
+
const {
|
|
651
|
+
position = { x: 0, y: 0 },
|
|
652
|
+
scale = { x: 1, y: 1 },
|
|
653
|
+
rotation = 0,
|
|
654
|
+
} = this.currentPathNode || {};
|
|
655
|
+
let x =
|
|
554
656
|
dragEvent.endPos.x / (this.config?.finalScale || 1) - position.x;
|
|
555
|
-
|
|
657
|
+
let y =
|
|
556
658
|
dragEvent.endPos.y / (this.config?.finalScale || 1) - position.y;
|
|
659
|
+
const { x: currentX, y: currentY } = inverseTransformToData(
|
|
660
|
+
{ x, y },
|
|
661
|
+
{ scale, rotation }
|
|
662
|
+
);
|
|
663
|
+
x = currentX;
|
|
664
|
+
y = currentY;
|
|
557
665
|
selectionNodes.forEach((p: PathChild, i) => {
|
|
558
666
|
const start = startNode[i];
|
|
559
667
|
const d = delta[i];
|
|
@@ -574,22 +682,35 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
|
|
|
574
682
|
p.x = toFixedValue(x + d.x, 4);
|
|
575
683
|
p.y = toFixedValue(y + d.y, 4);
|
|
576
684
|
});
|
|
685
|
+
|
|
577
686
|
this.updateNodeData();
|
|
578
687
|
},
|
|
579
688
|
});
|
|
580
|
-
|
|
581
689
|
this.draw();
|
|
582
690
|
}
|
|
583
691
|
protected onPathAddPoint(i: number, e: React.MouseEvent): void {
|
|
584
692
|
if (!this.currentPathNode || !this.document) {
|
|
585
693
|
return;
|
|
586
694
|
}
|
|
587
|
-
const {
|
|
695
|
+
const {
|
|
696
|
+
path,
|
|
697
|
+
position = { x: 0, y: 0 },
|
|
698
|
+
scale = { x: 1, y: 1 },
|
|
699
|
+
rotation = 0,
|
|
700
|
+
} = this.currentPathNode || {};
|
|
588
701
|
const { paths = [] } = path;
|
|
589
702
|
const p = this.getPosFromMouseEvent(e);
|
|
703
|
+
let x = p.x - position.x;
|
|
704
|
+
let y = p.y - position.y;
|
|
705
|
+
const { x: currentX, y: currentY } = inverseTransformToData(
|
|
706
|
+
{ x, y },
|
|
707
|
+
{ scale, rotation }
|
|
708
|
+
);
|
|
709
|
+
x = currentX;
|
|
710
|
+
y = currentY;
|
|
590
711
|
const pos = {
|
|
591
|
-
x
|
|
592
|
-
y
|
|
712
|
+
x,
|
|
713
|
+
y,
|
|
593
714
|
};
|
|
594
715
|
const point = paths[i];
|
|
595
716
|
const nextPoint = paths[i + 1] ? paths[i + 1] : paths[0];
|
|
@@ -625,31 +746,44 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
|
|
|
625
746
|
// this.editorState.toDefaultState();
|
|
626
747
|
return <></>;
|
|
627
748
|
}
|
|
749
|
+
|
|
628
750
|
const {
|
|
629
751
|
path = {} as PathSchema,
|
|
630
|
-
position = { x: 0, y: 0 }
|
|
752
|
+
position = { x: 0, y: 0 },
|
|
753
|
+
scale = { x: 1, y: 1 },
|
|
754
|
+
rotation = 0,
|
|
631
755
|
} = this.currentPathNode || ({} as Editor2dPathNode);
|
|
632
|
-
const { paths: p = []
|
|
756
|
+
const { paths: p = [] } = path;
|
|
633
757
|
const paths = [...p].map(c => {
|
|
634
758
|
const item = {
|
|
635
759
|
...c,
|
|
636
|
-
x: c.x
|
|
637
|
-
y: c.y
|
|
760
|
+
x: c.x,
|
|
761
|
+
y: c.y,
|
|
638
762
|
};
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
763
|
+
|
|
764
|
+
const { x, y } = transformToData({ x: c.x, y: c.y }, { scale, rotation });
|
|
765
|
+
item.x = x + position.x;
|
|
766
|
+
item.y = y + position.y;
|
|
767
|
+
|
|
768
|
+
if (typeof c.x1 === 'number' || typeof c.y1 === 'number') {
|
|
769
|
+
const { x: x1, y: y1 } = transformToData(
|
|
770
|
+
{ x: c.x1 || c.x, y: c.y1 || c.y },
|
|
771
|
+
{ scale, rotation }
|
|
772
|
+
);
|
|
773
|
+
item.x1 = x1 + position.x;
|
|
774
|
+
item.y1 = y1 + position.y;
|
|
647
775
|
}
|
|
648
|
-
if (typeof c.y2 === 'number') {
|
|
649
|
-
|
|
776
|
+
if (typeof c.x2 === 'number' || typeof c.y2 === 'number') {
|
|
777
|
+
const { x: x2, y: y2 } = transformToData(
|
|
778
|
+
{ x: c.x2 || c.x, y: c.y2 || c.y },
|
|
779
|
+
{ scale, rotation }
|
|
780
|
+
);
|
|
781
|
+
item.x2 = x2 + position.x;
|
|
782
|
+
item.y2 = y2 + position.y;
|
|
650
783
|
}
|
|
651
784
|
return item;
|
|
652
785
|
});
|
|
786
|
+
|
|
653
787
|
return (
|
|
654
788
|
<PathEditLayerEventContext.Provider
|
|
655
789
|
value={{
|
|
@@ -661,11 +795,11 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
|
|
|
661
795
|
}}
|
|
662
796
|
>
|
|
663
797
|
<SvgPath
|
|
664
|
-
getPosFromMouseEvent={this.getPosFromMouseEvent.bind(this)}
|
|
665
798
|
width={this.config.config.pageBounds?.width || 300}
|
|
666
799
|
height={this.config.config.pageBounds?.height || 300}
|
|
800
|
+
getPosFromMouseEvent={this.getPosFromMouseEvent.bind(this)}
|
|
801
|
+
node={this.currentPathNode}
|
|
667
802
|
paths={paths}
|
|
668
|
-
closed={closed}
|
|
669
803
|
selection={this.pathPointSelection?.selection as PointSelection[]}
|
|
670
804
|
selectMode={this.pathPointSelection?.selectMode}
|
|
671
805
|
getPointIsStartOrEnd={this.getPointIsStartOrEnd.bind(this)}
|
|
@@ -5,7 +5,7 @@ import { AppConfigService } from '@gedit/app-config';
|
|
|
5
5
|
import { debounce, Emitter, URI } from '@gedit/utils';
|
|
6
6
|
import { Editor2dEntity } from './entities/editor2d-entity';
|
|
7
7
|
import type { SelectionEntityManager } from './selection-entity-manager';
|
|
8
|
-
import {
|
|
8
|
+
import { PathPointSelectionEntity, PathSelectMode, Playground } from '@gedit/playground';
|
|
9
9
|
import { Editor2dDocument } from '../model/editor2d-document';
|
|
10
10
|
import { Editor2dSelection } from '../model/editor2d-selection';
|
|
11
11
|
import { Editor2dModelOptions, Editor2dNode } from '../model/editor2d';
|
|
@@ -42,7 +42,6 @@ export class PlaygroundContext2d {
|
|
|
42
42
|
@inject(OpenerService) readonly openerService: OpenerService,
|
|
43
43
|
@inject(WorkspaceService)
|
|
44
44
|
protected readonly workspaceService: WorkspaceService,
|
|
45
|
-
@inject(PathPointSelectionService) readonly pathPointSelection: PathPointSelectionService,
|
|
46
45
|
@inject(HistoryService) readonly historyService: HistoryService
|
|
47
46
|
) {
|
|
48
47
|
this.rootURI = new URI(this.workspaceService.currentRoot!.uri);
|
|
@@ -55,7 +54,8 @@ export class PlaygroundContext2d {
|
|
|
55
54
|
* 刷新 tree selection
|
|
56
55
|
*/
|
|
57
56
|
syncToSelectionTree = debounce((entities: SelectionEntityManager) => {
|
|
58
|
-
|
|
57
|
+
const pathPointSelection = entities.entityManager.getEntity<PathPointSelectionEntity>(PathPointSelectionEntity);
|
|
58
|
+
if (pathPointSelection?.selectMode !== PathSelectMode.ADD_PATH) {
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
61
|
const selectedEntities: Editor2dEntity[] = entities.getSelectedEntities();
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { inject, injectable, optional } from 'inversify';
|
|
2
2
|
import {
|
|
3
3
|
EditorStateConfigEntity,
|
|
4
|
-
PathPointSelectionService,
|
|
5
4
|
Playground,
|
|
6
5
|
PlaygroundConfig,
|
|
7
6
|
PlaygroundContribution,
|
|
@@ -31,7 +30,6 @@ export class PlaygroundContribution2d implements PlaygroundContribution {
|
|
|
31
30
|
@inject(CommandService) readonly commandService: CommandService;
|
|
32
31
|
@inject(ContextMenuRenderer) @optional() readonly menuRender: ContextMenuRenderer;
|
|
33
32
|
@inject(Editor2dSelection) readonly editor2dSelection: Editor2dSelection;
|
|
34
|
-
@inject(PathPointSelectionService) readonly pathPointSelectionService: PathPointSelectionService;
|
|
35
33
|
@inject(FrontendApplicationStateService) readonly stateService: FrontendApplicationStateService;
|
|
36
34
|
registerPlayground(registry: PlaygroundRegistry): void {
|
|
37
35
|
registry.registerLayer(CanvasLayer);
|
|
@@ -38,7 +38,7 @@ const numberToFixed4 = (data: {[key: string]: any}) => {
|
|
|
38
38
|
export class SelectionEntityManager {
|
|
39
39
|
nodeEntitiesCache: Map<string, Editor2dEntity> = new Map();
|
|
40
40
|
constructor(
|
|
41
|
-
|
|
41
|
+
public entityManager: EntityManager,
|
|
42
42
|
protected context: PlaygroundContext2d,
|
|
43
43
|
protected loading: () => boolean,
|
|
44
44
|
protected getDocument: () => Editor2dDocument | undefined,
|