-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_Selection.js.html
More file actions
1021 lines (879 loc) · 31.5 KB
/
base_Selection.js.html
File metadata and controls
1021 lines (879 loc) · 31.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: base/Selection.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: base/Selection.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/*
* Copyright 2020 WICKLETS LLC
*
* This file is part of Wick Engine.
*
* Wick Engine is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Wick Engine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Wick Engine. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Class representing a Wick Selection.
*/
Wick.Selection = class extends Wick.Base {
static get SELECTABLE_OBJECT_TYPES () {
return ['Path', 'Clip', 'Frame', 'Tween', 'Layer', 'Asset'];
}
static get LOCATION_NAMES () {
return ['Canvas', 'Timeline', 'AssetLibrary'];
}
/**
* Create a Wick Selection.
*/
constructor (args) {
if(!args) args = {};
super(args);
this._selectedObjectsUUIDs = args.selectedObjects || [];
this._widgetRotation = args.widgetRotation || 0;
this._pivotPoint = {x: 0, y: 0};
this._originalWidth = 0;
this._originalHeight = 0;
}
_serialize (args) {
var data = super._serialize(args);
data.selectedObjects = Array.from(this._selectedObjectsUUIDs);
data.widgetRotation = this._widgetRotation;
data.pivotPoint = {
x: this._pivotPoint.x,
y: this._pivotPoint.y,
};
data.originalWidth = this._originalWidth;
data.originalHeight = this._originalHeight;
return data;
}
_deserialize (data) {
super._deserialize(data);
this._selectedObjectsUUIDs = data.selectedObjects || [];
this._widgetRotation = data.widgetRotation;
this._pivotPoint = {
x: data.pivotPoint.x,
y: data.pivotPoint.y
};
this._originalWidth = data.originalWidth;
this._originalHeight = data.originalHeight;
}
get classname () {
return 'Selection';
}
/**
* The names of all attributes of the selection that can be changed.
* @type {string[]}
*/
get allAttributeNames () {
return [
"strokeWidth",
"fillColor",
"strokeColor",
"name",
"filename",
"fontSize",
"fontFamily",
"fontWeight",
"fontStyle",
"src",
"frameLength",
"x",
"y",
"originX",
"originY",
"width",
"height",
"rotation",
"opacity",
"sound",
"soundVolume",
"soundStart",
"identifier",
"easingType",
"fullRotations",
"scaleX",
"scaleY",
"animationType",
"singleFrameNumber",
];
}
/**
* Add a wick object to the selection.
* @param {Wick.Base} object - The object to select.
*/
select (object) {
// Do not allow selection of objects not defined to be selectable
if(!Wick.Selection.SELECTABLE_OBJECT_TYPES.find(type => {
return object instanceof Wick[type];
})) {
console.warn("Tried to select a " + object.classname + " object. This type is not selectable");
return;
}
// Don't do anything if the object is already selected
if(this.isObjectSelected(object)){
return;
}
// Activate the cursor tool when selection changes
if(this._locationOf(object) === 'Canvas') {
this.project.activeTool = this.project.tools.cursor;
object.parentLayer && object.parentLayer.activate();
}
// Only allow selection of objects of in the same location
if(this._locationOf(object) !== this.location) {
this.clear();
}
// Add the object to the selection!
this._selectedObjectsUUIDs.push(object.uuid);
// Select in between frames (for shift+click selecting frames)
if(object instanceof Wick.Frame) {
this._selectInBetweenFrames(object);
}
this._resetPositioningValues();
// Make sure the view gets updated the next time its needed...
this.view.dirty = true;
}
/**
* Remove a wick object from the selection.
* @param {Wick.Base} object - The object to deselect.
*/
deselect (object) {
this._selectedObjectsUUIDs = this._selectedObjectsUUIDs.filter(uuid => {
return uuid !== object.uuid;
});
this._resetPositioningValues();
// Make sure the view gets updated the next time its needed...
this.view.dirty = true;
}
/**
* Remove all objects from the selection with an optional filter.
* @param {string} filter - A location or a type (see SELECTABLE_OBJECT_TYPES and LOCATION_NAMES)
*/
clear (filter) {
this.project.selection.getSelectedObjects(filter).forEach(object => {
this.deselect(object);
});
}
/**
* Checks if a given object is selected.
* @param {Wick.Base} object - The object to check selection of.
*/
isObjectSelected (object) {
return this._selectedObjectsUUIDs.indexOf(object.uuid) !== -1;
}
/**
* Get the first object in the selection if there is a single object in the selection.
* @return {Wick.Base} The first object in the selection.
*/
getSelectedObject () {
if(this.numObjects === 1) {
return this.getSelectedObjects()[0];
} else {
return null;
}
}
/**
* Get the objects in the selection with an optional filter.
* @param {string} filter - A location or a type (see SELECTABLE_OBJECT_TYPES and LOCATION_NAMES)
* @return {Wick.Base[]} The selected objects.
*/
getSelectedObjects (filter) {
var objects = this._selectedObjectsUUIDs.map(uuid => {
return Wick.ObjectCache.getObjectByUUID(uuid);
});
if(Wick.Selection.LOCATION_NAMES.indexOf(filter) !== -1) {
var location = filter;
if(this.location !== location) {
return [];
} else {
return this.getSelectedObjects();
}
} else if (typeof filter === 'string') {
var classname = filter;
objects = objects.filter(object => {
return object instanceof Wick[classname];
});
}
return objects;
}
/**
* Get the UUIDs of the objects in the selection with an optional filter.
* @param {string} filter - A location or a type (see SELECTABLE_OBJECT_TYPES and LOCATION_NAMES)
* @return {string[]} The UUIDs of the selected objects.
*/
getSelectedObjectUUIDs (filter) {
return this.getSelectedObjects(filter).map(object => {
return object.uuid;
});
}
/**
* The location of the objects in the selection. (see LOCATION_NAMES)
* @type {string}
*/
get location () {
if(this.numObjects === 0) return null;
return this._locationOf(this.getSelectedObjects()[0]);
}
/**
* The types of the objects in the selection. (see SELECTABLE_OBJECT_TYPES)
* @type {string[]}
*/
get types () {
var types = this.getSelectedObjects().map(object => {
return object.classname;
});
var uniqueTypes = [...new Set(types)];
return uniqueTypes;
}
/**
* A single string describing the contents of the selection.
* @type {string}
*/
get selectionType () {
let selection = this;
if(selection.location === 'Canvas') {
if(selection.numObjects === 1) {
var selectedObject = selection.getSelectedObject();
if(selectedObject instanceof window.Wick.Path) {
return selectedObject.pathType;
} else if(selectedObject instanceof window.Wick.Button) {
return 'button';
} else if(selectedObject instanceof window.Wick.Clip) {
return 'clip';
}
} else if (selection.types.length === 1) {
if (selection.types[0] === 'Path') {
return 'multipath';
} else {
return 'multiclip';
}
} else {
return 'multicanvas';
}
} else if (selection.location === 'Timeline') {
if(selection.numObjects === 1) {
if(selection.getSelectedObject() instanceof window.Wick.Frame) {
return 'frame';
} else if(selection.getSelectedObject() instanceof window.Wick.Layer) {
return 'layer';
} else if(selection.getSelectedObject() instanceof window.Wick.Tween) {
return 'tween';
}
} else if (selection.types.length === 1) {
if(selection.getSelectedObjects()[0] instanceof window.Wick.Frame) {
return 'multiframe';
} else if(selection.getSelectedObjects()[0] instanceof window.Wick.Layer) {
return 'multilayer';
} else if(selection.getSelectedObjects()[0] instanceof window.Wick.Tween) {
return 'multitween';
}
} else {
return 'multitimeline';
}
} else if (selection.location === 'AssetLibrary') {
if(selection.getSelectedObjects()[0] instanceof window.Wick.ImageAsset) {
return 'imageasset';
} else if(selection.getSelectedObjects()[0] instanceof window.Wick.SoundAsset) {
return 'soundasset';
} else {
return 'multiassetmixed'
}
} else {
return 'unknown';
}
}
/**
* The number of objects in the selection.
* @type {number}
*/
get numObjects () {
return this._selectedObjectsUUIDs.length;
}
/**
* The rotation of the selection (used for canvas selections)
* @type {number}
*/
get widgetRotation () {
return this._widgetRotation;
}
set widgetRotation (widgetRotation) {
this._widgetRotation = widgetRotation;
}
/**
* The point that transformations to the selection will be based around.
* @type {object}
*/
get pivotPoint () {
return this._pivotPoint;
}
set pivotPoint (pivotPoint) {
this._pivotPoint = pivotPoint;
}
/**
* The animation type of a clip.
* @type {string}
*/
get animationType () {
if (this.getSelectedObject() && this.selectionType === 'clip') {
return this.getSelectedObject().animationType;
} else {
return null;
}
}
set animationType (newType) {
if (this.getSelectedObject()) {
this.getSelectedObject().animationType = newType;
} else {
console.error("Cannot set the animation type of multiple objects...");
}
}
/**
* If a clip is set to singleFrame, this number will be used to determine that frame.
*/
get singleFrameNumber () {
if (this.getSelectedObject() && this.selectionType === 'clip') {
return this.getSelectedObject().singleFrameNumber;
} else {
return null;
}
}
set singleFrameNumber (frame) {
if (this.getSelectedObject()) {
this.getSelectedObject().singleFrameNumber = frame;
} else {
console.error("Cannot set singleFrameNumber of multiple objects...");
}
}
/**
* The position of the selection.
* @type {number}
*/
get x () {
return this.view.x;
}
set x (x) {
this.view.x = x;
this.project.tryToAutoCreateTween();
}
/**
* The position of the selection.
* @type {number}
*/
get y () {
return this.view.y;
}
set y (y) {
this.view.y = y;
this.project.tryToAutoCreateTween();
}
/**
* The origin position the selection.
* @type {number}
*/
get originX () {
// If there's only 1 object selected, the origin is that object's position.
if(this.getSelectedObject() && (this.selectionType === "clip" || this.selectionType === "button")) {
return this.getSelectedObject().transformation.x;
} else {
return this.x + this.width/2;
}
}
set originX (x) {
if(this.getSelectedObject() && (this.selectionType === "clip" || this.selectionType === "button")) {
this.getSelectedObject().x = x;
this.pivotPoint = {x: x, y : this.pivotPoint.y};
} else {
this.x = x - this.width/2;
}
}
/**
* The origin position the selection.
* @type {number}
*/
get originY () {
// If there's only 1 object selected, the origin is that object's position.
if (this.getSelectedObject() && (this.selectionType === "clip" || this.selectionType === "button")) {
return this.getSelectedObject().y
} else {
return this.y + this.height/2;
}
}
set originY (y) {
if (this.getSelectedObject() && (this.selectionType === "clip" || this.selectionType === "button")) {
this.getSelectedObject().y = y;
this.pivotPoint = {x: this.pivotPoint.x, y : y};
} else {
this.y = y - this.height/2;
}
}
/**
* The width of the selection.
* @type {number}
*/
get width () {
return this.view.width;
}
set width (width) {
this.project.tryToAutoCreateTween();
this.view.width = width;
}
/**
* The height of the selection.
* @type {number}
*/
get height () {
return this.view.height;
}
set height (height) {
this.project.tryToAutoCreateTween();
this.view.height = height;
}
/**
* The rotation of the selection.
* @type {number}
*/
get rotation () {
return this.view.rotation;
}
set rotation (rotation) {
this.project.tryToAutoCreateTween();
this.view.rotation = rotation;
}
/**
* It is the original width of the selection at creation.
* @type {number}
*/
get originalWidth () {
return this._originalWidth;
}
set originalWidth (originalWidth) {
this._originalWidth = originalWidth;
}
/**
* It is the original height of the selection at creation.
* @type {number}
*/
get originalHeight () {
return this._originalHeight;
}
set originalHeight (originalHeight) {
this._originalHeight = originalHeight;
}
/**
* The scale of the selection on the X axis.
* @type {number}
*/
get scaleX () {
// Clips store their scale state internally
if (this.selectionType === "clip" || this.selectionType === "button") {
return this.getSelectedObject().transformation.scaleX;
} else {
// Paths do not save their internal scale state.
return this.width / this.originalWidth;
}
}
set scaleX (scaleX) {
// Clips store their scale state internally
if (this.selectionType === "clip" || this.selectionType === "button") {
this.getSelectedObject().scaleX = scaleX;
} else {
this.width = this.originalWidth * scaleX;
}
}
/**
* The scale of the selection on the Y axis.
* @type {number}
*/
get scaleY () {
// Clips store their scale state internally
if (this.selectionType === "clip" || this.selectionType === "button") {
return this.getSelectedObject().transformation.scaleY;
} else {
return this.height / this.originalHeight;
}
}
set scaleY (scaleY) {
// Clips store their scale state internally
if (this.selectionType === "clip" || this.selectionType === "button") {
this.getSelectedObject().scaleY = scaleY;
} else {
this.height = this.originalHeight * scaleY;
}
}
/**
* Flips the selected obejcts horizontally.
*/
flipHorizontally () {
this.project.tryToAutoCreateTween();
this.view.flipHorizontally();
}
/**
* Flips the selected obejcts vertically.
*/
flipVertically () {
this.project.tryToAutoCreateTween();
this.view.flipVertically();
}
/**
* Sends the selected objects to the back.
*/
sendToBack () {
this.view.sendToBack();
}
/**
* Brings the selected objects to the front.
*/
bringToFront () {
this.view.bringToFront();
}
/**
* Moves the selected objects forwards.
*/
moveForwards () {
this.view.moveForwards();
}
/**
* Moves the selected objects backwards.
*/
moveBackwards () {
this.view.moveBackwards();
}
/**
* The identifier of the selected object.
* @type {string}
*/
get identifier () {
return this._getSingleAttribute('identifier');
}
set identifier (identifier) {
this._setSingleAttribute('identifier', identifier);
}
/**
* The name of the selected object.
* @type {string}
*/
get name () {
return this._getSingleAttribute('name');
}
set name (name) {
this._setSingleAttribute('name', name);
}
/**
* The fill color of the selected object.
* @type {paper.Color}
*/
get fillColor () {
return this._getSingleAttribute('fillColor');
}
set fillColor (fillColor) {
this._setSingleAttribute('fillColor', fillColor);
}
/**
* The stroke color of the selected object.
* @type {paper.Color}
*/
get strokeColor () {
return this._getSingleAttribute('strokeColor');
}
set strokeColor (strokeColor) {
this._setSingleAttribute('strokeColor', strokeColor);
}
/**
* The stroke width of the selected object.
* @type {number}
*/
get strokeWidth () {
return this._getSingleAttribute('strokeWidth');
}
set strokeWidth (strokeWidth) {
this._setSingleAttribute('strokeWidth', strokeWidth);
}
/**
* The font family of the selected object.
* @type {string}
*/
get fontFamily () {
return this._getSingleAttribute('fontFamily');
}
set fontFamily (fontFamily) {
this._setSingleAttribute('fontFamily', fontFamily);
}
/**
* The font size of the selected object.
* @type {number}
*/
get fontSize () {
return this._getSingleAttribute('fontSize');
}
set fontSize (fontSize) {
this._setSingleAttribute('fontSize', fontSize);
}
/**
* The font weight of the selected object.
* @type {number}
*/
get fontWeight () {
return this._getSingleAttribute('fontWeight');
}
set fontWeight (fontWeight) {
this._setSingleAttribute('fontWeight', fontWeight);
}
/**
* The font style of the selected object. ('italic' or 'oblique')
* @type {string}
*/
get fontStyle () {
return this._getSingleAttribute('fontStyle');
}
set fontStyle (fontStyle) {
this._setSingleAttribute('fontStyle', fontStyle);
}
/**
* The opacity of the selected object.
* @type {number}
*/
get opacity () {
return this._getSingleAttribute('opacity');
}
set opacity (opacity) {
this.project.tryToAutoCreateTween();
this._setSingleAttribute('opacity', opacity);
}
/**
* The sound attached to the selected frame.
* @type {Wick.SoundAsset}
*/
get sound () {
return this._getSingleAttribute('sound');
}
set sound (sound) {
this._setSingleAttribute('sound', sound);
}
/**
* The length of the selected frame.
* @type {number}
*/
get frameLength () {
return this._getSingleAttribute('length');
}
set frameLength (frameLength) {
this._setSingleAttribute('length', frameLength);
var layer = this.project.activeLayer;
layer.resolveOverlap(this.getSelectedObjects());
layer.resolveGaps();
}
/**
* The volume of the sound attached to the selected frame.
* @type {number}
*/
get soundVolume () {
return this._getSingleAttribute('soundVolume');
}
set soundVolume (soundVolume) {
this._setSingleAttribute('soundVolume', soundVolume);
}
/**
* The starting position of the sound on the frame in ms.
* @type {number}
*/
get soundStart () {
return this._getSingleAttribute('soundStart');
}
set soundStart (soundStart) {
this._setSingleAttribute('soundStart', soundStart);
}
/**
* The easing type of a selected tween. See Wick.Tween.VALID_EASING_TYPES.
* @type {string}
*/
get easingType () {
return this._getSingleAttribute('easingType');
}
set easingType (easingType) {
return this._setSingleAttribute('easingType', easingType);
}
/**
* The amount of rotations to perform during a tween. Positive value = clockwise rotation.
* @type {Number}
*/
get fullRotations () {
return this._getSingleAttribute('fullRotations');
}
set fullRotations (fullRotations) {
return this._setSingleAttribute('fullRotations', fullRotations);
}
/**
* The filename of the selected asset. Read only.
* @type {string}
*/
get filename () {
return this._getSingleAttribute('filename');
}
/**
* True if the selection is scriptable. Read only.
* @type {boolean}
*/
get isScriptable () {
return this.numObjects === 1 && this.getSelectedObjects()[0].isScriptable;
}
/**
* The source (dataURL) of the selected ImageAsset or SoundAsset. Read only.
* @type {string}
*/
get src () {
return this.numObjects === 1 && this.getSelectedObjects()[0].src;
}
/**
* Get a list of only the farthest right frames on each layer.
* @returns {Wick.Frame[]}
*/
getRightmostFrames () {
var selectedFrames = this.getSelectedObjects('Frame');
var rightmostFrames = {};
selectedFrames.forEach(frame => {
var layerid = frame.parentLayer.uuid;
if(!rightmostFrames[layerid] || frame.end > rightmostFrames[layerid].end) {
rightmostFrames[layerid] = frame;
}
});
var result = [];
for(var id in rightmostFrames) {
result.push(rightmostFrames[id]);
}
return result;
}
/**
* Get a list of only the farthest left frames on each layer.
* @returns {Wick.Frame[]}
*/
getLeftmostFrames () {
var selectedFrames = this.getSelectedObjects('Frame');
var leftmostFrames = {};
selectedFrames.forEach(frame => {
var layerid = frame.parentLayer.uuid;
if(!leftmostFrames[layerid] || frame.start < leftmostFrames[layerid].end) {
leftmostFrames[layerid] = frame;
}
});
var result = [];
for(var id in leftmostFrames) {
result.push(leftmostFrames[id]);
}
return result;
}
_locationOf (object) {
if(object instanceof Wick.Frame
|| object instanceof Wick.Tween
|| object instanceof Wick.Layer) {
return 'Timeline';
} else if (object instanceof Wick.Asset) {
return 'AssetLibrary';
} else if (object instanceof Wick.Path
|| object instanceof Wick.Clip) {
return 'Canvas';
}
}
/* Helper function: Calculate the selection x,y */
_resetPositioningValues () {
var selectedObject = this.getSelectedObject();
if(selectedObject instanceof Wick.Clip) {
// Single clip selected: Use that Clip's transformation for the pivot point and rotation
this._widgetRotation = selectedObject.transformation.rotation;
this._pivotPoint = {
x: selectedObject.transformation.x,
y: selectedObject.transformation.y,
}
} else {
// Path selected or multiple objects selected: Reset rotation and use center for pivot point
this._widgetRotation = 0;
var boundsCenter = this.view._getSelectedObjectsBounds().center;
this._pivotPoint = {
x: boundsCenter.x,
y: boundsCenter.y,
};
// Always pull original size values.
this._originalWidth = this.view._getSelectedObjectsBounds().width;
this._originalHeight = this.view._getSelectedObjectsBounds().height;
}
}
/* helper function for getting a single value from multiple selected objects */
_getSingleAttribute (attributeName) {
if(this.numObjects === 0) return null;
return this.getSelectedObjects()[0][attributeName];
}
/* helper function for updating the same attribute on all items in the selection */
_setSingleAttribute (attributeName, value) {
this.getSelectedObjects().forEach(selectedObject => {
selectedObject[attributeName] = value;
});
}
/*helper function for shift+selecting frames*/
_selectInBetweenFrames (selectedFrame) {
var frameBounds = {
playheadStart: null,
playheadEnd: null,
};
// Calculate bounding box of all selected frames
var selectedFrames = this.getSelectedObjects('Frame');
selectedFrames.filter(frame => {
return frame.parentLayer === selectedFrame.parentLayer;
}).forEach(frame => {
var start = frame.start;
var end = frame.end;
if(!frameBounds.playheadStart || !frameBounds.playheadEnd) {
frameBounds.playheadStart = start;
frameBounds.playheadEnd = end;
}
if(start < frameBounds.playheadStart) {
frameBounds.playheadStart = start;
}
if(end > frameBounds.playheadEnd) {
frameBounds.playheadEnd = end;
}
});
// Select all frames inside bounding box
this.project.activeTimeline.getAllFrames().filter(frame => {
return !frame.isSelected &&
frame.parentLayer === selectedFrame.parentLayer &&
frame.inRange(frameBounds.playheadStart, frameBounds.playheadEnd)
}).forEach(frame => {
this._selectedObjectsUUIDs.push(frame.uuid);
});
}
}
</code></pre>
</article>