-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathdialogs.cpp
2091 lines (1824 loc) · 62.1 KB
/
dialogs.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
// Hyperbolic Rogue -- dialogs
// Copyright (C) 2011-2018 Zeno Rogue, see 'hyper.cpp' for details
/** \file dialogs.cpp
* \brief Implementation of various generic dialogs and elements of dialog windows
*/
#include "hyper.h"
namespace hr {
EX const char* COLORBAR = "###";
EX namespace dialog {
#if HDR
#define IFM(x) (mousing?"":x)
static constexpr int DONT_SHOW = 16;
enum tDialogItem {diTitle, diItem, diBreak, diHelp, diInfo, diIntSlider, diSlider, diBigItem, diKeyboard, diCustom, diColorItem, diListStart, diListEnd, diMatrixItem};
struct item {
tDialogItem type;
string body;
string value;
key_type key;
color_t color, colorv, colork, colors, colorc;
int scale;
double param;
int p1, p2, p3;
int position;
void *ptr;
reaction_t customfun;
item(tDialogItem t = diBreak);
};
struct scaler {
ld (*direct) (ld);
ld (*inverse) (ld);
bool positive;
};
static inline ld identity_f(ld x) { return x; }
const static scaler identity = {identity_f, identity_f, false};
const static scaler logarithmic = {log, exp, true};
const static scaler asinhic = {asinh, sinh, false};
const static scaler asinhic100 = {[] (ld x) { return asinh(x*100); }, [] (ld x) { return sinh(x)/100; }, false};
/** extendable dialog */
struct extdialog : funbase {
string title, help;
int dialogflags;
reaction_t reaction;
reaction_t reaction_final;
reaction_t extra_options;
virtual void draw() = 0;
void operator() () { draw(); }
virtual ~extdialog() {};
extdialog();
/** Pop screen, then call the final reaction. A bit more complex because it eeds to backup reaction_final due to popScreen */
void popfinal() { auto rf = std::move(reaction_final); popScreen(); if(rf) rf(); }
};
/** number dialog */
struct number_dialog : extdialog {
ld *editwhat;
string s;
ld vmin, vmax, step, dft;
scaler sc;
int *intval; ld intbuf;
bool animatable;
bool *boolval;
void draw() override;
void apply_edit();
void apply_slider();
string disp(ld x);
void reset_str() { s = disp(*editwhat); }
};
/** bool dialog */
struct bool_dialog : extdialog {
bool *editwhat, dft;
reaction_t switcher;
void draw() override;
};
#endif
EX number_dialog& get_ne() {
auto ptr = dynamic_cast<number_dialog*> (screens.back().target_base());
if(!ptr) throw hr_exception("get_ne() called without number dialog");
return *ptr;
}
EX extdialog& get_di() {
auto ptr = dynamic_cast<extdialog*> (screens.back().target_base());
if(!ptr) throw hr_exception("get_di() called without extdialog");
return *ptr;
}
EX void scaleLog() { get_ne().sc = logarithmic; }
EX void scaleSinh() { get_ne().sc = asinhic; }
EX void scaleSinh100() { get_ne().sc = asinhic100; }
EX color_t dialogcolor = 0xC0C0C0;
EX color_t dialogcolor_clicked = 0xFF8000;
EX color_t dialogcolor_selected = 0xFFD500;
EX color_t dialogcolor_key = 0x808080;
EX color_t dialogcolor_value = 0x80A040;
EX color_t dialogcolor_off = 0x40FF40;
EX color_t dialogcolor_on = 0xC04040;
EX color_t dialogcolor_big = 0xC06000;
/** pick the correct dialogcolor, based on whether mouse is over */
EX color_t dialogcolor_over(bool b) {
if(!b) return dialogcolor;
if(actonrelease) return dialogcolor_clicked;
return dialogcolor_selected;
}
EX void addBack() {
addItem(XLAT("go back"),
(cmode & sm::NUMBER) ? SDLK_RETURN :
ISWEB ? SDLK_BACKSPACE :
SDLK_ESCAPE);
}
EX void addHelp() {
addItem(XLAT("help"), SDLK_F1);
}
EX namespace zoom {
int zoomf = 1, shiftx, shifty;
bool zoomoff = false;
void nozoom() {
zoomf = 1; shiftx = 0; shifty = 0; zoomoff = false;
}
void initzoom() {
zoomf = 3;
shiftx = -2*mousex;
if(mousex < vid.xres / 6) shiftx = 0;
if(mousex > vid.xres * 5 / 6) shiftx = -2 * vid.xres;
shifty = -2*mousey;
if(mousey < vid.yres / 6) shifty = 0;
if(mousey > vid.yres * 5 / 6) shifty = -2 * vid.yres;
}
void stopzoom() { zoomoff = true; }
EX bool displayfr(int x, int y, int b, int size, const string &s, color_t color, int align) {
return hr::displayfr(x * zoomf + shiftx, y * zoomf + shifty, b, size * zoomf, s, color, align);
}
EX bool displayfr_highlight(int x, int y, int b, int size, const string &s, color_t color, int align, int hicolor IS(0xFFFF00)) {
bool clicked = hr::displayfr(x * zoomf + shiftx, y * zoomf + shifty, b, size * zoomf, s, color, align);
if(clicked) hr::displayfr(x * zoomf + shiftx, y * zoomf + shifty, b, size * zoomf, s, hicolor, align);
return clicked;
}
EX }
#if CAP_MENUSCALING && CAP_SDL
EX void handleZooming(SDL_Event &ev) {
using namespace zoom;
if(zoomoff || !(cmode & sm::ZOOMABLE)) {
nozoom(); return;
}
if(ev.type == SDL_MOUSEBUTTONDOWN) initzoom();
if(ev.type == SDL_MOUSEBUTTONUP && zoomf > 1) stopzoom();
}
#endif
#if !(CAP_MENUSCALING && CAP_SDL)
EX void handleZooming(SDL_Event &ev) {}
#endif
EX vector<item> items;
EX item& lastItem() { return items[items.size() - 1]; }
EX item& titleItem() { return items[0]; }
EX map<key_type, reaction_t> key_actions;
EX void add_key_action(key_type key, const reaction_t& action) {
key_actions[key] = action;
}
EX void add_key_action_adjust(key_type& key, const reaction_t& action) {
while(key_actions.count(key)) key++;
add_key_action(key, action);
}
EX void extend() {
items.back().key = items[isize(items)-2].key;
}
EX void add_action(const reaction_t& action) {
add_key_action_adjust(lastItem().key, action);
}
EX void add_action_push(const reaction_t& action) { add_action([action] { pushScreen(action); }); }
EX void add_action_push_clear(const reaction_t& action) { add_action([action] { clearMessages(); pushScreen(action); }); }
EX void handler(int sym, int uni) {
if(cmode & sm::PANNING) handlePanning(sym, uni);
dialog::handleNavigation(sym, uni);
if(doexiton(sym, uni)) popScreen();
}
EX int list_size_min, list_size_max, list_fake_key;
EX const int first_list_fake_key = 10000;
EX void init() {
list_size_min = list_size_max = 0;
list_fake_key = first_list_fake_key;
items.clear();
key_actions.clear();
keyhandler = dialog::handler;
}
EX string keyname(key_type k) {
if(k == 0) return "";
if(k == SDLK_ESCAPE) return "Esc";
if(k == SDLK_F1) return "F1";
if(k == SDLK_F2) return "F2";
if(k == SDLK_F3) return "F3";
if(k == SDLK_F4) return "F4";
if(k == SDLK_F5) return "F5";
if(k == SDLK_F6) return "F6";
if(k == SDLK_F7) return "F7";
if(k == SDLK_F8) return "F8";
if(k == SDLK_F9) return "F9";
if(k == SDLK_F10) return "F10";
if(k >= 10000 && k < 10500) return "";
if(k == SDLK_HOME) return "Home";
if(k == SDLK_BACKSPACE) return "Backspace";
if(k == SDLK_RETURN) return "Enter";
if(k == 32) return "space";
if(k >= 1 && k <= 26) { string s = "Ctrl+"; s += (k+64); return s; }
if(k < 128) { string s; s += k; return s; }
if(k == 508) return "Alt+8";
return "?";
}
item::item(tDialogItem t) {
type = t;
color = dialogcolor;
colorc = dialogcolor_clicked;
colors = dialogcolor_selected;
colork = dialogcolor_key;
colorv = dialogcolor_value;
scale = 100;
}
EX void addSlider(double d1, double d2, double d3, key_type key) {
item it(diSlider);
it.key = key;
it.param = (d2-d1) / (d3-d1);
items.push_back(it);
}
EX void addIntSlider(int d1, int d2, int d3, key_type key) {
item it(diIntSlider);
it.key = key;
it.p1 = (d2-d1);
it.p2 = (d3-d1);
items.push_back(it);
}
EX void addSelItem(string body, string value, key_type key) {
item it(diItem);
it.body = body;
it.value = value;
it.key = key;
if(value == ONOFF(true)) it.colorv = dialogcolor_off;
if(value == ONOFF(false)) it.colorv = dialogcolor_on;
items.push_back(it);
}
EX void addBoolItem(string body, bool value, key_type key) {
addSelItem(body, ONOFF(value), key);
}
EX int displaycolor(color_t col) {
int c = col >> 8;
if(!c) return 0x181818;
return c;
}
EX void addKeyboardItem(string keys) {
item it(diKeyboard);
it.body = keys;
it.scale = 150;
items.push_back(it);
}
EX void addCustom(int size, reaction_t custom) {
item it(diCustom);
it.scale = size;
it.customfun = custom;
items.push_back(it);
}
EX void addColorItem(string body, int value, key_type key) {
addSelItem(body, COLORBAR, key);
auto& it = items.back();
it.type = diColorItem;
it.colorv = displaycolor(value);
it.param = value & 0xFF;
}
ld as_degrees(transmatrix T) {
hyperpoint h = T * point31(1, 0, 0);
ld alpha = atan2(-h[1], h[0]);
if(alpha == 0) alpha = 0;
return alpha / degree;
}
EX void addMatrixItem(string body, transmatrix& value, key_type key, int dim IS(GDIM)) {
addSelItem(body, COLORBAR, key);
auto& it = items.back();
it.type = diMatrixItem;
it.ptr = &value;
it.value = "";
if(dim == 2) it.value = fts(as_degrees(value)) + "°";
if(dim == 3) {
for(int k=0; k<3; k++) {
if(value[k][k] != 1) continue;
int i=(k+1)%3;
int j=(i+1)%3;
if(i > j) swap(i, j);
hyperpoint h = Hypc; h[i] = 1;
h = value * h;
ld alpha = atan2(-h[j], h[i]);
if(alpha == 0) alpha = 0;
it.value = fts(alpha / degree) + "° ";
it.value += ('X' + i);
it.value += ('X' + j);
}
if(eqmatrix(value, Id)) it.value = "Id";
}
it.p1 = dim;
}
EX void addHelp(string body) {
item it(diHelp);
it.body = body;
if(isize(body) >= 500) it.scale = 70;
items.push_back(it);
}
EX void addInfo(string body, color_t color IS(dialogcolor)) {
item it(diInfo);
it.body = body;
it.color = color;
items.push_back(it);
}
EX void addItem(string body, key_type key) {
item it(diItem);
it.body = body;
it.key = key;
items.push_back(it);
}
EX void addBigItem(string body, key_type key) {
item it(diBigItem);
it.body = body;
it.key = key;
it.color = dialogcolor_big;
it.scale = 150;
items.push_back(it);
}
EX int addBreak(int val) {
item it(diBreak);
it.scale = val;
items.push_back(it);
return items.size()-1;
}
EX void start_list(int size_min, int size_max, int key_start IS(0)) {
item it(diListStart);
it.key = key_start;
it.scale = 0;
it.param = size_min;
list_size_min = size_min;
list_size_max = size_max;
items.push_back(it);
}
EX void end_list() {
item it(diListEnd);
it.scale = 0;
items.push_back(it);
}
EX void addTitle(string body, color_t color, int scale) {
item it(diTitle);
it.body = body;
it.color = color;
it.scale = scale;
items.push_back(it);
}
EX void init(string title, color_t color IS(0xE8E8E8), int scale IS(150), int brk IS(60)) {
init();
addTitle(title, color, scale);
addBreak(brk);
}
EX int dcenter, dwidth;
EX int displayLong(string str, int siz, int y, bool measure) {
int last = 0;
int lastspace = 0;
int xs, xo;
if(current_display->sidescreen)
xs = dwidth - vid.fsize*2, xo = vid.yres + vid.fsize;
else
xs = vid.xres * 618/1000, xo = vid.xres * 186/1000;
int last_i = 0;
for(int i=0; i<=isize(str); i++) {
int ls = 0;
int prev = last;
if(str[i] == ' ') lastspace = i;
unsigned char ch = str[i];
if(ch >= 128 && ch < 192) continue;
if(i < isize(str)) {
char *ch = &str[i];
if(*ch == ')') continue;
if(starts_with(ch, ")")) continue;
}
if(i > 0) {
char *ch = &str[i - utfsize_before(str,i)];
if(*ch == '(') continue;
if(starts_with(ch, "(")) continue;
}
if(textwidth(siz, str.substr(last, i-last)) > xs) {
if(lastspace == last) ls = last_i, last = last_i;
else ls = lastspace, last = ls+1;
}
if(str[i] == 10 || i == isize(str)) ls = i, last = i+1;
if(ls) {
if(!measure) displayfr(xo, y, 2, siz, str.substr(prev, ls-prev), dialogcolor, 0);
if(ls == prev) y += siz/2;
else y += siz;
lastspace = last;
}
last_i = i;
}
y += siz/2;
return y;
}
EX int tothei, dialogwidth, dfsize, dfspace, odfspace, leftwidth, rightwidth, innerwidth, itemx, keyx, valuex, top, list_starts_at, list_ends_at, list_full_size, list_actual_size, list_skip, fwidth;
EX string highlight_text;
EX int highlight_key;
EX bool is_highlight(item& I) { return I.body == highlight_text && among(highlight_key, I.key, PSEUDOKEY_SELECT); }
EX void set_highlight(item& I) { highlight_text = I.body; highlight_key = I.key; }
EX void find_highlight(const string& s) {
println(hlog, "highlight_text set to ", s);
highlight_text = s; highlight_key = PSEUDOKEY_SELECT;
}
EX void measure() {
tothei = 0;
dialogwidth = 0;
innerwidth = 0;
int N = items.size();
list_starts_at = list_ends_at = list_actual_size = 0;
bool autoval = cmode & sm::AUTO_VALUES;
rightwidth = 0;
if(!autoval) rightwidth = textwidth(dfsize, "MMMMMMMM") + dfsize/2;
if(cmode & sm::DIALOG_WIDE)
innerwidth = textwidth(dfsize, "MMMMM") * 7;
for(int i=0; i<N; i++) {
if(items[i].type == diListStart)
list_starts_at = tothei;
else if(items[i].type == diListEnd) {
list_full_size = tothei - list_starts_at;
list_actual_size = min(odfspace * list_size_max / 100, max(odfspace * list_size_min / 100, list_full_size));
if(list_full_size < list_actual_size) list_full_size = list_actual_size;
tothei = list_ends_at = list_starts_at + list_actual_size;
}
else if(items[i].type == diHelp)
tothei += displayLong(items[i].body, dfsize * items[i].scale / 100, 0, true);
else {
tothei += dfspace * items[i].scale / 100;
if(among(items[i].type, diItem, diColorItem))
innerwidth = max(innerwidth, textwidth(dfsize * items[i].scale / 100, items[i].body));
if(among(items[i].type, diItem))
rightwidth = max(rightwidth, textwidth(dfsize * items[i].scale / 100, items[i].value) + dfsize);
if(items[i].type == diTitle || items[i].type == diInfo || items[i].type == diBigItem)
dialogwidth = max(dialogwidth, textwidth(dfsize * items[i].scale / 100, items[i].body) * 10/9);
}
}
leftwidth = ISMOBILE ? 0 : textwidth(dfsize, "MMMMM") + dfsize/2;
fwidth = innerwidth + leftwidth + rightwidth;
if(list_actual_size) fwidth += dfsize;
dialogwidth = max(dialogwidth, fwidth);
itemx = dcenter - fwidth / 2 + leftwidth;
keyx = dcenter - fwidth / 2 + leftwidth - dfsize/2;
valuex = dcenter - fwidth / 2 + leftwidth + innerwidth + dfsize/2;
}
EX purehookset hooks_display_dialog;
EX vector<int> key_queue;
EX void queue_key(int key) { key_queue.push_back(key); }
EX int uishape() {
int a = S7;
if(a < 3) a = 3;
if(a > 36) a = 36;
return a;
}
EX void draw_list_slider(int x, int yt) {
int a = uishape();
flat_model_enabler fme;
initquickqueue();
ld pix = 1 / (2 * cgi.hcrossf / cgi.crossf);
shiftmatrix V = shiftless(atscreenpos(0, 0, pix));
color_t col = 0xFFFFFFFF;
ld siz = dfsize / 2;
ld si = siz / 2;
int yb = yt + list_actual_size;
curvepoint(hyperpoint(x-si, yt, 1, 1));
for(int i=0; i<=a/2; i++)
curvepoint(hyperpoint(x - si * cos(i*TAU/a), yb + si * sin(i*TAU/a), 1, 1));
for(int i=(a+1)/2; i<=a; i++)
curvepoint(hyperpoint(x - si * cos(i*TAU/a), yt + si * sin(i*TAU/a), 1, 1));
queuecurve(V, col, 0x80, PPR::LINE);
int yt1 = yt + (list_actual_size * list_skip) / list_full_size;
int yb1 = yt + (list_actual_size * (list_skip + list_actual_size)) / list_full_size;
curvepoint(hyperpoint(x-siz, yt1, 1, 1));
for(int i=0; i<=a/2; i++)
curvepoint(hyperpoint(x - siz * cos(i*TAU/a), yb1 + siz * sin(i*TAU/a), 1, 1));
for(int i=(a+1)/2; i<=a; i++)
curvepoint(hyperpoint(x - siz * cos(i*TAU/a), yt1 + siz * sin(i*TAU/a), 1, 1));
queuecurve(V, col, 0x80, PPR::LINE);
quickqueue();
}
EX void draw_slider(int sl, int sr, int y, item& I) {
int sw = sr-sl;
int mid = y;
if(!wmascii) {
int a =uishape();
flat_model_enabler fme;
initquickqueue();
ld pix = 1 / (2 * cgi.hcrossf / cgi.crossf);
shiftmatrix V = shiftless(atscreenpos(0, 0, pix));
color_t col = addalpha(I.color);
ld siz = dfsize * I.scale / 150;
ld si = siz / 2;
if(I.type == diIntSlider && I.p2 < sw/4) {
for(int a=0; a<=I.p2; a++) {
ld x = sl + sw * a * 1. / I.p2;
curvepoint(hyperpoint(x, y-si, 1, 1));
curvepoint(hyperpoint(x, y+si, 1, 1));
queuecurve(V, col, 0, PPR::LINE);
}
}
curvepoint(hyperpoint(sl, y-si, 1, 1));
for(int i=0; i<=a/2; i++)
curvepoint(hyperpoint(sr + si * sin(i*TAU/a), y - si * cos(i*TAU/a), 1, 1));
for(int i=(a+1)/2; i<=a; i++)
curvepoint(hyperpoint(sl + si * sin(i*TAU/a), y - si * cos(i*TAU/a), 1, 1));
queuecurve(V, col, 0x80, PPR::LINE);
quickqueue();
ld x = sl + sw * (I.type == diIntSlider ? I.p1 * 1. / I.p2 : I.param);
if(x < sl-si) {
curvepoint(hyperpoint(sl-si, y, 1, 1));
curvepoint(hyperpoint(x, y, 1, 1));
queuecurve(V, col, 0x80, PPR::LINE);
quickqueue();
}
if(x > sr+si) {
curvepoint(hyperpoint(sr+si, y, 1, 1));
curvepoint(hyperpoint(x, y, 1, 1));
queuecurve(V, col, 0x80, PPR::LINE);
quickqueue();
}
for(int i=0; i<=a; i++) curvepoint(hyperpoint(x + siz * sin(i*TAU/a), y - siz * cos(i*TAU/a), 1, 1));
queuecurve(V, col, col, PPR::LINE);
quickqueue();
}
else if(I.type == diSlider) {
displayfr(sl, mid, 2, dfsize * I.scale/100, "(", I.color, 16);
displayfr(sl + double(sw * I.param), mid, 2, dfsize * I.scale/100, "#", I.color, 8);
displayfr(sr, mid, 2, dfsize * I.scale/100, ")", I.color, 0);
}
else {
displayfr(sl, mid, 2, dfsize * I.scale/100, "{", I.color, 16);
if(I.p2 < sw / 4) for(int a=0; a<=I.p2; a++) if(a != I.p1)
displayfr(sl + double(sw * a / I.p2), mid, 2, dfsize * I.scale/100, a == I.p1 ? "#" : ".", I.color, 8);
displayfr(sl + double(sw * I.p1 / I.p2), mid, 2, dfsize * I.scale/100, "#", I.color, 8);
displayfr(sr, mid, 2, dfsize * I.scale/100, "}", I.color, 0);
}
}
EX void visualize_matrix(const trans23& T, ld x, ld y, ld r, int dim, ld tsize) {
vector<hyperpoint> pts;
for(int a=0; a<dim; a++) {
hyperpoint h = C0; h[a] = r;
pts.push_back(T.get() * h);
}
flat_model_enabler fme;
initquickqueue();
ld pix = 1 / (2 * cgi.hcrossf / cgi.crossf);
shiftmatrix V = shiftless(atscreenpos(x, y, pix));
for(int i=0; i<=360; i++)
curvepoint(hyperpoint(r * sin(i*degree), r*cos(i*degree), 1, 1));
queuecurve(V, 0xFFFFFFFF, 0x202020FF, PPR::LINE);
color_t cols[3] = {0xFF8080FF, 0x80FF80FF, 0x8080FFFF};
for(int a=0; a<dim; a++) {
auto pt = pts[a]; pt[2] = 1; pt[3] = 1;
curvepoint(hyperpoint(0,0,1,1));
curvepoint(pt);
// queueline(V * hyperpoint(0,0,1,1), V * pt, cols[a], 0);
queuecurve(V, cols[a], 0, PPR::LINE);
}
if(dim == 3) for(int a=0; a<dim; a++) {
auto pt = pts[a]; ld val = -pt[2] * tsize / r / 5;
curvepoint(hyperpoint(pt[0], pt[1]+val, 1, 1));
curvepoint(hyperpoint(pt[0]-val, pt[1]-val*sqrt(3)/2, 1, 1));
curvepoint(hyperpoint(pt[0]+val, pt[1]-val*sqrt(3)/2, 1, 1));
curvepoint(hyperpoint(pt[0], pt[1]+val, 1, 1));
queuecurve(V, cols[a], cols[a] & 0xFFFFFF80, PPR::LINE);
}
quickqueue();
}
EX void draw_side_shade() {
int steps = menu_darkening - darken;
color_t col = (backcolor << 8) | (255 - (255 >> steps));
if(svg::in || !(auraNOGL || vid.usingGL)) {
flat_model_enabler fme;
initquickqueue();
ld pix = 1 / (2 * cgi.hcrossf / cgi.crossf);
curvepoint(hyperpoint(vid.xres-dwidth, -10, 1, 1));
curvepoint(hyperpoint(vid.xres + 10, -10, 1, 1));
curvepoint(hyperpoint(vid.xres + 10, vid.yres + 10, 1, 1));
curvepoint(hyperpoint(vid.xres-dwidth, vid.yres + 10, 1, 1));
curvepoint(hyperpoint(vid.xres-dwidth, -10, 1, 1));
shiftmatrix V = shiftless(atscreenpos(0, 0, pix));
queuecurve(V, 0, col, PPR::LINE);
quickqueue();
}
#if CAP_GL
else {
auto full = part(col, 0);
static vector<glhr::colored_vertex> auravertices;
auravertices.clear();
ld width = vid.xres / 100;
for(int i=4; i<steps && i < 8; i++) width /= sqrt(2);
for(int x=0; x<16; x++) {
for(int c=0; c<6; c++) {
int bx = (c == 1 || c == 3 || c == 5) ? x+1 : x;
int by = (c == 2 || c == 4 || c == 5) ? vid.yres : 0;
int cx = bx == 0 ? 0 : bx == 16 ?vid.xres :
vid.xres - dwidth + width * tan((bx-8)/8. * 90._deg);
part(col, 0) = lerp(0, full, bx / 16.);
auravertices.emplace_back(hyperpoint(cx - current_display->xcenter, by - current_display->ycenter, 0, 1), col);
}
}
glflush();
current_display->next_shader_flags = GF_VARCOLOR;
dynamicval<eModel> m(pmodel, mdPixel);
current_display->set_all(0, 0);
glhr::id_modelview();
glhr::prepare(auravertices);
glhr::set_depthtest(false);
glDrawArrays(GL_TRIANGLES, 0, isize(auravertices));
}
#endif
}
EX void display() {
callhooks(hooks_display_dialog);
if(just_refreshing) return;
int N = items.size();
dfsize = vid.fsize;
#if ISMOBILE || ISPANDORA
dfsize *= 3;
#endif
dfspace = dfsize * 5/4;
odfspace = dfspace;
dcenter = vid.xres/2;
dwidth = vid.xres;
if(current_display->sidescreen) {
dwidth = vid.xres - vid.yres;
dcenter = vid.xres - dwidth / 2;
}
else if(cmode & sm::DIALOG_OFFMAP) {
dwidth = vid.xres / 3;
dcenter = vid.xres * 5 / 6;
}
measure();
while(tothei > vid.yres - 5 * vid.fsize) {
int adfsize = int(dfsize * sqrt((vid.yres - 5. * vid.fsize) / tothei));
if(adfsize < dfsize-1) dfsize = adfsize + 1;
else dfsize--;
odfspace = dfspace = dfsize * 5/4;
measure();
}
while(dialogwidth > dwidth) {
int adfsize = int(dfsize * sqrt(vid.xres * 1. / dialogwidth));
if(adfsize < dfsize-1) dfsize = adfsize + 1;
else dfsize--;
// usually we want to keep dfspace, but with NARROW_LINES, just odfspace
if(cmode & sm::NARROW_LINES)
dfspace = (dfsize + 3) * 5 / 4;
measure();
}
tothei = (vid.yres - tothei) / 2;
int list_left = list_actual_size;
int list_next_key;
if(!list_actual_size) {
if(list_skip) println(hlog, "list_skip reset");
list_skip = 0;
}
if(current_display->sidescreen && darken < menu_darkening) draw_side_shade();
bool inlist = false;
int need_to_skip = 0;
int list_more_skip = list_skip;
for(int i=0; i<N; i++) {
item& I = items[i];
if(I.type == diHelp) {
tothei = displayLong(items[i].body, dfsize * items[i].scale / 100, tothei, false);
continue;
}
int size = dfspace * I.scale / 100;
dynamicval<int> dkb(I.key);
bool to_highlight = is_highlight(I);
if(I.type == diListStart) {
list_left = list_actual_size;
inlist = true;
list_next_key = I.key;
list_starts_at = tothei;
continue;
}
if(I.type == diListEnd) {
tothei += list_left;
inlist = false;
list_ends_at = tothei;
draw_list_slider(dcenter + fwidth / 2 - dfsize/2, list_starts_at);
if(mousex >= dcenter + fwidth /2 - dfsize && mousey >= list_starts_at && mousey < list_ends_at)
getcstat = PSEUDOKEY_LIST_SLIDER;
if(list_left > 0) {
list_skip -= list_left;
list_skip -= list_more_skip;
if(list_skip < 0) list_skip = 0;
}
continue;
}
if(inlist && list_more_skip > 0) {
if(to_highlight) {
list_skip -= list_more_skip;
list_more_skip = 0;
}
else {
list_more_skip -= size;
if(list_more_skip < 0) { tothei -= list_more_skip; list_left += list_more_skip; list_more_skip = 0; }
continue;
}
}
if(inlist) {
if(list_left < size) {
tothei += list_left; size -= list_left; need_to_skip += size; list_left = 0;
if(to_highlight) list_skip += need_to_skip;
continue;
}
else list_left -= size;
if(list_next_key) { if(key_actions.count(I.key)) key_actions[list_next_key] = key_actions[I.key]; I.key = list_next_key++; }
}
top = tothei;
tothei += size;
int mid = (top + tothei) / 2;
I.position = mid;
if(I.type == diTitle || I.type == diInfo) {
bool xthis = (mousey >= top && mousey < tothei && I.key);
if(cmode & sm::DIALOG_STRICT_X)
xthis = xthis && (mousex >= dcenter - dialogwidth/2 && mousex <= dcenter + dialogwidth/2);
displayfr(dcenter, mid, 2, dfsize * I.scale/100, I.body, I.color, 8);
if(xthis) getcstat = I.key;
}
else if(among(I.type, diItem, diBigItem, diColorItem, diMatrixItem)) {
bool xthis = (mousey >= top && mousey < tothei);
if(cmode & sm::DIALOG_STRICT_X)
xthis = xthis && (mousex >= dcenter - dialogwidth/2 && mousex <= dcenter + dialogwidth/2);
#if ISMOBILE
if(xthis && mousepressed)
I.color = I.colorc;
#else
if(xthis && mousemoved) {
set_highlight(I);
highlight_key = dkb.backup;
mousemoved = false;
to_highlight = true;
}
if(to_highlight) {
I.color = (xthis&&mousepressed&&actonrelease) ? I.colorc : I.colors;
}
#endif
if(I.type == diBigItem) {
displayfr(dcenter, mid, 2, dfsize * I.scale/100, I.body, I.color, 8);
}
else {
if(!mousing)
displayfr(keyx, mid, 2, dfsize * I.scale/100, keyname(I.key), I.colork, 16);
displayfr(itemx, mid, 2, dfsize * I.scale/100, I.body, I.color, 0);
if(I.type == diColorItem && !wmascii) {
int a = uishape();
flat_model_enabler fme;
initquickqueue();
ld pix = 1 / (2 * cgi.hcrossf / cgi.crossf);
color_t col = addalpha(I.color);
ld sizf = dfsize * I.scale / 150;
ld siz = sizf * sqrt(0.15+0.85*I.param/255.);
for(int i=0; i<=a; i++) curvepoint(hyperpoint(siz * sin(i*TAU/a), -siz * cos(i*TAU/a), 1, 1));
shiftmatrix V = shiftless(atscreenpos(valuex + sizf, mid, pix));
queuecurve(V, col, (I.colorv << 8) | 0xFF, PPR::LINE);
quickqueue();
}
else {
int siz = dfsize * I.scale/100;
while(siz > 6 && textwidth(siz, I.value) + (I.type == diMatrixItem ? siz*3/2 : 0) >= vid.xres - valuex) siz--;
displayfr(valuex + (I.type == diMatrixItem ? siz*3/2 : 0), mid, 2, siz, I.value, I.colorv, 0);
if(I.type == diMatrixItem) visualize_matrix(*((transmatrix*)I.ptr), valuex + siz/2, mid, siz/2, I.p1, vid.fsize);
}
}
if(xthis) getcstat = I.key;
}
else if(among(I.type, diSlider, diIntSlider)) {
bool xthis = (mousey >= top && mousey < tothei);
int sl, sr;
if(current_display->sidescreen)
sl = vid.yres + vid.fsize*2, sr = vid.xres - vid.fsize*2;
else
sl = vid.xres/4, sr = vid.xres*3/4;
draw_slider(sl, sr, mid, I);
if(xthis) getcstat = I.key, inslider = true, slider_x = mousex;
}
else if(I.type == diCustom) {
I.customfun();
}
else if(I.type == diKeyboard) {
int len = 0;
for(char c: I.body)
if(c == ' ' || c == '\t') len += 3;
else len++;
int sl, sr;
if(current_display->sidescreen)
sl = vid.yres + vid.fsize*2, sr = vid.xres - vid.fsize*2;
else
sl = vid.xres/4, sr = vid.xres*3/4;
int pos = 0;
for(char c: I.body) {
string s = "";
s += c;
int nlen = 1;
if(c == ' ') s = "SPACE", nlen = 3;
if(c == '\b') s = "⌫", nlen = 1;
if(c == '\r' || c == '\n') s = "⏎", nlen = 1;
if(c == 1) s = "←", nlen = 1;
if(c == 2) s = "→", nlen = 1;
if(c == 3) s = "π";
if(c == '\t') s = "CLEAR", nlen = 3;
int left = sl + (sr-sl) * pos / len;
pos += nlen;
int right = sl + (sr-sl) * pos / len;
bool in = (mousex >= left && mousex <= right && mousey >= top && mousey < tothei);
int xpos = (left + right) / 2;
if(in) {
if(c == 1) getcstat = SDLK_LEFT;
else if(c == 2) getcstat = SDLK_RIGHT;
else getcstat = c;
}
displayfr(xpos, mid, 2, dfsize * I.scale/100, s, dialogcolor_over(in), 8);
}
}
}
}
bool isitem(item& it) {
return among(it.type, diItem, diBigItem, diColorItem, diMatrixItem);
}
EX void handle_actions(int &sym, int &uni) {
if(key_actions.count(uni)) {
key_actions[uni]();
sym = uni = 0;
return;
}
if(key_actions.count(sym)) {
key_actions[sym]();
sym = uni = 0;
return;
}
}
EX void handleNavigation(int &sym, int &uni) {
if(sym == PSEUDOKEY_LIST_SLIDER) invslider = true;
if(invslider) {
uni = sym = 0;
int max = list_full_size - list_actual_size;
list_skip = (max * (mousey - list_starts_at)) / list_actual_size;
if(list_skip < 0) list_skip = 0;
if(list_skip > max) list_skip = max;
highlight_text = "//missing";
return;
}
if(uni == '\n' || uni == '\r' || DIRECTIONKEY == SDLK_KP5) {
for(int i=0; i<isize(items); i++)
if(isitem(items[i]))
if(is_highlight(items[i])) {
uni = sym = items[i].key;
handle_actions(sym, uni);
return;
}
}
if(sym == PSEUDOKEY_WHEELUP && list_actual_size) {
sym = 0;
list_skip -= 30;
highlight_text = "//missing";
}
if(sym == PSEUDOKEY_WHEELDOWN && list_actual_size) {
sym = 0;
list_skip += 30;
highlight_text = "//missing";
}
if(DKEY == SDLK_PAGEDOWN) {
uni = sym = 0;
for(int i=0; i<isize(items); i++)
if(isitem(items[i])) {
set_highlight(items[i]);
}
}
if(DKEY == SDLK_PAGEUP) {
uni = sym = 0;
for(int i=0; i<isize(items); i++)
if(isitem(items[i])) {
set_highlight(items[i]);