@gedit/editor-2d 0.3.14 → 0.3.17
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/lib/browser/editor2d-contribution.d.ts.map +1 -1
- package/lib/browser/editor2d-contribution.js +19 -18
- package/lib/browser/editor2d-contribution.js.map +1 -1
- package/lib/browser/playground/canvas-layer.d.ts +2 -1
- package/lib/browser/playground/canvas-layer.d.ts.map +1 -1
- package/lib/browser/playground/canvas-layer.js +8 -1
- package/lib/browser/playground/canvas-layer.js.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 +38 -4
- 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 +9 -2
- 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 +232 -13
- package/lib/browser/playground/path-edit/path-edit-layer-svg-path.js.map +1 -1
- package/lib/browser/playground/path-edit/utils.d.ts +16 -3
- package/lib/browser/playground/path-edit/utils.d.ts.map +1 -1
- package/lib/browser/playground/path-edit/utils.js +63 -13
- package/lib/browser/playground/path-edit/utils.js.map +1 -1
- package/lib/browser/playground/path-edit-layer.d.ts +46 -3
- package/lib/browser/playground/path-edit-layer.d.ts.map +1 -1
- package/lib/browser/playground/path-edit-layer.js +533 -171
- package/lib/browser/playground/path-edit-layer.js.map +1 -1
- package/lib/browser/playground/playground-contribution.d.ts.map +1 -1
- package/lib/browser/playground/playground-contribution.js +2 -0
- package/lib/browser/playground/playground-contribution.js.map +1 -1
- package/lib/browser/utils/bezier.path.utils.d.ts.map +1 -1
- package/lib/browser/utils/bezier.path.utils.js +3 -0
- package/lib/browser/utils/bezier.path.utils.js.map +1 -1
- package/package.json +7 -7
- package/src/browser/editor2d-contribution.ts +19 -18
- package/src/browser/playground/canvas-layer.ts +6 -1
- package/src/browser/playground/path-edit/path-edit-layer-move-point.tsx +50 -5
- package/src/browser/playground/path-edit/path-edit-layer-svg-path.tsx +303 -26
- package/src/browser/playground/path-edit/utils.tsx +82 -17
- package/src/browser/playground/path-edit-layer.tsx +585 -216
- package/src/browser/playground/playground-contribution.ts +2 -0
- package/src/browser/style/path-edit-layer.less +17 -5
- package/src/browser/svg/drag_path.svg +17 -0
- package/src/browser/utils/bezier.path.utils.ts +3 -0
|
@@ -13,10 +13,51 @@ import { DocumentEntity } from './entities/document-entity';
|
|
|
13
13
|
import { domUtils } from '@gedit/utils/lib/browser';
|
|
14
14
|
import { GameObjectBaseType } from '@gedit/render-engine';
|
|
15
15
|
import { TreeSelection } from '@gedit/tree';
|
|
16
|
-
import { PATH_FUNC_TYPE, toFixedValue, } from '@gedit/canvas-draw';
|
|
16
|
+
import { asVec, PATH_FUNC_TYPE, toFixedValue, } from '@gedit/canvas-draw';
|
|
17
17
|
import { deepClone, DisposableCollection, generateUuid, } from '@gedit/utils';
|
|
18
|
-
import { SvgPath, getNewPoint, setBezierMovePoint, updatePathNodeData, inverseTransformToData, transformToData, } from './path-edit';
|
|
18
|
+
import { SvgPath, getNewPoint, setBezierMovePoint, updatePathNodeData, inverseTransformToData, transformToData, shiftAngleArray, } from './path-edit';
|
|
19
|
+
import { isOSX } from '@gedit/application-common';
|
|
20
|
+
import { getParallelPositionByPoint } from '../utils/bezier.path.utils';
|
|
19
21
|
export const PathEditLayerEventContext = React.createContext({});
|
|
22
|
+
export var Editor2dPathKeyCommands;
|
|
23
|
+
(function (Editor2dPathKeyCommands) {
|
|
24
|
+
const EDITOR2D_PATH_CATEGORY = 'Editor2dPath';
|
|
25
|
+
Editor2dPathKeyCommands.TAB_PATH = {
|
|
26
|
+
id: 'editor2d.path.tab',
|
|
27
|
+
category: EDITOR2D_PATH_CATEGORY,
|
|
28
|
+
label: '下一个点',
|
|
29
|
+
};
|
|
30
|
+
// export const SHOW_ALL_BEZIER: Command = {
|
|
31
|
+
// id: 'editor2d.path.showAllBezier',
|
|
32
|
+
// category: EDITOR2D_PATH_CATEGORY,
|
|
33
|
+
// label: '显示全部贝塞尔点',
|
|
34
|
+
// };
|
|
35
|
+
Editor2dPathKeyCommands.SELECT_All = {
|
|
36
|
+
id: 'editor2d.path.selectAll',
|
|
37
|
+
category: EDITOR2D_PATH_CATEGORY,
|
|
38
|
+
label: '选择全部',
|
|
39
|
+
};
|
|
40
|
+
Editor2dPathKeyCommands.BEZIER_STRAIGHT = {
|
|
41
|
+
id: 'editor2d.path.bezierStraight',
|
|
42
|
+
category: EDITOR2D_PATH_CATEGORY,
|
|
43
|
+
label: '无贝塞尔',
|
|
44
|
+
};
|
|
45
|
+
Editor2dPathKeyCommands.BEZIER_EQUAL = {
|
|
46
|
+
id: 'editor2d.path.bezierEqual',
|
|
47
|
+
category: EDITOR2D_PATH_CATEGORY,
|
|
48
|
+
label: '左右相等',
|
|
49
|
+
};
|
|
50
|
+
Editor2dPathKeyCommands.BEZIER_BREAK = {
|
|
51
|
+
id: 'editor2d.path.bezierBreak',
|
|
52
|
+
category: EDITOR2D_PATH_CATEGORY,
|
|
53
|
+
label: '左右断开',
|
|
54
|
+
};
|
|
55
|
+
Editor2dPathKeyCommands.BEZIER_UNEQUAL = {
|
|
56
|
+
id: 'editor2d.path.bezierUnequal',
|
|
57
|
+
category: EDITOR2D_PATH_CATEGORY,
|
|
58
|
+
label: '左右不相等',
|
|
59
|
+
};
|
|
60
|
+
})(Editor2dPathKeyCommands || (Editor2dPathKeyCommands = {}));
|
|
20
61
|
/**
|
|
21
62
|
* 动态绘制层
|
|
22
63
|
*/
|
|
@@ -25,9 +66,25 @@ export class PathEditLayer extends Layer {
|
|
|
25
66
|
super(...arguments);
|
|
26
67
|
this.node = domUtils.createDivWithClass('gedit-path-edit-layer');
|
|
27
68
|
this.id = 'pathEditLayer';
|
|
69
|
+
// 显示全部贝塞尔点
|
|
70
|
+
this.altKey = false;
|
|
71
|
+
// 按住 shit 键
|
|
72
|
+
this.shiftKey = false;
|
|
73
|
+
// 按住 ctrl 或 ⌘ 键;
|
|
74
|
+
this.ctrlKey = false;
|
|
75
|
+
this._historyIndex = 0;
|
|
76
|
+
this.noHistory = false;
|
|
28
77
|
// 访录当前图层在 timeline 里的监听事件
|
|
29
78
|
this.layerDisposeMap = new Map();
|
|
30
79
|
}
|
|
80
|
+
get historyIndex() {
|
|
81
|
+
const h = this._historyIndex;
|
|
82
|
+
this._historyIndex++;
|
|
83
|
+
return h;
|
|
84
|
+
}
|
|
85
|
+
set historyIndex(h) {
|
|
86
|
+
this._historyIndex = h;
|
|
87
|
+
}
|
|
31
88
|
get document() {
|
|
32
89
|
return this.documentEntity.config.document;
|
|
33
90
|
}
|
|
@@ -44,13 +101,14 @@ export class PathEditLayer extends Layer {
|
|
|
44
101
|
}
|
|
45
102
|
reNodeData() {
|
|
46
103
|
var _a;
|
|
104
|
+
this.clearHistory();
|
|
47
105
|
this.currentPathNode = undefined;
|
|
48
106
|
this.startPos = undefined;
|
|
49
107
|
this.pathPointSelection.clearSelection();
|
|
50
108
|
this.pathPointSelection.selectMode = PathSelectMode.ADD_PATH;
|
|
51
109
|
(_a = this.docDispose) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
52
110
|
}
|
|
53
|
-
updateNodeData() {
|
|
111
|
+
updateNodeData(noHistory) {
|
|
54
112
|
var _a;
|
|
55
113
|
if (!this.currentPathNode) {
|
|
56
114
|
return;
|
|
@@ -59,7 +117,68 @@ export class PathEditLayer extends Layer {
|
|
|
59
117
|
// console.log('updateNodeData', nodeData);
|
|
60
118
|
// 直接更新数据,,动画 updateAnimationNode 里会把数据删了;
|
|
61
119
|
this.currentPathNode.path = nodeData.path;
|
|
120
|
+
this.currentPathNode.selected = true;
|
|
62
121
|
(_a = this.document) === null || _a === void 0 ? void 0 : _a.updateNode(this.currentPathNode, nodeData, true);
|
|
122
|
+
this.addHistoryData(noHistory);
|
|
123
|
+
}
|
|
124
|
+
reloadNodeData(content) {
|
|
125
|
+
var _a;
|
|
126
|
+
if (!this.currentPathNode || !this.pathPointSelection) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const path = JSON.parse(content);
|
|
130
|
+
this.currentPathNode.path = path;
|
|
131
|
+
(_a = this.document) === null || _a === void 0 ? void 0 : _a.updateNode(this.currentPathNode, { path }, true);
|
|
132
|
+
this.pathPointSelection.selection = path.paths[path.paths.length - 1]
|
|
133
|
+
? [{ pointId: path.paths[path.paths.length - 1].id }]
|
|
134
|
+
: [];
|
|
135
|
+
if (!path.paths.length) {
|
|
136
|
+
this.pathPointSelection.enterPathMode([]);
|
|
137
|
+
}
|
|
138
|
+
this.draw();
|
|
139
|
+
}
|
|
140
|
+
clearHistory() {
|
|
141
|
+
if (this.historyUri) {
|
|
142
|
+
this.context.historyService.clearHistory(this.historyUri);
|
|
143
|
+
this.historyUri = undefined;
|
|
144
|
+
this.context.historyService.switchHistory(this.context.document.uri);
|
|
145
|
+
}
|
|
146
|
+
this.historyIndex = 0;
|
|
147
|
+
}
|
|
148
|
+
addHistoryData(noHistory) {
|
|
149
|
+
var _a;
|
|
150
|
+
const nodePath = (_a = this.currentPathNode) === null || _a === void 0 ? void 0 : _a.path;
|
|
151
|
+
if (!nodePath || noHistory || !this.historyUri) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const index = this.historyIndex;
|
|
155
|
+
this.context.historyService.add(this.historyUri, {
|
|
156
|
+
key: index,
|
|
157
|
+
data: {
|
|
158
|
+
content: JSON.stringify(nodePath),
|
|
159
|
+
resource: {
|
|
160
|
+
reload: (content) => {
|
|
161
|
+
this.reloadNodeData(content);
|
|
162
|
+
},
|
|
163
|
+
resource: {
|
|
164
|
+
uri: this.historyUri,
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
createHistory() {
|
|
171
|
+
var _a, _b;
|
|
172
|
+
if (!this.currentPathNode) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
this.historyUri = `${this.context.document.uri}?${(_a = this.currentPathNode) === null || _a === void 0 ? void 0 : _a.id}`;
|
|
176
|
+
if (this.context.historyService.currentUri !== this.historyUri) {
|
|
177
|
+
this.context.historyService.switchHistory(this.historyUri);
|
|
178
|
+
if (!((_b = this.context.historyService.getHistoryNavigator(this.historyUri)) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
179
|
+
this.addHistoryData();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
63
182
|
}
|
|
64
183
|
// updateNodePathData(): void {
|
|
65
184
|
// if (!this.currentPathNode) {
|
|
@@ -164,17 +283,196 @@ export class PathEditLayer extends Layer {
|
|
|
164
283
|
this.layerDisposeMap.set(this.currentPathNode.id, currentDispose);
|
|
165
284
|
}
|
|
166
285
|
}
|
|
286
|
+
updateCurrentPointBezierType(type) {
|
|
287
|
+
if (!this.currentPathNode || !this.pathPointSelection) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const { selection = [] } = this.pathPointSelection;
|
|
291
|
+
selection.forEach(item => {
|
|
292
|
+
const path = this.currentPathNode.path;
|
|
293
|
+
const point = path.paths.find(c => c.id === item.pointId);
|
|
294
|
+
if (point) {
|
|
295
|
+
point.type = type;
|
|
296
|
+
switch (type) {
|
|
297
|
+
case PATH_FUNC_TYPE.STRAIGHT:
|
|
298
|
+
delete point.x1;
|
|
299
|
+
delete point.y1;
|
|
300
|
+
delete point.x2;
|
|
301
|
+
delete point.y2;
|
|
302
|
+
break;
|
|
303
|
+
case PATH_FUNC_TYPE.EQUAL:
|
|
304
|
+
case PATH_FUNC_TYPE.UNEQUAL:
|
|
305
|
+
case PATH_FUNC_TYPE.BREAK: {
|
|
306
|
+
const inP1 = 'x1' in point && 'y1' in point;
|
|
307
|
+
const inP2 = 'x2' in point && 'y2' in point;
|
|
308
|
+
if (type === PATH_FUNC_TYPE.BREAK && inP1 && inP2) {
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
const index = path.paths.findIndex(c => c.id === point.id);
|
|
312
|
+
const prevPoint = path.paths[index - 1] || path.paths[path.paths.length - 1];
|
|
313
|
+
const nextPoint = path.paths[index + 1] || path.paths[0];
|
|
314
|
+
// 计算平衡线;
|
|
315
|
+
// 点线长度计算两个点的长的距一半;
|
|
316
|
+
const { p1, p2 /* isReverse */ } = getParallelPositionByPoint(prevPoint, nextPoint, point);
|
|
317
|
+
if (type === PATH_FUNC_TYPE.BREAK) {
|
|
318
|
+
if (inP1 && !inP2) {
|
|
319
|
+
point.x2 = p2.x;
|
|
320
|
+
point.y2 = p2.y;
|
|
321
|
+
}
|
|
322
|
+
else if (inP2 && !inP1) {
|
|
323
|
+
point.x1 = p1.x;
|
|
324
|
+
point.y1 = p1.y;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
point.x1 = p1.x;
|
|
328
|
+
point.y1 = p1.y;
|
|
329
|
+
point.x2 = p2.x;
|
|
330
|
+
point.y2 = p2.y;
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
default:
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
this.updateNodeData();
|
|
339
|
+
}
|
|
340
|
+
registerKeybindings() {
|
|
341
|
+
const ctrlKey = !isOSX ? 'control' : 'meta';
|
|
342
|
+
return [
|
|
343
|
+
// alt shift 之类在 keybindings 里面不能单个做快捷键
|
|
344
|
+
this.listenGlobalEvent('keydown', e => {
|
|
345
|
+
// alt 显示全部贝赛尔点
|
|
346
|
+
if (this.isEnabled && e.key.toLowerCase() === 'alt') {
|
|
347
|
+
this.altKey = true;
|
|
348
|
+
this.draw();
|
|
349
|
+
}
|
|
350
|
+
if (this.isEnabled && e.key.toLowerCase() === 'shift') {
|
|
351
|
+
this.shiftKey = true;
|
|
352
|
+
this.draw();
|
|
353
|
+
}
|
|
354
|
+
if (this.isEnabled && e.key.toLowerCase() === ctrlKey) {
|
|
355
|
+
this.ctrlKey = true;
|
|
356
|
+
this.draw();
|
|
357
|
+
}
|
|
358
|
+
}),
|
|
359
|
+
this.listenGlobalEvent('keyup', (e) => {
|
|
360
|
+
if (this.isEnabled && e.key.toLowerCase() === 'alt') {
|
|
361
|
+
this.altKey = false;
|
|
362
|
+
this.draw();
|
|
363
|
+
}
|
|
364
|
+
if (this.isEnabled && e.key.toLowerCase() === 'shift') {
|
|
365
|
+
this.shiftKey = false;
|
|
366
|
+
this.draw();
|
|
367
|
+
}
|
|
368
|
+
if (this.isEnabled && e.key.toLowerCase() === ctrlKey) {
|
|
369
|
+
this.ctrlKey = false;
|
|
370
|
+
this.draw();
|
|
371
|
+
}
|
|
372
|
+
}),
|
|
373
|
+
// tab 切换点
|
|
374
|
+
this.commands.registerCommand(Editor2dPathKeyCommands.TAB_PATH, {
|
|
375
|
+
execute: () => {
|
|
376
|
+
var _a, _b, _c;
|
|
377
|
+
const currentPoint = (_b = (_a = this.pathPointSelection.selection) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.pointId;
|
|
378
|
+
const { paths = [] } = ((_c = this.currentPathNode) === null || _c === void 0 ? void 0 : _c.path) || {};
|
|
379
|
+
const index = currentPoint
|
|
380
|
+
? paths.findIndex(c => c.id === currentPoint)
|
|
381
|
+
: -1;
|
|
382
|
+
let nextPoint;
|
|
383
|
+
if (index === -1) {
|
|
384
|
+
nextPoint = paths[0];
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
nextPoint = paths[index + 1] || paths[0];
|
|
388
|
+
}
|
|
389
|
+
this.selectionChange(nextPoint);
|
|
390
|
+
},
|
|
391
|
+
isEnabled: () => !!this.isEnabled,
|
|
392
|
+
}),
|
|
393
|
+
this.keybindings.registerKeybindings({
|
|
394
|
+
command: Editor2dPathKeyCommands.TAB_PATH.id,
|
|
395
|
+
keybinding: 'tab',
|
|
396
|
+
when: 'editor2dWidgetFocus',
|
|
397
|
+
}),
|
|
398
|
+
// all 全选
|
|
399
|
+
this.commands.registerCommand(Editor2dPathKeyCommands.SELECT_All, {
|
|
400
|
+
execute: () => {
|
|
401
|
+
if (!this.currentPathNode || !this.pathPointSelection) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
const { paths = [] } = this.currentPathNode.path;
|
|
405
|
+
const selection = paths.map(c => ({
|
|
406
|
+
pointId: c.id,
|
|
407
|
+
}));
|
|
408
|
+
this.pathPointSelection.enterSelectBezierMode(selection);
|
|
409
|
+
},
|
|
410
|
+
isEnabled: () => !!this.isEnabled,
|
|
411
|
+
}),
|
|
412
|
+
this.keybindings.registerKeybindings({
|
|
413
|
+
command: Editor2dPathKeyCommands.SELECT_All.id,
|
|
414
|
+
keybinding: isOSX ? 'cmd+a' : 'ctrl+a',
|
|
415
|
+
when: 'editor2dWidgetFocus',
|
|
416
|
+
}),
|
|
417
|
+
// 贝赛尔点
|
|
418
|
+
this.commands.registerCommand(Editor2dPathKeyCommands.BEZIER_STRAIGHT, {
|
|
419
|
+
execute: () => {
|
|
420
|
+
this.updateCurrentPointBezierType(PATH_FUNC_TYPE.STRAIGHT);
|
|
421
|
+
},
|
|
422
|
+
isEnabled: () => !!this.isEnabled,
|
|
423
|
+
}),
|
|
424
|
+
this.keybindings.registerKeybindings({
|
|
425
|
+
command: Editor2dPathKeyCommands.BEZIER_STRAIGHT.id,
|
|
426
|
+
keybinding: '1',
|
|
427
|
+
when: 'editor2dWidgetFocus',
|
|
428
|
+
}),
|
|
429
|
+
this.commands.registerCommand(Editor2dPathKeyCommands.BEZIER_EQUAL, {
|
|
430
|
+
execute: () => {
|
|
431
|
+
this.updateCurrentPointBezierType(PATH_FUNC_TYPE.EQUAL);
|
|
432
|
+
},
|
|
433
|
+
isEnabled: () => !!this.isEnabled,
|
|
434
|
+
}),
|
|
435
|
+
this.keybindings.registerKeybindings({
|
|
436
|
+
command: Editor2dPathKeyCommands.BEZIER_EQUAL.id,
|
|
437
|
+
keybinding: '2',
|
|
438
|
+
when: 'editor2dWidgetFocus',
|
|
439
|
+
}),
|
|
440
|
+
this.commands.registerCommand(Editor2dPathKeyCommands.BEZIER_BREAK, {
|
|
441
|
+
execute: () => {
|
|
442
|
+
this.updateCurrentPointBezierType(PATH_FUNC_TYPE.BREAK);
|
|
443
|
+
},
|
|
444
|
+
isEnabled: () => !!this.isEnabled,
|
|
445
|
+
}),
|
|
446
|
+
this.keybindings.registerKeybindings({
|
|
447
|
+
command: Editor2dPathKeyCommands.BEZIER_BREAK.id,
|
|
448
|
+
keybinding: '3',
|
|
449
|
+
when: 'editor2dWidgetFocus',
|
|
450
|
+
}),
|
|
451
|
+
this.commands.registerCommand(Editor2dPathKeyCommands.BEZIER_UNEQUAL, {
|
|
452
|
+
execute: () => {
|
|
453
|
+
this.updateCurrentPointBezierType(PATH_FUNC_TYPE.UNEQUAL);
|
|
454
|
+
},
|
|
455
|
+
isEnabled: () => !!this.isEnabled,
|
|
456
|
+
}),
|
|
457
|
+
this.keybindings.registerKeybindings({
|
|
458
|
+
command: Editor2dPathKeyCommands.BEZIER_UNEQUAL.id,
|
|
459
|
+
keybinding: '4',
|
|
460
|
+
when: 'editor2dWidgetFocus',
|
|
461
|
+
}),
|
|
462
|
+
];
|
|
463
|
+
}
|
|
167
464
|
onReady() {
|
|
168
465
|
var _a;
|
|
169
466
|
this.addDispose([
|
|
170
|
-
this.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
467
|
+
...this.registerKeybindings(),
|
|
468
|
+
// this.context.historyService.onHistoryBack(e => {
|
|
469
|
+
// this.reNodeData();
|
|
470
|
+
// this.pathPointSelection!.selectMode = PathSelectMode.ADD_PATH;
|
|
471
|
+
// this.pathPointSelection!.clearSelection();
|
|
472
|
+
// this.editorState.toDefaultState();
|
|
473
|
+
// }),
|
|
176
474
|
this.editorState.onStateChange(e => {
|
|
177
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
475
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
178
476
|
/**
|
|
179
477
|
* 1. 不是路径编辑状态时,清空数据
|
|
180
478
|
* 2. 是路径编辑状态时
|
|
@@ -196,6 +494,7 @@ export class PathEditLayer extends Layer {
|
|
|
196
494
|
if (selectNodes.length && pathSelectsNodes.length) {
|
|
197
495
|
// 选中一个 path 路径时;
|
|
198
496
|
this.currentPathNode = deepClone(pathSelectsNodes[0]);
|
|
497
|
+
this.createHistory();
|
|
199
498
|
if (this.currentPathNode.useAnimationId &&
|
|
200
499
|
((_c = (_b = this.document) === null || _b === void 0 ? void 0 : _b.timelineService) === null || _c === void 0 ? void 0 : _c.currentTimelineData) &&
|
|
201
500
|
this.document.timelineService.currentTimelineData.id ===
|
|
@@ -203,32 +502,34 @@ export class PathEditLayer extends Layer {
|
|
|
203
502
|
this.updateTimelineCurrentFrameDataToCurrentNode();
|
|
204
503
|
this.onRegisterTimelineEvent();
|
|
205
504
|
}
|
|
206
|
-
const selectionNode = [
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
505
|
+
const selectionNode = ((_d = this.currentPathNode.path.paths[this.currentPathNode.path.paths.length - 1]) === null || _d === void 0 ? void 0 : _d.id)
|
|
506
|
+
? [
|
|
507
|
+
{
|
|
508
|
+
pointId: this.currentPathNode.path.paths[this.currentPathNode.path.paths.length - 1].id,
|
|
509
|
+
},
|
|
510
|
+
]
|
|
511
|
+
: [];
|
|
211
512
|
this.currentPathNode.path.closed
|
|
212
513
|
? this.pathPointSelection.enterSelectBezierMode(selectionNode)
|
|
213
514
|
: this.pathPointSelection.enterPathMode(selectionNode);
|
|
214
515
|
// 如果中心点不同,更新数据;
|
|
215
|
-
if ((((
|
|
216
|
-
((
|
|
516
|
+
if ((((_e = this.currentPathNode.origin) === null || _e === void 0 ? void 0 : _e.x) ||
|
|
517
|
+
((_f = this.currentPathNode.origin) === null || _f === void 0 ? void 0 : _f.y)) &&
|
|
217
518
|
!this.currentPathNode.path.originChangeBeforeSize) {
|
|
218
519
|
// 初始 origin 是照这个宽度算的;计算偏差使用;
|
|
219
520
|
this.currentPathNode.path.originChangeBeforeSize = {
|
|
220
|
-
width: ((
|
|
221
|
-
height: ((
|
|
521
|
+
width: ((_g = this.currentPathNode.size) === null || _g === void 0 ? void 0 : _g.width) || 0,
|
|
522
|
+
height: ((_h = this.currentPathNode.size) === null || _h === void 0 ? void 0 : _h.height) || 0,
|
|
222
523
|
};
|
|
223
|
-
(
|
|
524
|
+
(_j = this.document) === null || _j === void 0 ? void 0 : _j.updateNode(this.currentPathNode, this.currentPathNode, true);
|
|
224
525
|
}
|
|
225
|
-
else if (!((
|
|
226
|
-
!((
|
|
526
|
+
else if (!((_k = this.currentPathNode.origin) === null || _k === void 0 ? void 0 : _k.x) &&
|
|
527
|
+
!((_l = this.currentPathNode.origin) === null || _l === void 0 ? void 0 : _l.y) &&
|
|
227
528
|
this.currentPathNode.path.originChangeBeforeSize) {
|
|
228
529
|
delete this.currentPathNode.path.originChangeBeforeSize;
|
|
229
|
-
(
|
|
530
|
+
(_m = this.document) === null || _m === void 0 ? void 0 : _m.updateNode(this.currentPathNode, this.currentPathNode, true);
|
|
230
531
|
}
|
|
231
|
-
this.docDispose = (
|
|
532
|
+
this.docDispose = (_o = this.document) === null || _o === void 0 ? void 0 : _o.onContentChanged(c => {
|
|
232
533
|
var _a, _b, _c, _d;
|
|
233
534
|
const newNode = (_a = c.nodes) === null || _a === void 0 ? void 0 : _a.find(c => { var _a; return c.id === ((_a = this.currentPathNode) === null || _a === void 0 ? void 0 : _a.id); });
|
|
234
535
|
if (newNode &&
|
|
@@ -262,23 +563,13 @@ export class PathEditLayer extends Layer {
|
|
|
262
563
|
const selectBound = this.selectorConfig.toRectangle(this.config.finalScale);
|
|
263
564
|
const { paths = [], closed } = ((_a = this.currentPathNode) === null || _a === void 0 ? void 0 : _a.path) || {};
|
|
264
565
|
const pathSelects = [];
|
|
265
|
-
const { position = { x: 0, y: 1 }, scale = { x: 1, y: 1 }, rotation = 0, } = this.currentPathNode;
|
|
266
|
-
const offset = this.getBoundsOffset();
|
|
267
|
-
const center = {
|
|
268
|
-
x: -offset.x,
|
|
269
|
-
y: -offset.y,
|
|
270
|
-
};
|
|
271
566
|
paths.forEach(p => {
|
|
272
|
-
const { x
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
x = r.x + position.x;
|
|
277
|
-
y = r.y + position.y;
|
|
278
|
-
const wh = (4 / this.config.finalScale) * 2;
|
|
279
|
-
if (x >= selectBound.x && // 左
|
|
567
|
+
const { x, y } = this.pathPosToCanvasPos(p);
|
|
568
|
+
// 半径
|
|
569
|
+
const wh = 4 * this.config.finalScale;
|
|
570
|
+
if (x - wh >= selectBound.x && // 左
|
|
280
571
|
x + wh <= selectBound.x + selectBound.width && // 右
|
|
281
|
-
y >= selectBound.y && // 上
|
|
572
|
+
y - wh >= selectBound.y && // 上
|
|
282
573
|
y + wh <= selectBound.y + selectBound.height // 下
|
|
283
574
|
) {
|
|
284
575
|
pathSelects.push({
|
|
@@ -310,60 +601,91 @@ export class PathEditLayer extends Layer {
|
|
|
310
601
|
}
|
|
311
602
|
this.reNodeData();
|
|
312
603
|
}), */
|
|
604
|
+
// 拦掉画布点击事件,失焦再次点击时会触发 widget 的点击事件, 会聚焦到 widget 上
|
|
605
|
+
this.listenPlaygroundEvent('click', (event) => {
|
|
606
|
+
if (this.isEnabled) {
|
|
607
|
+
event.preventDefault();
|
|
608
|
+
event.stopPropagation();
|
|
609
|
+
this.createHistory();
|
|
610
|
+
}
|
|
611
|
+
}),
|
|
313
612
|
// 画布新增点点击事件;
|
|
314
613
|
this.listenPlaygroundEvent('mousedown', (event) => {
|
|
315
614
|
// 只在左键点击时绘制
|
|
316
|
-
if (event.buttons !== 1) {
|
|
615
|
+
if (event.buttons !== 1 || !this.isEnabled) {
|
|
317
616
|
return;
|
|
318
617
|
}
|
|
618
|
+
event.preventDefault();
|
|
619
|
+
event.stopPropagation();
|
|
319
620
|
this.startDrag(event.clientX, event.clientY, {
|
|
320
621
|
onDragStart: e => {
|
|
321
|
-
var _a, _b, _c;
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
(
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
622
|
+
var _a, _b, _c, _d, _e, _f;
|
|
623
|
+
const { selectMode, selection } = this.pathPointSelection || {};
|
|
624
|
+
/**
|
|
625
|
+
* 拦截画布点击事件,不处理绘制;
|
|
626
|
+
* 1. 闭合路径时;
|
|
627
|
+
* 2. 带区域选择模式时;
|
|
628
|
+
* 3. 多点选择时;
|
|
629
|
+
*/
|
|
630
|
+
if (
|
|
631
|
+
// 判断当前 select 是否 path 路径
|
|
632
|
+
(this.currentPathNode && this.currentPathNode.path.closed) ||
|
|
633
|
+
selectMode !== PathSelectMode.ADD_PATH ||
|
|
634
|
+
(selection && selection.length > 1)) {
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
let { x, y } = this.canvasPosToPathPos({
|
|
638
|
+
x: e.endPos.x / (((_a = this.config) === null || _a === void 0 ? void 0 : _a.finalScale) || 1),
|
|
639
|
+
y: e.endPos.y / (((_b = this.config) === null || _b === void 0 ? void 0 : _b.finalScale) || 1),
|
|
640
|
+
});
|
|
641
|
+
if (selection) {
|
|
642
|
+
const selectionPoint = selection[0];
|
|
643
|
+
const index = (_d = (_c = this.currentPathNode) === null || _c === void 0 ? void 0 : _c.path.paths.findIndex(c => c.id === selectionPoint.pointId)) !== null && _d !== void 0 ? _d : -1;
|
|
644
|
+
const node = (_e = this.currentPathNode) === null || _e === void 0 ? void 0 : _e.path.paths[index];
|
|
645
|
+
if (node) {
|
|
646
|
+
// 按住 ctrl 加点时;
|
|
647
|
+
if (this.ctrlKey && node.type !== PATH_FUNC_TYPE.STRAIGHT) {
|
|
648
|
+
const isReverse = index === 0;
|
|
649
|
+
if (isReverse) {
|
|
650
|
+
node.x1 = node.x;
|
|
651
|
+
node.y1 = node.y;
|
|
652
|
+
}
|
|
653
|
+
else {
|
|
654
|
+
node.x2 = node.x;
|
|
655
|
+
node.y2 = node.y;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
// 按住 shift 时,生成固定角度的点;
|
|
659
|
+
if (this.shiftKey) {
|
|
660
|
+
const arc = asVec(node, { x, y });
|
|
661
|
+
let angle = (arc.ang / Math.PI) * 180;
|
|
662
|
+
angle = angle < 0 ? 360 + angle : angle;
|
|
663
|
+
const angleIndex = shiftAngleArray.findIndex(a => a > angle);
|
|
664
|
+
const prevAngle = (_f = shiftAngleArray[angleIndex - 1]) !== null && _f !== void 0 ? _f : shiftAngleArray[shiftAngleArray.length - 1];
|
|
665
|
+
const nextAngle = shiftAngleArray[angleIndex];
|
|
666
|
+
const convertAngle = Math.abs(angle - prevAngle) > Math.abs(nextAngle - angle)
|
|
667
|
+
? nextAngle
|
|
668
|
+
: prevAngle;
|
|
669
|
+
// 取转换角度后的坐标值
|
|
670
|
+
const rad = (convertAngle / 180) * Math.PI;
|
|
671
|
+
x = Math.cos(rad) * arc.len + node.x;
|
|
672
|
+
y = Math.sin(rad) * arc.len + node.y;
|
|
673
|
+
}
|
|
338
674
|
}
|
|
339
|
-
const { position = { x: 0, y: 0 }, scale = { x: 1, y: 1 }, rotation = 0, } = this.currentPathNode || {};
|
|
340
|
-
const offset = this.getBoundsOffset();
|
|
341
|
-
let x = e.endPos.x / (((_b = this.config) === null || _b === void 0 ? void 0 : _b.finalScale) || 1) -
|
|
342
|
-
position.x -
|
|
343
|
-
offset.x;
|
|
344
|
-
let y = e.endPos.y / (((_c = this.config) === null || _c === void 0 ? void 0 : _c.finalScale) || 1) -
|
|
345
|
-
position.y -
|
|
346
|
-
offset.y;
|
|
347
|
-
const center = {
|
|
348
|
-
x: -offset.x,
|
|
349
|
-
y: -offset.y,
|
|
350
|
-
};
|
|
351
|
-
const { x: rx, y: ry } = inverseTransformToData({ x, y }, { scale, rotation }, center);
|
|
352
|
-
x = rx;
|
|
353
|
-
y = ry;
|
|
354
|
-
this.startPos = {
|
|
355
|
-
x,
|
|
356
|
-
y,
|
|
357
|
-
};
|
|
358
|
-
this.startPos.id = generateUuid();
|
|
359
|
-
this.startPos.type = PATH_FUNC_TYPE.STRAIGHT;
|
|
360
|
-
this.addPath(this.startPos);
|
|
361
|
-
this.pathPointSelection.enterPathMode([
|
|
362
|
-
{
|
|
363
|
-
pointId: this.startPos.id,
|
|
364
|
-
},
|
|
365
|
-
]);
|
|
366
675
|
}
|
|
676
|
+
this.startPos = {
|
|
677
|
+
x,
|
|
678
|
+
y,
|
|
679
|
+
};
|
|
680
|
+
this.startPos.id = generateUuid();
|
|
681
|
+
this.startPos.type = PATH_FUNC_TYPE.STRAIGHT;
|
|
682
|
+
this.addPath(this.startPos);
|
|
683
|
+
this.pathPointSelection.enterPathMode([
|
|
684
|
+
{
|
|
685
|
+
pointId: this.startPos.id,
|
|
686
|
+
},
|
|
687
|
+
]);
|
|
688
|
+
this.updateNodeData(true);
|
|
367
689
|
},
|
|
368
690
|
onDrag: e => {
|
|
369
691
|
var _a, _b;
|
|
@@ -371,51 +693,60 @@ export class PathEditLayer extends Layer {
|
|
|
371
693
|
return;
|
|
372
694
|
}
|
|
373
695
|
// const pos = this.getPosFromMouseEvent(e);
|
|
374
|
-
const { path
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
offset.x;
|
|
379
|
-
let y = e.endPos.y / (((_b = this.config) === null || _b === void 0 ? void 0 : _b.finalScale) || 1) -
|
|
380
|
-
position.y -
|
|
381
|
-
offset.y;
|
|
382
|
-
const center = {
|
|
383
|
-
x: -offset.x,
|
|
384
|
-
y: -offset.y,
|
|
385
|
-
};
|
|
386
|
-
const { x: rx, y: ry } = inverseTransformToData({ x, y }, { scale, rotation }, center);
|
|
387
|
-
x = rx;
|
|
388
|
-
y = ry;
|
|
696
|
+
const { path } = this.currentPathNode || {};
|
|
697
|
+
const eX = e.endPos.x / (((_a = this.config) === null || _a === void 0 ? void 0 : _a.finalScale) || 1);
|
|
698
|
+
const eY = e.endPos.y / (((_b = this.config) === null || _b === void 0 ? void 0 : _b.finalScale) || 1);
|
|
699
|
+
let { x, y } = this.canvasPosToPathPos({ x: eX, y: eY });
|
|
389
700
|
const pathNode = path === null || path === void 0 ? void 0 : path.paths.find(c => { var _a; return c.id === ((_a = this.startPos) === null || _a === void 0 ? void 0 : _a.id); });
|
|
390
701
|
// 生成贝赛尔点;
|
|
391
702
|
if (pathNode &&
|
|
392
703
|
Math.max(Math.abs(x - this.startPos.x), Math.abs(y - this.startPos.y)) >= 5) {
|
|
393
|
-
|
|
394
|
-
|
|
704
|
+
let x1 = pathNode.x * 2 - x;
|
|
705
|
+
let y1 = pathNode.y * 2 - y;
|
|
395
706
|
const reverse = this.isOnePoint();
|
|
707
|
+
if (this.shiftKey) {
|
|
708
|
+
// 计算原点到当前点的角度
|
|
709
|
+
const a = Math.abs(x - this.startPos.x);
|
|
710
|
+
const b = Math.abs(y - this.startPos.y);
|
|
711
|
+
const max = Math.max(a, b);
|
|
712
|
+
if (max === a) {
|
|
713
|
+
y = this.startPos.y;
|
|
714
|
+
y1 = this.startPos.y;
|
|
715
|
+
}
|
|
716
|
+
else {
|
|
717
|
+
x = this.startPos.x;
|
|
718
|
+
x1 = this.startPos.x;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
396
721
|
pathNode.x2 = toFixedValue(reverse ? x1 : x, 2);
|
|
397
722
|
pathNode.y2 = toFixedValue(reverse ? y1 : y, 2);
|
|
398
723
|
pathNode.x1 = toFixedValue(reverse ? x : x1, 2);
|
|
399
724
|
pathNode.y1 = toFixedValue(reverse ? y : y1, 2);
|
|
400
725
|
pathNode.type = PATH_FUNC_TYPE.EQUAL;
|
|
401
726
|
// console.log(this.startPos, path?.paths);
|
|
402
|
-
this.updateNodeData();
|
|
727
|
+
this.updateNodeData(true);
|
|
403
728
|
}
|
|
404
729
|
},
|
|
405
730
|
onDragEnd: () => {
|
|
406
731
|
this.startPos = undefined;
|
|
732
|
+
this.updateNodeData();
|
|
407
733
|
},
|
|
408
734
|
});
|
|
409
735
|
}),
|
|
410
736
|
this.listenPlaygroundEvent('dblclick', (e) => {
|
|
411
737
|
var _a;
|
|
738
|
+
if (!this.isEnabled) {
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
e.preventDefault();
|
|
742
|
+
e.stopPropagation();
|
|
412
743
|
// 双击画布时,关闭路径
|
|
413
744
|
// 1. 在路径编辑状态时,不处理;
|
|
414
745
|
// 2. 选中的是 path 路径时,不处理,新增点;
|
|
415
746
|
// 3. 选中点时,不处理;
|
|
416
747
|
// 4. 右键时,不处理;
|
|
417
748
|
// 5. 不是路径编辑状态时,不处理;
|
|
418
|
-
const isExit = this.
|
|
749
|
+
const isExit = this.isEnabled &&
|
|
419
750
|
this.pathPointSelection.selectMode === PathSelectMode.SELECT_BEZIER;
|
|
420
751
|
if (isExit) {
|
|
421
752
|
const playgroundLayer = this.pipelineLayers.find(c => c.id === 'playgroundLayer');
|
|
@@ -438,6 +769,8 @@ export class PathEditLayer extends Layer {
|
|
|
438
769
|
// 选中一个 path 路径
|
|
439
770
|
if (!this.currentPathNode ||
|
|
440
771
|
selectNodes[0].id !== this.currentPathNode.id) {
|
|
772
|
+
// 清空上个 path 的 history
|
|
773
|
+
this.clearHistory();
|
|
441
774
|
// 选中的不是当前的 path 路径, 切换 currentPathNode;
|
|
442
775
|
this.currentPathNode = selectNodes[0];
|
|
443
776
|
if (this.currentPathNode.useAnimationId &&
|
|
@@ -456,6 +789,7 @@ export class PathEditLayer extends Layer {
|
|
|
456
789
|
this.currentPathNode.path.closed
|
|
457
790
|
? pathPointSelection.enterSelectBezierMode(selectionNode)
|
|
458
791
|
: pathPointSelection.enterPathMode(selectionNode);
|
|
792
|
+
this.createHistory();
|
|
459
793
|
// this.updateNodePathData();
|
|
460
794
|
}
|
|
461
795
|
return;
|
|
@@ -510,13 +844,18 @@ export class PathEditLayer extends Layer {
|
|
|
510
844
|
if (!this.currentPathNode) {
|
|
511
845
|
this.currentPathNode = this.document.createDisplayNode(GameObjectBaseType.PATH, undefined, { x: 0, y: 0 });
|
|
512
846
|
this.currentPathNode.selected = true;
|
|
847
|
+
this.currentPathNode.path.paths = [];
|
|
513
848
|
this.context.selection.clearSelection();
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
849
|
+
setTimeout(() => {
|
|
850
|
+
this.context.selection.addSelection({
|
|
851
|
+
node: this.currentPathNode,
|
|
852
|
+
type: TreeSelection.SelectionType.TOGGLE,
|
|
853
|
+
});
|
|
517
854
|
});
|
|
518
855
|
}
|
|
519
|
-
|
|
856
|
+
// 把空数组先插入历史;
|
|
857
|
+
this.createHistory();
|
|
858
|
+
// this.currentPathNode.path.paths = this.currentPathNode.path.paths || []; // array 会被复用,复制一个,保证不会被修改
|
|
520
859
|
if (this.isOnePoint() && this.currentPathNode.path.paths.length > 1) {
|
|
521
860
|
// 第一帧
|
|
522
861
|
this.currentPathNode.path.paths.unshift(pos);
|
|
@@ -529,16 +868,6 @@ export class PathEditLayer extends Layer {
|
|
|
529
868
|
// this.updateNodeData();
|
|
530
869
|
// });
|
|
531
870
|
}
|
|
532
|
-
onBezierPointMove(pos) {
|
|
533
|
-
const { key, path: p } = this.bezierStartPos;
|
|
534
|
-
const { path = { paths: [] } } = this.currentPathNode || {};
|
|
535
|
-
const pathNode = path.paths.find(c => c.id === p.id);
|
|
536
|
-
if (!pathNode || !this.currentPathNode) {
|
|
537
|
-
return;
|
|
538
|
-
}
|
|
539
|
-
setBezierMovePoint(pathNode, key, pos);
|
|
540
|
-
this.updateNodeData();
|
|
541
|
-
}
|
|
542
871
|
onBezierPointMouseDown(e, p, key) {
|
|
543
872
|
if (e.buttons !== 1) {
|
|
544
873
|
return;
|
|
@@ -546,9 +875,10 @@ export class PathEditLayer extends Layer {
|
|
|
546
875
|
e.preventDefault();
|
|
547
876
|
e.stopPropagation();
|
|
548
877
|
const pos = this.getPosFromMouseEvent(e);
|
|
878
|
+
const { x: startX, y: startY } = this.canvasPosToPathPos(pos);
|
|
549
879
|
this.bezierStartPos = {
|
|
550
|
-
x:
|
|
551
|
-
y:
|
|
880
|
+
x: startX,
|
|
881
|
+
y: startY,
|
|
552
882
|
key,
|
|
553
883
|
path: p,
|
|
554
884
|
};
|
|
@@ -562,18 +892,20 @@ export class PathEditLayer extends Layer {
|
|
|
562
892
|
onDrag: e => {
|
|
563
893
|
var _a, _b;
|
|
564
894
|
if (this.bezierStartPos) {
|
|
565
|
-
const {
|
|
566
|
-
const
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
x
|
|
575
|
-
|
|
576
|
-
|
|
895
|
+
const { path = { paths: [] } } = this.currentPathNode || {};
|
|
896
|
+
const { x, y } = this.canvasPosToPathPos({
|
|
897
|
+
x: e.endPos.x / (((_a = this.config) === null || _a === void 0 ? void 0 : _a.finalScale) || 1),
|
|
898
|
+
y: e.endPos.y / (((_b = this.config) === null || _b === void 0 ? void 0 : _b.finalScale) || 1),
|
|
899
|
+
});
|
|
900
|
+
const pathNode = path.paths.find(c => c.id === p.id);
|
|
901
|
+
if (!pathNode) {
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
setBezierMovePoint(pathNode, key, { x, y }, this.bezierStartPos, {
|
|
905
|
+
shiftKey: this.shiftKey,
|
|
906
|
+
ctrlKey: this.ctrlKey,
|
|
907
|
+
});
|
|
908
|
+
this.updateNodeData(true);
|
|
577
909
|
}
|
|
578
910
|
},
|
|
579
911
|
onDragEnd: () => {
|
|
@@ -590,6 +922,7 @@ export class PathEditLayer extends Layer {
|
|
|
590
922
|
]);
|
|
591
923
|
}
|
|
592
924
|
}
|
|
925
|
+
this.updateNodeData();
|
|
593
926
|
},
|
|
594
927
|
});
|
|
595
928
|
this.draw();
|
|
@@ -602,16 +935,13 @@ export class PathEditLayer extends Layer {
|
|
|
602
935
|
}
|
|
603
936
|
return event;
|
|
604
937
|
}
|
|
605
|
-
|
|
606
|
-
if (e.buttons !== 1) {
|
|
607
|
-
return;
|
|
608
|
-
}
|
|
938
|
+
selectionChange(currentPoint) {
|
|
609
939
|
// 如果在 selection 里拖动所有点, 没有则切换当前 selection 里的点
|
|
610
940
|
const { pathPointSelection } = this;
|
|
611
941
|
if (!pathPointSelection) {
|
|
612
942
|
return;
|
|
613
943
|
}
|
|
614
|
-
|
|
944
|
+
const selection = (pathPointSelection === null || pathPointSelection === void 0 ? void 0 : pathPointSelection.selection) || [];
|
|
615
945
|
const node = this.currentPathNode;
|
|
616
946
|
const selectionNode = [
|
|
617
947
|
{
|
|
@@ -654,12 +984,20 @@ export class PathEditLayer extends Layer {
|
|
|
654
984
|
}
|
|
655
985
|
}
|
|
656
986
|
}
|
|
987
|
+
}
|
|
988
|
+
onPointMouseDown(e, currentPoint) {
|
|
989
|
+
if (e.buttons !== 1) {
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
this.selectionChange(currentPoint);
|
|
993
|
+
const node = this.currentPathNode;
|
|
657
994
|
const startNodeClone = deepClone(node.path.paths);
|
|
658
995
|
this.startDrag(e.clientX, e.clientY, {
|
|
659
996
|
// 拖动
|
|
660
997
|
onDrag: dragEvent => {
|
|
661
998
|
var _a, _b;
|
|
662
|
-
|
|
999
|
+
const { pathPointSelection } = this;
|
|
1000
|
+
const selection = (pathPointSelection === null || pathPointSelection === void 0 ? void 0 : pathPointSelection.selection) || [];
|
|
663
1001
|
const selectionNodes = selection
|
|
664
1002
|
.map(s => node.path.paths.find(p => p.id === s.pointId))
|
|
665
1003
|
.filter(c => c);
|
|
@@ -675,70 +1013,92 @@ export class PathEditLayer extends Layer {
|
|
|
675
1013
|
};
|
|
676
1014
|
});
|
|
677
1015
|
const startNode = selectionNodes.map((s) => startNodeClone.find((c) => c.id === s.id));
|
|
678
|
-
const {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
offset.x;
|
|
683
|
-
let y = dragEvent.endPos.y / (((_b = this.config) === null || _b === void 0 ? void 0 : _b.finalScale) || 1) -
|
|
684
|
-
position.y -
|
|
685
|
-
offset.y;
|
|
686
|
-
const center = {
|
|
687
|
-
x: -offset.x,
|
|
688
|
-
y: -offset.y,
|
|
689
|
-
};
|
|
690
|
-
const { x: currentX, y: currentY } = inverseTransformToData({ x, y }, { scale, rotation }, center);
|
|
691
|
-
x = currentX;
|
|
692
|
-
y = currentY;
|
|
1016
|
+
const { x, y } = this.canvasPosToPathPos({
|
|
1017
|
+
x: dragEvent.endPos.x / (((_a = this.config) === null || _a === void 0 ? void 0 : _a.finalScale) || 1),
|
|
1018
|
+
y: dragEvent.endPos.y / (((_b = this.config) === null || _b === void 0 ? void 0 : _b.finalScale) || 1),
|
|
1019
|
+
});
|
|
693
1020
|
selectionNodes.forEach((p, i) => {
|
|
694
1021
|
const start = startNode[i];
|
|
695
1022
|
const d = delta[i];
|
|
696
1023
|
const deltaX = x - start.x + d.x;
|
|
697
1024
|
const deltaY = y - start.y + d.y;
|
|
1025
|
+
const max = Math.max(Math.abs(deltaX), Math.abs(deltaY));
|
|
1026
|
+
const isX = max === Math.abs(deltaX);
|
|
1027
|
+
const isY = max === Math.abs(deltaY);
|
|
1028
|
+
const noX = this.shiftKey && !isX;
|
|
1029
|
+
const noY = this.shiftKey && !isY;
|
|
698
1030
|
if (typeof p.x1 === 'number') {
|
|
699
|
-
p.x1 = toFixedValue(start.x1 + deltaX, 2);
|
|
1031
|
+
p.x1 = noX ? start.x1 : toFixedValue(start.x1 + deltaX, 2);
|
|
700
1032
|
}
|
|
701
1033
|
if (typeof p.x2 === 'number') {
|
|
702
|
-
p.x2 = toFixedValue(start.x2 + deltaX, 2);
|
|
1034
|
+
p.x2 = noX ? start.x2 : toFixedValue(start.x2 + deltaX, 2);
|
|
703
1035
|
}
|
|
704
1036
|
if (typeof p.y1 === 'number') {
|
|
705
|
-
p.y1 = toFixedValue(start.y1 + deltaY, 2);
|
|
1037
|
+
p.y1 = noY ? start.y1 : toFixedValue(start.y1 + deltaY, 2);
|
|
706
1038
|
}
|
|
707
1039
|
if (typeof p.y2 === 'number') {
|
|
708
|
-
p.y2 = toFixedValue(start.y2 + deltaY, 2);
|
|
1040
|
+
p.y2 = noY ? start.y2 : toFixedValue(start.y2 + deltaY, 2);
|
|
709
1041
|
}
|
|
710
|
-
p.x = toFixedValue(x + d.x, 2);
|
|
711
|
-
p.y = toFixedValue(y + d.y, 2);
|
|
1042
|
+
p.x = noX ? start.x : toFixedValue(x + d.x, 2);
|
|
1043
|
+
p.y = noY ? start.y : toFixedValue(y + d.y, 2);
|
|
712
1044
|
});
|
|
1045
|
+
this.updateNodeData(true);
|
|
1046
|
+
},
|
|
1047
|
+
onDragEnd: () => {
|
|
713
1048
|
this.updateNodeData();
|
|
714
1049
|
},
|
|
715
1050
|
});
|
|
716
1051
|
this.draw();
|
|
717
1052
|
}
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
}
|
|
722
|
-
const { path, position = { x: 0, y: 0 }, scale = { x: 1, y: 1 }, rotation = 0, } = this.currentPathNode || {};
|
|
723
|
-
const { paths = [] } = path;
|
|
724
|
-
const p = this.getPosFromMouseEvent(e);
|
|
1053
|
+
// 画布坐标转换成 path 坐标;
|
|
1054
|
+
canvasPosToPathPos(p) {
|
|
1055
|
+
const { position = { x: 0, y: 0 }, scale = { x: 1, y: 1 }, rotation = 0 } = this.currentPathNode || {};
|
|
725
1056
|
const offset = this.getBoundsOffset();
|
|
726
|
-
let x = p.x - position.x - offset.x;
|
|
727
|
-
let y = p.y - position.y - offset.y;
|
|
728
1057
|
const center = {
|
|
729
1058
|
x: -offset.x,
|
|
730
1059
|
y: -offset.y,
|
|
731
1060
|
};
|
|
1061
|
+
let x = p.x - position.x - offset.x;
|
|
1062
|
+
let y = p.y - position.y - offset.y;
|
|
732
1063
|
const { x: currentX, y: currentY } = inverseTransformToData({ x, y }, { scale, rotation }, center);
|
|
733
1064
|
x = currentX;
|
|
734
1065
|
y = currentY;
|
|
735
|
-
|
|
1066
|
+
return {
|
|
736
1067
|
x,
|
|
737
1068
|
y,
|
|
738
1069
|
};
|
|
1070
|
+
}
|
|
1071
|
+
pathPosToCanvasPos(c) {
|
|
1072
|
+
const { position = { x: 0, y: 0 }, scale = { x: 1, y: 1 }, rotation = 0 } = this.currentPathNode || {};
|
|
1073
|
+
const offset = this.getBoundsOffset();
|
|
1074
|
+
const center = {
|
|
1075
|
+
x: -offset.x,
|
|
1076
|
+
y: -offset.y,
|
|
1077
|
+
};
|
|
1078
|
+
const { x, y } = transformToData({ x: c.x, y: c.y }, { scale, rotation }, center);
|
|
1079
|
+
return {
|
|
1080
|
+
x: x + position.x + offset.x,
|
|
1081
|
+
y: y + position.y + offset.y,
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
getPathMousePos(e) {
|
|
1085
|
+
var _a, _b;
|
|
1086
|
+
const p = this.getPosFromMouseEvent({
|
|
1087
|
+
clientX: (_a = e.clientX) !== null && _a !== void 0 ? _a : 0,
|
|
1088
|
+
clientY: (_b = e.clientY) !== null && _b !== void 0 ? _b : 0,
|
|
1089
|
+
});
|
|
1090
|
+
return this.canvasPosToPathPos(p);
|
|
1091
|
+
}
|
|
1092
|
+
onPathAddPoint(i, e) {
|
|
1093
|
+
if (!this.currentPathNode || !this.document) {
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1096
|
+
const { path } = this.currentPathNode || {};
|
|
1097
|
+
const { paths = [] } = path;
|
|
1098
|
+
const pos = this.getPathMousePos(e);
|
|
739
1099
|
const point = paths[i];
|
|
740
1100
|
const nextPoint = paths[i + 1] ? paths[i + 1] : paths[0];
|
|
741
|
-
const newPoint = getNewPoint(point, nextPoint, pos);
|
|
1101
|
+
const newPoint = getNewPoint(point, nextPoint, pos, this.shiftKey);
|
|
742
1102
|
paths.splice(i + 1, 0, newPoint);
|
|
743
1103
|
this.pathPointSelection.enterPathMode([
|
|
744
1104
|
{
|
|
@@ -778,7 +1138,7 @@ export class PathEditLayer extends Layer {
|
|
|
778
1138
|
y: -offset.y,
|
|
779
1139
|
};
|
|
780
1140
|
const paths = [...p].map(c => {
|
|
781
|
-
const item = Object.assign(
|
|
1141
|
+
const item = Object.assign({}, c);
|
|
782
1142
|
const { x, y } = transformToData({ x: c.x, y: c.y }, { scale, rotation }, center);
|
|
783
1143
|
item.x = x + position.x + offset.x;
|
|
784
1144
|
item.y = y + position.y + offset.y;
|
|
@@ -800,8 +1160,10 @@ export class PathEditLayer extends Layer {
|
|
|
800
1160
|
onBezierPointMouseDown: this.onBezierPointMouseDown.bind(this),
|
|
801
1161
|
onClosePath: this.onClosePath.bind(this),
|
|
802
1162
|
onPathAddPoint: this.onPathAddPoint.bind(this),
|
|
1163
|
+
isShiftKey: this.shiftKey,
|
|
1164
|
+
isCtrlKey: this.ctrlKey,
|
|
803
1165
|
} },
|
|
804
|
-
React.createElement(SvgPath, { width: ((_b = this.config.config.pageBounds) === null || _b === void 0 ? void 0 : _b.width) || 300, height: ((_c = this.config.config.pageBounds) === null || _c === void 0 ? void 0 : _c.height) || 300, getPosFromMouseEvent: this.getPosFromMouseEvent.bind(this), node: this.currentPathNode, paths: paths, selection: (_d = this.pathPointSelection) === null || _d === void 0 ? void 0 : _d.selection, selectMode: (_e = this.pathPointSelection) === null || _e === void 0 ? void 0 : _e.selectMode, getPointIsStartOrEnd: this.getPointIsStartOrEnd.bind(this), scale: this.config.finalScale })));
|
|
1166
|
+
React.createElement(SvgPath, { width: ((_b = this.config.config.pageBounds) === null || _b === void 0 ? void 0 : _b.width) || 300, height: ((_c = this.config.config.pageBounds) === null || _c === void 0 ? void 0 : _c.height) || 300, getPosFromMouseEvent: this.getPosFromMouseEvent.bind(this), node: this.currentPathNode, showAllBezier: this.altKey, paths: paths, selection: (_d = this.pathPointSelection) === null || _d === void 0 ? void 0 : _d.selection, selectMode: (_e = this.pathPointSelection) === null || _e === void 0 ? void 0 : _e.selectMode, getPointIsStartOrEnd: this.getPointIsStartOrEnd.bind(this), onUpdateNodeData: this.updateNodeData.bind(this), scale: this.config.finalScale, getPathMousePos: this.getPathMousePos.bind(this), pathPosToCanvasPos: this.pathPosToCanvasPos.bind(this) })));
|
|
805
1167
|
}
|
|
806
1168
|
}
|
|
807
1169
|
__decorate([
|