forked from aibosan/anigen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uiManager.js
225 lines (176 loc) · 7.9 KB
/
uiManager.js
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
/**
* @author Ondrej Benda
* @date 2017
* @copyright GNU GPLv3
* @brief Manager for UI layout, keeps track of sections and windows.
*/
function uiManager() {
if(window.anigenManager) { return; }
this.sections = [];
this.activeSection = null;
this.named = {};
this.classes = {};
window.addEventListener("mousedown", this.eventMouseDown.bind(this), false);
window.addEventListener("mouseup", this.eventMouseUp.bind(this), false);
window.addEventListener("mousemove", this.eventMouseMove.bind(this), false);
window.addEventListener("resize", this.eventResize.bind(this), false);
window.anigenManager = this;
}
uiManager.prototype.seedAnigen = function() {
// wipes body
document.body.removeChildren();
// creates svg area for exporting
var svgArea = document.createElement('div');
svgArea.setAttribute('id', 'svgArea');
document.body.appendChild(svgArea);
// svg
this.named.svg = new uiSection([0,0,0,0],false,true,{'class': 'section-svg'},this);
// left
this.named.left = new uiSection([0,109,window.innerWidth/3,35],[false, true, false, false],[true, false, true, true],{'class': 'section-left'},this,'anigenActual.settings.set("treeWidth", this.width);');
// right
this.named.right = new uiSection([2*window.innerWidth/3,109,100,35],[false, false, false, true],[true, true, true, false],{'class': 'section-right'},this,'anigenActual.settings.set("windowsWidth", this.width);');
// bottom portion
var bottomAction = '';
bottomAction += 'var desired=Math.round((this.height)/24)*24;';
bottomAction += 'this.setY(window.innerHeight-(desired == 0 ? 6 : desired));';
bottomAction += 'this.refresh();';
bottomAction += 'anigenManager.refresh();';
bottomAction += 'anigenActual.settings.set("bottomHeight", this.height);';
this.named.bottom = new uiSection([0,window.innerHeight-24,100,24],[true, false, false, false],[false, true, true, true],{'class': 'section-bottom'},this,bottomAction);
// top portion
// selection info
this.named.selection = new uiSection([0,34,100,42],false,[false, true, false, true],{'class': 'section-top-row2'},this);
// editor info & menu
this.named.info = new uiSection([0,0,100,36],false,[true, true, false, true],{'class': 'section-top-row1'},this);
// context menu
this.named.context = new uiSection([0,76,100,32],false,[false, true, false, true],{'class': 'section-top-row3'},this);
// timeline
this.named.timeline = new uiSection([0,74,100,0],false,[false, true, false, true],null,this);
this.named.left.setLimits([this.named.context, this.named.right, this.named.bottom, null]);
this.named.right.setLimits([this.named.context, null, this.named.bottom, this.named.left]);
this.named.left.setSlacks([-1, 64, 0, 0]);
this.named.right.setSlacks([-1, 0, 0, 64]);
this.named.bottom.setLimits([this.named.context, null, null, null]);
this.named.bottom.setSlacks([64, 0, 0, 0]);
// listeners
//window.anigenActual.connectSVG(this.named.svg.content);
anigenManager.named.svg.container.addEventListener("mousemove", anigenActual.eventMouseMove, false);
anigenManager.named.svg.container.addEventListener("mousedown", anigenActual.eventMouseDown, false);
//anigenManager.named.svg.container.addEventListener("mouseup", anigenActual.eventMouseUp, false);
anigenManager.named.svg.container.addEventListener("wheel", anigenActual.eventScroll, false);
anigenManager.named.svg.container.addEventListener('mouseover', anigenActual.eventMouseOver, false);
for(var i in this.named) {
document.body.appendChild(this.named[i].container);
}
this.classes.timeline = new uiTimeline();
this.classes.editor = new infoEditor(this.classes.timeline);
this.classes.menu = new menu();
this.classes.selection = new infoSelection();
this.classes.context = new infoContext();
this.classes.windowAnimation = new windowAnimation();
this.classes.windowLayers = new windowLayers();
this.classes.windowColors = new windowColors();
this.classes.tree = new tree();
this.classes.rulerH = new uiRuler(false, this.named.context);
this.classes.rulerV = new uiRuler(true, this.named.left);
this.named.svg.container.appendChild(this.classes.rulerV.container);
this.named.svg.container.appendChild(this.classes.rulerH.container);
this.named.timeline.content.appendChild(this.classes.timeline.container);
this.named.info.content.appendChild(this.classes.editor.container);
this.named.info.content.appendChild(this.classes.menu.container);
this.named.selection.content.appendChild(this.classes.selection.container);
this.named.context.content.appendChild(this.classes.context.container);
this.named.right.content.appendChild(this.classes.windowAnimation.container);
this.named.right.content.appendChild(this.classes.windowColors.container);
this.named.right.content.appendChild(this.classes.windowLayers.container);
this.named.left.content.appendChild(this.classes.tree.container);
this.named.bottom.content.appendChild(logger.container);
// overlay and popup
window.popup = new popup();
window.popup.hide();
window.overlay = new overlay();
// confirmation dialogue
if(anigenActual.isConfirmed()) {
overlay.macroOpen();
} else {
overlay.macroDisclaimer();
}
overlay.animate = true;
// load settings
anigenActual.settings.loadData();
anigenActual.settings.apply();
anigenActual.resetTitle();
logger.report('UI built.');
}
uiManager.prototype.register = function(target) {
if(target instanceof uiSection) {
if(this.sections.indexOf(target) != -1) { return; }
this.sections.push(target);
target.container.removeEventListener("mousedown", target.eventResizerDown, false);
target.container.removeEventListener("mouseup", target.eventResizerUp, false);
target.container.removeEventListener("mousemove", target.eventResizerMove, false);
target.container.removeEventListener("mouseleave", target.eventResizerUp, false);
}
}
uiManager.prototype.unregister = function(target) {
if(target instanceof uiSection) {
if(this.sections.indexOf(target) == -1) { return; }
this.sections.splice(this.sections.indexOf(target), 1);
}
}
uiManager.prototype.eventMouseDown = function(event) {
this.downEvent = event;
if(event.target.hasClass('resizer') && !event.target.hasClass('disabled')) {
var owner = event.target.parentNode.shepherd;
if(!owner) { return; }
if(this.sections.indexOf(owner) == -1) {
this.activeSection = null;
}
this.activeSection = owner;
if(event.target.hasClass('top')) { owner.beingResized = 1; }
if(event.target.hasClass('right')) { owner.beingResized = 2; }
if(event.target.hasClass('bottom')) { owner.beingResized = 3; }
if(event.target.hasClass('left')) { owner.beingResized = 4; }
}
}
uiManager.prototype.eventMouseUp = function(event) {
this.downEvent = null;
this.activeSection = null;
this.classes.timeline.downEvent = null;
if(!event.target.isChildOf(this.classes.windowAnimation.tab1) &&
!event.target.isChildOf(popup.container)
) {
this.classes.windowAnimation.lastClicked = null;
}
}
uiManager.prototype.eventMouseMove = function(event) {
if(this.classes.timeline.downEvent) {
this.classes.timeline.eventMouseMove(event);
}
if(popup.lastEvent) {
popup.moveBy(event.clientX-popup.lastEvent.clientX, event.clientY-popup.lastEvent.clientY);
popup.lastPosition.x = popup.x;
popup.lastPosition.y = popup.y;
popup.lastEvent = event;
}
if(this.activeSection) {
this.activeSection.eventResizerAction(event);
}
}
uiManager.prototype.refresh =
uiManager.prototype.eventResize = function(event) {
this.named['right'].setX(window.innerWidth-this.named['right'].width);
this.named['bottom'].setY(window.innerHeight-this.named['bottom'].height);
for(var i = 0; i < this.sections.length; i++) {
this.sections[i].refresh();
}
}
uiManager.prototype.setCursor = function(cursorName) {
if(!this.named || !this.named['svg'] || !this.named['svg'].container) { return; }
if(!cursorName) {
cursorName = 'default';
} else {
cursorName += ',default';
}
this.named['svg'].container.style.cursor = cursorName;
}