-
Notifications
You must be signed in to change notification settings - Fork 2
/
classGUI.pde
397 lines (364 loc) · 7.63 KB
/
classGUI.pde
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
// *************************************************
// Spinner with bounded values
class SpinBound
{
float x, y, w, h;
String t;
float v, s;
float minv, maxv;
color c0, c1, ct;
String m;
SpinBound(float ix, float iy, float iw, float ih, String it, float iv, float is, float imin, float imax, color ic0, color ic1, color ict, String im)
{
x=ix; // start x
y=iy; // start y
w=iw; // width
h=ih; // height
t=it; // text
v=iv; // start value
s=is; // step value
minv = imin; // min value
maxv = imax; // max value
c0 = ic0; // stroke color
c1 = ic1; // fill color
ct = ict; // text color
m = im; // method
}
boolean isOver()
{
return(mouseX>=x&&mouseX<=x+w&&mouseY>=y&&mouseY<=y+h);
}
void onClick()
{
if (isOver() && !m.equals(""))
{
if ((mouseX>x)&&(mouseX<x+w/4)&&(mouseY>=y)&&(mouseY<=y+h)) //left press
{
if(keyPressed && keyCode == CONTROL)
{
v = constrain(v-s*10, minv, maxv); method(m);
}
else if(keyPressed && keyCode == ALT)
{
v = constrain(v-s*100, minv, maxv); method(m);
}
else
{
v = constrain(v-s, minv, maxv); method(m);
}
}
if ((mouseX>x+3*w/4)&&(mouseX<x+w)&&(mouseY>=y)&&(mouseY<=y+h)) //right press
{
if(keyPressed && keyCode == CONTROL)
{
v = constrain(v+s*10, minv, maxv); method(m);
}
else if(keyPressed && keyCode == ALT)
{
v = constrain(v+s*100, minv, maxv); method(m);
}
else
{
v = constrain(v+s, minv, maxv); method(m);
}
}
}
}
void setValue(float u) { v = u; }
float getValue() { return(v); }
void show()
{
pushStyle();
stroke(c0);
fill(c1);
rect(x, y, w, h);
line(x+w/4,y,x+w/4,y+h);
line(x+3*w/4,y,x+3*w/4,y+h);
fill(ct);
textAlign(CENTER, CENTER);
text(nf(v,0,0),x+w/2.0,y+h/2.0-1);
if (t != "") { text(t, x-17, y+6); }
fill(20);
text("-",x+w/8.0,y+h/2.0-2);
text("+",x+7*w/8.0,y+h/2.0-2);
popStyle();
}
}
// *************************************************
// Button (click)
class Button
{
// parameters
float x, y;
PImage icon;
String t;
color ct;
String m;
// variables
int ww; // icon width
int hh; // icon height
// constructor
Button(float ix, float iy, PImage _icon, String it, color ict, String im)
{
x = ix; // start x (upper left)
y = iy; // start y (upper left)
icon = _icon; // icon tool
t = it; // text string
ct = ict; // text color
m = im; // method (function)
// variables
ww = icon.width;
hh = icon.height;
}
boolean isOver()
{
return(mouseX>=x&&mouseX<=x+ww&&mouseY>=y&&mouseY<=y+hh);
}
void onClick()
{
if (isOver() && !m.equals(""))
{
method(m);
}
}
void show()
{
pushStyle();
image(icon, x, y);
if (t != "")
{
fill(ct);
textAlign(CENTER);
text(t,x+ww/2,y+hh+12);
}
popStyle();
}
}
// *************************************************
// ButtonColor
class ButtonColor
{
// parameters
int x, y;
int w, h;
color c0;
color c1;
String t;
color ct;
String m;
// constructor
ButtonColor(int ix, int iy, int iw, int ih, color ic0, color ic1, String it, color ict, String im)
{
x = ix; // start x (upper left)
y = iy; // start y (upper left)
w = iw; // weight
h = ih; // height
c0 = ic0; // stroke button
c1 = ic1; // fill button
t = it; // text string
ct = ict; // text color
m = im; // method (function)
}
boolean isOver()
{
return(mouseX>=x&&mouseX<=x+w&&mouseY>=y&&mouseY<=y+h);
}
void onClick()
{
if (isOver() && !m.equals(""))
{
method(m);
}
}
void show()
{
pushStyle();
stroke(c0);
fill(c1);
rect(x,y,w,h);
if (t != "")
{
fill(ct);
textAlign(CENTER);
text(t,x+w/2,y+h+12);
}
popStyle();
}
}
// *************************************************
// Button ON/OFF
class ButtonIMG
{
// parameters
float x, y;
PImage iconON, iconOFF;
boolean s;
String t;
color ct;
String m;
// variables
int ww; // icon width
int hh; // icon height
// constructor
ButtonIMG(float ix, float iy, PImage _iconON, PImage _iconOFF, boolean is, String it, color ict, String im)
{
x = ix; // start x (upper left)
y = iy; // start y (upper left)
iconOFF = _iconOFF; // icon tool OFF
iconON = _iconON; // icon tool ON
s = is; // status on-true/off-false
t = it; // text string
ct = ict; // text color
m = im; // method (function)
ww = iconOFF.width;
hh = iconOFF.height;
}
boolean isOver()
{
return(mouseX>=x&&mouseX<=x+ww&&mouseY>=y&&mouseY<=y+hh);
}
void onClick()
{
if (isOver() && !m.equals(""))
{
method(m);
}
}
void show()
{
pushStyle();
if (s) { image(iconON,x,y); }
else { image(iconOFF,x,y); }
if (t != "")
{
fill(ct);
textAlign(CENTER);
text(t,x+ww/2,y+hh+12);
}
popStyle();
}
}
// *************************************************
// Slider
class Slider
{
float x1, y1, x2, y2;
int p;
String t;
float v, v1, v2;
color c0, c1, cl, ct;
String m;
boolean locked;
// constructor
Slider(float ix1, float iy1, float ix2, float iy2, int ip, String it, float iv1, float iv2, float iv, color ic0, color ic1, color icl, color ict, String im)
{
x1=ix1; // start x
y1=iy1; // start y
x2=ix2; // end x
y2=iy2; // end y
p=ip; // pad space
t=it; // text
v1=iv1; // min value
v2=iv2; // max value
v=iv; // value
c0=ic0; // stroke color
c1=ic1; // fill color
cl=icl; // line color
ct=ict; // text color
m=im; // method name
locked = false;
}
boolean isOver()
{
return(mouseX>=x1-p && mouseX<=x2+p && mouseY>=y1-p && mouseY<=y2+p);
}
void onClick()
{
if (isOver())
{
locked = true;
v = constrain(int(map(mouseX,x1,x2,v1,v2)),v1,v2);
method(m);
}
}
void onDrag()
{
if (isOver() || locked)
{
v = constrain(int(map(mouseX,x1,x2,v1,v2)),v1,v2);
method(m);
}
}
void show()
{
pushStyle();
stroke(cl);
line(x1,y1,x2,y2);
int pos = int(map(v,v1,v2,x1,x2));
stroke(c0);
fill(c1);
rectMode(CENTER);
rect(pos, y2, 6, 6);
textSize(12);
textAlign(CENTER);
fill(ct);
text(nf(v,0,0), pos, y1+14);
//textAlign(LEFT);
textAlign(RIGHT);
//text(t, (x1+x2)/2, y1-6);
text(t, x2, y1-6);
popStyle();
}
}
// *************************************************
class Checkbox
{
float x, y, w, h;
String t;
boolean s;
color c0, c1, c2, c3 ,ct;
String m;
// constructor
Checkbox(float ix, float iy, float iw, float ih, String it, boolean is, color ic0, color ic1, color ic2, color ic3, color ict, String im)
{
x=ix; // start x
y=iy; // start y
w=iw; // width
h=ih; // height
t=it; // text
s=is; // status
c0=ic0; // stroke color
c1=ic1; // fill color
c2=ic2; // fill color on
c3=ic3; // fill color off
ct=ict; // text color
m=im; // method
}
boolean isOver()
{
return(mouseX>=x&&mouseX<=x+w&&mouseY>=y&&mouseY<=y+h);
}
void onClick()
{
if (isOver() && !m.equals(""))
{
s=!(s);
method(m);
}
}
void show()
{
pushStyle();
stroke(c0);
fill(c1);
rect(x, y, w, h);
noStroke();
if (s==true) { fill(c2); }//253,246,227); }
else { fill(c3); };
rect(x+3, y+3, w-5, h-5);
fill(ct);
textAlign(LEFT,CENTER);
text(t,x+w+5,y+h/2-1);
popStyle();
}
}