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.
- package/README.md +57 -0
- package/build/uil.js +7040 -4199
- package/build/uil.min.js +6 -4
- package/build/uil.module.js +7200 -2761
- package/examples/js/BufferGeometryUtils.js +921 -0
- package/examples/js/SimplexNoise.js +324 -0
- package/examples/js/controls/OrbitControls.js +1215 -0
- package/examples/js/controls/OrbitControls_.js +1042 -0
- package/examples/js/libs/sea3d.min.js +373 -0
- package/examples/js/libs/three.min.js +6 -0
- package/examples/js/math.js +447 -0
- package/examples/js/objects/Landscape.js +778 -0
- package/examples/js/objects/Lensflare.js +372 -0
- package/examples/js/objects/SuperSky.js +297 -0
- package/examples/js/objects/Water.js +329 -0
- package/package.json +56 -54
- package/src/Uil.js +2 -17
- package/src/Uil_dev.js +15 -0
- package/src/core/Gui.js +601 -299
- package/src/core/Proto.js +490 -220
- package/src/core/Roots.js +864 -0
- package/src/core/Tools.js +591 -140
- package/src/core/V2.js +131 -0
- package/src/core/add.js +52 -57
- package/src/proto/Bool.js +117 -52
- package/src/proto/Button.js +286 -146
- package/src/proto/Circular.js +162 -130
- package/src/proto/Color.js +331 -289
- package/src/proto/Empty.js +15 -0
- package/src/proto/Fps.js +232 -159
- package/src/proto/Graph.js +310 -0
- package/src/proto/Grid.js +297 -0
- package/src/proto/Group.js +334 -160
- package/src/proto/Item.js +120 -0
- package/src/proto/Joystick.js +159 -185
- package/src/proto/Knob.js +210 -91
- package/src/proto/List.js +661 -249
- package/src/proto/Numeric.js +329 -162
- package/src/proto/Pad2D.js +268 -0
- package/src/proto/Rubric.js +0 -0
- package/src/proto/Select.js +178 -0
- package/src/proto/Selector.js +13 -0
- package/src/proto/Slide.js +191 -185
- package/src/proto/TextInput.js +149 -59
- package/src/proto/Title.js +40 -31
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { Proto } from '../core/Proto.js';
|
|
2
|
+
import { Tools } from '../core/Tools.js';
|
|
3
|
+
import { V2 } from '../core/V2.js';
|
|
4
|
+
|
|
5
|
+
export class Pad2D extends Proto {
|
|
6
|
+
|
|
7
|
+
constructor( o = {} ) {
|
|
8
|
+
|
|
9
|
+
super( o );
|
|
10
|
+
|
|
11
|
+
this.autoWidth = false;
|
|
12
|
+
this.minw = this.w
|
|
13
|
+
this.diam = o.diam || this.w
|
|
14
|
+
|
|
15
|
+
//this.margin = 15;
|
|
16
|
+
this.pos = new V2(0,0);
|
|
17
|
+
this.maxPos = 90
|
|
18
|
+
|
|
19
|
+
this.model = o.stype || 0;
|
|
20
|
+
if( o.mode !== undefined ) this.model = o.mode;
|
|
21
|
+
|
|
22
|
+
this.min = o.min === undefined ? -1 : o.min;
|
|
23
|
+
this.max = o.max === undefined ? 1 : o.max;
|
|
24
|
+
|
|
25
|
+
this.range = (this.max - this.min)*0.5;
|
|
26
|
+
|
|
27
|
+
this.cmode = 0;
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
//console.log(this.range)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
this.precision = o.precision === undefined ? 2 : o.precision;
|
|
35
|
+
|
|
36
|
+
/*this.bounds = {};
|
|
37
|
+
this.bounds.x1 = o.x1 || -1;
|
|
38
|
+
this.bounds.x2 = o.x2 || 1;
|
|
39
|
+
this.bounds.y1 = o.y1 || -1;
|
|
40
|
+
this.bounds.y2 = o.y2 || 1;
|
|
41
|
+
|
|
42
|
+
this.lerpX = this.lerp( this.margin, this.w - this.margin , this.bounds.x1, this.bounds.x2 );
|
|
43
|
+
this.lerpY = this.lerp( this.margin, this.w - this.margin , this.bounds.y1, this.bounds.y2 );
|
|
44
|
+
|
|
45
|
+
this.alerpX = this.lerp( this.bounds.x1, this.bounds.x2, this.margin, this.w - this.margin );
|
|
46
|
+
this.alerpY = this.lerp( this.bounds.y1, this.bounds.y2, this.margin, this.w - this.margin );*/
|
|
47
|
+
|
|
48
|
+
this.value = ( Array.isArray( o.value ) && o.value.length == 2 ) ? o.value : [ 0, 0 ];
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
this.h = o.h || this.w + 10;
|
|
52
|
+
this.top = 0;
|
|
53
|
+
|
|
54
|
+
this.c[0].style.width = this.w + 'px';
|
|
55
|
+
|
|
56
|
+
// Title
|
|
57
|
+
if( this.c[1] !== undefined ) { // with title
|
|
58
|
+
|
|
59
|
+
this.c[1].style.width = '100%';
|
|
60
|
+
this.c[1].style.justifyContent = 'center';
|
|
61
|
+
this.top = 10;
|
|
62
|
+
this.h += 10;
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let cc = this.colors
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
// Value
|
|
70
|
+
this.c[2] = this.dom( 'div', this.css.txt + 'justify-content:center; top:'+ ( this.h - 20 ) + 'px; width:100%; color:' + cc.text );
|
|
71
|
+
this.c[2].textContent = this.value;
|
|
72
|
+
|
|
73
|
+
// Pad
|
|
74
|
+
|
|
75
|
+
let pad = this.getPad2d()
|
|
76
|
+
|
|
77
|
+
this.setSvg( pad, 'fill', cc.back, 0 )
|
|
78
|
+
this.setSvg( pad, 'fill', cc.button, 1 )
|
|
79
|
+
this.setSvg( pad, 'stroke', cc.back, 2 )
|
|
80
|
+
this.setSvg( pad, 'stroke', cc.back, 3 )
|
|
81
|
+
this.setSvg( pad, 'stroke', cc.text, 4 )
|
|
82
|
+
|
|
83
|
+
this.setSvg( pad, 'viewBox', '0 0 '+this.diam+' '+this.diam )
|
|
84
|
+
this.setCss( pad, { width:this.diam, height:this.diam, left:0, top:this.top })
|
|
85
|
+
|
|
86
|
+
this.c[3] = pad
|
|
87
|
+
|
|
88
|
+
this.init()
|
|
89
|
+
this.setValue()
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
testZone ( e ) {
|
|
94
|
+
|
|
95
|
+
let l = this.local;
|
|
96
|
+
|
|
97
|
+
if( l.x === -1 && l.y === -1 ) return '';
|
|
98
|
+
|
|
99
|
+
if( l.y <= this.c[ 1 ].offsetHeight ) return 'title';
|
|
100
|
+
else if ( l.y > this.h - this.c[ 2 ].offsetHeight ) return 'text';
|
|
101
|
+
else return 'pad';
|
|
102
|
+
|
|
103
|
+
/*if( ( l.x >= this.margin ) && ( l.x <= this.w - this.margin ) && ( l.y >= this.top + this.margin ) && ( l.y <= this.top + this.w - this.margin ) ) {
|
|
104
|
+
return 'pad';
|
|
105
|
+
}*/
|
|
106
|
+
|
|
107
|
+
//return '';
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
mouseup ( e ) {
|
|
112
|
+
|
|
113
|
+
this.isDown = false;
|
|
114
|
+
return this.mode(0);
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
mousedown ( e ) {
|
|
119
|
+
|
|
120
|
+
if ( this.testZone(e) === 'pad' ) {
|
|
121
|
+
this.isDown = true;
|
|
122
|
+
this.mousemove( e );
|
|
123
|
+
return this.mode(1);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
mousemove ( e ) {
|
|
129
|
+
|
|
130
|
+
if( !this.isDown ) return;
|
|
131
|
+
|
|
132
|
+
let x = (this.w*0.5) - ( e.clientX - this.zone.x )
|
|
133
|
+
let y = (this.diam*0.5) - ( e.clientY - this.zone.y - this.top )
|
|
134
|
+
let r = 256 / this.diam
|
|
135
|
+
|
|
136
|
+
x = -(x*r)
|
|
137
|
+
y = -(y*r)
|
|
138
|
+
|
|
139
|
+
x = Tools.clamp( x, -this.maxPos, this.maxPos )
|
|
140
|
+
y = Tools.clamp( y, -this.maxPos, this.maxPos )
|
|
141
|
+
|
|
142
|
+
//let x = e.clientX - this.zone.x;
|
|
143
|
+
//let y = e.clientY - this.zone.y - this.top;
|
|
144
|
+
|
|
145
|
+
/*if( x < this.margin ) x = this.margin;
|
|
146
|
+
if( x > this.w - this.margin ) x = this.w - this.margin;
|
|
147
|
+
if( y < this.margin ) y = this.margin;
|
|
148
|
+
if( y > this.w - this.margin ) y = this.w - this.margin;*/
|
|
149
|
+
|
|
150
|
+
//console.log(x,y)
|
|
151
|
+
|
|
152
|
+
this.setPos( [ x , y ] );
|
|
153
|
+
|
|
154
|
+
this.update( true );
|
|
155
|
+
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
mode ( mode ) {
|
|
159
|
+
|
|
160
|
+
if( this.cmode === mode ) return false;
|
|
161
|
+
|
|
162
|
+
let cc = this.colors
|
|
163
|
+
|
|
164
|
+
switch( mode ){
|
|
165
|
+
case 0: // base
|
|
166
|
+
|
|
167
|
+
this.s[2].color = cc.text;
|
|
168
|
+
this.setSvg( this.c[3], 'fill', cc.back, 0)
|
|
169
|
+
this.setSvg( this.c[3], 'fill', cc.button, 1)
|
|
170
|
+
this.setSvg( this.c[3], 'stroke', cc.back, 2)
|
|
171
|
+
this.setSvg( this.c[3], 'stroke', cc.back, 3)
|
|
172
|
+
this.setSvg( this.c[3], 'stroke', cc.text, 4 )
|
|
173
|
+
|
|
174
|
+
break;
|
|
175
|
+
case 1: // down
|
|
176
|
+
|
|
177
|
+
this.s[2].color = cc.textSelect;
|
|
178
|
+
this.setSvg( this.c[3], 'fill', cc.backoff, 0)
|
|
179
|
+
this.setSvg( this.c[3], 'fill', cc.overoff, 1)
|
|
180
|
+
this.setSvg( this.c[3], 'stroke', cc.backoff, 2)
|
|
181
|
+
this.setSvg( this.c[3], 'stroke', cc.backoff, 3)
|
|
182
|
+
this.setSvg( this.c[3], 'stroke', cc.textSelect, 4 )
|
|
183
|
+
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
this.cmode = mode;
|
|
188
|
+
return true;
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
update ( up ) {
|
|
195
|
+
|
|
196
|
+
//if( up === undefined ) up = true;
|
|
197
|
+
|
|
198
|
+
this.c[2].textContent = this.value;
|
|
199
|
+
|
|
200
|
+
this.updateSVG();
|
|
201
|
+
|
|
202
|
+
if( up ) this.send();
|
|
203
|
+
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
updateSVG() {
|
|
207
|
+
|
|
208
|
+
if ( this.model == 1 ) {
|
|
209
|
+
|
|
210
|
+
this.setSvg( this.c[3], 'y1', this.pos.y, 2 );
|
|
211
|
+
this.setSvg( this.c[3], 'y2', this.pos.y, 2 );
|
|
212
|
+
|
|
213
|
+
this.setSvg( this.c[3], 'x1', this.pos.x, 3 );
|
|
214
|
+
this.setSvg( this.c[3], 'x2', this.pos.x, 3 );
|
|
215
|
+
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
this.setSvg( this.c[3], 'cx', this.pos.x, 4 );
|
|
219
|
+
this.setSvg( this.c[3], 'cy', this.pos.y, 4 );
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
setPos ( p ) {
|
|
224
|
+
|
|
225
|
+
//if( p === undefined ) p = [ this.w / 2, this.w / 2 ];
|
|
226
|
+
|
|
227
|
+
this.pos.set( p[0]+128 , p[1]+128 );
|
|
228
|
+
|
|
229
|
+
let r = 1/this.maxPos
|
|
230
|
+
|
|
231
|
+
this.value[0] = ((p[0]*r)*this.range).toFixed( this.precision );
|
|
232
|
+
this.value[1] = ((p[1]*r)*this.range).toFixed( this.precision );
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
setValue ( v, up = false ) {
|
|
237
|
+
|
|
238
|
+
if( v === undefined ) v = this.value;
|
|
239
|
+
|
|
240
|
+
/*if ( v[0] < this.bounds.x1 ) v[0] = this.bounds.x1;
|
|
241
|
+
if ( v[0] > this.bounds.x2 ) v[0] = this.bounds.x2;
|
|
242
|
+
if ( v[1] < this.bounds.y1 ) v[1] = this.bounds.y1;
|
|
243
|
+
if ( v[1] > this.bounds.y2 ) v[1] = this.bounds.y2;*/
|
|
244
|
+
|
|
245
|
+
this.value[0] = Math.min( this.max, Math.max( this.min, v[0] ) ).toFixed( this.precision ) * 1;
|
|
246
|
+
this.value[1] = Math.min( this.max, Math.max( this.min, v[1] ) ).toFixed( this.precision ) * 1;
|
|
247
|
+
|
|
248
|
+
this.pos.set( ((this.value[0]/this.range)*this.maxPos)+128 , ((this.value[1]/this.range)*this.maxPos)+128 )
|
|
249
|
+
|
|
250
|
+
//console.log(this.pos)
|
|
251
|
+
|
|
252
|
+
this.update( up );
|
|
253
|
+
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/*lerp( s1, s2, d1, d2, c = true ) {
|
|
257
|
+
|
|
258
|
+
let s = ( d2 - d1 ) / ( s2 - s1 );
|
|
259
|
+
|
|
260
|
+
return c ? ( v ) => {
|
|
261
|
+
return ( ( v < s1 ? s1 : v > s2 ? s2 : v ) - s1 ) * s + d1
|
|
262
|
+
} : ( v ) => {
|
|
263
|
+
return ( v - s1 ) * s + d1
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
}*/
|
|
267
|
+
|
|
268
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { Proto } from '../core/Proto.js';
|
|
2
|
+
|
|
3
|
+
export class Select extends Proto {
|
|
4
|
+
|
|
5
|
+
constructor( o = {} ) {
|
|
6
|
+
|
|
7
|
+
super( o );
|
|
8
|
+
|
|
9
|
+
this.value = o.value || '';
|
|
10
|
+
|
|
11
|
+
this.isDown = false;
|
|
12
|
+
|
|
13
|
+
this.onActif = o.onActif || function(){};
|
|
14
|
+
|
|
15
|
+
let prefix = o.prefix || '';
|
|
16
|
+
|
|
17
|
+
this.c[2] = this.dom( 'div', this.css.txt + this.css.button + ' top:1px; background:'+this.colors.button+'; height:'+(this.h-2)+'px; border:'+this.colors.buttonBorder+'; border-radius:15px; width:30px; left:10px;' );
|
|
18
|
+
this.c[2].style.color = this.fontColor;
|
|
19
|
+
|
|
20
|
+
this.c[3] = this.dom( 'div', this.css.txtselect + 'height:' + (this.h-4) + 'px; background:' + this.colors.inputBg + '; borderColor:' + this.colors.inputBorder+'; border-radius:'+this.radius+'px;' );
|
|
21
|
+
this.c[3].textContent = this.value;
|
|
22
|
+
|
|
23
|
+
let fltop = Math.floor(this.h*0.5)-7;
|
|
24
|
+
this.c[4] = this.dom( 'path', this.css.basic + 'position:absolute; width:14px; height:14px; left:5px; top:'+fltop+'px;', { d:this.svgs[ 'cursor' ], fill:this.fontColor, stroke:'none'});
|
|
25
|
+
|
|
26
|
+
this.stat = 1;
|
|
27
|
+
this.isActif = false;
|
|
28
|
+
|
|
29
|
+
this.init();
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
testZone ( e ) {
|
|
34
|
+
|
|
35
|
+
let l = this.local;
|
|
36
|
+
if( l.x === -1 && l.y === -1 ) return '';
|
|
37
|
+
if( l.x > this.sa && l.x < this.sa+30 ) return 'over';
|
|
38
|
+
return '0'
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ----------------------
|
|
43
|
+
// EVENTS
|
|
44
|
+
// ----------------------
|
|
45
|
+
|
|
46
|
+
mouseup ( e ) {
|
|
47
|
+
|
|
48
|
+
if( this.isDown ){
|
|
49
|
+
//this.value = false;
|
|
50
|
+
this.isDown = false;
|
|
51
|
+
//this.send();
|
|
52
|
+
return this.mousemove( e );
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return false;
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
mousedown ( e ) {
|
|
60
|
+
|
|
61
|
+
let name = this.testZone( e );
|
|
62
|
+
|
|
63
|
+
if( !name ) return false;
|
|
64
|
+
|
|
65
|
+
this.isDown = true;
|
|
66
|
+
//this.value = this.values[ name-2 ];
|
|
67
|
+
//this.send();
|
|
68
|
+
return this.mousemove( e );
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
mousemove ( e ) {
|
|
73
|
+
|
|
74
|
+
let up = false;
|
|
75
|
+
|
|
76
|
+
let name = this.testZone( e );
|
|
77
|
+
//let sel = false;
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
//console.log(name)
|
|
82
|
+
|
|
83
|
+
if( name === 'over' ){
|
|
84
|
+
this.cursor('pointer');
|
|
85
|
+
up = this.mode( this.isDown ? 3 : 2 );
|
|
86
|
+
} else {
|
|
87
|
+
up = this.reset();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return up;
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ----------------------
|
|
95
|
+
|
|
96
|
+
apply ( v ) {
|
|
97
|
+
|
|
98
|
+
v = v || '';
|
|
99
|
+
|
|
100
|
+
if( v !== this.value ) {
|
|
101
|
+
this.value = v;
|
|
102
|
+
this.c[3].textContent = this.value;
|
|
103
|
+
this.send();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this.mode(1);
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
update () {
|
|
111
|
+
|
|
112
|
+
this.mode( 3 );
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
mode ( n ) {
|
|
117
|
+
|
|
118
|
+
let change = false
|
|
119
|
+
let cc = this.colors
|
|
120
|
+
|
|
121
|
+
if( this.stat !== n ){
|
|
122
|
+
|
|
123
|
+
if( n===1 ) this.isActif = false;;
|
|
124
|
+
|
|
125
|
+
if( n===3 ){
|
|
126
|
+
if( !this.isActif ){ this.isActif = true; n=4; this.onActif( this ); }
|
|
127
|
+
else { this.isActif = false; }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if( n===2 && this.isActif ) n = 4;
|
|
131
|
+
|
|
132
|
+
this.stat = n
|
|
133
|
+
|
|
134
|
+
switch( n ){
|
|
135
|
+
|
|
136
|
+
case 1: this.s[ 2 ].color = cc.text; this.s[ 2 ].background = cc.button; break; // base
|
|
137
|
+
case 2: this.s[ 2 ].color = cc.textOver; this.s[ 2 ].background = cc.over; break; // over
|
|
138
|
+
case 3: this.s[ 2 ].color = cc.textSelect; this.s[ 2 ].background = cc.select; break; // down
|
|
139
|
+
case 4: this.s[ 2 ].color = cc.textSelect; this.s[ 2 ].background = cc.action; break; // actif
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
change = true;
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return change;
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
reset () {
|
|
154
|
+
|
|
155
|
+
this.cursor();
|
|
156
|
+
return this.mode( this.isActif ? 4 : 1 );
|
|
157
|
+
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
text ( txt ) {
|
|
161
|
+
|
|
162
|
+
this.c[3].textContent = txt;
|
|
163
|
+
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
rSize () {
|
|
167
|
+
|
|
168
|
+
super.rSize();
|
|
169
|
+
|
|
170
|
+
let s = this.s;
|
|
171
|
+
s[2].left = this.sa + 'px';
|
|
172
|
+
s[3].left = (this.sa + 40) + 'px';
|
|
173
|
+
s[3].width = (this.sb - 40) + 'px';
|
|
174
|
+
s[4].left = (this.sa+8) + 'px';
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
}
|