-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkeyboard.pde
More file actions
492 lines (451 loc) · 10.9 KB
/
keyboard.pde
File metadata and controls
492 lines (451 loc) · 10.9 KB
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
489
490
491
492
//*********************************
//*********************************
void keyPressed()
{
// Panic button --> reset parameters
// sometimes you don't know why the program don't work as expected...
if (keyCode==123) // F12
{
aSelection = false;
stencil = false;
brushSize = 10; slSIZE.v = 10;
alfa = 255; slALFA.v = 255;
noGlitch = false; cbGLITCH.s = false;
brushCol = color(darkGray);
livelli[activeLyr].lv = true;
livelli[activeLyr].lt = 255;
selectTool("Ink");
mousePressed = false;
keyPressed= false;
}
// OPEN HELP
if (keyCode==112) // F1
{
launch(dataPath("LAYERS.PDF"));
}
if (keyCode==113) // F2
{
if (onTop)
{
surface.setAlwaysOnTop(false);
onTop = false;
}
else
{
surface.setAlwaysOnTop(true);
onTop = true;
}
}
// Toggle selection
if (keyCode==114) // F3
{
//aSelection = !aSelection;
//cbSELECT.s = aSelection;
if ((x1sel == x2sel) || (y1sel == y2sel)) { aSelection = false; }
else { aSelection = !aSelection; }
cbSELECT.s = aSelection;
}
// Toggle stencil
if (keyCode==115) // F4
{
stencil = !stencil;
cbSTENCIL.s = stencil;
}
// Copy selected pixels
if (keyCode==116) // F5
{
copyPixels();
}
// Paste copied pixels
if (keyCode==117) // F6
{
pastePixels();
}
// Draw selection contour
if (keyCode==118) // F7
{
selectionContour();
}
// Save selection as image
if (keyCode==119) // F8
{
selectionSaveDialog();
}
// toggle erase outside selection
if (keyCode==120) // F9
{
cbSELOUT.s = !cbSELOUT.s;
}
// draw palette on active layer from brushCol to oldCol (the colors on rgbhsb tool)
if ((key=='j') || (key=='J'))
{
int x0 = mouseX;
int y0 = mouseY;
float step = 0.1;
color c;
color toCol = rgbhsb.oldCol;
// store layer for undo
storeUNDO();
// draw palette from brushCol to oldCol
livelli[activeLyr].pg.beginDraw();
for(int i=0; i<11; i++)
{
c = lerpColor(brushCol, toCol, i*step);
livelli[activeLyr].pg.fill(c);
livelli[activeLyr].pg.noStroke();
livelli[activeLyr].pg.rect(x0+22*i,y0,20,20);
}
livelli[activeLyr].pg.endDraw();
// update swatch of current layer
livelli[activeLyr].updateLayerSwatch();
}
// HSB on/off
if (key==' ')
{
toolHSB = !toolHSB;
}
// MENU on/off
if (keyCode==TAB)
{
menu = !menu;
}
// POINTER COLOR: white <--> black
if (keyCode==ESC)
{
key = 0;
if (pointerCol == white) { pointerCol = black; }
else { pointerCol = white; }
}
// Layer GUI on/off
if (key=='.')
{
showLayerGUI = !showLayerGUI;
}
// SELECT TOOL
// select Stamp tool
if ((key=='t') || (key =='T')) { selectTool("Stamp"); }
// select Pencil tool
if ((key=='p') || (key =='P')) { selectTool("Pencil"); }
// select Liner tool
if ((key=='l') || (key =='L')) { selectTool("Liner"); }
// select Quad tool
if ((key=='q') || (key =='Q')) { selectTool("Quad"); }
// select Quad tool
if ((key=='c') || (key =='C')) { selectTool("Circle"); }
// select Eraser tool
if ((key=='e') || (key =='E')) { selectTool("Eraser"); }
// select Vernice tool
if ((key=='v') || (key =='V')) { selectTool("Vernice"); }
// select Ink tool
if ((key=='i') || (key =='I')) { selectTool("Ink"); }
// select Dyna tool
if ((key=='d') || (key =='D')) { selectTool("Dyna"); }
// select Filler tool
if ((key=='f') || (key =='F')) { selectTool("Filler"); }
// select Mixer tool
if ((key=='m') || (key =='M')) { selectTool("Mixer"); }
// select Clone tool
if ((key=='n') || (key =='N')) { selectTool("Clone"); }
// select Web tool
if ((key=='b') || (key =='B')) { selectTool("Web"); }
// select Select tool
if (key=='0') { selectTool("Select"); }
// select Stencil tool
if (key=='9') { selectTool("Stencil"); }
// select Stencil tool
if (key==';') { selectTool("Confetti"); }
// select Shape tool
if (key==',') { selectTool("Shape"); }
// set grid on/off
if ((key=='w') || (key=='W'))
{
grid = !grid;
cbGRID.s = grid;
}
// brushSize +/-
if (key=='[')
{
brushSize = constrain(--brushSize, brushSizeMin, brushSizeMax);
slSIZE.v = brushSize;
}
if (key==']')
{
brushSize = constrain(++brushSize, brushSizeMin, brushSizeMax);
slSIZE.v = brushSize;
}
// Zoom or Alpha +/-
if (key=='+')
{
if (zoom)
{ magnify = constrain(++magnify, 2, 32); }
else
{
alfa = constrain(++alfa,1,255);
slALFA.v = alfa; // update ALFA slider
//brushCol = color(red(brushCol),green(brushCol),blue(brushCol),alfa);
brushCol = color((brushCol >> 16) & 0xFF, (brushCol >> 8) & 0xFF, brushCol & 0xFF, alfa);
}
}
if (key=='-')
{
if (zoom)
{ magnify = constrain(--magnify, 2, 32); }
else
{
alfa = constrain(--alfa,1,255);
slALFA.v = alfa; // update ALFA slider
//brushCol = color(red(brushCol),green(brushCol),blue(brushCol),alfa);
brushCol = color((brushCol >> 16) & 0xFF, (brushCol >> 8) & 0xFF, brushCol & 0xFF, alfa);
}
}
// toggle antialiasing glitch
if ((key=='a') || (key=='A'))
{
noGlitch = !noGlitch;
cbGLITCH.s = noGlitch;
}
// redo
if ((key=='r') || (key=='R'))
{
redo();
}
// undo
if ((key=='u') || (key=='U'))
{
undo();
}
// zoom on/off
if ((key=='z') || (key=='Z'))
{
zoom = !zoom;
}
// X mirror
if ((key=='x') || (key=='X'))
{
symX = !symX;
cbSYMX.s = symX;
}
// Y mirror
if ((key=='y') || (key=='Y'))
{
symY = !symY;
cbSYMY.s = symY;
}
// move active layer UP
if (keyCode == UP)
{
if (stencil && aSelection)
{
if (tool == "Stencil") { ysten--; }
else if (tool == "Select") { y1sel--; y2sel--; }
else { y1sel--; y2sel--; }
}
else if (stencil) { ysten--; }
else if (aSelection) { y1sel--; y2sel--; }
else if ((menu) && (activeLyr != 0))
{
swapLayers(activeLyr,activeLyr-1);
activeLyr = activeLyr - 1;
}
}
// move active layer DOWN
if (keyCode == DOWN)
{
if (stencil && aSelection)
{
if (tool == "Stencil") { ysten++; }
else if (tool == "Select") { y1sel++; y2sel++; }
else { y1sel++; y2sel++; }
}
else if (stencil) { ysten++; }
else if (aSelection) { y1sel++; y2sel++; }
else if ((menu) && (activeLyr != numLayers-1))
{
// move current layer down
swapLayers(activeLyr,activeLyr+1);
activeLyr = activeLyr + 1;
}
}
// previous palette page
if (keyCode == LEFT)
{
if (stencil && aSelection)
{
if (tool == "Stencil") { xsten--; }
else if (tool == "Select") { x1sel--; x2sel--; }
else { x1sel--; x2sel--; }
}
else if (stencil) { xsten--; }
else if (aSelection) { x1sel--; x2sel--; }
else if (menu)
{
// move current layer up
activePalettePage = constrain(--activePalettePage,0,12);
}
}
// next palette page
if (keyCode == RIGHT)
{
if (stencil && aSelection)
{
if (tool == "Stencil") { xsten++; }
else if (tool == "Select") { x1sel++; x2sel++; }
else { x1sel++; x2sel++; }
}
else if (stencil) { xsten++; }
else if (aSelection) { x1sel++; x2sel++; }
else if (menu)
{
activePalettePage = constrain(++activePalettePage,0,12);
}
}
// clear current layer or current selection
if (key==BACKSPACE)
{
// store layer for undo
storeUNDO();
if (aSelection)
{
if (!cbSELOUT.s) // erase inside selection
{
int xmin = x1sel+1;
int xmax = x2sel-1;
int ymin = y1sel+1;
int ymax = y2sel-1;
int loc = 0;
livelli[activeLyr].pg.beginDraw();
livelli[activeLyr].pg.loadPixels();
for (int x = xmin; x <= xmax; x++)
{
for (int y = ymin; y <= ymax; y++)
{
loc = x + y*width;
livelli[activeLyr].pg.pixels[loc] = 0X0;
}
}
livelli[activeLyr].pg.updatePixels();
livelli[activeLyr].pg.endDraw();
}
else // erase outside selection
{
int loc = 0;
livelli[activeLyr].pg.beginDraw();
livelli[activeLyr].pg.loadPixels();
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
loc = x + y*width;
if ((x < x1sel) || (x > x2sel) || (y < y1sel) || (y > y2sel))
{
livelli[activeLyr].pg.pixels[loc] = 0X0;
}
}
}
livelli[activeLyr].pg.updatePixels();
livelli[activeLyr].pg.endDraw();
}
}
else // delete entire canvas of active layer
{
livelli[activeLyr].delete();
}
// update swatch of current layer
livelli[activeLyr].updateLayerSwatch();
}
// highlight cursor
if (key=='h')
{
highlightCursor = !highlightCursor;
}
// Activate a layer (1..numLayers)
if ((key > '0') && (key <= (char) (numLayers+48)))
{
livelli[activeLyr].la = false;
activeLyr = key - 49;
livelli[activeLyr].la = true;
livelli[activeLyr].lv = true; // set layer active --> visible
// update swatch of current layer
livelli[activeLyr].updateLayerSwatch(); // turn on the first time :)
}
// set random DynaDraw parameters
if (key=='8')
{
if (tool == "Dyna")
{
myDD.preset08();
setDynaSlider(8);
}
}
// show a dialog window to open an image file as layer
if (key=='o'||key=='O')
{
selectFolderOpenDialog();
}
// save image
if (key=='s'||key=='S')
{
selectFolderSaveDialog();
}
// force to draw square and circle
if (key=='k'||key=='K')
{
quadLock = !quadLock;
circleLock = !circleLock;
btnLOCK.s = !btnLOCK.s;
}
// snap to grid
if (key=='g'||key=='G')
{
snap2Grid = !snap2Grid;
cbSNAP.s = !cbSNAP.s;
}
// Reset tool parameters to default
if (key=='=')
{
if (tool == "RGB")
{
slRGBr.v = 0;
slRGBg.v = 0;
slRGBb.v = 0;
}
else if (tool == "HSB")
{
slHSBh.v = 0;
slHSBs.v = 0;
slHSBb.v = 0;
}
else if (tool == "RND")
{
slRNDa.v = 0;
slRNDr.v = 0;
slRNDg.v = 0;
slRNDb.v = 0;
}
else if (tool == "Tool01")
{
slRNDa.v = 0;
slRNDr.v = 0;
slRNDg.v = 0;
slRNDb.v = 0;
}
}
}
//*********************************
void keyReleased()
{
picker = false;
if (startAction) // started an action who modify the active layer
{
startAction = false;
// reset redo
for( int i=0; i< numRedo; i++)
{ redoLyr[i] = -1; }
}
// update undo/redo button
if (undoLyr[0] == -1) { btnUNDO.s = false; }
else { btnUNDO.s = true; }
if (redoLyr[0] == -1) { btnREDO.s = false; }
else { btnREDO.s = true; }
keyPressed = false; // per sicurezza
}