-
-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathView.Frame.js
More file actions
157 lines (134 loc) · 5.37 KB
/
Copy pathView.Frame.js
File metadata and controls
157 lines (134 loc) · 5.37 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
/*
* 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/>.
*/
Wick.View.Frame = class extends Wick.View {
/**
* A multiplier for the resolution for the rasterization process.
* E.g. a multiplier of 2 will make a path 100 pixels wide rasterize into an image 200 pixels wide.
*/
static get RASTERIZE_RESOLUTION_MODIFIER() {
return 1;
}
static get RASTERIZE_RESOLUTION_MODIFIER_FOR_DEVICE() {
return Wick.View.Frame.RASTERIZE_RESOLUTION_MODIFIER / window.devicePixelRatio;
}
/**
* Create a frame view.
*/
constructor() {
super();
this.objectsLayer = new this.paper.Layer();
this.objectsLayer.remove();
}
/**
* Write the changes made to the view to the frame.
*/
applyChanges() {
this._applyDrawableChanges();
}
/**
* Update the view based on the model
*/
render() {
this._renderObjects();
}
_renderObjects() {
this.objectsLayer.data.wickUUID = this.model.uuid;
this.objectsLayer.data.wickType = 'clipsandpaths';
this.objectsLayer.removeChildren();
// Remove placeholder paths if
// 1) this frame is focused, or
// 2) the project is playing
if(this.model.parentClip.isFocus || (this.model.project&&this.model.project.playing)) {
this.model.paths.forEach(path => {
if(path.isPlaceholder) {
path.remove();
}
});
}
let children = this.model.drawable.map(object => {
object.view.render();
if (object.view.model instanceof Wick.Path) {
return object.view.item;
} else {
return object.view.group;
}
});
this.objectsLayer.addChildren(children);
}
_applyDrawableChanges() {
this.model.drawable.filter(path => {
return path instanceof Wick.Path && path.isDynamicText;
}).forEach(path => {
path.view.item.bringToFront();
}); // Clear all WickPaths from the frame
// Reorder clips
var drawables = this.model.drawable.concat([]);
drawables.forEach(drawable => {
// should realkly be remove child
this.model.removeClip(drawable);
});
this.objectsLayer.children.filter(child => {
return child.data.wickType !== 'gui';
}).forEach(child => {
if (child instanceof paper.Group || child instanceof Wick.Clip) {
this.model.addClip(drawables.find(g => {
return g.uuid === child.data.wickUUID;
}));
} else {
var originalWickPath = child.data.wickUUID ? Wick.ObjectCache.getObjectByUUID(child.data.wickUUID) : null;
var pathJSON = Wick.View.Path.exportJSON(child);
var wickPath = new Wick.Path({
project: this.model.project,
json: pathJSON
});
this.model.addPath(wickPath);
wickPath.fontWeight = originalWickPath ? originalWickPath.fontWeight : 400;
wickPath.fontStyle = originalWickPath ? originalWickPath.fontStyle : 'normal';
wickPath.identifier = originalWickPath ? originalWickPath.identifier : null;
child.name = wickPath.uuid;
}
}); // Update clip transforms
this.objectsLayer.children.filter(child => {
return child.data.wickType !== 'gui';
}).forEach(child => {
if (child instanceof paper.Group || child instanceof Wick.Clip) {
var wickClip = Wick.ObjectCache.getObjectByUUID(child.data.wickUUID);
wickClip.transformation = new Wick.Transformation({
x: child.position.x,
y: child.position.y,
scaleX: child.scaling.x,
scaleY: child.scaling.y,
rotation: child.rotation,
opacity: child.opacity
});
}
});
/*
var originalWickPath = child.data.wickUUID ? Wick.ObjectCache.getObjectByUUID(child.data.wickUUID) : null;
var pathJSON = Wick.View.Path.exportJSON(child);
var wickPath = new Wick.Path({json:pathJSON});
this.model.addPath(wickPath);
wickPath.fontWeight = originalWickPath ? originalWickPath.fontWeight : 400;
wickPath.fontStyle = originalWickPath ? originalWickPath.fontStyle : 'normal';
wickPath.identifier = originalWickPath ? originalWickPath.identifier : null;
wickPath.isPlaceholder = originalWickPath ? originalWickPath.isPlaceholder : false;
child.name = wickPath.uuid;
*/
}
};