-
Notifications
You must be signed in to change notification settings - Fork 0
/
UI.pde
488 lines (378 loc) · 12.1 KB
/
UI.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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
void createUI() {
intf = new Interface(this);
intf.addFont("Arial", 14);
Widget w;
w = new ToggleButton(intf, 0, 0, 30, 30, "toggleUI", "toggleUI", "I");
intf.addWidget(w);
w = new Container(intf, 30, 0, width - 30, 30, "container");
intf.addWidget(w);
w.hide();
float left = 5;
w = new ToggleButton(intf, left, 0, 20, 30, "toggleLoop", "toggleLoop", "R");
intf.addWidget(w, intf.getWidget("container"));
((ToggleButton)w).toggled = true;
left += 20 + 5;
w = new ToggleButton(intf, left, 0, 20, 30, "toggleAuto", "toggleAuto", "1");
intf.addWidget(w, intf.getWidget("container"));
left += 20 + 5;
w = new ToggleButton(intf, left, 0, 20, 30, "toggleJoin", "toggleJoin", "U");
intf.addWidget(w, intf.getWidget("container"));
left += 20 + 5;
w = new ToggleButton(intf, left, 0, 20, 30, "delAll", "delAll", "B");
intf.addWidget(w, intf.getWidget("container"));
left += 20 + 5;
for (int i = 1; i <= 9; i++) {
w = new SelectButton(intf, left + (i-1) * 25, 10, 20, 20, "selectL" + i, "selectLayer", "C" + i);
intf.addWidget(w, intf.getWidget("container"));
((SelectButton)w).selected = i == 1;
}
for (int i = 1; i <= 9; i++) {
w = new ToggleButton(intf, left + (i-1) * 25, 0, 20, 10, "showL" + i, "showLayer", "-");
intf.addWidget(w, intf.getWidget("container"));
((ToggleButton)w).toggled = true;
}
left += 9 * 25;
w = new ToggleButton(intf, left, 0, 20, 10, "showAll", "showAll", "-");
intf.addWidget(w, intf.getWidget("container"));
((ToggleButton)w).toggled = true;
w = new ToggleButton(intf, left, 10, 20, 20, "selectAll", "selectAll", "T");
intf.addWidget(w, intf.getWidget("container"));
left += 25;
w = new ValueSlider(intf, left, 0, 10, 30, "layerOpacity", "setLayerOpacity");
((ValueSlider)w).setValue(1);
intf.addWidget(w, intf.getWidget("container"));
left += 45;
intf.addWidget(new Label(intf, left - 20, 5, 20, 20, "cp"), intf.getWidget("container"));
w = new ColorSelector(intf, left, 5, 100, 20, "brushColor", "setColor");
intf.addWidget(w, intf.getWidget("container"));
left += 125;
intf.addWidget(new Label(intf, left - 20, 5, 20, 20, "cf"), intf.getWidget("container"));
w = new ColorSelector(intf, left, 5, 100, 20, "backColor", "setColor");
((ColorSelector)w).setColor(255, 255, 255);
intf.addWidget(w, intf.getWidget("container"));
left += 125;
intf.addWidget(new Label(intf, left - 15, 2, 15, 20, "o"), intf.getWidget("container"));
w = new ValueSlider(intf, left, 10, 60, 10, "brushOpacity", "setOpacity");
((ValueSlider)w).setValue(1);
intf.addWidget(w, intf.getWidget("container"));
left += 80;
intf.addWidget(new Label(intf, left - 15, 2, 15, 20, "e"), intf.getWidget("container"));
w = new ValueSlider(intf, left, 10, 60, 10, "brushScale", "setScale");
((ValueSlider)w).setValue(0.5);
intf.addWidget(w, intf.getWidget("container"));
left += 80;
intf.addWidget(new Label(intf, left - 15, 2, 15, 20, "b"), intf.getWidget("container"));
w = new ValueSlider(intf, left, 10, 60, 10, "eraseSpeed", "setEraseSpeed");
((ValueSlider)w).setValue(0.5);
intf.addWidget(w, intf.getWidget("container"));
left += 80;
intf.addWidget(new Label(intf, left - 15, 2, 15, 20, "f"), intf.getWidget("container"));
w = new ValueSlider(intf, left, 10, 60, 10, "backChangeSpeed", "setBackChangeSpeed");
((ValueSlider)w).setValue(0.5);
intf.addWidget(w, intf.getWidget("container"));
left += 80;
agregarPincelesAlInterface(left);
}
void toggleUI(String name) {
estado.invertirMostrarUI();
}
void selectLayer(String name) {
for (int i = 1; i <= 9; i++) {
if (name.equals("selectL" + i)) {
int sel = i - 1;
estado.seleccionarCapa(sel);
for (int j = 1; j <= 9; j++) {
SelectButton w = (SelectButton)intf.getWidget("selectL" + j);
if (j - 1 != sel) {
w.selected = false;
}
}
}
}
}
void showLayer(String name) {
for (int i = 1; i <= 9; i++) {
if (name.equals("showL" + i)) {
int sel = i - 1;
if (estado.capaEstaOcultando(sel)) {
estado.mostrarCapa(sel);
} else {
estado.ocultarCapa(sel);
}
}
}
}
void toggleLoop(String name) {
estado.invertirRepetirTrazos();
}
void toggleAuto(String name) {
estado.invertirBorrarTrazosAuto();
}
void toggleJoin(String name) {
estado.invertirUnirTrazos();
}
void showAll(String name) {
ToggleButton button = (ToggleButton)intf.getWidget("showAll");
if (button.toggled) {
estado.mostrarTodasLasCapas();
} else {
estado.ocultarTodasLasCapas();
}
}
void selectAll(String name) {
estado.invertirSeleccionarTodasLasCapas();
}
void delAll(String name) {
estado.invertirBorrarTodos();
}
void setColor(String name) {
if (name.equals("brushColor")) {
ColorSelector csel = (ColorSelector)intf.getWidget("brushColor");
estado.crearTintaPincelSeleccionada(csel.getColor());
} else if (name.equals("backColor")) {
ColorSelector csel = (ColorSelector)intf.getWidget("backColor");
estado.crearTintaFondoSeleccionada(csel.getColor());
}
}
void setLayerOpacity(String name) {
ValueSlider vsli = (ValueSlider)intf.getWidget("layerOpacity");
estado.establecerOpacidadDeCapa(vsli.getValue());
}
void setOpacity(String name) {
ValueSlider vsli = (ValueSlider)intf.getWidget("brushOpacity");
estado.establecerFactorOpacidad(vsli.getValue());
}
void setScale(String name) {
ValueSlider vsli = (ValueSlider)intf.getWidget("brushScale");
estado.establecerFactorEscala(vsli.getValue());
}
void setEraseSpeed(String name) {
ValueSlider vsli = (ValueSlider)intf.getWidget("eraseSpeed");
estado.establecerTiempoBorradoTrazos(vsli.getValue());
}
void setBackChangeSpeed(String name) {
ValueSlider vsli = (ValueSlider)intf.getWidget("backChangeSpeed");
estado.establecerTiempoTransicionFondo(vsli.getValue());
}
class Label extends Widget {
String text = "";
Label() { }
Label(Interface intf, float x, float y, float w, float h, String txt) {
super(intf, x, y, w, h, "", "");
text = txt;
}
Label(Interface intf, float x, float y, float w, float h, String name, String txt) {
super(intf, x, y, w, h, name, "");
text = txt;
}
void draw() {
PApplet p = intf.sketch;
intf.setFont("Arial", 14);
p.fill(0);
p.textAlign(CENTER, CENTER);
p.text(text, 0, 0, width, height);
}
}
class SelectButton extends Widget {
String label = "";
boolean selected = false;
SelectButton() { }
SelectButton(Interface intf, float x, float y, float w, float h) {
super(intf, x, y, w, h, "", "");
}
SelectButton(Interface intf, float x, float y, float w, float h, String callback, String label) {
super(intf, x, y, w, h, "", callback);
this.label = label;
}
SelectButton(Interface intf, float x, float y, float w, float h, String name, String callback, String label) {
super(intf, x, y, w, h, name, callback);
this.label = label;
}
void draw() {
PApplet p = intf.sketch;
p.noStroke();
if (selected) p.fill(255, 0 ,0);
else p.fill(255);
p.rect(0, 0, width, height, 5);
intf.setFont("Arial", 14);
if (selected) p.fill(255);
else p.fill(0);
p.textAlign(CENTER, CENTER);
p.text(label, 0, 0, width, height);
}
void release() {
selected = true;
runCallback();
}
}
class ToggleButton extends Widget {
String label = "";
boolean toggled = false;
ToggleButton() { }
ToggleButton(Interface intf, float x, float y, float w, float h) {
super(intf, x, y, w, h, "", "");
}
ToggleButton(Interface intf, float x, float y, float w, float h, String callback, String label) {
super(intf, x, y, w, h, "", callback);
this.label = label;
}
ToggleButton(Interface intf, float x, float y, float w, float h, String name, String callback, String label) {
super(intf, x, y, w, h, name, callback);
this.label = label;
}
void draw() {
PApplet p = intf.sketch;
p.noStroke();
if (toggled) p.fill(255, 0 ,0);
else p.fill(255);
p.rect(0, 0, width, height, 5);
intf.setFont("Arial", 14);
if (toggled) p.fill(255);
else p.fill(0);
p.textAlign(CENTER, CENTER);
p.text(label, 0, 0, width, height);
}
void release() {
toggled = !toggled;
runCallback();
}
}
class Container extends Widget {
Container() { }
Container(Interface intf, float x, float y, float w, float h, String name) {
super(intf, x, y, w, h, name, "");
}
void draw() {
PApplet p = intf.sketch;
p.noStroke();
p.fill(255);
p.rect(0, 0, width, height, 5);
}
}
class ColorSelector extends Widget {
float r = 0;
float g = 0;
float b = 0;
boolean outdated = false;
ColorSelector() { }
ColorSelector(Interface intf, float x, float y, float w, float h) {
super(intf, x, y, w, h);
}
ColorSelector(Interface intf, float x, float y, float w, float h, String callback) {
super(intf, x, y, w, h, "", callback);
}
ColorSelector(Interface intf, float x, float y, float w, float h, String name, String callback) {
super(intf, x, y, w, h, name, callback);
}
void setColor(int r, int g, int b) {
this.r = r / 255.0;
this.g = g / 255.0;
this.b = b / 255.0;
}
void setColor(color c) {
this.r = red(c) / 255.0;
this.g = red(c) / 255.0;
this.b = blue(c) / 255.0;
}
color getColor() {
return color(255 * r, 255 * g, 255 * b);
}
void draw() {
PApplet p = intf.sketch;
float mixw = width * 0.2;
float cmpw = width * 0.27;
float x;
if (outdated) p.noStroke();
else p.stroke(0);
p.fill(255 * r, 255 * g, 255 * b);
rect(0, 0, mixw, height, 5);
p.noStroke();
p.fill(255 * r, 0, 0);
rect(mixw, 0, cmpw, height, 5);
p.fill(0, 255 * g, 0);
rect(mixw + cmpw, 0, cmpw, height, 5);
p.fill(0, 0, 255 * b);
rect(mixw + 2 * cmpw, 0, cmpw, height, 5);
p.stroke(255);
x = mixw + r * cmpw;
p.line(x, 0, x, height);
x = mixw + cmpw + g * cmpw;
p.line(x, 0, x, height);
x = mixw + 2 * cmpw + b * cmpw;
p.line(x, 0, x, height);
}
void drag() {
float mixw = width * 0.2;
float cmpw = width * 0.27;
if (mixw <= mouseX && mouseX <= mixw + cmpw) {
r = map(mouseX, mixw, mixw + cmpw, 0, 1);
outdated = true;
}
if (mixw + cmpw <= mouseX && mouseX <= mixw + 2 * cmpw) {
g = map(mouseX, mixw + cmpw, mixw + 2 * cmpw, 0, 1);
outdated = true;
}
if (mixw + 2 * cmpw <= mouseX && mouseX <= mixw + 3 * cmpw) {
b = map(mouseX, mixw + 2 * cmpw, mixw + 3 * cmpw, 0, 1);
outdated = true;
}
}
void release() {
float mixw = width * 0.2;
if (0 <= mouseX && mouseX <= mixw) {
runCallback();
outdated = false;
}
}
}
class ValueSlider extends Widget {
float value = 0;
boolean horizontal = true;
ValueSlider() { }
ValueSlider(Interface intf, float x, float y, float w, float h) {
super(intf, x, y, w, h);
horizontal = h < w;
}
ValueSlider(Interface intf, float x, float y, float w, float h, String callback) {
super(intf, x, y, w, h, "", callback);
horizontal = h < w;
}
ValueSlider(Interface intf, float x, float y, float w, float h, String name, String callback) {
super(intf, x, y, w, h, name, callback);
horizontal = h < w;
}
void setValue(float v) {
this.value = v;
}
float getValue() {
return value;
}
void draw() {
PApplet p = intf.sketch;
p.stroke(0);
p.noFill();
p.rect(0, 0, width, height, 5);
if (horizontal) {
float x = value * width;
p.line(x, 0, x, height);
} else {
float y = (1 - value) * height;
p.line(0, y, width, y);
}
}
void drag() {
if (horizontal) {
value = (float)(mouseX) / width;
} else {
value = 1 - (float)(mouseY) / height;
}
}
void release() {
if (horizontal) {
value = (float)(mouseX) / width;
} else {
value = 1 - (float)(mouseY) / height;
}
runCallback();
}
}