forked from crosire/reshade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtime_gui.cpp
3136 lines (2668 loc) · 123 KB
/
runtime_gui.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
/*
* Copyright (C) 2014 Patrick Mours. All rights reserved.
* License: https://github.com/crosire/reshade#license
*/
#if RESHADE_GUI
#include "version.h"
#include "dll_log.hpp"
#include "dll_config.hpp"
#include "dll_resources.hpp"
#include "addon_manager.hpp"
#include "runtime.hpp"
#include "runtime_objects.hpp"
#include "input.hpp"
#include "imgui_widgets.hpp"
#include "fonts/forkawesome.inl"
#include <fstream>
#include <algorithm>
#include <shellapi.h>
using namespace reshade::gui;
extern bool g_addons_enabled;
static std::string s_window_state_path;
static const ImVec4 COLOR_RED = ImColor(240, 100, 100);
static const ImVec4 COLOR_YELLOW = ImColor(204, 204, 0);
void reshade::runtime::init_gui()
{
if (s_window_state_path.empty())
s_window_state_path = (g_reshade_base_path / L"ReShadeGUI.ini").u8string();
// Default shortcut: Home
_overlay_key_data[0] = 0x24;
_overlay_key_data[1] = false;
_overlay_key_data[2] = false;
_overlay_key_data[3] = false;
_imgui_context = ImGui::CreateContext();
auto &imgui_io = _imgui_context->IO;
auto &imgui_style = _imgui_context->Style;
imgui_io.IniFilename = nullptr;
imgui_io.KeyMap[ImGuiKey_Tab] = 0x09; // VK_TAB
imgui_io.KeyMap[ImGuiKey_LeftArrow] = 0x25; // VK_LEFT
imgui_io.KeyMap[ImGuiKey_RightArrow] = 0x27; // VK_RIGHT
imgui_io.KeyMap[ImGuiKey_UpArrow] = 0x26; // VK_UP
imgui_io.KeyMap[ImGuiKey_DownArrow] = 0x28; // VK_DOWN
imgui_io.KeyMap[ImGuiKey_PageUp] = 0x21; // VK_PRIOR
imgui_io.KeyMap[ImGuiKey_PageDown] = 0x22; // VK_NEXT
imgui_io.KeyMap[ImGuiKey_Home] = 0x24; // VK_HOME
imgui_io.KeyMap[ImGuiKey_End] = 0x23; // VK_END
imgui_io.KeyMap[ImGuiKey_Insert] = 0x2D; // VK_INSERT
imgui_io.KeyMap[ImGuiKey_Delete] = 0x2E; // VK_DELETE
imgui_io.KeyMap[ImGuiKey_Backspace] = 0x08; // VK_BACK
imgui_io.KeyMap[ImGuiKey_Space] = 0x20; // VK_SPACE
imgui_io.KeyMap[ImGuiKey_Enter] = 0x0D; // VK_RETURN
imgui_io.KeyMap[ImGuiKey_Escape] = 0x1B; // VK_ESCAPE
imgui_io.KeyMap[ImGuiKey_A] = 'A';
imgui_io.KeyMap[ImGuiKey_C] = 'C';
imgui_io.KeyMap[ImGuiKey_V] = 'V';
imgui_io.KeyMap[ImGuiKey_X] = 'X';
imgui_io.KeyMap[ImGuiKey_Y] = 'Y';
imgui_io.KeyMap[ImGuiKey_Z] = 'Z';
imgui_io.ConfigFlags = ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_NavEnableKeyboard;
imgui_io.BackendFlags = ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_RendererHasVtxOffset;
// Disable rounding by default
imgui_style.GrabRounding = 0.0f;
imgui_style.FrameRounding = 0.0f;
imgui_style.ChildRounding = 0.0f;
imgui_style.ScrollbarRounding = 0.0f;
imgui_style.WindowRounding = 0.0f;
imgui_style.WindowBorderSize = 0.0f;
ImGui::SetCurrentContext(nullptr);
_menu_callables.emplace_back("Home", [this]() { draw_gui_home(); });
#if RESHADE_ADDON
_menu_callables.emplace_back("Add-ons", [this]() { draw_gui_addons(); });
#endif
_menu_callables.emplace_back("Settings", [this]() { draw_gui_settings(); });
_menu_callables.emplace_back("Statistics", [this]() { draw_gui_statistics(); });
_menu_callables.emplace_back("Log", [this]() { draw_gui_log(); });
_menu_callables.emplace_back("About", [this]() { draw_gui_about(); });
_load_config_callables.push_back([this, &imgui_io, &imgui_style](const ini_file &config) {
config.get("INPUT", "KeyOverlay", _overlay_key_data);
config.get("INPUT", "InputProcessing", _input_processing_mode);
config.get("OVERLAY", "ClockFormat", _clock_format);
config.get("OVERLAY", "FPSPosition", _fps_pos);
config.get("OVERLAY", "NoFontScaling", _no_font_scaling);
config.get("OVERLAY", "ShowClock", _show_clock);
config.get("OVERLAY", "ShowForceLoadEffectsButton", _show_force_load_effects_button);
config.get("OVERLAY", "ShowFPS", _show_fps);
config.get("OVERLAY", "ShowFrameTime", _show_frametime);
config.get("OVERLAY", "ShowScreenshotMessage", _show_screenshot_message);
config.get("OVERLAY", "TutorialProgress", _tutorial_index);
config.get("OVERLAY", "VariableListHeight", _variable_editor_height);
config.get("OVERLAY", "VariableListUseTabs", _variable_editor_tabs);
bool save_imgui_window_state = false;
config.get("OVERLAY", "SaveWindowState", save_imgui_window_state);
imgui_io.IniFilename = save_imgui_window_state ? s_window_state_path.c_str() : nullptr;
config.get("STYLE", "Alpha", imgui_style.Alpha);
config.get("STYLE", "ChildRounding", imgui_style.ChildRounding);
config.get("STYLE", "ColFPSText", _fps_col);
config.get("STYLE", "EditorFont", _editor_font);
config.get("STYLE", "EditorFontSize", _editor_font_size);
config.get("STYLE", "EditorStyleIndex", _editor_style_index);
config.get("STYLE", "Font", _font);
config.get("STYLE", "FontSize", _font_size);
config.get("STYLE", "FPSScale", _fps_scale);
config.get("STYLE", "FrameRounding", imgui_style.FrameRounding);
config.get("STYLE", "GrabRounding", imgui_style.GrabRounding);
config.get("STYLE", "PopupRounding", imgui_style.PopupRounding);
config.get("STYLE", "ScrollbarRounding", imgui_style.ScrollbarRounding);
config.get("STYLE", "StyleIndex", _style_index);
config.get("STYLE", "TabRounding", imgui_style.TabRounding);
config.get("STYLE", "WindowRounding", imgui_style.WindowRounding);
// For compatibility with older versions, set the alpha value if it is missing
if (_fps_col[3] == 0.0f)
_fps_col[3] = 1.0f;
load_custom_style();
});
_save_config_callables.push_back([this, &imgui_io, &imgui_style](ini_file &config) {
config.set("INPUT", "KeyOverlay", _overlay_key_data);
config.set("INPUT", "InputProcessing", _input_processing_mode);
config.set("OVERLAY", "ClockFormat", _clock_format);
config.set("OVERLAY", "FPSPosition", _fps_pos);
config.set("OVERLAY", "NoFontScaling", _no_font_scaling);
config.set("OVERLAY", "ShowClock", _show_clock);
config.set("OVERLAY", "ShowForceLoadEffectsButton", _show_force_load_effects_button);
config.set("OVERLAY", "ShowFPS", _show_fps);
config.set("OVERLAY", "ShowFrameTime", _show_frametime);
config.set("OVERLAY", "ShowScreenshotMessage", _show_screenshot_message);
config.set("OVERLAY", "TutorialProgress", _tutorial_index);
config.set("OVERLAY", "VariableListHeight", _variable_editor_height);
config.set("OVERLAY", "VariableListUseTabs", _variable_editor_tabs);
const bool save_imgui_window_state = imgui_io.IniFilename != nullptr;
config.set("OVERLAY", "SaveWindowState", save_imgui_window_state);
config.set("STYLE", "Alpha", imgui_style.Alpha);
config.set("STYLE", "ChildRounding", imgui_style.ChildRounding);
config.set("STYLE", "ColFPSText", _fps_col);
config.set("STYLE", "EditorFont", _editor_font);
config.set("STYLE", "EditorFontSize", _editor_font_size);
config.set("STYLE", "EditorStyleIndex", _editor_style_index);
config.set("STYLE", "Font", _font);
config.set("STYLE", "FontSize", _font_size);
config.set("STYLE", "FPSScale", _fps_scale);
config.set("STYLE", "FrameRounding", imgui_style.FrameRounding);
config.set("STYLE", "GrabRounding", imgui_style.GrabRounding);
config.set("STYLE", "PopupRounding", imgui_style.PopupRounding);
config.set("STYLE", "ScrollbarRounding", imgui_style.ScrollbarRounding);
config.set("STYLE", "StyleIndex", _style_index);
config.set("STYLE", "TabRounding", imgui_style.TabRounding);
config.set("STYLE", "WindowRounding", imgui_style.WindowRounding);
// Do not save custom style colors by default, only when actually used and edited
});
}
void reshade::runtime::deinit_gui()
{
ImGui::DestroyContext(_imgui_context);
}
void reshade::runtime::build_font_atlas()
{
ImFontAtlas *const atlas = _imgui_context->IO.Fonts;
// Remove any existing fonts from atlas first
atlas->Clear();
for (unsigned int i = 0; i < 2; ++i)
{
ImFontConfig cfg;
cfg.SizePixels = static_cast<float>(i == 0 ? _font_size : _editor_font_size);
const std::filesystem::path &font_path = i == 0 ? _font : _editor_font;
if (std::error_code ec; !std::filesystem::is_regular_file(font_path, ec) || !atlas->AddFontFromFileTTF(font_path.u8string().c_str(), cfg.SizePixels))
atlas->AddFontDefault(&cfg); // Use default font if custom font failed to load or does not exist
if (i == 0)
{
// Merge icons into main font
ImFontConfig icon_config;
icon_config.MergeMode = true;
icon_config.PixelSnapH = true;
icon_config.GlyphOffset = ImVec2(0.0f, 0.1f * _font_size);
const ImWchar icon_ranges[] = { ICON_MIN_FK, ICON_MAX_FK, 0 }; // Zero-terminated list
atlas->AddFontFromMemoryCompressedBase85TTF(FONT_ICON_BUFFER_NAME_FK, cfg.SizePixels, &icon_config, icon_ranges);
}
}
// If unable to build font atlas due to an invalid font, revert to the default font
if (!atlas->Build())
{
_font.clear();
_editor_font.clear();
atlas->Clear();
for (unsigned int i = 0; i < 2; ++i)
{
ImFontConfig cfg;
cfg.SizePixels = static_cast<float>(i == 0 ? _font_size : _editor_font_size);
atlas->AddFontDefault(&cfg);
}
}
_show_splash = true;
_rebuild_font_atlas = false;
int width, height;
unsigned char *pixels;
atlas->GetTexDataAsRGBA32(&pixels, &width, &height);
// Create font atlas texture and upload it
if (_imgui_font_atlas != nullptr)
destroy_texture(*_imgui_font_atlas);
if (_imgui_font_atlas == nullptr)
_imgui_font_atlas = std::make_unique<texture>();
_imgui_font_atlas->width = width;
_imgui_font_atlas->height = height;
_imgui_font_atlas->format = reshadefx::texture_format::rgba8;
_imgui_font_atlas->unique_name = "ImGUI Font Atlas";
if (init_texture(*_imgui_font_atlas))
upload_texture(*_imgui_font_atlas, pixels);
else
_imgui_font_atlas.reset();
}
void reshade::runtime::load_custom_style()
{
const ini_file &config = ini_file::load_cache(_config_path);
ImVec4 *const colors = _imgui_context->Style.Colors;
switch (_style_index)
{
case 0:
ImGui::StyleColorsDark(&_imgui_context->Style);
break;
case 1:
ImGui::StyleColorsLight(&_imgui_context->Style);
break;
case 2:
colors[ImGuiCol_Text] = ImVec4(0.862745f, 0.862745f, 0.862745f, 1.00f);
colors[ImGuiCol_TextDisabled] = ImVec4(0.862745f, 0.862745f, 0.862745f, 0.58f);
colors[ImGuiCol_WindowBg] = ImVec4(0.117647f, 0.117647f, 0.117647f, 1.00f);
colors[ImGuiCol_ChildBg] = ImVec4(0.156863f, 0.156863f, 0.156863f, 0.00f);
colors[ImGuiCol_Border] = ImVec4(0.862745f, 0.862745f, 0.862745f, 0.30f);
colors[ImGuiCol_FrameBg] = ImVec4(0.156863f, 0.156863f, 0.156863f, 1.00f);
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.392157f, 0.588235f, 0.941176f, 0.470588f);
colors[ImGuiCol_FrameBgActive] = ImVec4(0.392157f, 0.588235f, 0.941176f, 0.588235f);
colors[ImGuiCol_TitleBg] = ImVec4(0.392157f, 0.588235f, 0.941176f, 0.45f);
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.392157f, 0.588235f, 0.941176f, 0.35f);
colors[ImGuiCol_TitleBgActive] = ImVec4(0.392157f, 0.588235f, 0.941176f, 0.58f);
colors[ImGuiCol_MenuBarBg] = ImVec4(0.156863f, 0.156863f, 0.156863f, 0.57f);
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.156863f, 0.156863f, 0.156863f, 1.00f);
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.392157f, 0.588235f, 0.941176f, 0.31f);
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.392157f, 0.588235f, 0.941176f, 0.78f);
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.392157f, 0.588235f, 0.941176f, 1.00f);
colors[ImGuiCol_PopupBg] = ImVec4(0.117647f, 0.117647f, 0.117647f, 0.92f);
colors[ImGuiCol_CheckMark] = ImVec4(0.392157f, 0.588235f, 0.941176f, 0.80f);
colors[ImGuiCol_SliderGrab] = ImVec4(0.392157f, 0.588235f, 0.941176f, 0.784314f);
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.392157f, 0.588235f, 0.941176f, 1.00f);
colors[ImGuiCol_Button] = ImVec4(0.392157f, 0.588235f, 0.941176f, 0.44f);
colors[ImGuiCol_ButtonHovered] = ImVec4(0.392157f, 0.588235f, 0.941176f, 0.86f);
colors[ImGuiCol_ButtonActive] = ImVec4(0.392157f, 0.588235f, 0.941176f, 1.00f);
colors[ImGuiCol_Header] = ImVec4(0.392157f, 0.588235f, 0.941176f, 0.76f);
colors[ImGuiCol_HeaderHovered] = ImVec4(0.392157f, 0.588235f, 0.941176f, 0.86f);
colors[ImGuiCol_HeaderActive] = ImVec4(0.392157f, 0.588235f, 0.941176f, 1.00f);
colors[ImGuiCol_Separator] = ImVec4(0.862745f, 0.862745f, 0.862745f, 0.32f);
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.862745f, 0.862745f, 0.862745f, 0.78f);
colors[ImGuiCol_SeparatorActive] = ImVec4(0.862745f, 0.862745f, 0.862745f, 1.00f);
colors[ImGuiCol_ResizeGrip] = ImVec4(0.392157f, 0.588235f, 0.941176f, 0.20f);
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.392157f, 0.588235f, 0.941176f, 0.78f);
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.392157f, 0.588235f, 0.941176f, 1.00f);
colors[ImGuiCol_Tab] = colors[ImGuiCol_Button];
colors[ImGuiCol_TabActive] = colors[ImGuiCol_ButtonActive];
colors[ImGuiCol_TabHovered] = colors[ImGuiCol_ButtonHovered];
colors[ImGuiCol_TabUnfocused] = ImLerp(colors[ImGuiCol_Tab], colors[ImGuiCol_TitleBg], 0.80f);
colors[ImGuiCol_TabUnfocusedActive] = ImLerp(colors[ImGuiCol_TabActive], colors[ImGuiCol_TitleBg], 0.40f);
colors[ImGuiCol_DockingPreview] = colors[ImGuiCol_Header] * ImVec4(1.0f, 1.0f, 1.0f, 0.7f);
colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
colors[ImGuiCol_PlotLines] = ImVec4(0.862745f, 0.862745f, 0.862745f, 0.63f);
colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.392157f, 0.588235f, 0.941176f, 1.00f);
colors[ImGuiCol_PlotHistogram] = ImVec4(0.862745f, 0.862745f, 0.862745f, 0.63f);
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.392157f, 0.588235f, 0.941176f, 1.00f);
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.392157f, 0.588235f, 0.941176f, 0.43f);
break;
case 5:
colors[ImGuiCol_Text] = ImColor(0xff969483);
colors[ImGuiCol_TextDisabled] = ImColor(0xff756e58);
colors[ImGuiCol_WindowBg] = ImColor(0xff362b00);
colors[ImGuiCol_ChildBg] = ImColor();
colors[ImGuiCol_PopupBg] = ImColor(0xfc362b00); // Customized
colors[ImGuiCol_Border] = ImColor(0xff423607);
colors[ImGuiCol_BorderShadow] = ImColor();
colors[ImGuiCol_FrameBg] = ImColor(0xfc423607); // Customized
colors[ImGuiCol_FrameBgHovered] = ImColor(0xff423607);
colors[ImGuiCol_FrameBgActive] = ImColor(0xff423607);
colors[ImGuiCol_TitleBg] = ImColor(0xff362b00);
colors[ImGuiCol_TitleBgActive] = ImColor(0xff362b00);
colors[ImGuiCol_TitleBgCollapsed] = ImColor(0xff362b00);
colors[ImGuiCol_MenuBarBg] = ImColor(0xff423607);
colors[ImGuiCol_ScrollbarBg] = ImColor(0xff362b00);
colors[ImGuiCol_ScrollbarGrab] = ImColor(0xff423607);
colors[ImGuiCol_ScrollbarGrabHovered] = ImColor(0xff423607);
colors[ImGuiCol_ScrollbarGrabActive] = ImColor(0xff423607);
colors[ImGuiCol_CheckMark] = ImColor(0xff756e58);
colors[ImGuiCol_SliderGrab] = ImColor(0xff5e5025); // Customized
colors[ImGuiCol_SliderGrabActive] = ImColor(0xff5e5025); // Customized
colors[ImGuiCol_Button] = ImColor(0xff423607);
colors[ImGuiCol_ButtonHovered] = ImColor(0xff423607);
colors[ImGuiCol_ButtonActive] = ImColor(0xff362b00);
colors[ImGuiCol_Header] = ImColor(0xff423607);
colors[ImGuiCol_HeaderHovered] = ImColor(0xff423607);
colors[ImGuiCol_HeaderActive] = ImColor(0xff423607);
colors[ImGuiCol_Separator] = ImColor(0xff423607);
colors[ImGuiCol_SeparatorHovered] = ImColor(0xff423607);
colors[ImGuiCol_SeparatorActive] = ImColor(0xff423607);
colors[ImGuiCol_ResizeGrip] = ImColor(0xff423607);
colors[ImGuiCol_ResizeGripHovered] = ImColor(0xff423607);
colors[ImGuiCol_ResizeGripActive] = ImColor(0xff756e58);
colors[ImGuiCol_Tab] = ImColor(0xff362b00);
colors[ImGuiCol_TabHovered] = ImColor(0xff423607);
colors[ImGuiCol_TabActive] = ImColor(0xff423607);
colors[ImGuiCol_TabUnfocused] = ImColor(0xff362b00);
colors[ImGuiCol_TabUnfocusedActive] = ImColor(0xff423607);
colors[ImGuiCol_DockingPreview] = ImColor(0xee837b65); // Customized
colors[ImGuiCol_DockingEmptyBg] = ImColor();
colors[ImGuiCol_PlotLines] = ImColor(0xff756e58);
colors[ImGuiCol_PlotLinesHovered] = ImColor(0xff756e58);
colors[ImGuiCol_PlotHistogram] = ImColor(0xff756e58);
colors[ImGuiCol_PlotHistogramHovered] = ImColor(0xff756e58);
colors[ImGuiCol_TextSelectedBg] = ImColor(0xff756e58);
colors[ImGuiCol_DragDropTarget] = ImColor(0xff756e58);
colors[ImGuiCol_NavHighlight] = ImColor();
colors[ImGuiCol_NavWindowingHighlight] = ImColor(0xee969483); // Customized
colors[ImGuiCol_NavWindowingDimBg] = ImColor(0x20e3f6fd); // Customized
colors[ImGuiCol_ModalWindowDimBg] = ImColor(0x20e3f6fd); // Customized
break;
case 6:
colors[ImGuiCol_Text] = ImColor(0xff837b65);
colors[ImGuiCol_TextDisabled] = ImColor(0xffa1a193);
colors[ImGuiCol_WindowBg] = ImColor(0xffe3f6fd);
colors[ImGuiCol_ChildBg] = ImColor();
colors[ImGuiCol_PopupBg] = ImColor(0xfce3f6fd); // Customized
colors[ImGuiCol_Border] = ImColor(0xffd5e8ee);
colors[ImGuiCol_BorderShadow] = ImColor();
colors[ImGuiCol_FrameBg] = ImColor(0xfcd5e8ee); // Customized
colors[ImGuiCol_FrameBgHovered] = ImColor(0xffd5e8ee);
colors[ImGuiCol_FrameBgActive] = ImColor(0xffd5e8ee);
colors[ImGuiCol_TitleBg] = ImColor(0xffe3f6fd);
colors[ImGuiCol_TitleBgActive] = ImColor(0xffe3f6fd);
colors[ImGuiCol_TitleBgCollapsed] = ImColor(0xffe3f6fd);
colors[ImGuiCol_MenuBarBg] = ImColor(0xffd5e8ee);
colors[ImGuiCol_ScrollbarBg] = ImColor(0xffe3f6fd);
colors[ImGuiCol_ScrollbarGrab] = ImColor(0xffd5e8ee);
colors[ImGuiCol_ScrollbarGrabHovered] = ImColor(0xffd5e8ee);
colors[ImGuiCol_ScrollbarGrabActive] = ImColor(0xffd5e8ee);
colors[ImGuiCol_CheckMark] = ImColor(0xffa1a193);
colors[ImGuiCol_SliderGrab] = ImColor(0xffc3d3d9); // Customized
colors[ImGuiCol_SliderGrabActive] = ImColor(0xffc3d3d9); // Customized
colors[ImGuiCol_Button] = ImColor(0xffd5e8ee);
colors[ImGuiCol_ButtonHovered] = ImColor(0xffd5e8ee);
colors[ImGuiCol_ButtonActive] = ImColor(0xffe3f6fd);
colors[ImGuiCol_Header] = ImColor(0xffd5e8ee);
colors[ImGuiCol_HeaderHovered] = ImColor(0xffd5e8ee);
colors[ImGuiCol_HeaderActive] = ImColor(0xffd5e8ee);
colors[ImGuiCol_Separator] = ImColor(0xffd5e8ee);
colors[ImGuiCol_SeparatorHovered] = ImColor(0xffd5e8ee);
colors[ImGuiCol_SeparatorActive] = ImColor(0xffd5e8ee);
colors[ImGuiCol_ResizeGrip] = ImColor(0xffd5e8ee);
colors[ImGuiCol_ResizeGripHovered] = ImColor(0xffd5e8ee);
colors[ImGuiCol_ResizeGripActive] = ImColor(0xffa1a193);
colors[ImGuiCol_Tab] = ImColor(0xffe3f6fd);
colors[ImGuiCol_TabHovered] = ImColor(0xffd5e8ee);
colors[ImGuiCol_TabActive] = ImColor(0xffd5e8ee);
colors[ImGuiCol_TabUnfocused] = ImColor(0xffe3f6fd);
colors[ImGuiCol_TabUnfocusedActive] = ImColor(0xffd5e8ee);
colors[ImGuiCol_DockingPreview] = ImColor(0xeea1a193); // Customized
colors[ImGuiCol_DockingEmptyBg] = ImColor();
colors[ImGuiCol_PlotLines] = ImColor(0xffa1a193);
colors[ImGuiCol_PlotLinesHovered] = ImColor(0xffa1a193);
colors[ImGuiCol_PlotHistogram] = ImColor(0xffa1a193);
colors[ImGuiCol_PlotHistogramHovered] = ImColor(0xffa1a193);
colors[ImGuiCol_TextSelectedBg] = ImColor(0xffa1a193);
colors[ImGuiCol_DragDropTarget] = ImColor(0xffa1a193);
colors[ImGuiCol_NavHighlight] = ImColor();
colors[ImGuiCol_NavWindowingHighlight] = ImColor(0xee837b65); // Customized
colors[ImGuiCol_NavWindowingDimBg] = ImColor(0x20362b00); // Customized
colors[ImGuiCol_ModalWindowDimBg] = ImColor(0x20362b00); // Customized
break;
default:
for (ImGuiCol i = 0; i < ImGuiCol_COUNT; i++)
config.get("STYLE", ImGui::GetStyleColorName(i), (float(&)[4])colors[i]);
break;
}
switch (_editor_style_index)
{
case 0: // Dark
_editor_palette[code_editor::color_default] = 0xffffffff;
_editor_palette[code_editor::color_keyword] = 0xffd69c56;
_editor_palette[code_editor::color_number_literal] = 0xff00ff00;
_editor_palette[code_editor::color_string_literal] = 0xff7070e0;
_editor_palette[code_editor::color_punctuation] = 0xffffffff;
_editor_palette[code_editor::color_preprocessor] = 0xff409090;
_editor_palette[code_editor::color_identifier] = 0xffaaaaaa;
_editor_palette[code_editor::color_known_identifier] = 0xff9bc64d;
_editor_palette[code_editor::color_preprocessor_identifier] = 0xffc040a0;
_editor_palette[code_editor::color_comment] = 0xff206020;
_editor_palette[code_editor::color_multiline_comment] = 0xff406020;
_editor_palette[code_editor::color_background] = 0xff101010;
_editor_palette[code_editor::color_cursor] = 0xffe0e0e0;
_editor_palette[code_editor::color_selection] = 0x80a06020;
_editor_palette[code_editor::color_error_marker] = 0x800020ff;
_editor_palette[code_editor::color_warning_marker] = 0x8000ffff;
_editor_palette[code_editor::color_line_number] = 0xff707000;
_editor_palette[code_editor::color_current_line_fill] = 0x40000000;
_editor_palette[code_editor::color_current_line_fill_inactive] = 0x40808080;
_editor_palette[code_editor::color_current_line_edge] = 0x40a0a0a0;
break;
case 1: // Light
_editor_palette[code_editor::color_default] = 0xff000000;
_editor_palette[code_editor::color_keyword] = 0xffff0c06;
_editor_palette[code_editor::color_number_literal] = 0xff008000;
_editor_palette[code_editor::color_string_literal] = 0xff2020a0;
_editor_palette[code_editor::color_punctuation] = 0xff000000;
_editor_palette[code_editor::color_preprocessor] = 0xff409090;
_editor_palette[code_editor::color_identifier] = 0xff404040;
_editor_palette[code_editor::color_known_identifier] = 0xff606010;
_editor_palette[code_editor::color_preprocessor_identifier] = 0xffc040a0;
_editor_palette[code_editor::color_comment] = 0xff205020;
_editor_palette[code_editor::color_multiline_comment] = 0xff405020;
_editor_palette[code_editor::color_background] = 0xffffffff;
_editor_palette[code_editor::color_cursor] = 0xff000000;
_editor_palette[code_editor::color_selection] = 0x80600000;
_editor_palette[code_editor::color_error_marker] = 0xa00010ff;
_editor_palette[code_editor::color_warning_marker] = 0x8000ffff;
_editor_palette[code_editor::color_line_number] = 0xff505000;
_editor_palette[code_editor::color_current_line_fill] = 0x40000000;
_editor_palette[code_editor::color_current_line_fill_inactive] = 0x40808080;
_editor_palette[code_editor::color_current_line_edge] = 0x40000000;
break;
case 3: // Solarized Dark
_editor_palette[code_editor::color_default] = 0xff969483;
_editor_palette[code_editor::color_keyword] = 0xff0089b5;
_editor_palette[code_editor::color_number_literal] = 0xff98a12a;
_editor_palette[code_editor::color_string_literal] = 0xff98a12a;
_editor_palette[code_editor::color_punctuation] = 0xff969483;
_editor_palette[code_editor::color_preprocessor] = 0xff164bcb;
_editor_palette[code_editor::color_identifier] = 0xff969483;
_editor_palette[code_editor::color_known_identifier] = 0xff969483;
_editor_palette[code_editor::color_preprocessor_identifier] = 0xffc4716c;
_editor_palette[code_editor::color_comment] = 0xff756e58;
_editor_palette[code_editor::color_multiline_comment] = 0xff756e58;
_editor_palette[code_editor::color_background] = 0xff362b00;
_editor_palette[code_editor::color_cursor] = 0xff969483;
_editor_palette[code_editor::color_selection] = 0xa0756e58;
_editor_palette[code_editor::color_error_marker] = 0x7f2f32dc;
_editor_palette[code_editor::color_warning_marker] = 0x7f0089b5;
_editor_palette[code_editor::color_line_number] = 0xff756e58;
_editor_palette[code_editor::color_current_line_fill] = 0x7f423607;
_editor_palette[code_editor::color_current_line_fill_inactive] = 0x7f423607;
_editor_palette[code_editor::color_current_line_edge] = 0x7f423607;
break;
case 4: // Solarized Light
_editor_palette[code_editor::color_default] = 0xff837b65;
_editor_palette[code_editor::color_keyword] = 0xff0089b5;
_editor_palette[code_editor::color_number_literal] = 0xff98a12a;
_editor_palette[code_editor::color_string_literal] = 0xff98a12a;
_editor_palette[code_editor::color_punctuation] = 0xff756e58;
_editor_palette[code_editor::color_preprocessor] = 0xff164bcb;
_editor_palette[code_editor::color_identifier] = 0xff837b65;
_editor_palette[code_editor::color_known_identifier] = 0xff837b65;
_editor_palette[code_editor::color_preprocessor_identifier] = 0xffc4716c;
_editor_palette[code_editor::color_comment] = 0xffa1a193;
_editor_palette[code_editor::color_multiline_comment] = 0xffa1a193;
_editor_palette[code_editor::color_background] = 0xffe3f6fd;
_editor_palette[code_editor::color_cursor] = 0xff837b65;
_editor_palette[code_editor::color_selection] = 0x60a1a193;
_editor_palette[code_editor::color_error_marker] = 0x7f2f32dc;
_editor_palette[code_editor::color_warning_marker] = 0x7f0089b5;
_editor_palette[code_editor::color_line_number] = 0xffa1a193;
_editor_palette[code_editor::color_current_line_fill] = 0x7fd5e8ee;
_editor_palette[code_editor::color_current_line_fill_inactive] = 0x7fd5e8ee;
_editor_palette[code_editor::color_current_line_edge] = 0x7fd5e8ee;
break;
default:
case 2:
ImVec4 value;
for (ImGuiCol i = 0; i < code_editor::color_palette_max; i++)
value = ImGui::ColorConvertU32ToFloat4(_editor_palette[i]), // Get default value first
config.get("STYLE", code_editor::get_palette_color_name(i), (float(&)[4])value),
_editor_palette[i] = ImGui::ColorConvertFloat4ToU32(value);
break;
}
}
void reshade::runtime::save_custom_style()
{
ini_file &config = ini_file::load_cache(_config_path);
if (_style_index == 3 || _style_index == 4) // Custom Simple, Custom Advanced
{
for (ImGuiCol i = 0; i < ImGuiCol_COUNT; i++)
config.set("STYLE", ImGui::GetStyleColorName(i), (const float(&)[4])_imgui_context->Style.Colors[i]);
}
if (_editor_style_index == 2) // Custom
{
ImVec4 value;
for (ImGuiCol i = 0; i < code_editor::color_palette_max; i++)
value = ImGui::ColorConvertU32ToFloat4(_editor_palette[i]),
config.set("STYLE", code_editor::get_palette_color_name(i), (const float(&)[4])value);
}
}
void reshade::runtime::draw_gui()
{
assert(_is_initialized);
bool show_splash = _show_splash && (is_loading() || !_reload_compile_queue.empty() || (_reload_count <= 1 && (_last_present_time - _last_reload_time) < std::chrono::seconds(5)));
// Do not show this message in the same frame the screenshot is taken (so that it won't show up on the GUI screenshot)
const bool show_screenshot_message = (_show_screenshot_message || !_screenshot_save_success) && !_should_save_screenshot && (_last_present_time - _last_screenshot_time) < std::chrono::seconds(_screenshot_save_success ? 3 : 5);
if (show_screenshot_message || !_preset_save_success || (!_show_overlay && _tutorial_index == 0))
show_splash = true;
const bool show_stats_window = _show_clock || _show_fps || _show_frametime;
if (_show_overlay && !_ignore_shortcuts && !_imgui_context->IO.NavVisible && _input->is_key_pressed(0x1B /* VK_ESCAPE */))
_show_overlay = false; // Close when pressing the escape button and not currently navigating with the keyboard
else if (!_ignore_shortcuts && _input->is_key_pressed(_overlay_key_data, _force_shortcut_modifiers) && _imgui_context->ActiveId == 0)
_show_overlay = !_show_overlay;
_ignore_shortcuts = false;
_effects_expanded_state &= 2;
if (!show_splash && !show_stats_window && !_show_overlay && _preview_texture == nullptr)
{
_input->block_mouse_input(false);
_input->block_keyboard_input(false);
return; // Early-out to avoid costly ImGui calls when no GUI elements are on the screen
}
if (_rebuild_font_atlas)
build_font_atlas();
if (_imgui_font_atlas == nullptr)
return; // Cannot render GUI without font atlas
ImGui::SetCurrentContext(_imgui_context);
auto &imgui_io = _imgui_context->IO;
imgui_io.DeltaTime = _last_frame_duration.count() * 1e-9f;
imgui_io.MouseDrawCursor = _show_overlay && (!_should_save_screenshot || !_screenshot_save_gui);
imgui_io.MousePos.x = static_cast<float>(_input->mouse_position_x());
imgui_io.MousePos.y = static_cast<float>(_input->mouse_position_y());
imgui_io.DisplaySize.x = static_cast<float>(_width);
imgui_io.DisplaySize.y = static_cast<float>(_height);
imgui_io.Fonts->TexID = _imgui_font_atlas->impl;
// Add wheel delta to the current absolute mouse wheel position
imgui_io.MouseWheel += _input->mouse_wheel_delta();
// Scale mouse position in case render resolution does not match the window size
if (_window_width != 0 && _window_height != 0)
{
imgui_io.MousePos.x *= imgui_io.DisplaySize.x / _window_width;
imgui_io.MousePos.y *= imgui_io.DisplaySize.y / _window_height;
}
// Update all the button states
imgui_io.KeyAlt = _input->is_key_down(0x12); // VK_MENU
imgui_io.KeyCtrl = _input->is_key_down(0x11); // VK_CONTROL
imgui_io.KeyShift = _input->is_key_down(0x10); // VK_SHIFT
for (unsigned int i = 0; i < 256; i++)
imgui_io.KeysDown[i] = _input->is_key_down(i);
for (unsigned int i = 0; i < 5; i++)
imgui_io.MouseDown[i] = _input->is_mouse_button_down(i);
for (wchar_t c : _input->text_input())
imgui_io.AddInputCharacter(c);
ImGui::NewFrame();
ImVec2 viewport_offset = ImVec2(0, 0);
// Create ImGui widgets and windows
if (show_splash)
{
ImGui::SetNextWindowPos(ImVec2(10, 10));
ImGui::SetNextWindowSize(ImVec2(imgui_io.DisplaySize.x - 20.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 1.0f);
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.862745f, 0.862745f, 0.862745f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.117647f, 0.117647f, 0.117647f, 0.7f));
ImGui::Begin("Splash Screen", nullptr,
ImGuiWindowFlags_NoDecoration |
ImGuiWindowFlags_NoNav |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoInputs |
ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoDocking |
ImGuiWindowFlags_NoFocusOnAppearing);
if (!_preset_save_success)
{
ImGui::TextColored(COLOR_RED, "Unable to save current preset. Make sure you have write permissions to %s.", _current_preset_path.u8string().c_str());
}
else if (show_screenshot_message)
{
if (!_screenshot_save_success)
if (std::error_code ec; std::filesystem::exists(_screenshot_path, ec))
ImGui::TextColored(COLOR_RED, "Unable to save screenshot because of an internal error (the format may not be supported).");
else
ImGui::TextColored(COLOR_RED, "Unable to save screenshot because path doesn't exist: %s.", _screenshot_path.u8string().c_str());
else
ImGui::Text("Screenshot successfully saved to %s", _last_screenshot_file.u8string().c_str());
}
else
{
ImGui::TextUnformatted("ReShade " VERSION_STRING_PRODUCT);
if (_needs_update)
{
ImGui::TextColored(COLOR_YELLOW,
"An update is available! Please visit https://reshade.me and install the new version (v%lu.%lu.%lu).",
_latest_version[0], _latest_version[1], _latest_version[2]);
}
else
{
ImGui::TextUnformatted("Visit https://reshade.me for news, updates, effects and discussion.");
}
ImGui::Spacing();
if (_reload_remaining_effects != 0 && _reload_remaining_effects != std::numeric_limits<size_t>::max())
{
ImGui::ProgressBar((_effects.size() - _reload_remaining_effects) / float(_effects.size()), ImVec2(-1, 0), "");
ImGui::SameLine(15);
ImGui::Text(
"Loading (%zu effects remaining) ... "
"This might take a while. The application could become unresponsive for some time.",
_reload_remaining_effects.load());
}
else if (!_reload_compile_queue.empty())
{
ImGui::ProgressBar((_effects.size() - _reload_compile_queue.size()) / float(_effects.size()), ImVec2(-1, 0), "");
ImGui::SameLine(15);
ImGui::Text(
"Compiling (%zu effects remaining) ... "
"This might take a while. The application could become unresponsive for some time.",
_reload_compile_queue.size());
}
else if (_tutorial_index == 0)
{
ImGui::ProgressBar(0.0f, ImVec2(-1, 0), "");
ImGui::SameLine(15);
ImGui::TextUnformatted("ReShade is now installed successfully! Press '");
ImGui::SameLine(0.0f, 0.0f);
ImGui::TextColored(ImVec4(1, 1, 1, 1), "%s", input::key_name(_overlay_key_data).c_str());
ImGui::SameLine(0.0f, 0.0f);
ImGui::TextUnformatted("' to start the tutorial.");
}
else
{
ImGui::ProgressBar(0.0f, ImVec2(-1, 0), "");
ImGui::SameLine(15);
ImGui::TextUnformatted("Press '");
ImGui::SameLine(0.0f, 0.0f);
ImGui::TextColored(ImVec4(1, 1, 1, 1), "%s", input::key_name(_overlay_key_data).c_str());
ImGui::SameLine(0.0f, 0.0f);
ImGui::TextUnformatted("' to open the configuration overlay.");
}
if (!_last_reload_successfull)
{
ImGui::Spacing();
ImGui::TextColored(COLOR_RED,
"There were errors compiling some effects. Check the log for more details.");
}
}
viewport_offset.y += ImGui::GetWindowHeight() + 10; // Add small space between windows
ImGui::End();
ImGui::PopStyleColor(2);
ImGui::PopStyleVar();
}
else if (show_stats_window)
{
float window_height = _imgui_context->FontBaseSize * _fps_scale + _imgui_context->Style.ItemSpacing.y;
window_height *= (_show_clock ? 1 : 0) + (_show_fps ? 1 : 0) + (_show_frametime ? 1 : 0);
window_height += _imgui_context->Style.FramePadding.y * 4.0f;
ImVec2 fps_window_pos(5, 5);
if (_fps_pos % 2)
fps_window_pos.x = imgui_io.DisplaySize.x - 200.0f;
if (_fps_pos > 1)
fps_window_pos.y = imgui_io.DisplaySize.y - window_height - 5;
ImGui::SetNextWindowPos(fps_window_pos);
ImGui::SetNextWindowSize(ImVec2(200.0f, window_height));
ImGui::PushStyleColor(ImGuiCol_Text, (const ImVec4 &)_fps_col);
ImGui::Begin("FPS", nullptr,
ImGuiWindowFlags_NoDecoration |
ImGuiWindowFlags_NoNav |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoInputs |
ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoDocking |
ImGuiWindowFlags_NoFocusOnAppearing |
ImGuiWindowFlags_NoBackground);
ImGui::SetWindowFontScale(_fps_scale);
char temp[512];
if (_show_clock)
{
const std::time_t t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
tm tm; localtime_s(&tm, &t);
ImFormatString(temp, sizeof(temp), _clock_format != 0 ? "%02u:%02u:%02u" : "%02u:%02u", tm.tm_hour, tm.tm_min, tm.tm_sec);
if (_fps_pos % 2) // Align text to the right of the window
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionWidth() - ImGui::CalcTextSize(temp).x);
ImGui::TextUnformatted(temp);
}
if (_show_fps)
{
ImFormatString(temp, sizeof(temp), "%.0f fps", imgui_io.Framerate);
if (_fps_pos % 2)
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionWidth() - ImGui::CalcTextSize(temp).x);
ImGui::TextUnformatted(temp);
}
if (_show_frametime)
{
ImFormatString(temp, sizeof(temp), "%5.2f ms", 1000.0f / imgui_io.Framerate);
if (_fps_pos % 2)
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionWidth() - ImGui::CalcTextSize(temp).x);
ImGui::TextUnformatted(temp);
}
ImGui::End();
ImGui::PopStyleColor();
}
if (_show_overlay)
{
// Change font size if user presses the control key and moves the mouse wheel
if (imgui_io.KeyCtrl && imgui_io.MouseWheel != 0 && !_no_font_scaling)
{
_font_size = ImClamp(_font_size + static_cast<int>(imgui_io.MouseWheel), 8, 32);
_editor_font_size = ImClamp(_editor_font_size + static_cast<int>(imgui_io.MouseWheel), 8, 32);
_rebuild_font_atlas = true;
save_config();
}
const ImGuiID root_space_id = ImGui::GetID("Dockspace");
const ImGuiViewport *const viewport = ImGui::GetMainViewport();
// Set up default dock layout if this was not done yet
const bool init_window_layout = !ImGui::DockBuilderGetNode(root_space_id);
if (init_window_layout)
{
// Add the root node
ImGui::DockBuilderAddNode(root_space_id, ImGuiDockNodeFlags_DockSpace);
ImGui::DockBuilderSetNodeSize(root_space_id, viewport->Size);
// Split root node into two spaces
ImGuiID main_space_id = 0;
ImGuiID right_space_id = 0;
ImGui::DockBuilderSplitNode(root_space_id, ImGuiDir_Left, 0.35f, &main_space_id, &right_space_id);
// Attach most windows to the main dock space
for (const auto &widget : _menu_callables)
ImGui::DockBuilderDockWindow(widget.first.c_str(), main_space_id);
// Attach editor window to the remaining dock space
ImGui::DockBuilderDockWindow("###editor", right_space_id);
// Commit the layout
ImGui::DockBuilderFinish(root_space_id);
}
ImGui::SetNextWindowPos(viewport->Pos + viewport_offset);
ImGui::SetNextWindowSize(viewport->Size - viewport_offset);
ImGui::SetNextWindowViewport(viewport->ID);
ImGui::Begin("Viewport", nullptr,
ImGuiWindowFlags_NoDecoration |
ImGuiWindowFlags_NoNav |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoDocking | // This is the background viewport, the docking space is a child of it
ImGuiWindowFlags_NoFocusOnAppearing |
ImGuiWindowFlags_NoBringToFrontOnFocus |
ImGuiWindowFlags_NoBackground);
ImGui::DockSpace(root_space_id, ImVec2(0, 0), ImGuiDockNodeFlags_PassthruCentralNode);
ImGui::End();
for (const auto &widget : _menu_callables)
{
if (ImGui::Begin(widget.first.c_str(), nullptr, ImGuiWindowFlags_NoFocusOnAppearing)) // No focus so that window state is preserved between opening/closing the GUI
widget.second();
ImGui::End();
}
#if RESHADE_ADDON
if (g_addons_enabled)
{
for (const auto &widget : addon::overlay_list)
{
if (ImGui::Begin(widget.first.c_str(), nullptr, ImGuiWindowFlags_NoFocusOnAppearing))
widget.second(this, _imgui_context);
ImGui::End();
}
}
#endif
if (!_editors.empty())
{
if (ImGui::Begin("Edit###editor", nullptr, ImGuiWindowFlags_NoFocusOnAppearing) &&
ImGui::BeginTabBar("editor_tabs"))
{
for (auto it = _editors.begin(); it != _editors.end();)
{
std::string title = it->entry_point_name.empty() ? it->file_path.filename().u8string() : it->entry_point_name;
title += " ###editor" + std::to_string(std::distance(_editors.begin(), it));
bool is_open = true;
ImGuiTabItemFlags flags = ImGuiTabItemFlags_None;
if (it->editor.is_modified())
flags |= ImGuiTabItemFlags_UnsavedDocument;
if (it->selected)
flags |= ImGuiTabItemFlags_SetSelected;
if (ImGui::BeginTabItem(title.c_str(), &is_open, flags))
{
draw_code_editor(*it);
ImGui::EndTabItem();
}
it->selected = false;
if (!is_open)
it = _editors.erase(it);
else
++it;
}
ImGui::EndTabBar();
}
ImGui::End();
}
}
if (_preview_texture != nullptr && _effects_enabled)
{
if (!_show_overlay)
{
// Create a temporary viewport window to attach image to when overlay is not open
ImGui::SetNextWindowPos(ImVec2(0, 0));
ImGui::SetNextWindowSize(ImVec2(imgui_io.DisplaySize.x, imgui_io.DisplaySize.y));
ImGui::Begin("Viewport", nullptr,
ImGuiWindowFlags_NoDecoration |
ImGuiWindowFlags_NoNav |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoDocking |
ImGuiWindowFlags_NoFocusOnAppearing |
ImGuiWindowFlags_NoBringToFrontOnFocus |
ImGuiWindowFlags_NoBackground);
ImGui::End();
}
// The preview texture is unset in 'unload_effects', so should not be able to reach this while loading
assert(!is_loading() && _reload_compile_queue.empty());
// Scale image to fill the entire viewport by default
ImVec2 preview_min = ImVec2(0, 0);
ImVec2 preview_max = imgui_io.DisplaySize;
// Positing image in the middle of the viewport when using original size
if (_preview_size[0])
{
preview_min.x = (preview_max.x * 0.5f) - (_preview_size[0] * 0.5f);
preview_max.x = (preview_max.x * 0.5f) + (_preview_size[0] * 0.5f);
}
if (_preview_size[1])
{
preview_min.y = (preview_max.y * 0.5f) - (_preview_size[1] * 0.5f);
preview_max.y = (preview_max.y * 0.5f) + (_preview_size[1] * 0.5f);
}
ImGui::FindWindowByName("Viewport")->DrawList->AddImage(_preview_texture, preview_min, preview_max, ImVec2(0, 0), ImVec2(1, 1), _preview_size[2]);
}
// Disable keyboard shortcuts while typing into input boxes
_ignore_shortcuts |= ImGui::IsAnyItemActive();
// Render ImGui widgets and windows
ImGui::Render();
_input->block_mouse_input(_input_processing_mode != 0 && _show_overlay && (imgui_io.WantCaptureMouse || _input_processing_mode == 2));
_input->block_keyboard_input(_input_processing_mode != 0 && _show_overlay && (imgui_io.WantCaptureKeyboard || _input_processing_mode == 2));
if (_input->is_blocking_mouse_input())
{
// Some games setup ClipCursor with a tiny area which could make the cursor stay in that area instead of the whole window
ClipCursor(nullptr);
}
if (ImDrawData *const draw_data = ImGui::GetDrawData();
draw_data != nullptr && draw_data->CmdListsCount != 0 && draw_data->TotalVtxCount != 0)
render_imgui_draw_data(draw_data);
}
void reshade::runtime::draw_gui_home()
{
const char *tutorial_text =
"Welcome! Since this is the first time you start ReShade, we'll go through a quick tutorial covering the most important features.\n\n"
"If you have difficulties reading this text, press the 'Ctrl' key and adjust the font size with your mouse wheel. "
"The window size is variable as well, just grab the right edge and move it around.\n\n"
"You can also use the keyboard for navigation in case mouse input does not work. Use the arrow keys to navigate, space bar to confirm an action or enter a control and the 'Esc' key to leave a control. "
"Press 'Ctrl + Tab' to switch between tabs and windows (use this to focus this page in case the other navigation keys do not work at first).\n\n"
"Click on the 'Continue' button to continue the tutorial.";
// It is not possible to follow some of the tutorial steps while performance mode is active, so skip them
if (_performance_mode && _tutorial_index <= 3)
_tutorial_index = 4;
if (_tutorial_index > 0)
{
if (_tutorial_index == 1)
{
tutorial_text =
"This is the preset selection. All changes will be saved to the selected preset file.\n\n"
"Click on the '+' button to name and add a new one.\n\n"
"Make sure you always have a preset selected here before starting to tweak any values later, or else your changes won't be saved!";
ImGui::PushStyleColor(ImGuiCol_FrameBg, COLOR_RED);
ImGui::PushStyleColor(ImGuiCol_Button, COLOR_RED);
}
const float button_size = ImGui::GetFrameHeight();
const float button_spacing = _imgui_context->Style.ItemInnerSpacing.x;
const float browse_button_width = ImGui::GetWindowContentRegionWidth() - (button_spacing + button_size) * 3;
bool reload_preset = false;
ImGuiButtonFlags button_flags = ImGuiButtonFlags_NoNavFocus;
if (is_loading())
{
button_flags |= ImGuiButtonFlags_Disabled;
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));
}
if (ImGui::ArrowButtonEx("<", ImGuiDir_Left, ImVec2(button_size, button_size), button_flags))
if (switch_to_next_preset(_current_preset_path.parent_path(), true))
reload_preset = true;
ImGui::SameLine(0, button_spacing);
if (ImGui::ArrowButtonEx(">", ImGuiDir_Right, ImVec2(button_size, button_size), button_flags))
if (switch_to_next_preset(_current_preset_path.parent_path(), false))
reload_preset = true;
ImGui::SameLine(0, button_spacing);
const ImVec2 popup_pos = ImGui::GetCursorScreenPos() + ImVec2(-_imgui_context->Style.WindowPadding.x, ImGui::GetFrameHeightWithSpacing());
ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.0f, 0.5f));
if (ImGui::ButtonEx(_current_preset_path.stem().u8string().c_str(), ImVec2(browse_button_width, 0), button_flags))
{
_file_selection_path = _current_preset_path;
ImGui::OpenPopup("##browse");
}
ImGui::PopStyleVar();
ImGui::SameLine(0, button_spacing);
if (ImGui::ButtonEx(ICON_FK_PLUS, ImVec2(button_size, 0), button_flags | ImGuiButtonFlags_PressedOnClick))
{
_file_selection_path = _current_preset_path.parent_path();
ImGui::OpenPopup("##create");
}
if (is_loading())
ImGui::PopStyleColor();
ImGui::SetNextWindowPos(popup_pos);
if (widgets::file_dialog("##browse", _file_selection_path, browse_button_width, { L".ini", L".txt" }))
{
// Check that this is actually a valid preset file
if (ini_file::load_cache(_file_selection_path).has("", "Techniques"))
{
reload_preset = true;