forked from crosire/reshade
-
Notifications
You must be signed in to change notification settings - Fork 11
/
runtime_gui.cpp
4037 lines (3418 loc) · 155 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
* SPDX-License-Identifier: BSD-3-Clause
*/
#if RESHADE_GUI
#include "version.h"
#include "dll_log.hpp"
#include "dll_resources.hpp"
#include "ini_file.hpp"
#include "addon_manager.hpp"
#include "runtime.hpp"
#include "runtime_objects.hpp"
#include "input.hpp"
#include "input_gamepad.hpp"
#include "imgui_widgets.hpp"
#include "process_utils.hpp"
#include "fonts/forkawesome.inl"
#include <fstream>
#include <algorithm>
static bool filter_text(const std::string_view &text, const std::string_view &filter)
{
return filter.empty() ||
std::search(text.begin(), text.end(), filter.begin(), filter.end(),
[](const char c1, const char c2) { // Search case-insensitive
return (('a' <= c1 && c1 <= 'z') ? static_cast<char>(c1 - ' ') : c1) == (('a' <= c2 && c2 <= 'z') ? static_cast<char>(c2 - ' ') : c2);
}) != text.end();
}
template <typename F>
static void parse_errors(const std::string_view &errors, F &&callback)
{
for (size_t offset = 0, next; offset != std::string::npos; offset = next)
{
const size_t pos_error = errors.find(": ", offset);
const size_t pos_error_line = errors.rfind('(', pos_error); // Paths can contain '(', but no ": ", so search backwards from th error location to find the line info
if (pos_error == std::string::npos || pos_error_line == std::string::npos)
break;
const size_t pos_linefeed = errors.find('\n', pos_error);
next = pos_linefeed != std::string::npos ? pos_linefeed + 1 : std::string::npos;
const std::string error_file(errors.data() + offset, pos_error_line - offset);
int error_line = std::strtol(errors.data() + pos_error_line + 1, nullptr, 10);
const std::string error_text(errors.substr(pos_error + 2 /* skip space */, pos_linefeed - pos_error - 2));
callback(error_file, error_line, error_text);
}
}
static const ImVec4 COLOR_RED = ImColor(240, 100, 100);
static const ImVec4 COLOR_YELLOW = ImColor(204, 204, 0);
void reshade::runtime::init_gui()
{
// 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();
ImGuiIO &imgui_io = _imgui_context->IO;
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;
ImGuiStyle &imgui_style = _imgui_context->Style;
// 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);
}
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 (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;
std::error_code ec;
if (!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);
constexpr 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())
{
LOG(ERROR) << "Failed to build front atlas!";
_font.clear();
_editor_font.clear();
atlas->Clear();
for (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);
// Make sure font atlas is not currently in use before destroying it
_graphics_queue->wait_idle();
_device->destroy_resource(_font_atlas_tex);
_font_atlas_tex = {};
_device->destroy_resource_view(_font_atlas_srv);
_font_atlas_srv = {};
const api::subresource_data initial_data = { pixels, static_cast<uint32_t>(width * 4), static_cast<uint32_t>(width * height * 4) };
// Create font atlas texture and upload it
if (!_device->create_resource(
api::resource_desc(width, height, 1, 1, api::format::r8g8b8a8_unorm, 1, api::memory_heap::gpu_only, api::resource_usage::shader_resource),
&initial_data, api::resource_usage::shader_resource, &_font_atlas_tex))
{
LOG(ERROR) << "Failed to create front atlas resource!";
return;
}
if (!_device->create_resource_view(_font_atlas_tex, api::resource_usage::shader_resource, api::resource_view_desc(api::format::r8g8b8a8_unorm), &_font_atlas_srv))
{
LOG(ERROR) << "Failed to create font atlas resource view!";
return;
}
_device->set_resource_name(_font_atlas_tex, "ImGui font atlas");
}
void reshade::runtime::load_config_gui(const ini_file &config)
{
if (_input_gamepad != nullptr)
_imgui_context->IO.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
else
_imgui_context->IO.ConfigFlags &= ~ImGuiConfigFlags_NavEnableGamepad;
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);
#if RESHADE_FX
config.get("OVERLAY", "ShowForceLoadEffectsButton", _show_force_load_effects_button);
#endif
config.get("OVERLAY", "ShowFPS", _show_fps);
config.get("OVERLAY", "ShowFrameTime", _show_frametime);
config.get("OVERLAY", "ShowScreenshotMessage", _show_screenshot_message);
#if RESHADE_FX
config.get("OVERLAY", "TutorialProgress", _tutorial_index);
config.get("OVERLAY", "VariableListHeight", _variable_editor_height);
config.get("OVERLAY", "VariableListUseTabs", _variable_editor_tabs);
config.get("OVERLAY", "SavePresetOnModification", _save_present_on_modification);
#endif
ImGuiStyle &imgui_style = _imgui_context->Style;
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();
if (_imgui_context->SettingsLoaded)
return;
ImGuiContext *const backup_context = ImGui::GetCurrentContext();
ImGui::SetCurrentContext(_imgui_context);
// Call all pre-read handlers, before reading config data (since they affect state that is then updated in the read handlers below)
for (ImGuiSettingsHandler &handler : _imgui_context->SettingsHandlers)
if (handler.ReadInitFn)
handler.ReadInitFn(_imgui_context, &handler);
for (ImGuiSettingsHandler &handler : _imgui_context->SettingsHandlers)
{
std::vector<std::string> lines;
if (config.get("OVERLAY", handler.TypeName, lines))
{
void *entry_data = nullptr;
for (const std::string &line : lines)
{
if (line.empty())
continue;
if (line[0] == '[')
{
const size_t name_beg = line.find('[', 1) + 1;
const size_t name_end = line.rfind(']');
entry_data = handler.ReadOpenFn(_imgui_context, &handler, line.substr(name_beg, name_end - name_beg).c_str());
}
else
{
assert(entry_data != nullptr);
handler.ReadLineFn(_imgui_context, &handler, entry_data, line.c_str());
}
}
}
}
_imgui_context->SettingsLoaded = true;
for (ImGuiSettingsHandler &handler : _imgui_context->SettingsHandlers)
if (handler.ApplyAllFn)
handler.ApplyAllFn(_imgui_context, &handler);
ImGui::SetCurrentContext(backup_context);
}
void reshade::runtime::save_config_gui(ini_file &config) const
{
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);
#if RESHADE_FX
config.set("OVERLAY", "ShowForceLoadEffectsButton", _show_force_load_effects_button);
#endif
config.set("OVERLAY", "ShowFPS", _show_fps);
config.set("OVERLAY", "ShowFrameTime", _show_frametime);
config.set("OVERLAY", "ShowScreenshotMessage", _show_screenshot_message);
#if RESHADE_FX
config.set("OVERLAY", "TutorialProgress", _tutorial_index);
config.set("OVERLAY", "VariableListHeight", _variable_editor_height);
config.set("OVERLAY", "VariableListUseTabs", _variable_editor_tabs);
config.set("OVERLAY", "SavePresetOnModification", _save_present_on_modification);
#endif
const ImGuiStyle &imgui_style = _imgui_context->Style;
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
ImGuiContext *const backup_context = ImGui::GetCurrentContext();
ImGui::SetCurrentContext(_imgui_context);
for (ImGuiSettingsHandler &handler : _imgui_context->SettingsHandlers)
{
ImGuiTextBuffer buffer;
handler.WriteAllFn(_imgui_context, &handler, &buffer);
std::vector<std::string> lines;
for (int i = 0, offset = 0; i < buffer.size(); ++i)
{
if (buffer[i] == '\n')
{
lines.emplace_back(buffer.c_str() + offset, i - offset);
offset = i + 1;
}
}
if (!lines.empty())
config.set("OVERLAY", handler.TypeName, lines);
}
ImGui::SetCurrentContext(backup_context);
}
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[imgui::code_editor::color_default] = 0xffffffff;
_editor_palette[imgui::code_editor::color_keyword] = 0xffd69c56;
_editor_palette[imgui::code_editor::color_number_literal] = 0xff00ff00;
_editor_palette[imgui::code_editor::color_string_literal] = 0xff7070e0;
_editor_palette[imgui::code_editor::color_punctuation] = 0xffffffff;
_editor_palette[imgui::code_editor::color_preprocessor] = 0xff409090;
_editor_palette[imgui::code_editor::color_identifier] = 0xffaaaaaa;
_editor_palette[imgui::code_editor::color_known_identifier] = 0xff9bc64d;
_editor_palette[imgui::code_editor::color_preprocessor_identifier] = 0xffc040a0;
_editor_palette[imgui::code_editor::color_comment] = 0xff206020;
_editor_palette[imgui::code_editor::color_multiline_comment] = 0xff406020;
_editor_palette[imgui::code_editor::color_background] = 0xff101010;
_editor_palette[imgui::code_editor::color_cursor] = 0xffe0e0e0;
_editor_palette[imgui::code_editor::color_selection] = 0x80a06020;
_editor_palette[imgui::code_editor::color_error_marker] = 0x800020ff;
_editor_palette[imgui::code_editor::color_warning_marker] = 0x8000ffff;
_editor_palette[imgui::code_editor::color_line_number] = 0xff707000;
_editor_palette[imgui::code_editor::color_current_line_fill] = 0x40000000;
_editor_palette[imgui::code_editor::color_current_line_fill_inactive] = 0x40808080;
_editor_palette[imgui::code_editor::color_current_line_edge] = 0x40a0a0a0;
break;
case 1: // Light
_editor_palette[imgui::code_editor::color_default] = 0xff000000;
_editor_palette[imgui::code_editor::color_keyword] = 0xffff0c06;
_editor_palette[imgui::code_editor::color_number_literal] = 0xff008000;
_editor_palette[imgui::code_editor::color_string_literal] = 0xff2020a0;
_editor_palette[imgui::code_editor::color_punctuation] = 0xff000000;
_editor_palette[imgui::code_editor::color_preprocessor] = 0xff409090;
_editor_palette[imgui::code_editor::color_identifier] = 0xff404040;
_editor_palette[imgui::code_editor::color_known_identifier] = 0xff606010;
_editor_palette[imgui::code_editor::color_preprocessor_identifier] = 0xffc040a0;
_editor_palette[imgui::code_editor::color_comment] = 0xff205020;
_editor_palette[imgui::code_editor::color_multiline_comment] = 0xff405020;
_editor_palette[imgui::code_editor::color_background] = 0xffffffff;
_editor_palette[imgui::code_editor::color_cursor] = 0xff000000;
_editor_palette[imgui::code_editor::color_selection] = 0x80600000;
_editor_palette[imgui::code_editor::color_error_marker] = 0xa00010ff;
_editor_palette[imgui::code_editor::color_warning_marker] = 0x8000ffff;
_editor_palette[imgui::code_editor::color_line_number] = 0xff505000;
_editor_palette[imgui::code_editor::color_current_line_fill] = 0x40000000;
_editor_palette[imgui::code_editor::color_current_line_fill_inactive] = 0x40808080;
_editor_palette[imgui::code_editor::color_current_line_edge] = 0x40000000;
break;
case 3: // Solarized Dark
_editor_palette[imgui::code_editor::color_default] = 0xff969483;
_editor_palette[imgui::code_editor::color_keyword] = 0xff0089b5;
_editor_palette[imgui::code_editor::color_number_literal] = 0xff98a12a;
_editor_palette[imgui::code_editor::color_string_literal] = 0xff98a12a;
_editor_palette[imgui::code_editor::color_punctuation] = 0xff969483;
_editor_palette[imgui::code_editor::color_preprocessor] = 0xff164bcb;
_editor_palette[imgui::code_editor::color_identifier] = 0xff969483;
_editor_palette[imgui::code_editor::color_known_identifier] = 0xff969483;
_editor_palette[imgui::code_editor::color_preprocessor_identifier] = 0xffc4716c;
_editor_palette[imgui::code_editor::color_comment] = 0xff756e58;
_editor_palette[imgui::code_editor::color_multiline_comment] = 0xff756e58;
_editor_palette[imgui::code_editor::color_background] = 0xff362b00;
_editor_palette[imgui::code_editor::color_cursor] = 0xff969483;
_editor_palette[imgui::code_editor::color_selection] = 0xa0756e58;
_editor_palette[imgui::code_editor::color_error_marker] = 0x7f2f32dc;
_editor_palette[imgui::code_editor::color_warning_marker] = 0x7f0089b5;
_editor_palette[imgui::code_editor::color_line_number] = 0xff756e58;
_editor_palette[imgui::code_editor::color_current_line_fill] = 0x7f423607;
_editor_palette[imgui::code_editor::color_current_line_fill_inactive] = 0x7f423607;
_editor_palette[imgui::code_editor::color_current_line_edge] = 0x7f423607;
break;
case 4: // Solarized Light
_editor_palette[imgui::code_editor::color_default] = 0xff837b65;
_editor_palette[imgui::code_editor::color_keyword] = 0xff0089b5;
_editor_palette[imgui::code_editor::color_number_literal] = 0xff98a12a;
_editor_palette[imgui::code_editor::color_string_literal] = 0xff98a12a;
_editor_palette[imgui::code_editor::color_punctuation] = 0xff756e58;
_editor_palette[imgui::code_editor::color_preprocessor] = 0xff164bcb;
_editor_palette[imgui::code_editor::color_identifier] = 0xff837b65;
_editor_palette[imgui::code_editor::color_known_identifier] = 0xff837b65;
_editor_palette[imgui::code_editor::color_preprocessor_identifier] = 0xffc4716c;
_editor_palette[imgui::code_editor::color_comment] = 0xffa1a193;
_editor_palette[imgui::code_editor::color_multiline_comment] = 0xffa1a193;
_editor_palette[imgui::code_editor::color_background] = 0xffe3f6fd;
_editor_palette[imgui::code_editor::color_cursor] = 0xff837b65;
_editor_palette[imgui::code_editor::color_selection] = 0x60a1a193;
_editor_palette[imgui::code_editor::color_error_marker] = 0x7f2f32dc;
_editor_palette[imgui::code_editor::color_warning_marker] = 0x7f0089b5;
_editor_palette[imgui::code_editor::color_line_number] = 0xffa1a193;
_editor_palette[imgui::code_editor::color_current_line_fill] = 0x7fd5e8ee;
_editor_palette[imgui::code_editor::color_current_line_fill_inactive] = 0x7fd5e8ee;
_editor_palette[imgui::code_editor::color_current_line_edge] = 0x7fd5e8ee;
break;
case 2:
default:
ImVec4 value;
for (ImGuiCol i = 0; i < imgui::code_editor::color_palette_max; i++)
value = ImGui::ColorConvertU32ToFloat4(_editor_palette[i]), // Get default value first
config.get("STYLE", imgui::code_editor::get_palette_color_name(i), (float(&)[4])value),
_editor_palette[i] = ImGui::ColorConvertFloat4ToU32(value);
break;
}
}
void reshade::runtime::save_custom_style() const
{
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 < imgui::code_editor::color_palette_max; i++)
value = ImGui::ColorConvertU32ToFloat4(_editor_palette[i]),
config.set("STYLE", imgui::code_editor::get_palette_color_name(i), (const float(&)[4])value);
}
}
void reshade::runtime::draw_gui()
{
assert(_is_initialized);
#if RESHADE_FX
bool show_splash = _show_splash && (is_loading() || (_reload_count <= 1 && (_last_present_time - _last_reload_time) < std::chrono::seconds(5)) || (!_show_overlay && _tutorial_index == 0));
#else
bool show_splash = _show_splash && (_last_present_time - _last_reload_time) < std::chrono::seconds(5);
#endif
const bool show_stats_window = _show_clock || _show_fps || _show_frametime;
// 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 || !_last_screenshot_save_successfull) && !_should_save_screenshot && (_last_present_time - _last_screenshot_time) < std::chrono::seconds(_last_screenshot_save_successfull ? 3 : 5);
if (show_screenshot_message || !_preset_save_successfull)
show_splash = true;
if (_input != nullptr)
{
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;
}
if (_input_gamepad != nullptr)
{
if (_input_gamepad->is_button_down(input_gamepad::button_left_shoulder) &&
_input_gamepad->is_button_down(input_gamepad::button_right_shoulder) &&
_input_gamepad->is_button_pressed(input_gamepad::button_start))
{
_show_overlay = !_show_overlay;
_imgui_context->NavInputSource = ImGuiInputSource_Gamepad;
}
}
_ignore_shortcuts = false;
#if RESHADE_FX
_gather_gpu_statistics = false;
_effects_expanded_state &= 2;
#endif
if (!show_splash && !show_stats_window && !_show_overlay
#if RESHADE_FX
&& _preview_texture == 0
#endif
#if RESHADE_ADDON
&& !has_addon_event<addon_event::reshade_overlay>()
#endif
)
{
if (_input != 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 (_font_atlas_srv == 0)
return; // Cannot render GUI without font atlas
ImGuiContext *const backup_context = ImGui::GetCurrentContext();
ImGui::SetCurrentContext(_imgui_context);
ImGuiIO &imgui_io = _imgui_context->IO;
imgui_io.DeltaTime = _last_frame_duration.count() * 1e-9f;
imgui_io.DisplaySize.x = static_cast<float>(_width);
imgui_io.DisplaySize.y = static_cast<float>(_height);
imgui_io.Fonts->TexID = _font_atlas_srv.handle;
if (_input != nullptr)
{
imgui_io.MouseDrawCursor = _show_overlay && (!_should_save_screenshot || !_screenshot_save_gui);
// Scale mouse position in case render resolution does not match the window size
unsigned int max_position[2];
_input->max_mouse_position(max_position);
imgui_io.MousePos.x = _input->mouse_position_x() * (imgui_io.DisplaySize.x / max_position[0]);
imgui_io.MousePos.y = _input->mouse_position_y() * (imgui_io.DisplaySize.y / max_position[1]);
// Add wheel delta to the current absolute mouse wheel position
imgui_io.MouseWheel += _input->mouse_wheel_delta();
// 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);
}
if (_input_gamepad != nullptr)
{
if (_input_gamepad->is_connected())
{
imgui_io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
imgui_io.NavInputs[ImGuiNavInput_Activate] = _input_gamepad->is_button_down(input_gamepad::button_a) ? 1.0f : 0.0f;
imgui_io.NavInputs[ImGuiNavInput_Cancel] = _input_gamepad->is_button_down(input_gamepad::button_b) ? 1.0f : 0.0f;
imgui_io.NavInputs[ImGuiNavInput_Input] = _input_gamepad->is_button_down(input_gamepad::button_y) != 0 ? 1.0f : 0.0f;
imgui_io.NavInputs[ImGuiNavInput_Menu] = _input_gamepad->is_button_down(input_gamepad::button_x) ? 1.0f : 0.0f;
imgui_io.NavInputs[ImGuiNavInput_DpadLeft] = _input_gamepad->is_button_down(input_gamepad::button_dpad_left) ? 1.0f : 0.0f;
imgui_io.NavInputs[ImGuiNavInput_DpadRight] = _input_gamepad->is_button_down(input_gamepad::button_dpad_right) ? 1.0f : 0.0f;
imgui_io.NavInputs[ImGuiNavInput_DpadUp] = _input_gamepad->is_button_down(input_gamepad::button_dpad_up) ? 1.0f : 0.0f;
imgui_io.NavInputs[ImGuiNavInput_DpadDown] = _input_gamepad->is_button_down(input_gamepad::button_dpad_down) ? 1.0f : 0.0f;
imgui_io.NavInputs[ImGuiNavInput_LStickLeft] = -std::min(_input_gamepad->left_thumb_axis_x(), 0.0f);
imgui_io.NavInputs[ImGuiNavInput_LStickRight] = std::max(_input_gamepad->left_thumb_axis_x(), 0.0f);
imgui_io.NavInputs[ImGuiNavInput_LStickUp] = std::max(_input_gamepad->left_thumb_axis_y(), 0.0f);
imgui_io.NavInputs[ImGuiNavInput_LStickDown] = -std::min(_input_gamepad->left_thumb_axis_y(), 0.0f);
imgui_io.NavInputs[ImGuiNavInput_FocusPrev] = _input_gamepad->is_button_down(input_gamepad::button_left_shoulder) ? 1.0f : 0.0f;
imgui_io.NavInputs[ImGuiNavInput_FocusNext] = _input_gamepad->is_button_down(input_gamepad::button_right_shoulder) ? 1.0f : 0.0f;
imgui_io.NavInputs[ImGuiNavInput_TweakSlow] = _input_gamepad->left_trigger_position();
imgui_io.NavInputs[ImGuiNavInput_TweakFast] = _input_gamepad->right_trigger_position();
}
else
{
imgui_io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
}
}
ImGui::NewFrame();
ImVec2 viewport_offset = ImVec2(0, 0);
// Create ImGui widgets and windows
if (show_splash)
{
ImGui::SetNextWindowPos(_imgui_context->Style.WindowPadding);
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_successfull)
{
#if RESHADE_FX
ImGui::TextColored(COLOR_RED, "Unable to save configuration and/or current preset. Make sure file permissions are set up to allow writing to these paths and their parent directories:\n%s\n%s", _config_path.u8string().c_str(), _current_preset_path.u8string().c_str());
#else
ImGui::TextColored(COLOR_RED, "Unable to save configuration. Make sure file permissions are set up to allow writing to %s.", _config_path.u8string().c_str());
#endif
}
else if (show_screenshot_message)
{
if (!_last_screenshot_save_successfull)
if (_screenshot_directory_creation_successfull)
ImGui::TextColored(COLOR_RED, "Unable to save screenshot because of an internal error (the format may not be supported or the drive may be full).");
else
ImGui::TextColored(COLOR_RED, "Unable to save screenshot because path could not be created: %s.", (g_reshade_base_path / _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 RESHADE_FX
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(
"Compiling (%zu effects remaining) ... "
"This might take a while. The application could become unresponsive for some time.",
_reload_remaining_effects.load());
}
else
#endif
{
ImGui::ProgressBar(0.0f, ImVec2(-1, 0), "");
ImGui::SameLine(15);
if (_input == nullptr)
{
ImGui::TextColored(COLOR_YELLOW, "No keyboard or mouse input available.%s", _input_gamepad != nullptr ? " Use gamepad instead: Press 'left + right shoulder + start button' to open the configuration overlay." : "");
}
#if RESHADE_FX
else if (_tutorial_index == 0)
{
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.");
}
#endif
else
{
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.");
}
}
std::string error_message;
#if RESHADE_ADDON
if (!addon_all_loaded)
error_message += "loading some add-ons";
#endif
#if RESHADE_FX
if (!_last_reload_successfull)
error_message += (error_message.empty() ? std::string() : " and ") + "compiling some effects";
#endif
if (!error_message.empty())
{
ImGui::Spacing();
ImGui::TextColored(COLOR_RED,
"There were errors %s. Check the log for more details.", error_message.c_str());
}
}
viewport_offset.y += ImGui::GetWindowHeight() + _imgui_context->Style.WindowPadding.x; // Add small space between windows
ImGui::End();
ImGui::PopStyleColor(2);
ImGui::PopStyleVar();
}
else if (show_stats_window)
{
ImVec2 fps_window_pos(5, 5);
ImVec2 fps_window_size(200, 0);
// Get last calculated window size (because of 'ImGuiWindowFlags_AlwaysAutoResize')
if (ImGuiWindow *const fps_window = ImGui::FindWindowByName("OSD"))
{
fps_window_size = fps_window->Size;
fps_window_size.y = std::max(fps_window_size.y, _imgui_context->Style.FramePadding.y * 4.0f + _imgui_context->Style.ItemSpacing.y +
(_imgui_context->Style.ItemSpacing.y + _imgui_context->FontBaseSize * _fps_scale) * ((_show_clock ? 1 : 0) + (_show_fps ? 1 : 0) + (_show_frametime ? 1 : 0)));
}
if (_fps_pos % 2)
fps_window_pos.x = imgui_io.DisplaySize.x - fps_window_size.x - 5;
if (_fps_pos > 1)
fps_window_pos.y = imgui_io.DisplaySize.y - fps_window_size.y - 5;
ImGui::SetNextWindowPos(fps_window_pos);
ImGui::PushStyleColor(ImGuiCol_Text, (const ImVec4 &)_fps_col);
ImGui::Begin("OSD", nullptr,
ImGuiWindowFlags_NoDecoration |
ImGuiWindowFlags_NoNav |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoInputs |
ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoDocking |
ImGuiWindowFlags_NoFocusOnAppearing |
ImGuiWindowFlags_NoBackground |
ImGuiWindowFlags_AlwaysAutoResize);
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());
struct 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::GetContentRegionAvail().x - ImGui::CalcTextSize(temp).x + _imgui_context->Style.ItemSpacing.x);
ImGui::TextUnformatted(temp);
}
if (_show_fps)
{
ImFormatString(temp, sizeof(temp), "%.0f fps", imgui_io.Framerate);
if (_fps_pos % 2)
ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(temp).x + _imgui_context->Style.ItemSpacing.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::GetContentRegionAvail().x - ImGui::CalcTextSize(temp).x + _imgui_context->Style.ItemSpacing.x);
ImGui::TextUnformatted(temp);
}
ImGui::Dummy(ImVec2(200, 0)); // Force a minimum window width
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();
}
static constexpr std::pair<const char *, void(runtime::*)()> overlay_callbacks[] = {
#if RESHADE_FX
{ "Home", &runtime::draw_gui_home },
#endif
#if RESHADE_ADDON
{ "Add-ons", &runtime::draw_gui_addons },
#endif
{ "Settings", &runtime::draw_gui_settings },
{ "Statistics", &runtime::draw_gui_statistics },
{ "Log", &runtime::draw_gui_log },
{ "About", &runtime::draw_gui_about }
};
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 std::pair<const char *, void(runtime::*)()> &widget : overlay_callbacks)
ImGui::DockBuilderDockWindow(widget.first, main_space_id);
// Attach editor window to the remaining dock space