uil 1.0.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +57 -0
  2. package/build/uil.js +7040 -4199
  3. package/build/uil.min.js +6 -4
  4. package/build/uil.module.js +7200 -2761
  5. package/examples/js/BufferGeometryUtils.js +921 -0
  6. package/examples/js/SimplexNoise.js +324 -0
  7. package/examples/js/controls/OrbitControls.js +1215 -0
  8. package/examples/js/controls/OrbitControls_.js +1042 -0
  9. package/examples/js/libs/sea3d.min.js +373 -0
  10. package/examples/js/libs/three.min.js +6 -0
  11. package/examples/js/math.js +447 -0
  12. package/examples/js/objects/Landscape.js +778 -0
  13. package/examples/js/objects/Lensflare.js +372 -0
  14. package/examples/js/objects/SuperSky.js +297 -0
  15. package/examples/js/objects/Water.js +329 -0
  16. package/package.json +56 -54
  17. package/src/Uil.js +2 -17
  18. package/src/Uil_dev.js +15 -0
  19. package/src/core/Gui.js +601 -299
  20. package/src/core/Proto.js +490 -220
  21. package/src/core/Roots.js +864 -0
  22. package/src/core/Tools.js +591 -140
  23. package/src/core/V2.js +131 -0
  24. package/src/core/add.js +52 -57
  25. package/src/proto/Bool.js +117 -52
  26. package/src/proto/Button.js +286 -146
  27. package/src/proto/Circular.js +162 -130
  28. package/src/proto/Color.js +331 -289
  29. package/src/proto/Empty.js +15 -0
  30. package/src/proto/Fps.js +232 -159
  31. package/src/proto/Graph.js +310 -0
  32. package/src/proto/Grid.js +297 -0
  33. package/src/proto/Group.js +334 -160
  34. package/src/proto/Item.js +120 -0
  35. package/src/proto/Joystick.js +159 -185
  36. package/src/proto/Knob.js +210 -91
  37. package/src/proto/List.js +661 -249
  38. package/src/proto/Numeric.js +329 -162
  39. package/src/proto/Pad2D.js +268 -0
  40. package/src/proto/Rubric.js +0 -0
  41. package/src/proto/Select.js +178 -0
  42. package/src/proto/Selector.js +13 -0
  43. package/src/proto/Slide.js +191 -185
  44. package/src/proto/TextInput.js +149 -59
  45. package/src/proto/Title.js +40 -31
package/src/core/Gui.js CHANGED
@@ -1,505 +1,807 @@
1
1
 
2
- import { Tools } from './Tools';
3
- import { add } from './add';
2
+ import { Roots } from './Roots.js';
3
+ import { Tools } from './Tools.js';
4
+ import { add } from './add.js';
5
+ import { V2 } from './V2.js';
4
6
 
5
7
  /**
6
- * @author lo-th / https://github.com/lo-th
8
+ * @author lth / https://github.com/lo-th
7
9
  */
8
10
 
9
- function Gui ( o ) {
11
+ export class Gui {
10
12
 
11
- o = o || {};
13
+ constructor( o = {} ) {
12
14
 
13
- // css plus
14
- this.css = o.css !== undefined ? o.css : '';
15
+ this.isGui = true
15
16
 
16
- // size define
17
- this.size = Tools.size;
18
- if( o.p !== undefined ) this.size.p = o.p;
19
- if( o.w !== undefined ) this.size.w = o.w;
20
- if( o.h !== undefined ) this.size.h = o.h;
21
- if( o.s !== undefined ) this.size.s = o.s;
17
+ this.name = 'gui'
22
18
 
23
- this.size.h = this.size.h < 11 ? 11 : this.size.h;
19
+ // for 3d
20
+ this.canvas = null
21
+ this.screen = null
22
+ this.plane = o.plane || null
24
23
 
25
- this.width = this.size.w;
24
+ this.isEmpty = true
26
25
 
27
- // bottom height
28
- this.bh = this.size.h;
26
+ // color
27
+ if( o.config ) o.colors = o.config
28
+
29
+ if ( o.colors ) this.setConfig( o.colors )
30
+ else this.colors = Tools.defineColor( o )
29
31
 
32
+ // style
33
+ this.css = Tools.cloneCss()
30
34
 
35
+ this.isReset = true
36
+ this.tmpAdd = null
37
+ //this.tmpH = 0
31
38
 
39
+ this.isCanvas = o.isCanvas || false
40
+ this.isCanvasOnly = false
41
+
42
+ this.callback = o.callback === undefined ? null : o.callback
32
43
 
33
- //this.width = o.width !== undefined ? o.width : Tools.size.width;
34
- //this.width = o.size !== undefined ? o.size : this.width;
44
+ this.forceHeight = o.maxHeight || 0
45
+ this.lockHeight = o.lockHeight || false
35
46
 
47
+ this.isItemMode = o.itemMode !== undefined ? o.itemMode : false
36
48
 
37
- // tmp variable
38
- this.height = 0;
39
- this.left = 0;
40
- this.h = 0;
41
- this.prevY = -1;
42
- this.sw = 0;
49
+ this.cn = ''
50
+
51
+ // size define
52
+ this.size = Tools.size;
53
+ if( o.p !== undefined ) this.size.p = o.p;
54
+ if( o.w !== undefined ) this.size.w = o.w;
55
+ if( o.h !== undefined ) this.size.h = o.h;
56
+ if( o.s !== undefined ) this.size.s = o.s;
43
57
 
58
+ this.size.h = this.size.h < 11 ? 11 : this.size.h;
44
59
 
45
- // color
46
- this.colors = Tools.colors;
47
- this.bg = o.bg || Tools.colors.background;
60
+ // local mouse and zone
61
+ this.local = new V2().neg();
62
+ this.zone = { x:0, y:0, w:this.size.w, h:0 };
48
63
 
49
- // bottom and close height
50
- this.isWithClose = true;
51
-
64
+ // virtual mouse
65
+ this.mouse = new V2().neg();
52
66
 
53
- //this.baseH = Tools.size.height;
67
+ this.h = 0;
68
+ //this.prevY = -1;
69
+ this.sw = 0;
54
70
 
55
- if(o.close !== undefined ){
56
- this.isWithClose = o.close;
57
- this.bh = !this.isWithClose ? 0 : this.bh;
58
- }
71
+
59
72
 
73
+ // bottom and close height
74
+ this.isWithClose = o.close !== undefined ? o.close : true;
75
+ this.bh = !this.isWithClose ? 0 : this.size.h;
60
76
 
77
+ this.autoResize = o.autoResize === undefined ? true : o.autoResize;
61
78
 
62
-
79
+ // default position
80
+ this.isCenter = o.center || false
81
+ this.cssGui = o.css !== undefined ? o.css : (this.isCenter ? '' : 'right:10px;')
63
82
 
64
- Tools.main = this;
83
+ this.isOpen = o.open !== undefined ? o.open : true;
84
+ this.isDown = false;
85
+ this.isScroll = false;
65
86
 
66
- this.callback = o.callback === undefined ? null : o.callback;
87
+ this.uis = [];
67
88
 
68
-
69
-
70
- this.isCenter = o.center || false;
71
- this.lockwheel = false;
72
- this.onWheel = false;
73
- this.isOpen = true;
74
-
75
- this.uis = [];
76
-
77
- this.content = Tools.dom( 'div', Tools.css.basic + 'display:block; width:'+this.width+'px; height:auto; top:0; right:10px; transition:height 0.1s ease-out;' + this.css );
78
- if( o.parent !== undefined ) o.parent.appendChild( this.content );
79
- else document.body.appendChild( this.content );
80
-
81
- this.innerContent = Tools.dom( 'div', Tools.css.basic + 'width:100%; top:0; left:0; height:auto; overflow:hidden;');
82
- this.content.appendChild( this.innerContent );
83
-
84
- this.inner = Tools.dom( 'div', Tools.css.basic + 'width:100%; top:0; left:0; height:auto;');
85
- this.innerContent.appendChild(this.inner);
86
- this.inner.name = 'inner';
87
-
88
- // scroll background
89
- this.scrollBG = Tools.dom( 'div', Tools.css.basic + 'right:0; top:0; width:'+this.size.s+'px; height:10px; cursor:s-resize; pointer-events:auto; display:none; background:'+this.bg+'; border-left:1px solid '+this.colors.stroke+';');
90
- this.content.appendChild( this.scrollBG );
91
- this.scrollBG.name = 'scroll';
92
-
93
- // scroll
94
- this.scroll = Tools.dom( 'div', Tools.css.basic + 'background:'+this.colors.scroll+'; right:0px; top:0; width:'+this.size.s+'px; height:10px;');
95
- this.scrollBG.appendChild( this.scroll );
96
-
97
- this.bottom = Tools.dom( 'div', Tools.css.txt + 'width:100%; top:auto; bottom:0; left:0; border-bottom-right-radius:10px; border-bottom-left-radius:10px; text-align:center; pointer-events:auto; cursor:pointer; height:'+this.bh+'px; line-height:'+(this.bh-5)+'px; border-top:1px solid '+Tools.colors.stroke+';');
98
- this.content.appendChild(this.bottom);
99
- this.bottom.textContent = 'close';
100
- this.bottom.name = 'bottom';
101
- this.bottom.style.background = this.bg;
102
-
103
- this.isDown = false;
104
- this.isScroll = false;
89
+ this.current = -1;
90
+ this.target = null;
91
+ this.decal = 0;
92
+ this.ratio = 1;
93
+ this.oy = 0;
105
94
 
106
- this.callbackClose = function(){};
107
95
 
108
- this.content.addEventListener( 'mousedown', this, false );
109
- this.content.addEventListener( 'mousemove', this, false );
110
- this.content.addEventListener( 'mouseout', this, false );
111
- this.content.addEventListener( 'mouseup', this, false );
112
- this.content.addEventListener( 'mouseover', this, false );
96
+ this.isNewTarget = false;
113
97
 
114
- //console.log(this.content.getBoundingClientRect().top);
98
+ let cc = this.colors
115
99
 
116
- this.top = o.top || this.content.getBoundingClientRect().top;
117
- //this.content.addEventListener( 'mousewheel', this, false );
100
+ this.content = Tools.dom( 'div', this.css.basic + ' width:0px; height:auto; top:0px; background:'+cc.content+'; ' + this.cssGui );
118
101
 
119
- document.addEventListener( 'mousewheel', function(e){this.wheel(e)}.bind(this), false );
120
- window.addEventListener("resize", function(e){this.resize(e)}.bind(this), false );
102
+ this.innerContent = Tools.dom( 'div', this.css.basic + 'width:100%; top:0; left:0; height:auto; overflow:hidden;');
103
+ //this.innerContent = Tools.dom( 'div', this.css.basic + this.css.button + 'width:100%; top:0; left:0; height:auto; overflow:hidden;');
104
+ this.content.appendChild( this.innerContent );
121
105
 
122
- //
106
+ //this.inner = Tools.dom( 'div', this.css.basic + 'width:100%; left:0; ')
107
+ this.useFlex = true
108
+ let flexible = this.useFlex ? 'display:flex; flex-flow: row wrap;' : '' //' display:flex; justify-content:start; align-items:start;flex-direction: column; justify-content: center; align-items: center;';
109
+ this.inner = Tools.dom( 'div', this.css.basic + flexible + 'width:100%; left:0; ');
110
+ this.innerContent.appendChild(this.inner);
123
111
 
124
- this.setWidth( this.width );
112
+ // scroll
113
+ this.scrollBG = Tools.dom( 'div', this.css.basic + 'right:0; top:0; width:'+ (this.size.s - 1) +'px; height:10px; display:none; background:'+cc.background+';');
114
+ this.content.appendChild( this.scrollBG );
125
115
 
126
- }
116
+ this.scroll = Tools.dom( 'div', this.css.basic + 'background:'+cc.button+'; right:2px; top:0; width:'+(this.size.s-4)+'px; height:10px;');
117
+ this.scrollBG.appendChild( this.scroll );
127
118
 
128
- Gui.prototype = {
119
+ // bottom button
120
+ this.bottomText = o.bottomText || ['open', 'close'];
129
121
 
130
- constructor: Gui,
122
+ let r = cc.radius;
123
+ this.bottom = Tools.dom( 'div', this.css.txt + 'width:100%; top:auto; bottom:0; left:0; border-bottom-right-radius:'+r+'px; border-bottom-left-radius:'+r+'px; justify-content:center; height:'+this.bh+'px; line-height:'+(this.bh-5)+'px; color:' + cc.text+';' );// border-top:1px solid '+Tools.colors.stroke+';');
124
+ this.content.appendChild( this.bottom )
125
+ this.bottom.textContent = this.isOpen ? this.bottomText[1] : this.bottomText[0]
126
+ this.bottom.style.background = cc.background
131
127
 
132
- hide : function (b) {
128
+ //
133
129
 
134
- if(b) this.content.style.display = 'none';
135
- else this.content.style.display = 'block';
130
+ this.parent = o.parent !== undefined ? o.parent : null;
131
+ this.parent = o.target !== undefined ? o.target : this.parent;
136
132
 
137
- },
133
+ if( this.parent === null && !this.isCanvas ){
134
+ this.parent = document.body
135
+ }
138
136
 
139
- setBG : function(c){
137
+ if( this.parent !== null ) this.parent.appendChild( this.content );
140
138
 
141
- this.bg = c;
139
+ if( this.isCanvas && this.parent === null ) this.isCanvasOnly = true;
142
140
 
143
- var i = this.uis.length;
144
- while(i--){
145
- this.uis[i].setBG(c);
141
+ if( !this.isCanvasOnly ){
142
+ this.content.style.pointerEvents = 'auto';
143
+ } else {
144
+ o.transition = 0
146
145
  }
147
146
 
148
- this.bottom.style.background = c;
149
147
 
150
- },
148
+ // height transition
149
+ this.transition = o.transition || Tools.transition
150
+ if( this.transition ) setTimeout( this.addTransition.bind( this ), 0 );
151
+
151
152
 
152
- getHTML : function(){
153
+ this.setWidth();
153
154
 
154
- return this.content;
155
+ if( this.isCanvas ) this.makeCanvas();
155
156
 
156
- },
157
+ Roots.add( this );
157
158
 
158
- onChange : function( f ){
159
+ }
159
160
 
160
- this.callback = f;
161
- return this;
161
+ setTop( t, h ) {
162
162
 
163
- },
163
+ this.content.style.top = t + 'px';
164
+ if( h !== undefined ) this.forceHeight = h;
165
+ this.calc();
164
166
 
165
- handleEvent : function( e ) {
167
+ Roots.needReZone = true;
166
168
 
167
- //e.preventDefault();
168
- //e.stopPropagation();
169
+ }
169
170
 
170
- switch( e.type ) {
171
- case 'mousedown': this.down( e ); break;
172
- case 'mouseout': this.out( e ); break;
173
- case 'mouseover': this.over( e ); break;
174
- //case 'mousewheel': this.wheel( e ); break;
171
+ addTransition(){
175
172
 
176
- case 'mouseup': this.up( e ); break;
177
- case 'mousemove': this.move( e ); break;
173
+ if( this.transition && !this.isCanvas ){
174
+ this.innerContent.style.transition = 'height '+this.transition+'s ease-out';
175
+ this.content.style.transition = 'height '+this.transition+'s ease-out';
176
+ this.bottom.style.transition = 'top '+this.transition+'s ease-out';
177
+ //this.bottom.addEventListener("transitionend", Roots.resize, true);
178
178
  }
179
179
 
180
- },
180
+ }
181
181
 
182
- // Mouse event
182
+ // ----------------------
183
+ // CANVAS
184
+ // ----------------------
183
185
 
184
- down: function( e ){
186
+ onDraw () {}
185
187
 
186
- if( !e.target.name ) return;
188
+ makeCanvas () {
187
189
 
188
- if(e.target.name === 'scroll'){
189
- this.isDown = true;
190
- this.move( e );
191
- document.addEventListener( 'mouseup', this, false );
192
- document.addEventListener( 'mousemove', this, false );
193
- }
194
- if(e.target.name === 'bottom'){
195
- this.isOpen = this.isOpen ? false : true;
196
- this.bottom.textContent = this.isOpen ? 'close' : 'open';
197
- this.testHeight();
190
+ this.canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', "canvas" );
191
+ this.canvas.width = this.zone.w;
192
+ this.canvas.height = this.forceHeight ? this.forceHeight : this.zone.h;
193
+
194
+ }
195
+
196
+ draw ( force ) {
197
+
198
+ if( this.canvas === null ) return;
199
+
200
+ let w = this.zone.w;
201
+ let h = this.forceHeight ? this.forceHeight : this.zone.h;
202
+ Roots.toCanvas( this, w, h, force );
203
+
204
+ }
205
+
206
+ //////
207
+
208
+ getDom () {
209
+
210
+ return this.content;
211
+
212
+ }
213
+
214
+ noMouse () {
215
+
216
+ this.mouse.neg();
217
+
218
+ }
219
+
220
+ setMouse ( uv, flip = true ) {
221
+
222
+ if(flip) this.mouse.set( Math.round( uv.x * this.canvas.width ), this.canvas.height - Math.round( uv.y * this.canvas.height ) );
223
+ else this.mouse.set( Math.round( uv.x * this.canvas.width ), Math.round( uv.y * this.canvas.height ) );
224
+ //this.mouse.set( m.x, m.y );
225
+
226
+ }
227
+
228
+ setConfig ( o ) {
229
+
230
+ // reset to default text
231
+ Tools.setText()
232
+ this.colors = Tools.defineColor( o )
233
+
234
+ }
235
+
236
+ setColors ( o ) {
237
+
238
+ for( let c in o ){
239
+ if( this.colors[c] ) this.colors[c] = o[c];
198
240
  }
241
+
242
+ }
243
+
244
+ setText ( size, color, font, shadow ) {
245
+
246
+ Tools.setText( size, color, font, shadow );
247
+
248
+ }
249
+
250
+ hide ( b ) {
251
+
252
+ this.content.style.display = b ? 'none' : 'block';
199
253
 
200
- },
254
+ }
201
255
 
202
- move: function( e ){
256
+ onChange ( f ) {
203
257
 
204
- if(!this.isDown) return;
205
- this.scroll.style.background = this.colors.down;
206
- this.update( (e.clientY-this.top)-(this.sh*0.5) );
258
+ this.callback = f || null;
259
+ return this;
207
260
 
208
- },
261
+ }
209
262
 
210
-
263
+ // ----------------------
264
+ // STYLES
265
+ // ----------------------
211
266
 
212
- out: function( e ){
267
+ mode ( n ) {
213
268
 
214
- if( !e.target.name ) return;
269
+ let needChange = false;
270
+ let cc = this.colors;
215
271
 
216
- if(e.target.name === 'scroll'){
217
- this.scroll.style.background = this.colors.scroll;
218
- }
272
+ if( n !== this.cn ){
219
273
 
220
- if(e.target.name === 'bottom'){
221
- this.bottom.style.color = '#CCC';
222
- }
274
+ this.cn = n;
223
275
 
224
- },
276
+ switch( n ){
225
277
 
226
- up: function( e ){
278
+ case 'def':
279
+ Roots.cursor();
280
+ this.scroll.style.background = cc.button;
281
+ this.bottom.style.background = cc.background
282
+ this.bottom.style.color = cc.text
283
+ break;
227
284
 
228
- this.isDown = false;
229
- this.scroll.style.background = this.colors.scroll;
230
- document.removeEventListener( 'mouseup', this, false );
231
- document.removeEventListener( 'mousemove', this, false );
285
+ //case 'scrollDef': this.scroll.style.background = this.colors.scroll; break;
286
+ case 'scrollOver':
287
+ Roots.cursor('ns-resize');
288
+ this.scroll.style.background = cc.select
289
+ break;
290
+ case 'scrollDown':
291
+ this.scroll.style.background = cc.select
292
+ break;
293
+
294
+ //case 'bottomDef': this.bottom.style.background = this.colors.background; break;
295
+ case 'bottomOver':
296
+ Roots.cursor('pointer');
297
+ this.bottom.style.background = cc.backgroundOver;
298
+ this.bottom.style.color = cc.textOver;
299
+ break;
300
+ //case 'bottomDown': this.bottom.style.background = this.colors.select; this.bottom.style.color = '#000'; break;
301
+
302
+ }
303
+
304
+ needChange = true;
305
+
306
+ }
307
+
308
+ return needChange;
309
+
310
+ }
311
+
312
+ // ----------------------
313
+ // TARGET
314
+ // ----------------------
315
+
316
+ clearTarget () {
317
+
318
+ if( this.current === -1 ) return false;
319
+ //if(!this.target) return;
320
+ this.target.uiout();
321
+ this.target.reset();
322
+ this.target = null;
323
+ this.current = -1;
324
+
325
+ ///console.log(this.isDown)//if(this.isDown)Roots.clearInput();
326
+
327
+
328
+
329
+ Roots.cursor();
330
+ return true;
331
+
332
+ }
333
+
334
+ // ----------------------
335
+ // ZONE TEST
336
+ // ----------------------
337
+
338
+ testZone ( e ) {
339
+
340
+ let l = this.local;
341
+ if( l.x === -1 && l.y === -1 ) return '';
342
+
343
+ this.isReset = false;
344
+
345
+ let name = '';
346
+
347
+ let s = this.isScroll ? this.zone.w - this.size.s : this.zone.w;
348
+
349
+ if( l.y > this.zone.h - this.bh && l.y < this.zone.h ) name = 'bottom';
350
+ else name = l.x > s ? 'scroll' : 'content';
351
+
352
+ return name;
353
+
354
+ }
355
+
356
+ // ----------------------
357
+ // EVENTS
358
+ // ----------------------
359
+
360
+ handleEvent ( e ) {
361
+
362
+ let type = e.type;
363
+
364
+ let change = false;
365
+ let targetChange = false;
366
+
367
+ let name = this.testZone( e );
368
+
369
+ if( type === 'mouseup' && this.isDown ) this.isDown = false;
370
+ if( type === 'mousedown' && !this.isDown ) this.isDown = true;
371
+
372
+ if( this.isDown && this.isNewTarget ){ Roots.clearInput(); this.isNewTarget=false; }
373
+
374
+ if( !name ) return;
375
+
376
+ switch( name ){
377
+
378
+ case 'content':
379
+
380
+ e.clientY = this.isScroll ? e.clientY + this.decal : e.clientY;
232
381
 
233
- },
382
+ if( Roots.isMobile && type === 'mousedown' ) this.getNext( e, change );
234
383
 
235
- over: function( e ){
384
+ if( this.target ) targetChange = this.target.handleEvent( e );
385
+
386
+ if( type === 'mousemove' ) change = this.mode('def');
387
+ if( type === 'wheel' && !targetChange && this.isScroll ) change = this.onWheel( e );
388
+
389
+ if( !Roots.lock ) {
390
+ this.getNext( e, change );
391
+ }
392
+
393
+ break;
394
+ case 'bottom':
395
+
396
+ this.clearTarget();
397
+ if( type === 'mousemove' ) change = this.mode('bottomOver');
398
+ if( type === 'mousedown' ) {
399
+ this.isOpen = this.isOpen ? false : true;
400
+ this.bottom.textContent = this.isOpen ? this.bottomText[1] : this.bottomText[0];
401
+ //this.setHeight();
402
+ this.calc();
403
+ this.mode('def');
404
+ change = true;
405
+ }
406
+
407
+ break;
408
+ case 'scroll':
409
+
410
+ this.clearTarget();
411
+ if( type === 'mousemove' ) change = this.mode('scrollOver');
412
+ if( type === 'mousedown' ) change = this.mode('scrollDown');
413
+ if( type === 'wheel' ) change = this.onWheel( e );
414
+ if( this.isDown ) this.update( (e.clientY-this.zone.y)-(this.sh*0.5) );
415
+
416
+ break;
417
+
418
+
419
+ }
420
+
421
+ if( this.isDown ) change = true;
422
+ if( targetChange ) change = true;
423
+
424
+ if( type === 'keyup' ) change = true;
425
+ if( type === 'keydown' ) change = true;
426
+
427
+ if( change ) this.draw();
428
+
429
+ }
430
+
431
+ getNext ( e, change ) {
432
+
433
+
434
+
435
+ let next = Roots.findTarget( this.uis, e );
436
+
437
+ if( next !== this.current ){
438
+ this.clearTarget();
439
+ this.current = next;
440
+ change = true;
441
+
442
+ this.isNewTarget = true;
236
443
 
237
- if( !e.target.name ) return;
238
- if(e.target.name === 'scroll'){
239
- this.scroll.style.background = this.colors.select;
240
444
  }
241
- if(e.target.name === 'bottom'){
242
- this.bottom.style.color = '#FFF';
445
+
446
+ if( next !== -1 ){
447
+ this.target = this.uis[ this.current ];
448
+ this.target.uiover();
243
449
  }
244
450
 
245
- },
451
+ }
452
+
453
+ onWheel ( e ) {
246
454
 
247
- // Wheel event
455
+ this.oy += 20*e.delta;
456
+ this.update( this.oy );
457
+ return true;
248
458
 
249
- wheel: function ( e ){
459
+ }
250
460
 
251
- //e.preventDefault();
252
- //e.stopPropagation();
461
+ // ----------------------
462
+ // RESET
463
+ // ----------------------
253
464
 
254
- if( this.lockwheel || !this.isScroll ) return;
465
+ reset ( force ) {
255
466
 
256
- //this.onWheel = true;
467
+ if( this.isReset ) return;
257
468
 
258
- var x = e.clientX;
259
- var px = this.content.getBoundingClientRect().left;
469
+ //this.resetItem();
260
470
 
261
- if(x<px) return;
262
- if(x>(px+this.width)) return;
471
+ this.mouse.neg();
472
+ this.isDown = false;
263
473
 
264
- var delta = 0;
265
- if(e.wheelDeltaY) delta = -e.wheelDeltaY*0.04;
266
- else if(e.wheelDelta) delta = -e.wheelDelta*0.2;
267
- else if(e.detail) delta = e.detail*4.0;
474
+ //Roots.clearInput();
475
+ let r = this.mode('def');
476
+ let r2 = this.clearTarget();
268
477
 
269
- this.py += delta;
478
+ if( r || r2 ) this.draw( true );
270
479
 
271
- this.update( this.py );
480
+ this.isReset = true;
272
481
 
273
- },
482
+ //Roots.lock = false;
274
483
 
275
- // -----------------------------------
484
+ }
276
485
 
277
- // Add node to gui
486
+ // ----------------------
487
+ // ADD NODE
488
+ // ----------------------
278
489
 
279
- add:function(){
490
+ add () {
280
491
 
281
- var a = arguments;
492
+ let a = arguments
493
+ let ontop = false
282
494
 
283
495
  if( typeof a[1] === 'object' ){
284
496
 
285
497
  a[1].isUI = true;
286
498
  a[1].main = this;
287
499
 
500
+ ontop = a[1].ontop ? a[1].ontop : false;
501
+
288
502
  } else if( typeof a[1] === 'string' ){
289
503
 
290
504
  if( a[2] === undefined ) [].push.call(a, { isUI:true, main:this });
291
505
  else {
292
506
  a[2].isUI = true;
293
507
  a[2].main = this;
508
+
509
+ ontop = a[1].ontop ? a[1].ontop : false;
294
510
  }
295
511
 
296
512
  }
297
513
 
514
+ let u = add.apply( this, a )
298
515
 
299
- var n = add.apply( this, a );
300
- //var n = UIL.add( ...args );
516
+ if( u === null ) return;
301
517
 
302
- this.uis.push( n );
303
- n.py = this.h;
518
+ if( ontop ) this.uis.unshift( u )
519
+ else this.uis.push( u )
304
520
 
305
- if( !n.autoWidth ){
306
- var y = n.c[0].getBoundingClientRect().top;
521
+ /*if( !u.autoWidth ){
522
+ let y = u.c[0].getBoundingClientRect().top;
307
523
  if( this.prevY !== y ){
308
- this.calc( n.h + 1 );
524
+ this.calc( u.h + 1 );
309
525
  this.prevY = y;
310
526
  }
311
527
  }else{
312
- this.prevY = -1;
313
- this.calc( n.h + 1 );
314
- }
528
+ this.prevY = 0;//-1;
529
+ this.calc( u.h + 1 );
530
+ }*/
531
+
532
+ this.calc()
315
533
 
316
- return n;
317
- },
534
+ this.isEmpty = false
535
+
536
+ return u
537
+
538
+ }
539
+
540
+ /*applyCalc () {
541
+
542
+ //console.log(this.uis.length, this.tmpH )
543
+
544
+ this.calc( this.tmpH );
545
+ //this.tmpH = 0;
546
+ this.tmpAdd = null;
547
+
548
+ }*/
549
+
550
+
318
551
 
319
552
  // remove one node
320
553
 
321
- remove: function ( n ) {
554
+ remove ( n ) {
322
555
 
323
- var i = this.uis.indexOf( n );
324
- if ( i !== -1 ) this.uis[i].clear();
556
+ if( n.clear ) n.clear();
325
557
 
326
- },
558
+ }
327
559
 
328
560
  // call after uis clear
329
561
 
330
- clearOne: function ( n ) {
562
+ clearOne ( n ) {
331
563
 
332
- var i = this.uis.indexOf( n );
333
- if ( i !== -1 ) {
334
- this.inner.removeChild( this.uis[i].c[0] );
335
- this.uis.splice( i, 1 );
564
+ let id = this.uis.indexOf( n );
565
+ if ( id !== -1 ) {
566
+ //this.calc( - (this.uis[ id ].h + 1 ) );
567
+ this.inner.removeChild( this.uis[ id ].c[0] );
568
+ this.uis.splice( id, 1 );
569
+ this.calc()
336
570
  }
337
571
 
338
- },
572
+ }
339
573
 
340
574
  // clear all gui
341
575
 
342
- clear:function(){
576
+ empty() {
577
+
578
+ //this.close();
343
579
 
344
- var i = this.uis.length;
345
- while(i--) this.uis[i].clear();
580
+ let i = this.uis.length, item;
581
+
582
+ while( i-- ){
583
+ item = this.uis.pop();
584
+ this.inner.removeChild( item.c[0] );
585
+ item.clear( true );
586
+
587
+ //this.uis[i].clear()
588
+ }
346
589
 
347
590
  this.uis = [];
348
- Tools.listens = [];
591
+ this.isEmpty = true;
592
+ //this.zone = { x:0, y:0, w:this.size.w, h:0 };
593
+ //this.setWidth()
594
+ //Roots.listens = [];
595
+ this.calc();
349
596
 
350
- this.calc( - this.h );
351
597
 
352
- },
353
598
 
354
- // -----------------------------------
599
+ }
355
600
 
356
- // Scroll
601
+ clear() {
357
602
 
358
- update: function ( y ){
603
+ this.empty();
359
604
 
360
- y = y < 0 ? 0 :y;
361
- y = y > this.range ? this.range : y;
605
+ //this.callback = null;
362
606
 
363
- this.inner.style.top = - Math.floor( y / this.ratio ) + 'px';
364
- this.scroll.style.top = Math.floor( y ) + 'px';
607
+ /*let i = this.uis.length;
608
+ while( i-- ) this.uis[i].clear();
365
609
 
366
- this.py = y;
610
+ this.uis = [];
611
+ Roots.listens = [];
367
612
 
368
- //this.onWheel = false;
613
+ this.calc( -this.h );*/
369
614
 
370
- },
615
+ }
371
616
 
372
- showScroll:function(h){
617
+ dispose() {
373
618
 
374
- this.isScroll = true;
375
- this.sw = this.size.s;
619
+ this.clear();
620
+ if( this.parent !== null ) this.parent.removeChild( this.content );
621
+ Roots.remove( this );
376
622
 
377
- this.total = this.h;
378
- this.maxView = this.maxHeight;// - this.height;
623
+ }
379
624
 
380
- this.ratio = this.maxView / this.total;
381
- this.sh = this.maxView * this.ratio;
625
+ // ----------------------
626
+ // ITEMS SPECIAL
627
+ // ----------------------
382
628
 
383
- if( this.sh < 20 ) this.sh = 20;
384
629
 
385
- this.range = this.maxView - this.sh;
630
+ resetItem () {
386
631
 
387
- this.scrollBG.style.display = 'block';
388
- this.scrollBG.style.height = this.maxView + 'px';
389
- this.scroll.style.height = this.sh + 'px';
632
+ if( !this.isItemMode ) return;
390
633
 
391
-
634
+ let i = this.uis.length;
635
+ while(i--) this.uis[i].selected();
392
636
 
393
- this.setItemWidth( this.width - this.sw );
637
+ }
394
638
 
395
- this.update( 0 );
639
+ setItem ( name ) {
396
640
 
397
- },
641
+ if( !this.isItemMode ) return;
642
+
643
+ name = name || '';
644
+
645
+ this.resetItem();
646
+
647
+ if( !name ){
648
+ this.update(0);
649
+ return;
650
+ }
651
+
652
+ let i = this.uis.length;
653
+ while(i--){
654
+ if( this.uis[i].value === name ){
655
+ this.uis[i].selected( true );
656
+ if( this.isScroll ) this.update( ( i*(this.uis[i].h+1) )*this.ratio );
657
+ }
658
+ }
659
+
660
+ }
398
661
 
399
- hideScroll:function(){
400
662
 
401
- this.isScroll = false;
402
- this.sw = 0;
403
-
404
663
 
405
- this.setItemWidth( this.width - this.sw );
664
+ // ----------------------
665
+ // SCROLL
666
+ // ----------------------
406
667
 
407
- this.update( 0 );
668
+ upScroll ( b ) {
408
669
 
409
- this.scrollBG.style.display = 'none';
670
+ this.sw = b ? this.size.s : 0;
671
+ this.oy = b ? this.oy : 0;
672
+ this.scrollBG.style.display = b ? 'block' : 'none';
410
673
 
411
- },
674
+ if( b ){
412
675
 
413
- // -----------------------------------
676
+ this.total = this.h;
414
677
 
415
- resize:function(e){
678
+ this.maxView = this.maxHeight;
416
679
 
417
- this.testHeight();
680
+ this.ratio = this.maxView / this.total;
681
+ this.sh = this.maxView * this.ratio;
418
682
 
419
- },
683
+ //if( this.sh < 20 ) this.sh = 20;
420
684
 
421
- calc:function( y ) {
685
+ this.range = this.maxView - this.sh;
422
686
 
423
- this.h += y;
424
- clearTimeout( this.tmp );
425
- this.tmp = setTimeout( this.testHeight.bind(this), 10);
687
+ this.oy = Tools.clamp( this.oy, 0, this.range );
426
688
 
427
- },
689
+ this.scrollBG.style.height = this.maxView + 'px';
690
+ this.scroll.style.height = this.sh + 'px';
428
691
 
429
- testHeight:function(){
692
+ }
693
+
694
+ this.setItemWidth( this.zone.w - this.sw );
695
+ this.update( this.oy );
696
+
697
+ }
430
698
 
431
- if( this.tmp ) clearTimeout( this.tmp );
699
+ update ( y ) {
700
+
701
+ y = Tools.clamp( y, 0, this.range );
702
+
703
+ this.decal = Math.floor( y / this.ratio );
704
+ this.inner.style.top = - this.decal + 'px';
705
+ this.scroll.style.top = Math.floor( y ) + 'px';
706
+ this.oy = y;
707
+
708
+ }
709
+
710
+ // ----------------------
711
+ // RESIZE FUNCTION
712
+ // ----------------------
713
+
714
+ calcUis() {
715
+
716
+ return Roots.calcUis( this.uis, this.zone, this.zone.y )
717
+ }
432
718
 
433
- this.height = this.top + this.bh;
719
+ calc() {
720
+
721
+ clearTimeout( this.tmp )
722
+ this.tmp = setTimeout( this.setHeight.bind( this ), 10 )
723
+
724
+ }
725
+
726
+ setHeight() {
727
+
728
+ if( this.tmp ) clearTimeout( this.tmp )
729
+
730
+ this.zone.h = this.bh
731
+ this.isScroll = false
434
732
 
435
733
  if( this.isOpen ){
436
734
 
437
- this.maxHeight = window.innerHeight - this.top - this.bh;
735
+ this.h = this.calcUis()
438
736
 
439
- if( this.h > this.maxHeight ){
737
+ let hhh = this.forceHeight ? this.forceHeight + this.zone.y : window.innerHeight;
440
738
 
441
- this.height = this.maxHeight + this.bh;
442
- this.showScroll();
739
+ this.maxHeight = hhh - this.zone.y - this.bh;
443
740
 
444
- }else{
741
+ let diff = this.h - this.maxHeight;
445
742
 
446
- this.height = this.h + this.bh;
447
- this.hideScroll();
743
+ if( diff > 1 ){ //this.h > this.maxHeight ){
448
744
 
449
- }
745
+ this.isScroll = true;
746
+ this.zone.h = this.maxHeight + this.bh;
450
747
 
451
- } else {
748
+ } else {
452
749
 
453
- this.height = this.bh;
454
- this.hideScroll();
750
+ this.zone.h = this.h + this.bh;
751
+
752
+ }
455
753
 
456
754
  }
457
755
 
458
- this.innerContent.style.height = this.height - this.bh + 'px';
459
- this.content.style.height = this.height + 'px';
460
- this.bottom.style.top = this.height - this.bh + 'px';
756
+ this.upScroll( this.isScroll )
461
757
 
462
- },
758
+ this.innerContent.style.height = this.zone.h - this.bh + 'px'
759
+ this.content.style.height = this.zone.h + 'px'
760
+ this.bottom.style.top = this.zone.h - this.bh + 'px'
463
761
 
464
- setWidth: function( w ) {
465
762
 
466
- if( w ) this.width = w;
467
- this.content.style.width = this.width + 'px';
763
+ if( this.forceHeight && this.lockHeight ) this.content.style.height = this.forceHeight + 'px';
468
764
 
469
- //console.log(this.width)
765
+ //if( this.isOpen ) this.calcUis()
766
+ if( this.isCanvas ) this.draw( true )
767
+ //else if( !this.transition ) this.rezone()
470
768
 
769
+ }
471
770
 
472
- if( this.isCenter ) this.content.style.marginLeft = -(~~ (this.width*0.5)) + 'px';
771
+ rezone () {
772
+ Roots.needReZone = true;
773
+ }
473
774
 
474
- this.setItemWidth( this.width - this.sw );
775
+ setWidth ( w ) {
475
776
 
476
- /*var l = this.uis.length;
477
- var i = l;
478
- while(i--){
479
- this.uis[i].setSize( this.width );
480
- }
777
+ if( w ) this.zone.w = w;
481
778
 
482
- i = l;
483
- while(i--){
484
- this.uis[i].rSize();
485
- }*/
779
+ this.zone.w = Math.floor( this.zone.w )
486
780
 
487
- this.resize();
781
+ //console.log( this.zone.w )
488
782
 
489
- },
783
+ this.content.style.width = this.zone.w + 'px';
490
784
 
491
- setItemWidth: function( w ){
785
+ if( this.isCenter ) this.content.style.marginLeft = -(Math.floor(this.zone.w*0.5)) + 'px';
492
786
 
493
- var i = this.uis.length;
494
- while(i--){
495
- this.uis[i].setSize( w );
496
- this.uis[i].rSize()
497
- }
787
+ this.setItemWidth( this.zone.w - this.sw );
788
+
789
+ //this.setHeight();
790
+ //this.calc()
498
791
 
499
- },
792
+ //if( this.isCanvasOnly ) Roots.needReZone = true;
793
+ //Roots.resize();
500
794
 
795
+ }
796
+
797
+ setItemWidth ( w ) {
501
798
 
502
- };
799
+ let i = this.uis.length;
800
+ while(i--){
801
+ this.uis[i].setSize( w )
802
+ this.uis[i].rSize()
803
+ }
503
804
 
805
+ }
504
806
 
505
- export { Gui };
807
+ }