1 | |
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | import * as go from '../release/go-module.js';
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | export class NonRealtimeDraggingTool extends go.DraggingTool {
|
23 | private _duration: number = 0;
|
24 | private _imagePart: go.Part | null = null;
|
25 | private _ghostDraggedParts: go.Map<go.Part, go.DraggingInfo> | null = null;
|
26 | private _originalDraggedParts: go.Map<go.Part, go.DraggingInfo> | null = null;
|
27 |
|
28 | |
29 |
|
30 |
|
31 |
|
32 | get duration(): number { return this._duration; }
|
33 | set duration(val: number) { this._duration = val; }
|
34 |
|
35 | |
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | public computeEffectiveCollection(coll: go.Iterable<go.Part>): go.Map<go.Part, go.DraggingInfo> {
|
42 | const map = super.computeEffectiveCollection(coll, this.dragOptions);
|
43 | if (this.isActive && this._imagePart === null) {
|
44 | const bounds = this.diagram.computePartsBounds(map.toKeySet());
|
45 | const offset = this.diagram.lastInput.documentPoint.copy().subtract(bounds.position);
|
46 | const $ = go.GraphObject.make;
|
47 | this._imagePart =
|
48 | $(go.Part,
|
49 | { layerName: 'Tool', opacity: 0.5, locationSpot: new go.Spot(0, 0, offset.x, offset.y) },
|
50 | $(go.Picture,
|
51 | { element: this.diagram.makeImage({ parts: map.toKeySet() }) })
|
52 | );
|
53 | }
|
54 | return map;
|
55 | }
|
56 |
|
57 | |
58 |
|
59 |
|
60 |
|
61 | public doActivate(): void {
|
62 | super.doActivate();
|
63 | if (this._imagePart !== null) {
|
64 | this._imagePart.location = this.diagram.lastInput.documentPoint;
|
65 | this.diagram.add(this._imagePart);
|
66 | this._originalDraggedParts = this.draggedParts;
|
67 | this._ghostDraggedParts = super.computeEffectiveCollection(new go.List<go.Part>().add(this._imagePart), this.dragOptions);
|
68 | this.draggedParts = this._ghostDraggedParts;
|
69 | }
|
70 | }
|
71 |
|
72 | |
73 |
|
74 |
|
75 | public doDeactivate(): void {
|
76 | if (this._imagePart !== null) {
|
77 | this.diagram.remove(this._imagePart);
|
78 | }
|
79 | this._imagePart = null;
|
80 | this._ghostDraggedParts = null;
|
81 | this._originalDraggedParts = null;
|
82 | super.doDeactivate();
|
83 | }
|
84 |
|
85 | |
86 |
|
87 |
|
88 | public doMouseUp(): void {
|
89 | const partsmap = this._originalDraggedParts;
|
90 | if (partsmap !== null) {
|
91 | this.draggedParts = partsmap;
|
92 | }
|
93 | super.doMouseUp();
|
94 | if (partsmap !== null && this.duration > 0) {
|
95 | var anim = new go.Animation();
|
96 | anim.duration = this.duration;
|
97 | partsmap.each(function(kvp) {
|
98 | var part = kvp.key;
|
99 | anim.add(part, "location", kvp.value.point, part.location);
|
100 | });
|
101 | anim.start();
|
102 | }
|
103 | }
|
104 |
|
105 | |
106 |
|
107 |
|
108 |
|
109 | public doKeyDown(): void {
|
110 | if (this._imagePart !== null && this._originalDraggedParts !== null &&
|
111 | (this.diagram.lastInput.control || this.diagram.lastInput.meta) && this.mayCopy()) {
|
112 | this.draggedParts = this._originalDraggedParts;
|
113 | this.diagram.remove(this._imagePart);
|
114 | }
|
115 | super.doKeyDown();
|
116 | }
|
117 |
|
118 | |
119 |
|
120 |
|
121 |
|
122 | public doKeyUp(): void {
|
123 | if (this._imagePart !== null && this._ghostDraggedParts !== null && this.mayMove()) {
|
124 | this._imagePart.location = this.diagram.lastInput.documentPoint;
|
125 | this.diagram.add(this._imagePart);
|
126 | this.draggedParts = this._ghostDraggedParts;
|
127 | }
|
128 | super.doKeyUp();
|
129 | }
|
130 | }
|