-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIMan.js
170 lines (151 loc) · 5.4 KB
/
UIMan.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
function UIMan(delegate, model)
{
console.log('creating uiman');
//Create
var self = this;
self.currentEditor = "triangle";
self.drawingarea = createDrawingarea(self, model);
self.triangleinspector = createTriangleinspector(self);
self.lightinspector = createLightinspector(self);
self.triangleselector = createTriangleselector(self, model);
self.lightselector = createLightselector(self, model);
self.jsonrenderer = createJsonrenderer(self, model);
//Style
self.veditor = document.getElementById('veditor'); //The whole page/app
self.veditor.style.width = '1040px';
self.veditor.style.margin = '0px auto';
//Main sections of editor
self.leftpane = document.createElement('div');
self.leftpane.style.width = '200px';
self.leftpane.style.height = '640px';
self.leftpane.style.margin = '0px';
self.leftpane.style.padding = '0px';
self.leftpane.style.float = 'left';
self.centerpane = document.createElement('div');
self.centerpane.style.width = '640px';
self.centerpane.style.height = '640px';
self.centerpane.style.margin = '0px';
self.centerpane.style.padding = '0px';
self.centerpane.style.float = 'left';
self.rightpane = document.createElement('div');
self.rightpane.style.width = '200px';
self.rightpane.style.height = '640px';
self.rightpane.style.margin = '0px';
self.rightpane.style.padding = '0px';
self.rightpane.style.float = 'left';
self.editTrianglesButton = createButton('edit triangles',function(e) { console.log('uiman edittrianglesbutton clicked'); self.setEditor("triangle"); });
self.editLightsButton = createButton('edit lights',function(e) { console.log('uiman editlightsbutton clicked'); self.setEditor("light"); });
//Functionality
self.setEditor = function(editor)
{
console.log('uiman seteditor');
switch(editor)
{
case "triangle":
self.lightinspector.style.display = "none";
self.lightselector.style.display = "none";
self.triangleinspector.style.display = "block";
self.triangleselector.style.display = "block";
break;
case "light":
self.triangleinspector.style.display = "none";
self.triangleselector.style.display = "none";
self.lightinspector.style.display = "block";
self.lightselector.style.display = "block";
}
}
self.addTriangleButtonClicked = function(ts)
{
console.log('uiman addtrianglebuttonclicked');
if(typeof delegate.addTriangle == 'function')
delegate.addTriangle();
}
self.removeTriangleButtonClicked = function(ts)
{
console.log('uiman removetrianglebuttonclicked');
var index = self.triangleselector.selectedIndex;
if(index == -1) return;
self.triangleselector.clearSelection();
self.triangleinspector.clearTriangle();
if(typeof delegate.removeTriangle == 'function')
delegate.removeTriangle(index);
}
self.addLightButtonClicked = function(ls)
{
console.log('uiman addlightbuttonclicked');
if(typeof delegate.addLight == 'function')
delegate.addLight();
}
self.removeLightButtonClicked = function(ts)
{
console.log('uiman removelightbuttonclicked');
var index = self.lightselector.selectedIndex;
if(index == -1) return;
self.lightselector.clearSelection();
self.lightinspector.clearLight();
if(typeof delegate.removeLight == 'function')
delegate.removeLight(index);
}
self.loadJsonButtonClicked = function(jr, triangles, lights)
{
console.log('uiman loadjsonbuttonclicked');
if(typeof delegate.loadJson == 'function')
delegate.loadJson(triangles, lights);
}
self.outputJsonButtonClicked = function(jr)
{
console.log('uiman outputjsonbuttonclicked');
if(typeof delegate.outputJson == 'function')
delegate.outputJson();
}
self.triangleChanged = function(ti, triangle)
{
console.log('uiman trianglechanged');
if(typeof delegate.triangleChanged == 'function')
delegate.triangleChanged(triangle,self.triangleselector.selectedIndex);
}
self.lightChanged = function(li, light)
{
console.log('uiman lightchanged');
if(typeof delegate.lightChanged == 'function')
delegate.lightChanged(light,self.lightselector.selectedIndex);
}
self.triangleSelected = function(ts, index, triangle)
{
console.log('uiman triangleselected');
if(index == -1)
self.triangleinspector.clearTriangle();
else
self.triangleinspector.setTriangle(triangle);
}
self.lightSelected = function(ls, index, light)
{
console.log('uiman lightselected');
if(index == -1)
self.lightinspector.clearLight();
else
self.lightinspector.setLight(light);
}
//Construct
self.veditor.appendChild(self.leftpane);
self.veditor.appendChild(self.centerpane);
self.veditor.appendChild(self.rightpane);
self.leftpane.appendChild(self.editTrianglesButton);
self.leftpane.appendChild(self.editLightsButton);
self.leftpane.appendChild(self.triangleinspector);
self.leftpane.appendChild(self.lightinspector);
self.rightpane.appendChild(self.triangleselector);
self.rightpane.appendChild(self.lightselector);
self.centerpane.appendChild(self.drawingarea);
self.centerpane.appendChild(self.jsonrenderer);
self.setEditor("triangle");
}
function createButton(text, func)
{
console.log('uiman createbutton');
var b = document.createElement('input');
b.setAttribute('type','button');
b.setAttribute('value',text);
b.addEventListener('click',func);
return b;
}