forked from vpinball/vpinball
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LiveUI.cpp
3980 lines (3742 loc) · 197 KB
/
LiveUI.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
#include "stdafx.h"
#include "LiveUI.h"
#include "renderer/Shader.h"
#include "renderer/Anaglyph.h"
#include "core/TableDB.h"
#include "fonts/DroidSans.h"
#include "fonts/DroidSansBold.h"
#include "fonts/IconsForkAwesome.h"
#include "fonts/ForkAwesome.h"
#include "wintimer.h"
#include "imgui/imgui.h"
#include "imgui/imgui_internal.h" // Needed for FindRenderedTextEnd in HelpSplash (should be adapted when this function will refactored in ImGui)
#ifdef ENABLE_SDL
#include "imgui/imgui_impl_opengl3.h"
#else
#include "imgui/imgui_impl_dx9.h"
#include <shellapi.h>
#endif
#include "imgui/imgui_impl_win32.h"
#include "imgui/implot/implot.h"
#include "imgui/imgui_stdlib.h"
#include "imgui/ImGuizmo.h"
#include "imgui_markdown/imgui_markdown.h"
#if __cplusplus >= 202002L && !defined(__clang__)
#define stable_sort std::ranges::stable_sort
#define sort std::ranges::sort
#else
#define stable_sort std::stable_sort
#define sort std::sort
#endif
#include "BAM/BAMView.h"
// Titles (used as Ids) of modal dialogs
#define ID_MODAL_SPLASH "In Game UI"
#define ID_VIDEO_SETTINGS "Video Options"
#define ID_AUDIO_SETTINGS "Audio Options"
#define ID_RENDERER_INSPECTION "Renderer Inspection"
#define ID_BAM_SETTINGS "Headtracking Settings"
#define ID_ANAGLYPH_CALIBRATION "Anaglyph Calibration"
#define PROP_WIDTH (125.f * m_dpi)
#define PROP_TIMER(is_live, startup_obj, live_obj) \
if (ImGui::CollapsingHeader("Timer", ImGuiTreeNodeFlags_DefaultOpen) && BEGIN_PROP_TABLE) \
{ \
PropCheckbox("Enabled", startup_obj, is_live, startup_obj ? &(startup_obj->m_d.m_tdr.m_TimerEnabled) : nullptr, live_obj ? &(live_obj->m_d.m_tdr.m_TimerEnabled) : nullptr); \
PropInt("Interval (ms)", startup_obj, is_live, startup_obj ? &(startup_obj->m_d.m_tdr.m_TimerInterval) : nullptr, live_obj ? &(live_obj->m_d.m_tdr.m_TimerInterval) : nullptr); \
ImGui::EndTable(); \
}
#define BEGIN_PROP_TABLE ImGui::BeginTable("props", 2, ImGuiTableFlags_Borders)
#define PROP_TABLE_SETUP \
if (ImGui::TableGetRowIndex() == -1) \
{ \
ImGui::TableSetupColumn("Property", ImGuiTableColumnFlags_WidthStretch); \
ImGui::TableSetupColumn("Sync", ImGuiTableColumnFlags_WidthFixed); \
}
#define ICON_SAVE ICON_FK_FLOPPY_O
// utility structure for realtime plot //!! cleanup
class ScrollingData
{
private:
int MaxSize;
public:
int Offset;
ImVector<ImVec2> Data;
ScrollingData()
{
MaxSize = 500;
Offset = 0;
Data.reserve(MaxSize);
}
void AddPoint(const float x, const float y)
{
if (Data.size() < MaxSize)
Data.push_back(ImVec2(x, y));
else
{
Data[Offset] = ImVec2(x, y);
Offset++;
if (Offset == MaxSize)
Offset = 0;
}
}
void Erase()
{
if (!Data.empty())
{
Data.shrink(0);
Offset = 0;
}
}
ImVec2 GetLast()
{
if (Data.empty())
return ImVec2{ 0.f, 0.f };
else if (Data.size() < MaxSize || Offset == 0)
return Data.back();
else
return Data[Offset - 1];
}
};
// utility structure for realtime plot
/*class RollingData {
float Span;
ImVector<ImVec2> Data;
RollingData() {
Span = 10.0f;
Data.reserve(500);
}
void AddPoint(const float x, const float y) {
const float xmod = fmodf(x, Span);
if (!Data.empty() && xmod < Data.back().x)
Data.shrink(0);
Data.push_back(ImVec2(xmod, y));
}
};*/
// Maps directinput keycode used by VPX to ImGui keycode enum
// FIXME This is not ok and will fail for all non QWERTY keyboards, since VPX (DirectInput Keyboard) is keyboard layout neutral while ImGui is layout aware
// For the time being, this is used to translate global shortcuts for:
// - Debugger (default is D which should be ok on all keyboards),
// - FPS display (default is F11 which should be ok)
// - Exit (default is Escape which should be ok)
static constexpr ImGuiKey dikToImGuiKeys[] = {
ImGuiKey_None,
ImGuiKey_Escape, //DIK_ESCAPE 0x01
ImGuiKey_1, //DIK_1 0x02
ImGuiKey_2, //DIK_2 0x03
ImGuiKey_3, //DIK_3 0x04
ImGuiKey_4, //DIK_4 0x05
ImGuiKey_5, //DIK_5 0x06
ImGuiKey_6, //DIK_6 0x07
ImGuiKey_7, //DIK_7 0x08
ImGuiKey_8, //DIK_8 0x09
ImGuiKey_9, //DIK_9 0x0A
ImGuiKey_0, //DIK_0 0x0B
ImGuiKey_Minus, //DIK_MINUS 0x0C /* - on main keyboard */
ImGuiKey_Equal, //DIK_EQUALS 0x0D
ImGuiKey_Backspace, //DIK_BACK 0x0E /* backspace */
ImGuiKey_Tab, //DIK_TAB 0x0F
ImGuiKey_Q, //DIK_Q 0x10
ImGuiKey_W, //DIK_W 0x11
ImGuiKey_E, //DIK_E 0x12
ImGuiKey_R, //DIK_R 0x13
ImGuiKey_T, //DIK_T 0x14
ImGuiKey_Y, //DIK_Y 0x15
ImGuiKey_U, //DIK_U 0x16
ImGuiKey_I, //DIK_I 0x17
ImGuiKey_O, //DIK_O 0x18
ImGuiKey_P, //DIK_P 0x19
ImGuiKey_LeftBracket, //DIK_LBRACKET 0x1A
ImGuiKey_RightBracket, //DIK_RBRACKET 0x1B
ImGuiKey_Enter, //DIK_RETURN 0x1C /* Enter on main keyboard */
ImGuiKey_LeftCtrl, //DIK_LCONTROL 0x1D
ImGuiKey_A, //DIK_A 0x1E
ImGuiKey_S, //DIK_S 0x1F
ImGuiKey_D, //DIK_D 0x20
ImGuiKey_F, //DIK_F 0x21
ImGuiKey_G, //DIK_G 0x22
ImGuiKey_H, //DIK_H 0x23
ImGuiKey_J, //DIK_J 0x24
ImGuiKey_K, //DIK_K 0x25
ImGuiKey_L, //DIK_L 0x26
ImGuiKey_Semicolon, //DIK_SEMICOLON 0x27
ImGuiKey_Apostrophe,//DIK_APOSTROPHE 0x28
ImGuiKey_GraveAccent, //DIK_GRAVE 0x29 /* accent grave */
ImGuiKey_LeftShift, //DIK_LSHIFT 0x2A
ImGuiKey_Backslash, //DIK_BACKSLASH 0x2B
ImGuiKey_Z, //DIK_Z 0x2C
ImGuiKey_X, //DIK_X 0x2D
ImGuiKey_C, //DIK_C 0x2E
ImGuiKey_V, //DIK_V 0x2F
ImGuiKey_B, //DIK_B 0x30
ImGuiKey_N, //DIK_N 0x31
ImGuiKey_M, //DIK_M 0x32
ImGuiKey_Comma, //DIK_COMMA 0x33
ImGuiKey_Period, //DIK_PERIOD 0x34 /* . on main keyboard */
ImGuiKey_Slash, //DIK_SLASH 0x35 /* / on main keyboard */
ImGuiKey_RightShift,//DIK_RSHIFT 0x36
ImGuiKey_KeypadMultiply, //DIK_MULTIPLY 0x37 /* * on numeric keypad */
ImGuiKey_Menu, //DIK_LMENU 0x38 /* left Alt */
ImGuiKey_Space, //DIK_SPACE 0x39
ImGuiKey_CapsLock, //DIK_CAPITAL 0x3A
ImGuiKey_F1, //DIK_F1 0x3B
ImGuiKey_F2, //DIK_F2 0x3C
ImGuiKey_F3, //DIK_F3 0x3D
ImGuiKey_F4, //DIK_F4 0x3E
ImGuiKey_F5, //DIK_F5 0x3F
ImGuiKey_F6, //DIK_F6 0x40
ImGuiKey_F7, //DIK_F7 0x41
ImGuiKey_F8, //DIK_F8 0x42
ImGuiKey_F9, //DIK_F9 0x43
ImGuiKey_F10, //DIK_F10 0x44
ImGuiKey_NumLock, //DIK_NUMLOCK 0x45
ImGuiKey_ScrollLock,//DIK_SCROLL 0x46 /* Scroll Lock */
ImGuiKey_Keypad7, //DIK_NUMPAD7 0x47
ImGuiKey_Keypad8, //DIK_NUMPAD8 0x48
ImGuiKey_Keypad9, //DIK_NUMPAD9 0x49
ImGuiKey_KeypadSubtract, //DIK_SUBTRACT 0x4A /* - on numeric keypad */
ImGuiKey_Keypad4, //DIK_NUMPAD4 0x4B
ImGuiKey_Keypad5, //DIK_NUMPAD5 0x4C
ImGuiKey_Keypad6, //DIK_NUMPAD6 0x4D
ImGuiKey_KeypadAdd, //DIK_ADD 0x4E /* + on numeric keypad */
ImGuiKey_Keypad1, //DIK_NUMPAD1 0x4F
ImGuiKey_Keypad2, //DIK_NUMPAD2 0x50
ImGuiKey_Keypad3, //DIK_NUMPAD3 0x51
ImGuiKey_Keypad0, //DIK_NUMPAD0 0x52
ImGuiKey_KeypadDecimal, //DIK_DECIMAL 0x53 /* . on numeric keypad */
ImGuiKey_None, //0x54
ImGuiKey_None, //0x55
ImGuiKey_None, //DIK_OEM_102 0x56 /* < > | on UK/Germany keyboards */
ImGuiKey_F11, //DIK_F11 0x57
ImGuiKey_F12, //DIK_F12 0x58
ImGuiKey_None, //0x59
ImGuiKey_None, //0x5A
ImGuiKey_None, //0x5B
ImGuiKey_None, //0x5C
ImGuiKey_None, //0x5D
ImGuiKey_None, //0x5E
ImGuiKey_None, //0x5F
ImGuiKey_None, //0x60
ImGuiKey_None, //0x61
ImGuiKey_None, //0x62
ImGuiKey_None, //0x63
ImGuiKey_None, //DIK_F13 0x64 /* (NEC PC98) */
ImGuiKey_None, //DIK_F14 0x65 /* (NEC PC98) */
ImGuiKey_None, //DIK_F15 0x66 /* (NEC PC98) */
ImGuiKey_None, //0x67
ImGuiKey_None, //0x68
ImGuiKey_None, //0x69
ImGuiKey_None, //0x6A
ImGuiKey_None, //0x6B
ImGuiKey_None, //0x6C
ImGuiKey_None, //0x6D
ImGuiKey_None, //0x6E
ImGuiKey_None, //0x6F
ImGuiKey_None, //0x70
ImGuiKey_None, //0x71
ImGuiKey_None, //0x72
ImGuiKey_None, //0x73
ImGuiKey_None, //0x74
ImGuiKey_None, //0x75
ImGuiKey_None, //0x76
ImGuiKey_None, //0x77
ImGuiKey_None, //0x78
ImGuiKey_None, //0x79
ImGuiKey_None, //0x7A
ImGuiKey_None, //0x7B
ImGuiKey_None, //0x7C
ImGuiKey_None, //0x7D
ImGuiKey_None, //0x7E
ImGuiKey_None, //0x7F
ImGuiKey_None, //0x80
ImGuiKey_None, //0x81
ImGuiKey_None, //0x82
ImGuiKey_None, //0x83
ImGuiKey_None, //0x84
ImGuiKey_None, //0x85
ImGuiKey_None, //0x86
ImGuiKey_None, //0x87
ImGuiKey_None, //0x88
ImGuiKey_None, //0x89
ImGuiKey_None, //0x8A
ImGuiKey_None, //0x8B
ImGuiKey_None, //0x8C
ImGuiKey_None, //0x8D
ImGuiKey_None, //0x8E
ImGuiKey_None, //0x8F
ImGuiKey_None, //0x90
ImGuiKey_None, //0x91
ImGuiKey_None, //0x92
ImGuiKey_None, //0x93
ImGuiKey_None, //0x94
ImGuiKey_None, //0x95
ImGuiKey_None, //0x96
ImGuiKey_None, //0x97
ImGuiKey_None, //0x98
ImGuiKey_None, //0x99
ImGuiKey_None, //0x9A
ImGuiKey_None, //0x9B
ImGuiKey_KeypadEnter, //DIK_NUMPADENTER 0x9C /* Enter on numeric keypad */
ImGuiKey_RightCtrl, //DIK_RCONTROL 0x9D
ImGuiKey_None, //0x9E
ImGuiKey_None, //0x9F
ImGuiKey_None, //0xA0
ImGuiKey_None, //0xA1
ImGuiKey_None, //0xA2
ImGuiKey_None, //0xA3
ImGuiKey_None, //0xA4
ImGuiKey_None, //0xA5
ImGuiKey_None, //0xA6
ImGuiKey_None, //0xA7
ImGuiKey_None, //0xA8
ImGuiKey_None, //0xA9
ImGuiKey_None, //0xAA
ImGuiKey_None, //0xAB
ImGuiKey_None, //0xAC
ImGuiKey_None, //0xAD
ImGuiKey_None, //0xAE
ImGuiKey_None, //0xAF
ImGuiKey_None, //0xB0
ImGuiKey_None, //0xB1
ImGuiKey_None, //0xB2
ImGuiKey_None, //0xB3
ImGuiKey_None, //0xB4
ImGuiKey_KeypadDivide, //DIK_DIVIDE 0xB5 /* / on numeric keypad */
ImGuiKey_None, //0xB6
ImGuiKey_None, //DIK_SYSRQ 0xB7
ImGuiKey_RightAlt, //DIK_RMENU 0xB8 /* right Alt */
ImGuiKey_None, //0xB9
ImGuiKey_None, //0xBA
ImGuiKey_None, //0xBB
ImGuiKey_None, //0xBC
ImGuiKey_None, //0xBD
ImGuiKey_None, //0xBE
ImGuiKey_None, //0xBF
ImGuiKey_None, //0xC0
ImGuiKey_None, //0xC1
ImGuiKey_None, //0xC2
ImGuiKey_None, //0xC3
ImGuiKey_None, //0xC4
ImGuiKey_None, //0xC5
ImGuiKey_None, //0xC6
ImGuiKey_Home, //DIK_HOME 0xC7 /* Home on arrow keypad */
ImGuiKey_UpArrow, //DIK_UP 0xC8 /* UpArrow on arrow keypad */
ImGuiKey_PageUp, //DIK_PRIOR 0xC9 /* PgUp on arrow keypad */
ImGuiKey_None, //0xCA
ImGuiKey_LeftArrow, //DIK_LEFT 0xCB /* LeftArrow on arrow keypad */
ImGuiKey_None, //0xCC
ImGuiKey_RightArrow, //DIK_RIGHT 0xCD /* RightArrow on arrow keypad */
ImGuiKey_None, //0xCE
ImGuiKey_End, //DIK_END 0xCF /* End on arrow keypad */
ImGuiKey_DownArrow, //DIK_DOWN 0xD0 /* DownArrow on arrow keypad */
ImGuiKey_PageDown, //DIK_NEXT 0xD1 /* PgDn on arrow keypad */
ImGuiKey_Insert, //DIK_INSERT 0xD2 /* Insert on arrow keypad */
ImGuiKey_Delete, //DIK_DELETE 0xD3 /* Delete on arrow keypad */
ImGuiKey_None, //0xD4
ImGuiKey_None, //0xD5
ImGuiKey_None, //0xD6
ImGuiKey_None, //0xD7
ImGuiKey_None, //0xD8
ImGuiKey_None, //0xD9
ImGuiKey_None, //0xDA
ImGuiKey_LeftSuper, //DIK_LWIN 0xDB /* Left Windows key */
ImGuiKey_RightSuper, //DIK_RWIN 0xDC /* Right Windows key */
ImGuiKey_None, //DIK_APPS 0xDD /* AppMenu key */
};
static void SetupImGuiStyle(const float overall_alpha)
{
// Rounded Visual Studio style by RedNicStone from ImThemes
ImGuiStyle &style = ImGui::GetStyle();
style.Alpha = 1.0f;
style.DisabledAlpha = 0.6000000238418579f;
style.WindowPadding = ImVec2(8.0f, 8.0f);
style.WindowRounding = 4.0f;
style.WindowBorderSize = 0.0f;
style.WindowMinSize = ImVec2(32.0f, 32.0f);
style.WindowTitleAlign = ImVec2(0.0f, 0.5f);
style.WindowMenuButtonPosition = ImGuiDir_Left;
style.ChildRounding = 0.0f;
style.ChildBorderSize = 1.0f;
style.PopupRounding = 4.0f;
style.PopupBorderSize = 1.0f;
style.FramePadding = ImVec2(4.0f, 3.0f);
style.FrameRounding = 2.5f;
style.FrameBorderSize = 0.0f;
style.ItemSpacing = ImVec2(8.0f, 4.0f);
style.ItemInnerSpacing = ImVec2(4.0f, 4.0f);
style.CellPadding = ImVec2(4.0f, 2.0f);
style.IndentSpacing = 21.0f;
style.ColumnsMinSpacing = 6.0f;
style.ScrollbarSize = 11.0f;
style.ScrollbarRounding = 2.5f;
style.GrabMinSize = 10.0f;
style.GrabRounding = 2.0f;
style.TabRounding = 3.5f;
style.TabBorderSize = 0.0f;
style.TabMinWidthForCloseButton = 0.0f;
style.ColorButtonPosition = ImGuiDir_Right;
style.ButtonTextAlign = ImVec2(0.5f, 0.5f);
style.SelectableTextAlign = ImVec2(0.0f, 0.0f);
style.Colors[ImGuiCol_Text] = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.5921568870544434f, 0.5921568870544434f, 0.5921568870544434f, overall_alpha);
style.Colors[ImGuiCol_WindowBg] = ImVec4(0.1450980454683304f, 0.1450980454683304f, 0.1490196138620377f, overall_alpha);
style.Colors[ImGuiCol_ChildBg] = ImVec4(0.1450980454683304f, 0.1450980454683304f, 0.1490196138620377f, overall_alpha);
style.Colors[ImGuiCol_PopupBg] = ImVec4(0.1450980454683304f, 0.1450980454683304f, 0.1490196138620377f, overall_alpha);
style.Colors[ImGuiCol_Border] = ImVec4(0.3058823645114899f, 0.3058823645114899f, 0.3058823645114899f, overall_alpha);
style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.3058823645114899f, 0.3058823645114899f, 0.3058823645114899f, overall_alpha);
style.Colors[ImGuiCol_FrameBg] = ImVec4(0.2000000029802322f, 0.2000000029802322f, 0.2156862765550613f, overall_alpha);
style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.1137254908680916f, 0.5921568870544434f, 0.9254902005195618f, overall_alpha);
style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.0f, 0.4666666686534882f, 0.7843137383460999f, overall_alpha);
style.Colors[ImGuiCol_TitleBg] = ImVec4(0.1450980454683304f, 0.1450980454683304f, 0.1490196138620377f, overall_alpha);
style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.1450980454683304f, 0.1450980454683304f, 0.1490196138620377f, overall_alpha);
style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.1450980454683304f, 0.1450980454683304f, 0.1490196138620377f, overall_alpha);
style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.2000000029802322f, 0.2000000029802322f, 0.2156862765550613f, overall_alpha);
style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.2000000029802322f, 0.2000000029802322f, 0.2156862765550613f, overall_alpha);
style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.321568638086319f, 0.321568638086319f, 0.3333333432674408f, overall_alpha);
style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.3529411852359772f, 0.3529411852359772f, 0.3725490272045135f, overall_alpha);
style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.3529411852359772f, 0.3529411852359772f, 0.3725490272045135f, overall_alpha);
style.Colors[ImGuiCol_CheckMark] = ImVec4(0.0f, 0.4666666686534882f, 0.7843137383460999f, overall_alpha);
style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.1137254908680916f, 0.5921568870544434f, 0.9254902005195618f, overall_alpha);
style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.0f, 0.4666666686534882f, 0.7843137383460999f, overall_alpha);
style.Colors[ImGuiCol_Button] = ImVec4(0.2000000029802322f, 0.2000000029802322f, 0.2156862765550613f, overall_alpha);
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.1137254908680916f, 0.5921568870544434f, 0.9254902005195618f, overall_alpha);
style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.1137254908680916f, 0.5921568870544434f, 0.9254902005195618f, overall_alpha);
style.Colors[ImGuiCol_Header] = ImVec4(0.2000000029802322f, 0.2000000029802322f, 0.2156862765550613f, overall_alpha);
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.1137254908680916f, 0.5921568870544434f, 0.9254902005195618f, overall_alpha);
style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.0f, 0.4666666686534882f, 0.7843137383460999f, overall_alpha);
style.Colors[ImGuiCol_Separator] = ImVec4(0.3058823645114899f, 0.3058823645114899f, 0.3058823645114899f, overall_alpha);
style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.3058823645114899f, 0.3058823645114899f, 0.3058823645114899f, overall_alpha);
style.Colors[ImGuiCol_SeparatorActive] = ImVec4(0.3058823645114899f, 0.3058823645114899f, 0.3058823645114899f, overall_alpha);
style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.1450980454683304f, 0.1450980454683304f, 0.1490196138620377f, overall_alpha);
style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.2000000029802322f, 0.2000000029802322f, 0.2156862765550613f, overall_alpha);
style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.321568638086319f, 0.321568638086319f, 0.3333333432674408f, overall_alpha);
style.Colors[ImGuiCol_Tab] = ImVec4(0.1450980454683304f, 0.1450980454683304f, 0.1490196138620377f, overall_alpha);
style.Colors[ImGuiCol_TabHovered] = ImVec4(0.1137254908680916f, 0.5921568870544434f, 0.9254902005195618f, overall_alpha);
style.Colors[ImGuiCol_TabActive] = ImVec4(0.0f, 0.4666666686534882f, 0.7843137383460999f, overall_alpha);
style.Colors[ImGuiCol_TabUnfocused] = ImVec4(0.1450980454683304f, 0.1450980454683304f, 0.1490196138620377f, overall_alpha);
style.Colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.0f, 0.4666666686534882f, 0.7843137383460999f, overall_alpha);
style.Colors[ImGuiCol_PlotLines] = ImVec4(0.0f, 0.4666666686534882f, 0.7843137383460999f, overall_alpha);
style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.1137254908680916f, 0.5921568870544434f, 0.9254902005195618f, overall_alpha);
style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.0f, 0.4666666686534882f, 0.7843137383460999f, overall_alpha);
style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.1137254908680916f, 0.5921568870544434f, 0.9254902005195618f, overall_alpha);
style.Colors[ImGuiCol_TableHeaderBg] = ImVec4(0.1882352977991104f, 0.1882352977991104f, 0.2000000029802322f, overall_alpha);
style.Colors[ImGuiCol_TableBorderStrong] = ImVec4(0.3098039329051971f, 0.3098039329051971f, 0.3490196168422699f, overall_alpha);
style.Colors[ImGuiCol_TableBorderLight] = ImVec4(0.2274509817361832f, 0.2274509817361832f, 0.2470588237047195f, overall_alpha);
style.Colors[ImGuiCol_TableRowBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f * overall_alpha);
style.Colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.0f, 1.0f, 1.0f, 0.05999999865889549f * overall_alpha);
style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.0f, 0.4666666686534882f, 0.7843137383460999f, overall_alpha);
style.Colors[ImGuiCol_DragDropTarget] = ImVec4(0.1450980454683304f, 0.1450980454683304f, 0.1490196138620377f, overall_alpha);
style.Colors[ImGuiCol_NavHighlight] = ImVec4(0.1450980454683304f, 0.1450980454683304f, 0.1490196138620377f, overall_alpha);
style.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.0f, 1.0f, 1.0f, 0.699999988079071f * overall_alpha);
style.Colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.800000011920929f, 0.800000011920929f, 0.800000011920929f, 0.2000000029802322f * overall_alpha);
style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.1450980454683304f, 0.1450980454683304f, 0.1490196138620377f, overall_alpha);
}
// Helper to display a little (?) mark which shows a tooltip when hovered.
static void HelpMarker(const char *desc)
{
ImGui::TextDisabled("(?)");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayShort))
{
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
ImGui::TextUnformatted(desc);
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}
}
template <class T> static std::vector<T> SortedCaseInsensitive(std::vector<T>& list, const std::function<string(T)>& map)
{
std::vector<T> sorted;
sorted.reserve(list.size());
sorted.insert(sorted.begin(), list.begin(), list.end());
sort(sorted.begin(), sorted.end(), [map](const T &a, const T &b) -> bool
{
string str1 = map(a), str2 = map(b);
for (string::const_iterator c1 = str1.begin(), c2 = str2.begin(); c1 != str1.end() && c2 != str2.end(); ++c1, ++c2)
{
const auto cl1 = tolower(static_cast<unsigned char>(*c1));
const auto cl2 = tolower(static_cast<unsigned char>(*c2));
if (cl1 > cl2)
return false;
if (cl1 < cl2)
return true;
}
return str1.size() > str2.size();
});
return sorted;
}
static void HelpTextCentered(const std::string& text)
{
const ImVec2 win_size = ImGui::GetWindowSize();
const ImVec2 text_size = ImGui::CalcTextSize(text.c_str());
// calculate the indentation that centers the text on one line, relative
// to window left, regardless of the `ImGuiStyleVar_WindowPadding` value
float text_indentation = (win_size.x - text_size.x) * 0.5f;
// if text is too long to be drawn on one line, `text_indentation` can
// become too small or even negative, so we check a minimum indentation
constexpr float min_indentation = 20.0f;
if (text_indentation <= min_indentation)
text_indentation = min_indentation;
ImGui::SameLine(text_indentation);
ImGui::PushTextWrapPos(win_size.x - text_indentation);
ImGui::TextWrapped("%s", text.c_str());
ImGui::PopTextWrapPos();
}
static void HelpSplash(const std::string &text, int rotation)
{
const ImVec2 win_size = ImGui::GetIO().DisplaySize;
vector<string> lines;
ImVec2 text_size(0, 0);
constexpr float padding = 60.f;
const float maxWidth = win_size.x - padding;
ImFont *const font = ImGui::GetFont();
const char *textEnd = text.c_str();
while (*textEnd)
{
const char *nextLineTextEnd = ImGui::FindRenderedTextEnd(textEnd, nullptr);
ImVec2 lineSize = font->CalcTextSizeA(font->FontSize, FLT_MAX, 0.0f, textEnd, nextLineTextEnd);
if (lineSize.x > maxWidth)
{
const char *wrapPoint = font->CalcWordWrapPositionA(font->Scale, textEnd, nextLineTextEnd, maxWidth);
if (wrapPoint == textEnd)
wrapPoint++;
nextLineTextEnd = wrapPoint;
lineSize = font->CalcTextSizeA(font->FontSize, FLT_MAX, 0.0f, textEnd, wrapPoint);
}
string line(textEnd, nextLineTextEnd);
lines.push_back(line);
if (lineSize.x > text_size.x)
text_size.x = lineSize.x;
text_size.y += (float)(std::count(line.begin(), line.end(), '\n') + 1) * ImGui::GetTextLineHeightWithSpacing();
textEnd = nextLineTextEnd;
if (*textEnd == '\n' || *textEnd == ' ')
textEnd++;
}
text_size.x += (padding / 2);
text_size.y += (padding / 2);
constexpr ImGuiWindowFlags window_flags
= ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav;
ImGui::SetNextWindowBgAlpha(0.35f);
ImGui::SetNextWindowPos(ImVec2((win_size.x - text_size.x) / 2, (win_size.y - text_size.y) / 2));
ImGui::SetNextWindowSize(ImVec2(text_size.x, text_size.y));
ImGui::Begin("ToolTip", nullptr, window_flags);
ImGui::SetCursorPosY(padding / 4);
for (const string& line : lines)
{
const ImVec2 lineSize = font->CalcTextSizeA(font->FontSize, FLT_MAX, 0.0f, line.c_str());
ImGui::SetCursorPosX(((text_size.x - lineSize.x) / 2));
ImGui::Text("%s", line.c_str());
}
ImGui::End();
}
static void HelpEditableHeader(bool is_live, IEditable *editable, IEditable *live_editable)
{
IEditable *notnull_editable = editable ? editable : live_editable;
IEditable *select_editable = is_live ? live_editable : editable;
if (notnull_editable == nullptr)
return;
string title;
switch (notnull_editable->GetItemType())
{
// Missing: eItemLightCenter, eItemDragPoint, eItemCollection
case eItemBumper: title = "Bumper"s; break;
case eItemDecal: title = "Decal"s; break;
case eItemDispReel: title = "Reel"s; break;
case eItemGate: title = "Gate"s; break;
case eItemFlasher: title = "Flasher"s; break;
case eItemFlipper: title = "Flipper"s; break;
case eItemHitTarget: title = "Target"s; break;
case eItemKicker: title = "Kicker"s; break;
case eItemLight: title = "Light"s; break;
case eItemLightSeq: title = "Light Sequencer"s; break;
case eItemPlunger: title = "Plunger"s; break;
case eItemPrimitive: title = ((Primitive *)notnull_editable)->IsPlayfield() ? "Playfield"s : "Primitive"s; break;
case eItemRamp: title = "Ramp"s; break;
case eItemRubber: title = "Rubber"s; break;
case eItemSpinner: title = "Spinner"s; break;
case eItemSurface: title = "Surface"s; break;
case eItemTable: title = "Table"s; break;
case eItemTextbox: title = "TextBox"s; break;
case eItemTimer: title = "Timer"s; break;
case eItemTrigger: title = "Trigger"s; break;
default: break;
}
HelpTextCentered(title);
ImGui::BeginDisabled(is_live); // Do not edit name of live objects, it would likely break the script
string name = select_editable ? select_editable->GetName() : string();
if (ImGui::InputText("Name", &name))
{
editable->SetName(name);
}
ImGui::EndDisabled();
ImGui::Separator();
}
ImGui::MarkdownConfig LiveUI::markdown_config;
LiveUI::LiveUI(RenderDevice *const rd)
: m_rd(rd)
{
m_StartTime_msec = msec();
m_app = g_pvp;
m_player = g_pplayer;
m_table = m_player->m_pEditorTable;
m_live_table = m_player->m_ptable;
m_pininput = &(m_player->m_pininput);
m_pin3d = &(m_player->m_pin3d);
m_disable_esc = m_live_table->m_settings.LoadValueWithDefault(Settings::Player, "DisableESC"s, m_disable_esc);
memset(m_tweakState, 0, sizeof(m_tweakState));
m_selection.type = Selection::SelectionType::S_NONE;
m_useEditorCam = false;
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImPlot::CreateContext();
ImGuiIO &io = ImGui::GetIO();
io.IniFilename = nullptr; //don't use an ini file for configuration
// Editor camera position. We use a right handed system for easy ImGuizmo integration while VPX renderer is left handed, so reverse X axis
m_orthoCam = true;
m_camDistance = m_live_table->m_bottom * 0.7f;
const vec3 eye(m_live_table->m_right * 0.5f, m_live_table->m_bottom * 0.5f, -m_camDistance);
const vec3 at(m_live_table->m_right * 0.5f, m_live_table->m_bottom * 0.5f, 0.f);
const vec3 up(0.f, -1.f, 0.f);
m_camView.SetLookAtRH(eye, at, up);
ImGuizmo::AllowAxisFlip(false);
ImGui_ImplWin32_Init(rd->getHwnd());
SetupImGuiStyle(1.0f);
m_dpi = ImGui_ImplWin32_GetDpiScaleForHwnd(rd->getHwnd());
ImGui::GetStyle().ScaleAllSizes(m_dpi);
// UI fonts
m_baseFont = io.Fonts->AddFontFromMemoryCompressedTTF(droidsans_compressed_data, droidsans_compressed_size, 13.0f * m_dpi);
ImFontConfig icons_config;
icons_config.MergeMode = true;
icons_config.PixelSnapH = true;
icons_config.GlyphMinAdvanceX = 13.0f * m_dpi;
static constexpr ImWchar icons_ranges[] = { ICON_MIN_FK, ICON_MAX_16_FK, 0 };
io.Fonts->AddFontFromMemoryCompressedTTF(fork_awesome_compressed_data, fork_awesome_compressed_size, 13.0f * m_dpi, &icons_config, icons_ranges);
// Overlays are displayed in the VR headset for which we do not have a meaningful DPI. This is somewhat hacky but we would really need 2 UI for VR.
const float overlaySize = rd->m_stereo3D == STEREO_VR ? 20.0f : min(32.f * m_dpi, (float)min(m_player->m_wnd_width, m_player->m_wnd_height) / (26.f * 2.0f)); // Fit 26 lines of text on screen
m_overlayFont = io.Fonts->AddFontFromMemoryCompressedTTF(droidsans_compressed_data, droidsans_compressed_size, overlaySize);
m_overlayBoldFont = io.Fonts->AddFontFromMemoryCompressedTTF(droidsansbold_compressed_data, droidsansbold_compressed_size, overlaySize);
ImFont *H1 = io.Fonts->AddFontFromMemoryCompressedTTF(droidsansbold_compressed_data, droidsansbold_compressed_size, overlaySize * 20.0f / 13.f);
ImFont *H2 = io.Fonts->AddFontFromMemoryCompressedTTF(droidsansbold_compressed_data, droidsansbold_compressed_size, overlaySize * 18.0f / 13.f);
ImFont *H3 = io.Fonts->AddFontFromMemoryCompressedTTF(droidsansbold_compressed_data, droidsansbold_compressed_size, overlaySize * 15.0f / 13.f);
markdown_config.linkCallback = MarkdownLinkCallback;
markdown_config.tooltipCallback = NULL;
markdown_config.imageCallback = MarkdownImageCallback;
//markdown_config.linkIcon = ICON_FA_LINK;
markdown_config.headingFormats[0] = { H1, true };
markdown_config.headingFormats[1] = { H2, true };
markdown_config.headingFormats[2] = { H3, false };
markdown_config.userData = this;
markdown_config.formatCallback = MarkdownFormatCallback;
#ifdef ENABLE_SDL
ImGui_ImplOpenGL3_Init();
#else
ImGui_ImplDX9_Init(rd->GetCoreDevice());
#endif
}
LiveUI::~LiveUI()
{
HideUI();
if (ImGui::GetCurrentContext())
{
#ifdef ENABLE_SDL
ImGui_ImplOpenGL3_Shutdown();
#else
ImGui_ImplDX9_Shutdown();
#endif
ImGui_ImplWin32_Shutdown();
ImPlot::DestroyContext();
ImGui::DestroyContext();
}
}
void LiveUI::MarkdownFormatCallback(const ImGui::MarkdownFormatInfo &markdownFormatInfo, bool start)
{
LiveUI *ui = (LiveUI *)(markdownFormatInfo.config->userData);
switch (markdownFormatInfo.type)
{
case ImGui::MarkdownFormatType::EMPHASIS:
ImGui::defaultMarkdownFormatCallback(markdownFormatInfo, start);
if (markdownFormatInfo.level == 1)
{ // normal emphasis
if (start)
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyle().Colors[ImGuiCol_TextDisabled]);
else
ImGui::PopStyleColor();
}
else
{ // strong emphasis
if (start)
ImGui::PushFont(ui->m_overlayBoldFont);
else
ImGui::PopFont();
}
break;
case ImGui::MarkdownFormatType::HEADING:
{
ImGui::MarkdownHeadingFormat fmt;
if (markdownFormatInfo.level > ImGui::MarkdownConfig::NUMHEADINGS)
fmt = markdownFormatInfo.config->headingFormats[ImGui::MarkdownConfig::NUMHEADINGS - 1];
else
fmt = markdownFormatInfo.config->headingFormats[markdownFormatInfo.level - 1];
if (start)
{
if (fmt.font)
ImGui::PushFont(fmt.font);
if (ImGui::GetItemID() != ui->markdown_start_id)
ImGui::NewLine();
}
else
{
if (fmt.separator)
{
ImGui::PushStyleColor(ImGuiCol_Separator, ImVec4(1.f, 1.f, 1.f, 1.f));
ImGui::Separator();
ImGui::PopStyleColor();
ImGui::NewLine();
}
else
{
ImGui::NewLine();
}
if (fmt.font)
ImGui::PopFont();
}
break;
}
default: ImGui::defaultMarkdownFormatCallback(markdownFormatInfo, start); break;
}
}
void LiveUI::MarkdownLinkCallback(ImGui::MarkdownLinkCallbackData data)
{
if (!data.isImage)
{
std::string url(data.link, data.linkLength);
#ifdef ENABLE_SDL
SDL_OpenURL(url.c_str());
#else
ShellExecuteA(NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
#endif
}
}
ImGui::MarkdownImageData LiveUI::MarkdownImageCallback(ImGui::MarkdownLinkCallbackData data)
{
LiveUI *ui = (LiveUI *)data.userData;
Texture *const ppi = ui->m_live_table->GetImage(std::string(data.link, data.linkLength));
if (ppi == nullptr)
return ImGui::MarkdownImageData {};
Sampler *sampler = g_pplayer->m_pin3d.m_pd3dPrimaryDevice->m_texMan.LoadTexture(ppi->m_pdsBuffer, SamplerFilter::SF_BILINEAR, SamplerAddressMode::SA_CLAMP, SamplerAddressMode::SA_CLAMP, false);
if (sampler == nullptr)
return ImGui::MarkdownImageData {};
#ifdef ENABLE_SDL
ImTextureID image = (void *)(intptr_t)sampler->GetCoreTexture();
#else
ImTextureID image = (void *)sampler->GetCoreTexture();
#endif
ImGui::MarkdownImageData imageData { true, false, image, ImVec2((float)sampler->GetWidth(), (float)sampler->GetHeight()) };
ImVec2 const contentSize = ImGui::GetContentRegionAvail();
if (imageData.size.x > contentSize.x)
{
float const ratio = imageData.size.y / imageData.size.x;
imageData.size.x = contentSize.x;
imageData.size.y = contentSize.x * ratio;
}
return imageData;
}
bool LiveUI::HasKeyboardCapture() const {
return ImGui::GetIO().WantCaptureKeyboard;
}
bool LiveUI::HasMouseCapture() const
{
return ImGui::GetIO().WantCaptureKeyboard;
}
void LiveUI::Render()
{
// For the time being, the UI is only available inside a running player
if (m_player == nullptr || m_player->GetCloseState() != Player::CS_PLAYING)
return;
if (m_rotate != 0 && !m_rotation_callback_added)
{
// We hack into ImGui renderer for the simple tooltips that must be displayed facing the user
m_rotation_callback_added = true; // Only add it once per frame
ImGui::GetBackgroundDrawList()->AddCallback(
[](const ImDrawList *parent_list, const ImDrawCmd *cmd)
{
LiveUI *const lui = (LiveUI *)cmd->UserCallbackData;
Matrix3D matRotate, matTranslate;
matRotate.SetRotateZ((float)(lui->m_rotate * (M_PI / 2.0)));
switch (lui->m_rotate)
{
case 1: matTranslate.SetTranslation(ImGui::GetIO().DisplaySize.y, 0, 0); break;
case 2: matTranslate.SetTranslation(ImGui::GetIO().DisplaySize.x, ImGui::GetIO().DisplaySize.y, 0); break;
case 3: matTranslate.SetTranslation(0, ImGui::GetIO().DisplaySize.x, 0); break;
}
matTranslate.Multiply(matRotate, matTranslate);
#ifdef ENABLE_SDL
const float L = 0, R = (lui->m_rotate == 1 || lui->m_rotate == 3) ? ImGui::GetIO().DisplaySize.y : ImGui::GetIO().DisplaySize.x;
const float T = 0, B = (lui->m_rotate == 1 || lui->m_rotate == 3) ? ImGui::GetIO().DisplaySize.x : ImGui::GetIO().DisplaySize.y;
Matrix3D matProj(
2.0f / (R - L), 0.0f, 0.0f, 0.0f,
0.0f, 2.0f / (T - B), 0.0f, 0.0f,
0.0f, 0.0f, -1.0f, 0.0f,
(R + L) / (L - R), (T + B) / (B - T), 0.0f, 1.0f);
matProj.Multiply(matTranslate, matProj);
GLint shaderHandle;
glGetIntegerv(GL_CURRENT_PROGRAM, &shaderHandle);
GLuint attribLocationProjMtx = glGetUniformLocation(shaderHandle, "ProjMtx");
glUniformMatrix4fv(attribLocationProjMtx, 1, GL_FALSE, &(matProj.m[0][0]));
glDisable(GL_SCISSOR_TEST);
#else
lui->m_rd->GetCoreDevice()->SetTransform(D3DTS_WORLD, (const D3DXMATRIX *)&matTranslate);
lui->m_rd->GetCoreDevice()->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
#endif
}, this);
}
ImGui::Render();
ImDrawData * const draw_data = ImGui::GetDrawData();
if (m_rotate == 1 || m_rotate == 3)
{
const float tmp = draw_data->DisplaySize.x;
draw_data->DisplaySize.x = draw_data->DisplaySize.y;
draw_data->DisplaySize.y = tmp;
}
#ifdef ENABLE_SDL
if (GLAD_GL_VERSION_4_3)
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "ImGui");
ImGui_ImplOpenGL3_RenderDrawData(draw_data);
if (GLAD_GL_VERSION_4_3)
glPopDebugGroup();
#else
ImGui_ImplDX9_RenderDrawData(draw_data);
#endif
}
void LiveUI::OpenMainSplash()
{
if (!m_ShowUI && !m_ShowSplashModal)
{
while (ShowCursor(FALSE)>=0) ;
while (ShowCursor(TRUE)<0) ;
m_ShowUI = true;
m_ShowSplashModal = true;
m_OpenUITime = msec();
PausePlayer(true);
}
}
void LiveUI::OpenLiveUI()
{
if (!m_ShowUI && !m_ShowSplashModal)
{
while (ShowCursor(FALSE) >= 0) ;
while (ShowCursor(TRUE) < 0) ;
m_OpenUITime = msec();
PausePlayer(true);
m_ShowUI = true;
m_ShowSplashModal = false;
m_useEditorCam = true;
m_orthoCam = false;
m_player->DisableStaticPrePass(true);
ResetCameraFromPlayer();
}
}
void LiveUI::ToggleFPS()
{
m_show_fps = (m_show_fps + 1) % 3;
if (m_show_fps == 1)
{
m_player->InitFPS();
g_frameProfiler.EnableWorstFrameLogging(true);
}
if (m_show_fps == 0)
m_rd->LogNextFrame();
}
void LiveUI::ResetCameraFromPlayer()
{
// Try to setup editor camera to match the used one, but only mostly since the LiveUI does not have some view setup features like off-center, ...
m_camView = Matrix3D::MatrixScale(1.f, 1.f, -1.f) * m_pin3d->GetMVP().GetView() * Matrix3D::MatrixScale(1.f, -1.f, 1.f);
}
void LiveUI::Update(const RenderTarget *rt)
{
// For the time being, the UI is only available inside a running player
if (m_player == nullptr || m_player->GetCloseState() != Player::CS_PLAYING)
return;
m_rotation_callback_added = false;
#ifdef ENABLE_SDL
ImGui_ImplOpenGL3_NewFrame();
#else
ImGui_ImplDX9_NewFrame();
#endif
ImGui_ImplWin32_NewFrame();
// The render size may not match the window size used by ImGui_ImplWin32_NewFrame (for example for VR)
ImGui::GetIO().DisplaySize = ImVec2((float)rt->GetWidth(), (float)rt->GetHeight());
ImGui::NewFrame();
ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_NavEnableKeyboard; // We use it for main splash popup, but needs it to be disabled to allow keyboard shortcuts
const bool isInteractiveUI = m_ShowUI || m_ShowSplashModal || ImGui::IsPopupOpen(ID_BAM_SETTINGS);
if (isInteractiveUI)
m_rotate = 0;
else
{
// If we are only showing overlays (no mouse interaction), apply main camera rotation
ImGuiIO &io = ImGui::GetIO();
m_rotate = (int)(m_player->m_ptable->mViewSetups[m_player->m_ptable->m_BG_current_set].GetRotation((int)io.DisplaySize.x, (int)io.DisplaySize.y) / 90.0f);
if (m_rotate == 1 || m_rotate == 3)
{
ImGui::EndFrame();
const float tmp = io.DisplaySize.x;
io.DisplaySize.x = io.DisplaySize.y;
io.DisplaySize.y = tmp;
ImGui::NewFrame();
}
}
ImGuizmo::SetOrthographic(m_orthoCam);
ImGuizmo::BeginFrame();
const ImGuiIO &io = ImGui::GetIO();
ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y);
ImGui::PushFont(m_baseFont);
// Display notification (except when script has an unaligned rotation)
const U32 tick = msec();
float notifY = io.DisplaySize.y * 0.5f;
const bool showNotifications = ((float)m_rotate * 90.0f == m_player->m_ptable->mViewSetups[m_player->m_ptable->m_BG_current_set].GetRotation(m_player->m_pin3d.m_pd3dPrimaryDevice->m_width, m_player->m_pin3d.m_pd3dPrimaryDevice->m_height));
ImGui::PushFont(m_overlayFont);
for (int i = (int)m_notifications.size() - 1; i >= 0; i--)
{
if (tick > m_notifications[i].disappearTick)
{
m_notifications.erase(m_notifications.begin() + i);
}
else if (showNotifications)
{
ImFont *const font = ImGui::GetFont();
ImVec2 textSize = font->CalcTextSizeA(font->FontSize, FLT_MAX, 0.0f, m_notifications[i].message.c_str()) + ImVec2(30.f, 30.f);
constexpr ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav;
ImGui::SetNextWindowBgAlpha(0.666f);
ImGui::SetNextWindowPos(ImVec2((io.DisplaySize.x - textSize.x) / 2, notifY));
ImGui::SetNextWindowSize(textSize);
ImGui::Begin("Notification"s.append(std::to_string(i)).c_str(), nullptr, window_flags);
ImGui::Text("%s", m_notifications[i].message.c_str());
ImGui::End();
notifY += textSize.y + 10.f;
}
}
ImGui::PopFont();
if (isInteractiveUI)