-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdraw.c
1010 lines (899 loc) · 30.5 KB
/
draw.c
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
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <math.h>
#include <stdio.h>
#include "draw.h"
#define COLOR_POW nvgRGBA(0x00,0xcf,0xf7,255)
#define COLOR_BRIGHT nvgRGBA(0x3a,0xc5,0xec,255)
#define COLOR_DIM nvgRGBA(0x11,0x45,0x75,255)
#define COLOR_DIM_OUTLINE nvgRGBA(0x10,0x7a,0xa3,255)
static char* cpToUTF8(int cp, char* str)
{
int n = 0;
if (cp < 0x80) n = 1;
else if (cp < 0x800) n = 2;
else if (cp < 0x10000) n = 3;
else if (cp < 0x200000) n = 4;
else if (cp < 0x4000000) n = 5;
else if (cp <= 0x7fffffff) n = 6;
str[n] = '\0';
switch (n) {
case 6: str[5] = 0x80 | (cp & 0x3f); cp = cp >> 6; cp |= 0x4000000;
case 5: str[4] = 0x80 | (cp & 0x3f); cp = cp >> 6; cp |= 0x200000;
case 4: str[3] = 0x80 | (cp & 0x3f); cp = cp >> 6; cp |= 0x10000;
case 3: str[2] = 0x80 | (cp & 0x3f); cp = cp >> 6; cp |= 0x800;
case 2: str[1] = 0x80 | (cp & 0x3f); cp = cp >> 6; cp |= 0xc0;
case 1: str[0] = cp;
}
return str;
}
#define ICON_SEARCH 0x1F50D
#define ICON_CIRCLED_CROSS 0x2716
#define ICON_CHEVRON_RIGHT 0xE75E
#define ICON_CHECK 0x2713
#define ICON_LOGIN 0xE740
#define ICON_TRASH 0xE729
#define ICON_DOWN 0xE764
void drawDial(NVGcontext *vg, int x, int y, int w, int h)
{
int cy = y+h/2;
int cx = x+w/2;
int kr = h/4;
nvgBeginPath(vg);
nvgArc(vg, cx, cy, 0.4*h, 0, 1.0/2.0*M_PI, 1);
nvgArc(vg, cx, cy, 0.2*h, 1.0/2.0*M_PI, 0, 2);
nvgClosePath(vg);
nvgFillColor(vg, nvgRGBA(0x11,0x45,0x75,255));
nvgFill(vg);
nvgBeginPath(vg);
nvgArc(vg, cx, cy, 0.4*h, -1.8, 0.5*M_PI, 1);
nvgArc(vg, cx, cy, 0.2*h, 0.5*M_PI, -1.8, 2);
nvgClosePath(vg);
nvgFillColor(vg, nvgRGBA(0x3a,0xc5,0xec,255));
nvgFill(vg);
}
void drawDialValue(NVGcontext *vg, int val, int x, int y, int w, int h)
{
char str[128];
snprintf(str, 128, "%d", val);
int X = x+w/2;
int Y = y+h/2;
int W = w/2;
int H = h/2;
nvgFontSize(vg, H*0.6);
nvgFontFace(vg, "sans");
nvgFillColor(vg, nvgRGBA(255,255,255,128));
nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE);
nvgText(vg, X+W/2,Y+H*0.5f,str, NULL);
}
//------------------------------------------------------------------------------
void drawLabel(NVGcontext *vg, const char *str, int x, int y, int w, int h)
{
nvgFontSize(vg, h*1.0);
nvgFontFace(vg, "sans");
//nvgFillColor(vg, nvgRGBA(0x22, 0x9b, 0xdb, 128));
nvgFillColor(vg, nvgRGBA(0x32, 0xb7, 0xdd, 255));
nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE);
float bounds[4];
nvgTextBounds(vg, x,y, str, NULL, bounds);
if((bounds[2]-bounds[0]) > w) //horizontally constrained case
nvgFontSize(vg, h*w*1.0/(bounds[2]-bounds[0]));
nvgText(vg, x+w/2,y+h*0.5f,str, NULL);
}
//------------------------------------------------------------------------------
void drawRightLabel(NVGcontext *vg, const char *str, int x, int y, int w, int h)
{
nvgFontSize(vg, h*1.0);
nvgFontFace(vg, "sans");
//nvgFillColor(vg, nvgRGBA(0x22, 0x9b, 0xdb, 128));
nvgFillColor(vg, nvgRGBA(0x32, 0xb7, 0xdd, 255));
nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE);
float bounds[4];
nvgTextBounds(vg, x,y, str, NULL, bounds);
if((bounds[2]-bounds[0]) > w) { //horizontally constrained case
nvgFontSize(vg, h*w*1.0/(bounds[2]-bounds[0]));
nvgTextBounds(vg, x,y, str, NULL, bounds);
}
nvgText(vg, x+w-bounds[2],y+h*0.5f,str, NULL);
}
//------------------------------------------------------------------------------
void drawLeftLabel(NVGcontext *vg, const char *str, int x, int y, int w, int h)
{
nvgFontSize(vg, h*1.0);
nvgFontFace(vg, "sans");
//nvgFillColor(vg, nvgRGBA(0x22, 0x9b, 0xdb, 128));
nvgFillColor(vg, nvgRGBA(0x32, 0xb7, 0xdd, 255));
nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE);
float bounds[4];
nvgTextBounds(vg, x,y, str, NULL, bounds);
if((bounds[2]-bounds[0]) > w) //horizontally constrained case
nvgFontSize(vg, h*w*1.0/(bounds[2]-bounds[0]));
nvgText(vg, x,y+h*0.5f,str, NULL);
}
//------------------------------------------------------------------------------
void drawBox(NVGcontext *vg, int x, int y, int w, int h)
{
nvgBeginPath(vg);
nvgRect(vg, x,y,w,h);
nvgFillColor(vg, nvgRGBA(0x04, 0x37, 0x5e, 255));
nvgStrokeColor(vg, COLOR_BRIGHT);
nvgFill(vg);
nvgStroke(vg);
}
//------------------------------------------------------------------------------
void drawButtonScale(NVGcontext *vg, float scale, const char *str, int x, int y,
int w, int h)
{
drawBox(vg, x,y,w,h);
nvgFontSize(vg, h*scale);
nvgFontFace(vg, "sans");
nvgFillColor(vg, nvgRGBA(0x00, 0xcf, 0xf7, 255));
nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE);
float bounds[4];
nvgTextBounds(vg, x,y, str, NULL, bounds);
if((bounds[2]-bounds[0]) > w) //horizontally constrained case
nvgFontSize(vg, h*scale*w*1.0/(bounds[2]-bounds[0]));
nvgText(vg, x+w/2,y+h*0.5f,str, NULL);
}
//------------------------------------------------------------------------------
void drawButton(NVGcontext *vg, const char *str, int x, int y, int w, int h)
{
drawButtonScale(vg, 0.6, str, x,y,w,h);
}
//------------------------------------------------------------------------------
void drawRelaxedButton(NVGcontext *vg, const char *str, int x, int y, int w, int h)
{
NVGpaint grad = nvgLinearGradient(vg, x, y, x, y+h,
nvgRGBA(0x47,0x47,0x47,255),
nvgRGBA(0x32,0x32,0x32,255));
nvgStrokeColor(vg, nvgRGBA(0,0,0,12));
nvgBeginPath(vg);
nvgRect(vg, x,y,w,h);
nvgFillPaint(vg, grad);
nvgStroke(vg);
nvgFill(vg);
float scale = 0.8;
nvgFontSize(vg, h*scale);
nvgFontFace(vg, "sans");
#
nvgFillColor(vg, nvgRGBA(0x00,0xe0,0xcc, 255));
nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE);
float bounds[4];
nvgTextBounds(vg, x,y, str, NULL, bounds);
if((bounds[2]-bounds[0]) > w) //horizontally constrained case
nvgFontSize(vg, h*scale*w*1.0/(bounds[2]-bounds[0]));
nvgText(vg, x+w/2,y+h*0.5f,str, NULL);
}
//------------------------------------------------------------------------------
void drawOptButton(NVGcontext *vg, const char *str, int x, int y, int w, int h)
{
char icon[8];
nvgBeginPath(vg);
nvgRect(vg, x,y,w,h);
nvgFillColor(vg, COLOR_DIM);
nvgStrokeColor(vg, nvgRGBA(0x10,0x7a,0xa3,255));
nvgFill(vg);
nvgStroke(vg);
nvgFontSize(vg, h*0.6);
nvgFontFace(vg, "icons");
nvgFillColor(vg, nvgRGBA(255,255,255,128));
nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE);
nvgText(vg, x+w-h/2,y+h*0.5f,cpToUTF8(ICON_DOWN,icon), NULL);
nvgFontSize(vg, h*0.6);
nvgFontFace(vg, "sans");
nvgFillColor(vg, nvgRGBA(0x00, 0xcf, 0xf7, 255));
nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE);
float bounds[4];
nvgTextBounds(vg, x,y, str, NULL, bounds);
if((bounds[2]-bounds[0]) > w-h-h/4) //horizontally constrained case
nvgFontSize(vg, h*(w-h-h/4)*0.6/(bounds[2]-bounds[0]));
nvgText(vg, x+h/4+(w-h)/2,y+h*0.5f,str, NULL);
}
//------------------------------------------------------------------------------
void drawButtonGrid(NVGcontext *vg, int n, int m, int x, int y, int w, int h)
{
float W=w*1.0/n;
float H=h*1.0/m;
char buf[8] = {0};
int cnt = 0;
for(int i=0; i<n; ++i) {
for(int j=0; j<m; ++j) {
int xx = x+0.05*W + W*i;
int yy = y+0.05*H + H*j;
snprintf(buf, 7, "%d", ++cnt);
drawButtonScale(vg, 0.9, buf, xx, yy, 0.9*W, 0.9*H);
}
}
}
//------------------------------------------------------------------------------
void drawGrid(NVGcontext *vg, int n, int m, int x, int y, int w, int h)
{
float W=w*1.0/n;
float H=h*1.0/m;
int cnt = 0;
for(int i=0; i<=n; ++i) {
nvgBeginPath(vg);
nvgMoveTo(vg, i*W+x, y);
nvgLineTo(vg, i*W+x, y+h);
nvgStrokeColor(vg, nvgRGBA(0x06,0x35,0x04b,255));
nvgStroke(vg);
}
for(int i=0; i<=m; ++i) {
nvgBeginPath(vg);
nvgMoveTo(vg, x, y+i*H);
nvgLineTo(vg, x+w, y+i*H);
nvgStrokeColor(vg, nvgRGBA(0x06,0x35,0x04b,255));
nvgStroke(vg);
}
}
//------------------------------------------------------------------------------
void drawSin(NVGcontext *vg, int x, int y, int w, int h)
{
int N = 128;
float W=w*1.0/N;
nvgBeginPath(vg);
{
int i=0;
nvgMoveTo(vg, x+i*W, y+h/2-0.95*h*0.5*sin(2*M_PI*i*1.0/(N-1)));
}
for(int i=0; i<N; ++i) {
nvgLineTo(vg, x+i*W, y+h/2-0.95*h*0.5*sin(2*M_PI*i*1.0/(N-1)));
}
nvgStrokeWidth(vg, w/40.0);
nvgStrokeColor(vg, nvgRGBA(0x00,0xcf,0xf7,255));
nvgStroke(vg);
}
//------------------------------------------------------------------------------
void drawAltDial(NVGcontext *vg, float val, int x, int y, int w, int h)
{
float start = M_PI/4;
float end = M_PI*3.0/4.0;
int cy = y+h/2;
int cx = x+w/2;
int kr = h/4;
nvgBeginPath(vg);
nvgArc(vg, cx, cy, 0.4*h, start, end, 1);
nvgArc(vg, cx, cy, 0.2*h, end, start, 2);
nvgClosePath(vg);
nvgFillColor(vg, nvgRGBA(0x11,0x45,0x75,255));
nvgFill(vg);
const float len = (3.0/2.0*M_PI)*val;//0.3;
float startt = end + len;
nvgBeginPath(vg);
nvgArc(vg, cx, cy, 0.2*h, end, startt, 2);
nvgArc(vg, cx, cy, 0.4*h, startt, end, 1);
nvgClosePath(vg);
nvgFillColor(vg, nvgRGBA(0x3a,0xc5,0xec,255));
nvgFill(vg);
}
//------------------------------------------------------------------------------
void drawPanDial(NVGcontext *vg, const char *desc, float val, int x, int y, int w, int h)
{
const float start = M_PI/4;
const float end = M_PI*3.0/4.0;
const float inner = 0.35*h;
const float outter = 0.5*h;
const int cy = y+h/2;
const int cx = x+w/2;
const int kr = h/4;
nvgBeginPath(vg);
nvgArc(vg, cx, cy, outter, start, end, 1);
nvgArc(vg, cx, cy, inner, end, start, 2);
nvgClosePath(vg);
nvgFillColor(vg, COLOR_DIM);
nvgFill(vg);
const float len = (3.0/2.0*M_PI)*val;//0.3;
float startt = end + len;
nvgBeginPath(vg);
nvgArc(vg, cx, cy, inner, end, startt, 2);
nvgArc(vg, cx, cy, outter, startt, end, 1);
nvgClosePath(vg);
nvgFillColor(vg, nvgRGBA(0x3a,0xc5,0xec,255));
nvgFill(vg);
//Consider bounding box for text hitting +-30
//degrees of the inner circle
const float sinAngle = 0.5;
const float cosAngle = 0.866;
//Half width/height terms
const float textW = cosAngle*inner;
const float textH = sinAngle*inner;
drawLabel(vg, desc, cx-textW, cy-textH, textW*2, textH*2);
}
//------------------------------------------------------------------------------
void drawEnvEdit(NVGcontext *vg, float *dat, int n, int m, int x, int y, int w, int h)
{
nvgBeginPath(vg);
nvgRect(vg, x,y,w,h);
nvgFillColor(vg, nvgRGBA(0x0d,0x0d,0x0d,255));
nvgStrokeColor(vg, nvgRGBA(0x01, 0x47, 0x67,255));
nvgFill(vg);
nvgStroke(vg);
//Draw UnderLine
////Bottom Half
nvgScissor(vg, x,y+h/2,w,h/2);
nvgBeginPath(vg);
nvgMoveTo(vg, x,y);
for(int i=0; i<n; ++i)
nvgLineTo(vg, x+w*dat[2*i+1], y+h/2-h/2*dat[2*i]);
nvgLineTo(vg, x+w, y);
nvgClosePath(vg);
nvgFillColor(vg, nvgRGBA(0x11,0x45,0x75,55));
nvgFill(vg);
nvgResetScissor(vg);
////Upper Half
nvgScissor(vg, x,y,w,h/2);
nvgBeginPath(vg);
nvgMoveTo(vg, x,y+h);
for(int i=0; i<n; ++i)
nvgLineTo(vg, x+w*dat[2*i+1], y+h/2-h/2*dat[2*i]);
nvgLineTo(vg, x+w, y+h);
nvgClosePath(vg);
nvgFillColor(vg, nvgRGBA(0x11,0x45,0x75,55));
nvgFill(vg);
nvgResetScissor(vg);
//Draw Zero Line
nvgBeginPath(vg);
nvgMoveTo(vg, x, y+h/2);
nvgLineTo(vg, x+w, y+h/2);
nvgStrokeColor(vg, COLOR_DIM);
nvgStroke(vg);
//Draw Sel Line
if(m >= 0 && m <n) {
nvgBeginPath(vg);
nvgMoveTo(vg, x+w*dat[2*m+1], y);
nvgLineTo(vg, x+w*dat[2*m+1], y+h);
nvgStrokeColor(vg, COLOR_DIM);
nvgStroke(vg);
}
//Draw Actual Line
nvgBeginPath(vg);
nvgMoveTo(vg, x+w*dat[1], y+h/2-h/2*dat[0]);
for(int i=1; i<n; ++i)
nvgLineTo(vg, x+w*dat[2*i+1], y+h/2-h/2*dat[2*i]);
nvgStrokeWidth(vg, 3);
nvgStrokeColor(vg, COLOR_BRIGHT);
nvgStroke(vg);
nvgStrokeWidth(vg, 1);
//Draw Grabbable Points
for(int i=0; i<n; ++i) {
float xx = x+w*dat[2*i+1];
float yy = y+h/2-h/2*dat[2*i];
nvgBeginPath(vg);
nvgRect(vg, xx-3,yy-3,6,6);
nvgFillColor(vg, nvgRGBA(0,0,0,255));
nvgStrokeColor(vg, COLOR_BRIGHT);//nvgRGBA(0x10,0x7a,0xa3,255));
nvgFill(vg);
nvgStroke(vg);
}
}
//------------------------------------------------------------------------------
void drawLinx(NVGcontext *vg, float xmin, float xmax, float x, float y, float w, float h)
{
//1,2,3,4,5,6,7,8,9,10,20
for(int xx=xmin; xx<=(int)xmax; ++xx) {
float base = (xx-xmin)/(xmax-xmin);
//for(int shift=0; shift<10; ++shift) {
//float delta = log10((shift+1)*1.0)/(xmax_-xmin_);
float dy = h*base;
if(dy < 0 || dy > h)
continue;
nvgBeginPath(vg);
nvgMoveTo(vg, x, y+dy);
nvgLineTo(vg, x+w, y+dy);
nvgStrokeColor(vg, nvgRGBA(0x01, 0x47, 0x67,255));
if(xx == 0)
nvgStrokeColor(vg, nvgRGBA(0x00, 0xb3, 0xd5, 255));
nvgStroke(vg);
}
}
//------------------------------------------------------------------------------
void drawLogx(NVGcontext *vg, float xmin, float xmax, float x, float y, float w, float h)
{
float xmin_ = logf(xmin),
xmax_ = logf(xmax);
//1,2,3,4,5,6,7,8,9,10,20
for(int xx=xmin_; xx<=(int)xmax_; ++xx) {
float base = (xx-xmin_)/(xmax_-xmin_);
for(int shift=0; shift<10; ++shift) {
float delta = log10((shift+1)*1.0)/(xmax_-xmin_);
float dy = h*(base+delta);
if(dy < 0 || dy > h)
continue;
nvgBeginPath(vg);
nvgMoveTo(vg, x, y+dy);
nvgLineTo(vg, x+w, y+dy);
nvgStrokeColor(vg, nvgRGBA(0x01, 0x47, 0x67,255));
nvgStroke(vg);
}
}
}
//------------------------------------------------------------------------------
void drawLogy(NVGcontext *vg, float ymin, float ymax, float x, float y, float w, float h)
{
float ymin_ = logf(ymin),
ymax_ = logf(ymax);
for(int yy=ymin_; yy<=(int)ymax_; ++yy) {
float base = (yy-ymin_)/(ymax_-ymin_);
for(int shift=0; shift<10; ++shift) {
float delta = log10((shift+1)*1.0)/(ymax_-ymin_);
float dx = w*(base+delta);
if(dx < 0 || dx > w)
continue;
nvgBeginPath(vg);
nvgMoveTo(vg, x+dx, y);
nvgLineTo(vg, x+dx, y+h);
nvgStrokeColor(vg, nvgRGBA(0x01, 0x47, 0x67,255));
nvgStroke(vg);
}
}
}
//------------------------------------------------------------------------------
void drawLogLogGrid(NVGcontext *vg, float xmin, float xmax, float ymin, float ymax, float x, float y, float w, float h)
{
drawLogy(vg,xmin,xmax,x,y,w,h);
drawLogy(vg,ymin,ymax,x,y,w,h);
}
//------------------------------------------------------------------------------
void drawSemiLogy(NVGcontext *vg, float xmin, float xmax, float ymin, float ymax, float x, float y, float w, float h)
{
drawLogy(vg,ymin,ymax,x,y,w,h);
drawLinx(vg,xmin,xmax,x,y,w,h);
}
//------------------------------------------------------------------------------
void drawEqGrid(NVGcontext *vg, int x, int y, int w, int h)
{
//nvgBeginPath(vg);
//nvgRect(vg, x,y,w,h);
//nvgFillColor(vg, nvgRGBA(0x0d,0x0d,0x0d,255));
//nvgStrokeColor(vg, nvgRGBA(0x01, 0x47, 0x67,255));
//nvgFill(vg);
//nvgStroke(vg);
drawSemiLogy(vg, -10,10,2,5000,x,y,w,h);
}
//------------------------------------------------------------------------------
void drawEqLine(NVGcontext *vg, float *dat, int n, int x, int y, int w, int h)
{
//Draw UnderLine
nvgBeginPath(vg);
nvgMoveTo(vg, x,y+h);
for(int i=0; i<n; ++i) {
float dx = w*(i*1.0/(n-1));
nvgLineTo(vg, x+dx, y+h/2-h/2*dat[i]);
}
nvgLineTo(vg, x+w, y+h);
nvgClosePath(vg);
nvgFillColor(vg, nvgRGBA(0x11,0x45,0x75,150));
nvgFill(vg);
//Draw Actual Line
nvgBeginPath(vg);
nvgMoveTo(vg, x+w*dat[1], y+h-h*dat[0]);
for(int i=0; i<n; ++i) {
float dx = w*(i*1.0/(n-1));
nvgLineTo(vg, x+dx, y+h/2-h/2*dat[i]);
}
nvgStrokeWidth(vg, 2);
nvgStrokeColor(vg, nvgRGBA(0xfe, 0x84, 0x02, 150));
nvgStroke(vg);
nvgStrokeWidth(vg, 1);
}
//------------------------------------------------------------------------------
void drawHarmonicPlot(NVGcontext *vg, float *dat, int n, int x, int y, int w, int h)
{
nvgBeginPath(vg);
nvgRect(vg, x,y,w,h);
nvgFillColor(vg, nvgRGBA(0x0d,0x0d,0x0d,255));
nvgStrokeColor(vg, nvgRGBA(0x01, 0x47, 0x67,255));
nvgFill(vg);
nvgStroke(vg);
float width = w*0.8/n;
//Draw Actual Spikes
for(int i=0; i<n; ++i) {
float dx = w*(i*1.0/(n-1));
nvgBeginPath(vg);
nvgMoveTo(vg, x+dx, y+h);
nvgLineTo(vg, x+dx, y+(h-h*dat[i]));
nvgStrokeWidth(vg, width);
nvgStrokeColor(vg, nvgRGBA(0x11,0x45,0x75,255));
nvgStroke(vg);
}
nvgStrokeWidth(vg, 1);
}
//------------------------------------------------------------------------------
void drawVSlider(NVGcontext *vg, float val, int x, int y, int w, int h)
{
float pos[4] = {(float)x,(float)y,(float)w,(float)h};
boarder(0.1*w, pos);
float cy = y+h/2;
nvgBeginPath(vg);
nvgRect(vg, SPLAT(pos));
nvgFillColor(vg, nvgRGBA(0x0d,0x0d,0x0d,255));
nvgFill(vg);
//fill color
nvgBeginPath(vg);
nvgRect(vg, pos[0], pos[1]+pos[3] ,pos[2],-pos[3]*val);
nvgFillColor(vg, nvgRGBA(0x00, 0xcf, 0xf7, 255));
nvgFill(vg);
}
//------------------------------------------------------------------------------
void drawVAltSlider(NVGcontext *vg, float val, int x, int y, int w, int h)
{
float markerHeight = h*0.1;
//Draw main body
float pos[4] = {(float)x,(float)y,(float)w,(float)h};
boarder(0.1*w, pos);
//fill color
nvgBeginPath(vg);
nvgRect(vg, pos[0], pos[1] ,pos[2],pos[3]);
nvgFillColor(vg, nvgRGBA(0x11,0x45,0x75,255));
nvgFill(vg);
//Slider
const float virtualHeight = pos[3]-2*markerHeight;
const float cy = val*virtualHeight+pos[1];
nvgStrokeColor(vg, nvgRGBA(0x00, 0xcf, 0xf7, 255));
nvgBeginPath(vg);
nvgRect(vg, pos[0], cy-markerHeight*0.5, pos[2], markerHeight);
nvgStroke(vg);
}
//------------------------------------------------------------------------------
void drawHZSlider(NVGcontext *vg, float val, int x, int y, int w, int h)
{
nvgBeginPath(vg);
nvgRect(vg, x,y,w,h);
nvgFillColor(vg, nvgRGBA(0x0d,0x0d,0x0d,255));
nvgFill(vg);
float pos[4] = {(float)x,(float)y,(float)w,(float)h};
boarder(0.1*h, pos);
float cx = x+w/2;
//fill color
nvgBeginPath(vg);
nvgRect(vg, cx,pos[1],pos[2]*-val,pos[3]);
nvgFillColor(vg, nvgRGBA(0xb, 0x2b, 0x4d,255));
nvgFill(vg);
}
//------------------------------------------------------------------------------
void drawVZSlider(NVGcontext *vg, float val, int x, int y, int w, int h)
{
nvgBeginPath(vg);
nvgRect(vg, x,y,w,h);
nvgFillColor(vg, nvgRGBA(0x0d,0x0d,0x0d,255));
nvgFill(vg);
float pos[4] = {(float)x,(float)y,(float)w,(float)h};
boarder(0.1*w, pos);
float cy = y+h/2;
//fill color
nvgBeginPath(vg);
nvgRect(vg, pos[0], cy ,pos[2],-pos[3]*val);
nvgFillColor(vg, nvgRGBA(0x3a,0xc5,0xec,255));
nvgFill(vg);
}
//------------------------------------------------------------------------------
void drawOscArray(NVGcontext *vg, int x, int y, int w, int h)
{
for(int i=0; i<10; ++i)
{
//Draw BackGround
{
float pos[4] = {30.0f*i, 0.0f, 30.0f, 270.0f};
boarder(2, pos);
nvgBeginPath(vg);
nvgRect(vg, SPLAT(pos));
nvgFillColor(vg, nvgRGBA(0x6, 0x27, 0x37, 255));
nvgFill(vg);
}
{
float pos[4] = {30.0f*i, 0.0f, 30.0f, 150.0f};
boarder(4, pos);
drawVZSlider(vg, 0.3, SPLAT(pos));
}
{
float pos[4] = {30.0f*i, 200.0f, 30.0f, 90.0f};
boarder(4, pos);
drawVZSlider(vg, 0.3, SPLAT(pos));
}
}
}
//------------------------------------------------------------------------------
void drawLogPlot(NVGcontext *vg, float *X, int x, int y, int w, int h)
{
float dBmin = X[0];
float dBmax = X[1];
float fMin = X[2];
float fMax = X[3];
char dash[] = {5,5,0};
//Db grid is easy, it is just a linear spacing
for(int i=0; i<8; ++i) {
int level = y+h*i/8.0;
nvgBeginPath(vg);
//fl_line(x, level, x()+w(), level);
}
//The frequency grid is defined with points at
//10,11,12,...,18,19,20,30,40,50,60,70,80,90,100,200,400,...
//Thus we find each scale that we cover and draw the nine lines unique to
//that scale
const int min_base = log(fMin)/log(10);
const int max_base = log(fMax)/log(10);
const float b = log(fMin)/log(10);
const float a = log(fMax)/log(10)-b;
for(int i=min_base; i<=max_base; ++i) {
for(int j=1; j<10; ++j) {
const float freq = pow(10.0, i)*j;
const float xloc = (log(freq)/log(10)-b)/a;
if(xloc<1.0 && xloc > -0.001)
;//fl_line(xloc*w()+x(), y(), xloc*w()+x(), y()+h());
}
}
;//fl_end_line();
//Place the text labels
char label[1024];
for(int i=0; i<8; ++i) {
int level = y+h*i/8.0;
float value = (1-i/8.0)*(dBmax-dBmin) + dBmin;
sprintf(label, "%.2f dB", value);
;//fl_draw(label, x+w, level);
}
for(int i=min_base; i<=max_base; ++i) {
{
const float freq = pow(10.0, i)*1;
const float xloc = (log(freq)/log(10)-b)/a;
sprintf(label, "%0.f Hz", freq);
if(xloc<1.0)
;//fl_draw(label, xloc*w()+x()+10, y()+h());
}
}
}
//------------------------------------------------------------------------------
void drawPowLabel(NVGcontext *vg, int x, int y, int w, int h)
{
float cx = x+w/2.0;
float cy = y+h/2.0;
float center = -M_PI/2.0;
float sw = h/10.0;
nvgLineCap(vg, NVG_ROUND);
nvgStrokeWidth(vg, sw);
nvgBeginPath(vg);
nvgArc(vg, cx, cy, 0.3*h, center-0.4, center+0.4, 1);
nvgMoveTo(vg, cx, y+0.4*h);
nvgLineTo(vg, cx, y+0.1*h);
nvgStroke(vg);
}
//------------------------------------------------------------------------------
void drawPowerButton(NVGcontext *vg, int x, int y, int w, int h)
{
drawBox(vg, x, y, w, h);
nvgStrokeColor(vg, COLOR_POW);
drawPowLabel(vg, x, y, w, h);
}
//------------------------------------------------------------------------------
void nvgTextHere(NVGcontext *vg, const char *str, float x,
float y, float w, float h)
{
nvgFontSize(vg, h);
nvgFontFace(vg, "sans");
nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE);
float bounds[4];
nvgTextBounds(vg, x,y, str, NULL, bounds);
if((bounds[2]-bounds[0]) > w) //horizontally constrained case
nvgFontSize(vg, h*w*1.0/(bounds[2]-bounds[0]));
nvgText(vg, x+w/2,y+h*0.5f,str, NULL);
}
void drawPanicButton(NVGcontext *vg, int x, int y, int w, int h)
{
//orig - 32px wide vs 25px tall
drawBox(vg, x, y, w, h);
nvgBeginPath(vg);
nvgMoveTo(vg, x+w*0.5, y+h*0.47);
nvgLineTo(vg, x+w*0.7, y+h*0.47);
nvgLineTo(vg, x+w*0.5, y+h*0.17);
nvgLineTo(vg, x+w*0.3, y+h*0.47);
nvgClosePath(vg);
nvgFillColor(vg, nvgRGBA(0x00,0xcf,0xf7,255));
nvgFill(vg);
//nvgFillColor(vg, nvgRGBA(0x04, 0x37, 0x5e, 255));
nvgFillColor(vg, nvgRGBA(0x0c, 0x0c, 0x0c, 255));
nvgTextHere(vg, "!", x, y+0.25*h, w, 0.2*h);
nvgFillColor(vg, nvgRGBA(0x00,0xcf,0xf7,255));
nvgTextHere(vg, "PANIC", x+0.1*w, y+0.45*h, w*0.8, 0.5*h);
}
//------------------------------------------------------------------------------
void drawStopButton(NVGcontext *vg, int x, int y, int w, int h)
{
drawBox(vg, x, y, w, h);
float bb[4] = {(float)x, (float)y, (float)w, (float)h};
square(pad(0.5, bb));
nvgBeginPath(vg);
nvgRect(vg, SPLAT(bb));
nvgFillColor(vg, nvgRGBA(0x00,0xcf,0xf7,255));
nvgFill(vg);
//nvgStrokeColor(vg, nvgRGBA(0x00,0xcf,0xf7,255));
//drawPowLabel(vg, x, y, w, h);
}
//------------------------------------------------------------------------------
void drawPauseButton(NVGcontext *vg, int x, int y, int w, int h)
{
drawBox(vg, x, y, w, h);
float bb[4] = {(float)x, (float)y, (float)w, (float)h};
square(pad(0.5, bb));
nvgFillColor(vg, nvgRGBA(0x00,0xcf,0xf7,255));
nvgBeginPath(vg);
nvgRect(vg, bb[0], bb[1],bb[2]/4,bb[3]);
nvgFill(vg);
nvgBeginPath(vg);
nvgRect(vg, bb[0]+bb[2]/2,bb[1],bb[2]/4,bb[3]);
nvgFill(vg);
}
void drawRecButton(NVGcontext *vg, int x, int y, int w, int h)
{
drawBox(vg, x, y, w, h);
float bb[4] = {(float)x, (float)y, (float)w, (float)h};
square(pad(0.5, bb));
nvgFillColor(vg, nvgRGBA(0x00,0xcf,0xf7,255));
nvgBeginPath(vg);
nvgCircle(vg, bb[0]+bb[2]/2, bb[1]+bb[3]/2,bb[2]/2);
nvgFill(vg);
}
void drawKeyButton(NVGcontext *vg, int x, int y, int w, int h)
{
drawBox(vg, x, y, w, h);
float bb[4] = {(float)x, (float)y, (float)w, (float)h};
square(pad(0.5, bb));
//nvgFillColor(vg, nvgRGBA(0x00,0xcf,0xf7,255));
const int white_keys = 3;
const int black_pattern[] = {1,1,0};
//draw the white keys
for(int i=0; i<white_keys; ++i) {
float box[4] = {(float)bb[0]+i*bb[2]*1.0f/(white_keys-1),
(float)bb[1], bb[2]*1.0f/(white_keys), (float)bb[3]};
pad(0.9, box);
nvgBeginPath(vg);
nvgRect(vg, SPLAT(box));
nvgFillColor(vg, nvgRGBA(0xaa, 0xaa, 0xaa, 255));
nvgFill(vg);
}
//draw the black keys at the joints
for(int i=0; i<white_keys; ++i) {
if(!black_pattern[i])
continue;
float box[4] = {(float)bb[0]+(i+0.5f)*bb[2]*1.0f/(white_keys-1),
(float)bb[1], bb[2]*1.0f/(white_keys), (float)bb[3]*0.7f};
pad(0.9, box);
nvgBeginPath(vg);
nvgRect(vg, SPLAT(box));
nvgFillColor(vg, nvgRGBA(0x0C, 0x0C, 0x0C, 255));
nvgFill(vg);
}
}
//------------------------------------------------------------------------------
void drawToggleBox(NVGcontext *vg, const char *str, int x, int y, int w, int h)
{
nvgBeginPath(vg);
nvgRect(vg, x,y,w,h);
nvgFillColor(vg, nvgRGBA(0x00, 0xcf, 0xf7, 255));
nvgFill(vg);
float scale = 0.8;
nvgFontSize(vg, h*scale);
nvgFontFace(vg, "sans");
nvgFillColor(vg, nvgRGBA(0x0c, 0x0c, 0x0c, 255));
nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE);
float bounds[4];
nvgTextBounds(vg, x,y, str, NULL, bounds);
if((bounds[2]-bounds[0]) > w) //horizontally constrained case
nvgFontSize(vg, h*scale*w*1.0/(bounds[2]-bounds[0]));
nvgText(vg, x+w/2,y+h*0.5f,str, NULL);
}
//------------------------------------------------------------------------------
void drawModuleBox(NVGcontext *vg, const char *str, int x, int y, int w, int h)
{
float pos_[4] = {(float)x, (float)y, (float)w, (float)h};
nvgBeginPath(vg);
nvgRect(vg, x, y, w, h);
nvgFillColor(vg, nvgRGBA(0, 0, 0, 255));
nvgFill(vg);
{
////paint the top half
float pos[4] = {SPLAT(pos_)};
pos[3] *= 0.2;
nvgBeginPath(vg);
boarder(pos_[3]*0.01, pos);
nvgRect(vg, SPLAT(pos));
nvgFillColor(vg, nvgRGBA(0xa, 0x2e, 0x4c, 255));
nvgFill(vg);
float upperspace[4] = {pos[0]+pos[2]*2.0f/3.0f,
pos[1], pos[2]/3.0f, pos[3]};
//upper.draw(upperspace);
float pos2[4] = {SPLAT(pos)};
pos2[2] /= 3;
pad(0.9, pos2);
drawLeftLabel(vg, str, SPLAT(pos2));
}
{
//SMAP(pos_);
float innerspace[4] = {(float)x, y+h*0.2f, (float)w, h*0.8f};
boarder(h*0.01, innerspace);
//paint the inner panel
nvgBeginPath(vg);
nvgRect(vg, SPLAT(innerspace));
nvgFillColor(vg, nvgRGBA(0x6, 0x27, 0x37, 255));
nvgFill(vg);
//inner.draw(innerspace);
}
}
//------------------------------------------------------------------------------
void drawKeyboard(NVGcontext *vg, int x, int y, int w, int h)
{
const int white_keys = 8*7+2;
const int black_pattern[] = {1,0,1,1,0,1,1};
//draw the white keys 7 octaves + 2
for(int i=0; i<white_keys; ++i) {
float box[4] = {(float)x+i*w*1.0f/(white_keys-1),
(float)y, w*1.0f/(white_keys), (float)h};
pad(0.9, box);
nvgBeginPath(vg);
nvgRect(vg, SPLAT(box));
nvgFillColor(vg, nvgRGBA(0xaa, 0xaa, 0xaa, 255));
nvgFill(vg);
}
//draw the black keys at the joints
for(int i=0; i<white_keys; ++i) {
if(!black_pattern[i%7])
continue;
float box[4] = {(float)x+(i+0.5f)*w*1.0f/(white_keys-1),
(float)y, w*1.0f/(white_keys), (float)h*0.7f};
pad(0.9, box);
nvgBeginPath(vg);
nvgRect(vg, SPLAT(box));
nvgFillColor(vg, nvgRGBA(0x0C, 0x0C, 0x0C, 255));
nvgFill(vg);
}
}
int getKeyboardKey(int x, int y, int w, int h)
{
return -1;
}
//------------------------------------------------------------------------------
void renderDial(NVGcontext *vg, dial_t dial)
{
drawDial(vg, dial.x, dial.y,dial.w,dial.w);
drawDialValue(vg, dial.val, dial.x, dial.y, dial.w, dial.w);
drawLabel(vg, dial.label,dial.x, dial.y+dial.w, dial.w, dial.w/3);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//[0:x, 1:y, 2:w, 3:h]
float *pad(float scale, float *bb)
{
float cx = bb[0] + bb[2]/2.0;
float cy = bb[1] + bb[3]/2.0;
float w = bb[2]*scale;
float h = bb[3]*scale;
bb[0] = cx - w/2.0;
bb[1] = cy - h/2.0;
bb[2] = w;
bb[3] = h;
return bb;
}
float *boarder(float scale, float *bb)
{
bb[0] += scale;
bb[1] += scale;
bb[2] -= 2*scale;
bb[3] -= 2*scale;
return bb;
}
float *square(float *bb)
{
float cx = bb[0]+bb[2]/2;
float cy = bb[1]+bb[3]/2;
float d = (bb[2]<bb[3]?bb[2]:bb[3])/2;
bb[0] = cx-d;
bb[1] = cy-d;
bb[2] = 2*d;
bb[3] = 2*d;
return bb;
}