forked from msokalski/ascii-patrol
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.cpp
4816 lines (3998 loc) · 101 KB
/
menu.cpp
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
// extern "C" _declspec(dllimport) void __stdcall OutputDebugStringA(const char* s);
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <memory.h>
#include <string.h>
#include "game.h"
#include "spec.h"
#include "menu.h"
#include "conf.h"
#include "twister.h"
// remove!
void DBG(const char* str);
HISCORE hiscore =
{
0,0,0,"",""
};
bool hiscore_sync = false;
struct MENU_ASSET : ASSET
{
void Init(const ASSET* a)
{
mono = a->mono;
shade = a->shade;
color = a->color;
const char** anim = mono;
if (!anim || !anim[0])
{
w = 0;
h = 0;
frames = 0;
}
else
{
const char* brk = strchr(anim[0],'\n');
if (brk)
w = (int)(brk-anim[0]);
else
w = (int)strlen(anim[0]);
h=1;
brk = strchr(anim[0],'\n');
for (int i=0; brk; i++)
{
brk = strchr(brk+1,'\n');
h++;
}
frames=0;
for (int i=0; anim[i]; i++)
frames++;
}
}
MENU_ASSET(const ASSET* a)
{
Init(a);
l=r=t=b=0;
}
MENU_ASSET(const ASSET* a, int left, int right, int top, int bottom)
{
Init(a);
l=left;
r=right;
t=top;
b=bottom;
}
int w,h,frames;
int l,r,t,b;
};
static int menu_write(CON_OUTPUT* s, int dw, int dh, int sx, int sy, int sw, int sh)
{
if (sw<0)
sw=s->w;
if (sh<0)
sh=s->h;
if (sx<0)
{
sw+=sx;
sx=0;
}
if (sy<0)
{
sh+=sy;
sy=0;
}
if (sx+sw>s->w)
{
sw = s->w-sx;
}
if (sy+sh>s->h)
{
sh = s->h-sy;
}
vsync_wait();
return screen_write(s, dw,dh,sx,sy,sw,sh);
}
static void menu_print(CON_OUTPUT* s, int dx, int dy, const char* str, char color, int sw, const int* clip = 0)
{
int sx=0;
int sy=0;
int sh=1;
if (clip)
{
if (dx<clip[0])
{
sx+=clip[0]-dx;
sw-=clip[0]-dx;
dx=clip[0];
}
if (dy<clip[1])
{
sy+=clip[1]-dy;
sh-=clip[1]-dy;
dy=clip[1];
}
if (dx+sw>clip[0]+clip[2])
{
sw=clip[0]+clip[2]-dx;
}
if (dy+sh>clip[1]+clip[3])
{
sh=clip[1]+clip[3]-dy;
}
}
if (dx<0)
{
sx-=dx;
sw+=dx;
dx=0;
}
if (dy<0)
{
sy-=dy;
sh+=dy;
dy=0;
}
if (sx<0)
{
dx-=sx;
sw+=sx;
sx=0;
}
if (sy<0)
{
dy-=sy;
sh+=sy;
sy=0;
}
if (dx+sw>s->w)
{
sw = s->w - dx;
}
if (dy+sh>s->h)
{
sh = s->h - dy;
}
if (sw<=0 || sh<=0)
return;
memcpy( s->buf + (s->w+1)*dy + dx, str+sx, sw);
if (s->color)
memset( s->color + (s->w+1)*dy + dx, color, sw);
}
static void menu_fill(CON_OUTPUT* s, int dx, int dy, char glyph, char color, int sw, int sh, const int* clip = 0)
{
if (clip)
{
if (dx<clip[0])
{
sw-=clip[0]-dx;
dx=clip[0];
}
if (dy<clip[1])
{
sh-=clip[1]-dy;
dy=clip[1];
}
if (dx+sw>clip[0]+clip[2])
{
sw=clip[0]+clip[2]-dx;
}
if (dy+sh>clip[1]+clip[3])
{
sh=clip[1]+clip[3]-dy;
}
}
if (dx<0)
{
sw+=dx;
dx=0;
}
if (dy<0)
{
sh+=dy;
dy=0;
}
if (dx+sw>s->w)
{
sw = s->w - dx;
}
if (dy+sh>s->h)
{
sh = s->h - dy;
}
if (sw<=0 || sh<=0)
return;
for (int y=0; y<sh; y++)
memset( s->buf + (s->w+1)*(dy+y) + dx, glyph, sw);
if (s->color)
for (int y=0; y<sh; y++)
memset( s->color + (s->w+1)*(dy+y) + dx, color, sw);
}
static void menu_blit(CON_OUTPUT* s, int dx, int dy, const MENU_ASSET* a, int sx, int sy, int sw, int sh, int fr, const int* clip = 0)
{
if (!a->frames)
return;
fr %= a->frames;
const char* glyph = s->color ? a->shade[fr] : a->mono[fr];
const char* color = s->color ? a->color[fr] : 0;
if (clip)
{
if (dx<clip[0])
{
sx+=clip[0]-dx;
sw-=clip[0]-dx;
dx=clip[0];
}
if (dy<clip[1])
{
sy+=clip[1]-dy;
sh-=clip[1]-dy;
dy=clip[1];
}
if (dx+sw>clip[0]+clip[2])
{
sw=clip[0]+clip[2]-dx;
}
if (dy+sh>clip[1]+clip[3])
{
sh=clip[1]+clip[3]-dy;
}
}
if (dx<0)
{
sx-=dx;
sw+=dx;
dx=0;
}
if (dy<0)
{
sy-=dy;
sh+=dy;
dy=0;
}
if (sx<0)
{
dx-=sx;
sw+=sx;
sx=0;
}
if (sy<0)
{
dy-=sy;
sh+=sy;
sy=0;
}
if (dx+sw>s->w)
{
sw = s->w - dx;
}
if (dy+sh>s->h)
{
sh = s->h - dy;
}
if (sx+sw>a->w)
{
sw = a->w-sx;
}
if (sy+sh>a->h)
{
sh = a->h-sy;
}
if (sw<=0 || sh<=0)
return;
for (int y=0; y<sh; y++)
memcpy( s->buf + (s->w+1)*(dy+y) + dx, glyph + (a->w+1)*(sy+y) + sx, sw);
if (color)
for (int y=0; y<sh; y++)
memcpy( s->color + (s->w+1)*(dy+y) + dx, color + (a->w+1)*(sy+y) + sx, sw);
}
static void menu_stretch(CON_OUTPUT* s, int dx, int dy, int dw, int dh, const MENU_ASSET* a, int fr, const int* clip = 0)
{
int l = dx + a->l;
int r = dx + dw - a->r;
int t = dy + a->t;
int b = dy + dh - a->b;
if (l>r)
{
int avr = (l+r+1)/2;
l = avr-dx;
r = dx+dw-avr;
}
else
{
l=a->l;
r=a->r;
}
if (t>b)
{
int avr = (t+b+1)/2;
t = avr-dy;
b = dy+dh-avr;
}
else
{
t=a->t;
b=a->b;
}
// corners
menu_blit(s, dx,dy, a, 0,0, l,t, fr, clip);
menu_blit(s, dx+dw-r,dy, a, a->w-r,0, r,t, fr, clip);
menu_blit(s, dx,dy+dh-b, a, 0,a->h-b, l,b, fr, clip);
menu_blit(s, dx+dw-r,dy+dh-b, a, a->w-r,a->h-b, r,b, fr, clip);
// v-edges
for (int y = t; y<dh-b; y++)
{
menu_blit(s, dx,dy+y, a, 0,t, l,1, fr, clip);
menu_blit(s, dx+dw-r,dy+y, a, a->w-r,t, r,1, fr, clip);
}
// h-edges
for (int x = l; x<dw-r; x++)
{
menu_blit(s, dx+x,dy, a, l,0, 1,t, fr, clip);
menu_blit(s, dx+x,dy+dh-b, a, r,a->h-b, 1,b, fr, clip);
}
// interior
char glyph = s->color ? a->shade[fr][ (a->w+1)*t+l ] : a->mono[fr][ (a->w+1)*t+l ];
char color = a->color ? a->color[fr][ (a->w+1)*t+l ] : 0;
menu_fill(s,dx+l,dy+t,glyph,color,dw-l-r,dh-t-b, clip);
}
static MENU_ASSET window(&menu_wnd,5,5,2,3);
static MENU_ASSET module(&menu_mod,1,1,4,1);
static unsigned char cl_menu_a[3];
static unsigned char cl_menu_b[3];
static unsigned char cl_menu_c[3];
struct MODULE
{
int x,y; // current rounded
float fx,fy; // current floating
int dx,dy; // destination (by update layout)
int w,h;
int col;
bool dbl; // 2 cols module
int state; // 0 inactive, 1 hover, 2 focus
const char* title;
int (*proc)(MODULE* m, int msg, void* p1, void* p2);
MODULE* left;
MODULE* right;
MODULE* upper;
MODULE* lower;
// only if dbl is set!
MODULE* upper2;
MODULE* lower2;
};
struct WINDOW
{
unsigned long time;
int scroll;
int smooth;
float fsmooth;
int height;
int modules;
MODULE* module;
MODULE* focus;
int state; // 0: hovering , 1: focused
int focus_col;
int center_x;
int columns;
const int* layout;
int layout_w;
int layout_h;
const int* layout_2;
const int* layout_3;
const int* layout_4;
bool prompt_active;
};
static WINDOW menu_window;
static MENU_ASSET backdrop(&menu_bkg);
static struct
{
int org_scroll; // must be >=0, otherwise it is inactive
int org_x;
int org_y;
int cur_x;
int cur_y;
int id;
bool dirty; // scroll (don't click on touch end)
bool redirect;
} touch_scroll = {-1,0,0,0,0,-1,false,false};
static void UpdateLayout(CON_OUTPUT* s, bool force=false)
{
WINDOW* mw = &menu_window;
if (s->w==mw->layout_w && s->h==mw->layout_h && !force)
return;
// calc columns
int cw = s->w - window.l - window.r - 3;
int mod_width = 31;
int mod_space = 2;
int mod_left_mrg = 1;
int mod_right_mrg = 1;
// left , mod_left_mrg , (mods-1) x (mod,space) , mod, mod_right_mrg , scroll | right
int mod_cols = (cw + mod_space - mod_left_mrg - mod_right_mrg) / (mod_width + mod_space);
if (mw->modules < mod_cols)
{
int cols=0;
for (int i=0; i<mw->modules; i++)
{
if (mw->module[i].dbl)
cols+=2;
else
cols++;
}
mod_cols = MIN(mod_cols, cols);
}
// calc height (currently we don't reorder modules)
int height[4]={0,0,0,0}; // total heights of each module column
MODULE* bottom[2][4]={{0,0,0,0},{0,0,0,0}}; // last module added to given column
const int* layout=0;
switch (mod_cols)
{
case 2: layout = mw->layout_2; break;
case 3: if (mw->layout_3) layout = mw->layout_3; else { mod_cols=2; layout = mw->layout_2; } break;
case 4: if (mw->layout_4) layout = mw->layout_4; else if (mw->layout_3) { mod_cols=3; layout = mw->layout_3; } else { mod_cols=2; layout = mw->layout_2; } break;
}
int center_x = window.l + mod_left_mrg + (cw - ((mod_left_mrg + mod_right_mrg + mod_cols * mod_width + (mod_cols-1) * mod_space)|1) +1 ) / 2;
if (mw->center_x<0)
mw->center_x = center_x;
mw->columns = mod_cols;
mw->layout = layout;
if (!mw->focus)
{
mw->focus = mw->module + layout[0];
mw->focus->state = 1;
mw->state = 0; // hover over first layout item
}
int col=0;
int row=0;
for (int j=0; j<mw->modules; j++)
{
int i = layout[j];
mw->module[i].col = col;
mw->module[i].dx = center_x + col * (mod_width + mod_space);
mw->module[i].left = 0;
mw->module[i].right = 0;
mw->module[i].lower = 0;
mw->module[i].lower2 = 0;
mw->module[i].upper = 0;
mw->module[i].upper2 = 0;
if (mw->module+i == mw->focus)
mw->focus_col = col;
if (mw->module[i].dbl)
{
assert(col<mod_cols-1);
mw->module[i].w = mod_width * 2 + mod_space;
mw->module[i].dy = MAX(height[col],height[col+1]);
height[col] = mw->module[i].dy + mw->module[i].h +1; // extra spacing
height[col+1] = mw->module[i].dy + mw->module[i].h +1;
mw->module[i].upper = bottom[0][col];
mw->module[i].upper2 = bottom[0][col+1];
if (row)
{
if (bottom[0][col]==bottom[0][col+1])
{
// |*-*|
// |*-*|
bottom[0][col]->lower = mw->module+i;
bottom[0][col+1]->lower2 = mw->module+i;
}
else
if (col>0 && col<mod_cols-2 &&
bottom[0][col-1]==bottom[0][col] &&
bottom[0][col+1]==bottom[0][col+2])
{
// |*-*|*-*|
// |*-*|
bottom[0][col]->lower2 = mw->module+i;
bottom[0][col+1]->lower = mw->module+i;
}
else
if (col>0 &&
bottom[0][col-1]==bottom[0][col])
{
// |*-*|*|
// |*-*|
bottom[0][col]->lower2 = mw->module+i;
bottom[0][col+1]->lower = mw->module+i;
}
else
if (col<mod_cols-2 &&
bottom[0][col+1]==bottom[0][col+2])
{
// |*|*-*|
// |*-*|
bottom[0][col]->lower = mw->module+i;
bottom[0][col+1]->lower = mw->module+i;
}
else
{
// |*|*|
// |*-*|
bottom[0][col]->lower = mw->module+i;
bottom[0][col+1]->lower = mw->module+i;
}
}
bottom[1][col] = mw->module+i;
bottom[1][col+1] = mw->module+i;
col+=2;
if (col==mod_cols)
{
col=0;
row++;
bottom[0][0] = bottom[1][0];
bottom[0][1] = bottom[1][1];
bottom[0][2] = bottom[1][2];
bottom[0][3] = bottom[1][3];
}
}
else
{
mw->module[i].w = mod_width;
mw->module[i].dy = height[col];
height[col] = mw->module[i].dy + mw->module[i].h +1; // extra spacing
mw->module[i].upper = bottom[0][col];
if (row)
{
if (col>0 &&
bottom[0][col-1]==bottom[0][col])
{
// |*-*|
// |*|
bottom[0][col]->lower2 = mw->module+i;
}
else
if (col<mod_cols-1 &&
bottom[0][col]==bottom[0][col+1])
{
// |*-*|
// |*|
bottom[0][col]->lower = mw->module+i;
}
else
{
// |*|
// |*|
bottom[0][col]->lower = mw->module+i;
}
}
bottom[1][col] = mw->module+i;
col++;
if (col==mod_cols)
{
col=0;
row++;
bottom[0][0] = bottom[1][0];
bottom[0][1] = bottom[1][1];
bottom[0][2] = bottom[1][2];
bottom[0][3] = bottom[1][3];
}
}
}
int max_height = 0;
for (int i=0; i<mod_cols; i++)
if (max_height<height[i])
max_height=height[i];
mw->height = max_height -1 -1; // -1 as underscores on top of layout don't count! and another -1 for extra space removal
int center_y = ( s->h-window.t-window.b-1 - max_height +1 )/2;
if (center_y<0)
center_y=window.t;
else
center_y+=window.t;
// change it to ensure focus/hover visibility
int client_h = s->h - window.t - window.b;
if (mw->scroll>mw->height-client_h+1)
mw->scroll=mw->height-client_h+1;
if (mw->scroll<0)
mw->scroll=0;
for (int i=0; i<mw->modules; i++)
{
mw->module[i].dy += center_y;
if (mw->module[i].y<0)
{
mw->module[i].y = mw->module[i].dy;
mw->module[i].fx = (float)mw->module[i].dy;
}
if (mw->module[i].x<0)
{
mw->module[i].x = mw->module[i].dx;
mw->module[i].fx = (float)mw->module[i].dx;
}
else
{
/*
mw->module[i].x += center_x - mw->center_x;
mw->module[i].fx += (float)(center_x - mw->center_x);
*/
}
}
mw->center_x = center_x;
// determine cols and rows
// assign x,y
// stretch to cutify layout if possible
mw->layout_w = s->w;
mw->layout_h = s->h;
mw->smooth = mw->scroll;
// build horizontal graph for hovering
for (int j=0; j<mw->modules; j++)
{
// calc center
int left = -1;
int right = -1;
int left_err = 0;
int right_err = 0;
int yj = mw->module[j].dy + mw->module[j].h/2;
for (int i=0; i<mw->modules; i++)
{
if (mw->module[j].col == mw->module[i].col)
continue;
if (!mw->module[i].dbl && mw->module[i].col == mw->module[j].col-1 ||
mw->module[i].dbl && mw->module[i].col == mw->module[j].col-2)
{
// j->left = i
int err = ABS(mw->module[i].dy + mw->module[i].h/2 - yj);
if (left<0 || err<left_err)
{
left = i;
left_err = err;
}
}
else
if (!mw->module[j].dbl && mw->module[i].col == mw->module[j].col+1 ||
mw->module[j].dbl && mw->module[i].col == mw->module[j].col+2)
{
// j->right = i
int err = ABS(mw->module[i].dy + mw->module[i].h/2 - yj);
if (right<0 || err<right_err)
{
right = i;
right_err = err;
}
}
}
if (left>=0)
mw->module[j].left = mw->module + left;
if (right>=0)
mw->module[j].right = mw->module + right;
}
// smooth scroll to hovered mod
if (mw->focus->dy - window.t - mw->scroll < 0)
mw->scroll = mw->focus->dy - window.t;
if (mw->focus->dy+mw->focus->h - window.t - mw->scroll > client_h)
mw->scroll = mw->focus->dy+mw->focus->h - window.t - client_h;
}
enum MODULE_MSG
{
MM_INIT, // return height if ok
MM_LOAD, // overwrite menu data with conf
MM_INPUT, // p1 contains single CON_INPUT
MM_PAINT, // p1 contains CON_OUTPUT, p2 contains clip rect to apply, use menu_window.scroll
MM_FOCUS,
// p1 is flag indicating if focus is being gained or lost,
// if focus is being lost, p2 MUST be filled with Y coordinate of focused element in the module
// if focus is being gained p2 contains Y coordinate of previously focused element in module the focus is comming from
};
#define LABEL_CL(m,h,f) ((m)->state==2) ? ((h)&&!(f) ? cl_menu_c[(m)->state] : cl_menu_b[(m)->state] ) : cl_menu_a[(m)->state];
#define VALUE_CL(m,h,f) ((m)->state==2) ? ((h)&&(f) ? cl_menu_c[(m)->state] : cl_menu_b[(m)->state] ) : cl_menu_b[(m)->state];
void PaintScroll(CON_OUTPUT* s, int x, int dy, int h, int pos, int size, int state, const int* clip);
int ProfileProc(MODULE* m, int msg, void* p1, void* p2);
int CampaignProc(MODULE* m, int msg, void* p1, void* p2);
int PromptProc(int msg, void* p1, void* p2)
{
static MENU_ASSET prompt(&keyb);
enum FuncKey
{
EXIT = 1,
BKSPC,
TAB,
CAPSLK,
ENTER,
L_SHIFT,
R_SHIFT,
L_CTRL,
L_WIN,
L_ALT,
R_ALT,
R_WIN,
APP,
R_CTRL
};
struct Key
{
int ch; // if smaller than 0x20 it is some FuncKey
int shift_ch;
bool caps; // if false don't xor shift with capslk
int x,y,w,h;
};
const static Key keymap[] =
{
{ L_SHIFT,L_SHIFT, false, 2,17, 11,3 }, // [0] - so no lookup needed
{ R_SHIFT,R_SHIFT, false, 64,17, 11,3 }, // [1] - so no lookup needed
{ EXIT,EXIT, false, 72,1, 3,3 },
{ BKSPC,BKSPC, false, 67,5, 8,3 },
// { TAB,TAB, false, 2,9, 7,3 },
{ CAPSLK,CAPSLK, false, 2,13, 9,3 },
{ ENTER,ENTER, false, 67,13, 8,3 },
// { L_CTRL,L_CTRL, false, 2,21, 7,3 },
// { L_WIN,L_WIN, false, 10,21, 5,3 },
// { L_ALT,L_ALT, false, 16,21, 5,3 },
// { R_ALT,R_ALT, false, 50,21, 5,3 },
// { R_WIN,R_WIN, false, 56,21, 5,3 },
// { APP,APP, false, 62,21, 5,3 },
// { R_CTRL,R_CTRL, false, 68,21, 7,3 },
{ '`','~', false, 2,5, 4,3 },
{ '1','!', false, 7,5, 4,3 },
{ '2','@', false, 12,5, 4,3 },
{ '3','#', false, 17,5, 4,3 },
{ '4','$', false, 22,5, 4,3 },
{ '5','%', false, 27,5, 4,3 },
{ '6','^', false, 32,5, 4,3 },
{ '7','&', false, 37,5, 4,3 },
{ '8','*', false, 42,5, 4,3 },
{ '9','(', false, 47,5, 4,3 },
{ '0',')', false, 52,5, 4,3 },
{ '-','_', false, 57,5, 4,3 },
{ '=','+', false, 62,5, 4,3 },
{ 'q','Q', true, 10,9, 4,3 },
{ 'w','W', true, 15,9, 4,3 },
{ 'e','E', true, 20,9, 4,3 },
{ 'r','R', true, 25,9, 4,3 },
{ 't','T', true, 30,9, 4,3 },
{ 'y','Y', true, 35,9, 4,3 },
{ 'u','U', true, 40,9, 4,3 },
{ 'i','I', true, 45,9, 4,3 },
{ 'o','O', true, 50,9, 4,3 },
{ 'p','P', true, 55,9, 4,3 },
{ '[','{', false, 60,9, 4,3 },
{ ']','}', false, 65,9, 4,3 },
{ '\\','|',false, 70,9, 5,3 },
{ 'a','A', true, 12,13, 4,3 },
{ 's','S', true, 17,13, 4,3 },
{ 'd','D', true, 22,13, 4,3 },
{ 'f','F', true, 27,13, 4,3 },
{ 'g','G', true, 32,13, 4,3 },
{ 'h','H', true, 37,13, 4,3 },
{ 'j','J', true, 42,13, 4,3 },
{ 'k','K', true, 47,13, 4,3 },
{ 'l','L', true, 52,13, 4,3 },
{ ';',':', false, 57,13, 4,3 },
{ '\'','\"', false, 62,13, 4,3 },
{ 'z','Z', true, 14,17, 4,3 },
{ 'x','X', true, 19,17, 4,3 },
{ 'c','C', true, 24,17, 4,3 },
{ 'v','V', true, 29,17, 4,3 },
{ 'b','B', true, 34,17, 4,3 },
{ 'n','N', true, 39,17, 4,3 },
{ 'm','M', true, 44,17, 4,3 },
{ ',','<', false, 49,17, 4,3 },
{ '.','>', false, 54,17, 4,3 },
{ '/','?', false, 59,17, 4,3 },
{ ' ',' ', false, 22,21, 27,3 },
{ 0,0, false, 0,0, 0,0 }
};
struct PromptData
{
int sx, sy;
int len;
char str[256];
int capslk_key;
int left_shift;
int right_shift;
int last_key_idx;
unsigned long last_key_blink;
// track touches
// ...
};
static PromptData data =
{
0,0,
0,"",
-1,
false,false,
-1,0
};
switch (msg)
{
case MM_LOAD:
{
break;
}
case MM_INIT:
{
break;
}
case MM_FOCUS:
{
int f = *(int*)p1;
const char* str = (const char*)p1;
data.len = strlen(str);
strcpy(data.str,str);
data.sx = 0;
data.sy = -prompt.h; // outa screen
data.capslk_key = -1;
data.left_shift = -1;
data.right_shift = -1;
data.last_key_idx = -1;
data.last_key_blink = 0;
break;
}
case MM_PAINT:
{
CON_OUTPUT* s = (CON_OUTPUT*)p1;
int* clip = (int*)p2;
data.sx = (s->w - prompt.w) / 2;
data.sy = s->h - prompt.h;
menu_blit(s, data.sx, data.sy, &prompt, 0,0, prompt.w, prompt.h, 0, 0);
if (data.capslk_key >=0)
{
int key = data.capslk_key;
menu_blit(s, data.sx + keymap[key].x-1, data.sy + keymap[key].y-1, &prompt,
keymap[key].x-1, keymap[key].y-1, keymap[key].w+2, keymap[key].h+1, 1, 0);
}
if (data.left_shift >=0)
{
int key = 0;
menu_blit(s, data.sx + keymap[key].x-1, data.sy + keymap[key].y-1, &prompt,
keymap[key].x-1, keymap[key].y-1, keymap[key].w+2, keymap[key].h+1, 1, 0);
}
if (data.right_shift >=0)
{
int key = 1;
menu_blit(s, data.sx + keymap[key].x-1, data.sy + keymap[key].y-1, &prompt,
keymap[key].x-1, keymap[key].y-1, keymap[key].w+2, keymap[key].h+1, 1, 0);
}