-
-
Notifications
You must be signed in to change notification settings - Fork 548
/
runtime_gui.cpp
4939 lines (4221 loc) · 192 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 "runtime.hpp"
#include "runtime_internal.hpp"
#include "version.h"
#include "dll_log.hpp"
#include "dll_resources.hpp"
#include "ini_file.hpp"
#include "addon_manager.hpp"
#include "input.hpp"
#include "input_gamepad.hpp"
#include "imgui_widgets.hpp"
#include "localization.hpp"
#include "platform_utils.hpp"
#include "fonts/forkawesome.inl"
#include "fonts/glyph_ranges.hpp"
#include <cmath> // std::abs, std::ceil, std::floor
#include <cctype> // std::tolower
#include <cstdlib> // std::lldiv, std::strtol
#include <cstring> // std::memcmp, std::memcpy
#include <algorithm> // std::any_of, std::count_if, std::find, std::find_if, std::max, std::min, std::replace, std::rotate, std::search, std::swap, std::transform
static bool filter_text(const std::string_view text, const std::string_view filter)
{
return filter.empty() ||
std::search(text.cbegin(), text.cend(), filter.cbegin(), filter.cend(),
[](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.cend();
}
static auto filter_name(ImGuiInputTextCallbackData *data) -> int
{
// A file name cannot contain any of the following characters
return data->EventChar == L'\"' || data->EventChar == L'*' || data->EventChar == L'/' || data->EventChar == L':' || data->EventChar == L'<' || data->EventChar == L'>' || data->EventChar == L'?' || data->EventChar == L'\\' || data->EventChar == L'|';
}
template <typename F>
static void parse_errors(const std::string_view errors, F &&callback)
{
for (size_t offset = 0, next; offset != std::string_view::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 the error location to find the line info
if (pos_error == std::string_view::npos || pos_error_line == std::string_view::npos || pos_error_line < offset)
break;
const size_t pos_linefeed = errors.find('\n', pos_error);
next = pos_linefeed != std::string_view::npos ? pos_linefeed + 1 : std::string_view::npos;
const std::string_view error_file = errors.substr(offset, pos_error_line - offset);
int error_line = static_cast<int>(std::strtol(errors.data() + pos_error_line + 1, nullptr, 10));
const std::string_view error_text = errors.substr(pos_error + 2 /* skip space */, pos_linefeed - pos_error - 2);
callback(error_file, error_line, error_text);
}
}
template <typename T>
static std::string_view get_localized_annotation(T &object, const std::string_view ann_name, [[maybe_unused]] std::string language)
{
#if RESHADE_LOCALIZATION
if (language.size() >= 2)
{
// Transform language name from e.g. 'en-US' to 'en_us'
std::replace(language.begin(), language.end(), '-', '_');
std::transform(language.begin(), language.end(), language.begin(),
[](std::string::value_type c) {
return static_cast<std::string::value_type>(std::tolower(c));
});
for (int attempt = 0; attempt < 2; ++attempt)
{
const std::string_view localized_result = object.annotation_as_string(std::string(ann_name) + '_' + language);
if (!localized_result.empty())
return localized_result;
else if (attempt == 0)
language.erase(2); // Remove location information from language name, so that it e.g. becomes 'en'
}
}
#endif
return object.annotation_as_string(ann_name);
}
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;
ImGuiContext *const backup_context = ImGui::GetCurrentContext();
_imgui_context = ImGui::CreateContext();
ImGuiIO &imgui_io = _imgui_context->IO;
imgui_io.IniFilename = nullptr;
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;
// Restore previous context in case this was called from a new runtime being created from an add-on event triggered by an existing runtime
ImGui::SetCurrentContext(backup_context);
}
void reshade::runtime::deinit_gui()
{
ImGui::DestroyContext(_imgui_context);
}
void reshade::runtime::build_font_atlas()
{
ImFontAtlas *const atlas = _imgui_context->IO.Fonts;
if (atlas->IsBuilt())
return;
ImGuiContext *const backup_context = ImGui::GetCurrentContext();
ImGui::SetCurrentContext(_imgui_context);
// Remove any existing fonts from atlas first
atlas->Clear();
std::error_code ec;
const ImWchar *glyph_ranges = nullptr;
std::filesystem::path resolved_font_path;
#if RESHADE_LOCALIZATION
std::string language = _selected_language;
if (language.empty())
language = resources::get_current_language();
if (language.find("bg") == 0 || language.find("ru") == 0)
{
glyph_ranges = atlas->GetGlyphRangesCyrillic();
_default_font_path = L"C:\\Windows\\Fonts\\calibri.ttf";
}
else
if (language.find("ja") == 0)
{
glyph_ranges = atlas->GetGlyphRangesJapanese();
// Morisawa BIZ UDGothic Regular, available since Windows 10 October 2018 Update (1809) Build 17763.1
_default_font_path = L"C:\\Windows\\Fonts\\BIZ-UDGothicR.ttc";
if (!std::filesystem::exists(_default_font_path, ec))
_default_font_path = L"C:\\Windows\\Fonts\\msgothic.ttc"; // MS Gothic
}
else
if (language.find("ko") == 0)
{
glyph_ranges = atlas->GetGlyphRangesKorean();
_default_font_path = L"C:\\Windows\\Fonts\\malgun.ttf"; // Malgun Gothic
}
else
if (language.find("zh") == 0)
{
glyph_ranges = GetGlyphRangesChineseSimplifiedGB2312();
_default_font_path = L"C:\\Windows\\Fonts\\msyh.ttc"; // Microsoft YaHei
if (!std::filesystem::exists(_default_font_path, ec))
_default_font_path = L"C:\\Windows\\Fonts\\simsun.ttc"; // SimSun
}
else
#endif
{
glyph_ranges = atlas->GetGlyphRangesDefault();
_default_font_path.clear();
}
const auto add_font_from_file = [atlas](std::filesystem::path &font_path, ImFontConfig cfg, const ImWchar *glyph_ranges, std::error_code &ec) -> bool {
if (font_path.empty())
return true;
extern bool resolve_path(std::filesystem::path &path, std::error_code &ec);
if (!resolve_path(font_path, ec))
return false;
if (FILE *const file = _wfsopen(font_path.c_str(), L"rb", SH_DENYNO))
{
fseek(file, 0, SEEK_END);
const size_t data_size = ftell(file);
fseek(file, 0, SEEK_SET);
void *data = IM_ALLOC(data_size);
const size_t data_size_read = fread(data, 1, data_size, file);
fclose(file);
if (data_size_read != data_size)
{
IM_FREE(data);
return false;
}
ImFormatString(cfg.Name, IM_ARRAYSIZE(cfg.Name), "%s, %.0fpx", font_path.stem().u8string().c_str(), cfg.SizePixels);
return atlas->AddFontFromMemoryTTF(data, static_cast<int>(data_size), cfg.SizePixels, &cfg, glyph_ranges) != nullptr;
}
return false;
};
ImFontConfig cfg;
cfg.GlyphOffset.y = std::floor(_font_size / 13.0f); // Not used in AddFontDefault()
cfg.SizePixels = static_cast<float>(_font_size);
#if RESHADE_LOCALIZATION
// Add latin font
resolved_font_path = _latin_font_path;
if (!_default_font_path.empty())
{
if (!add_font_from_file(resolved_font_path, cfg, atlas->GetGlyphRangesDefault(), ec))
{
log::message(log::level::error, "Failed to load latin font from '%s' with error code %d!", resolved_font_path.u8string().c_str(), ec.value());
resolved_font_path.clear();
}
if (resolved_font_path.empty())
atlas->AddFontDefault(&cfg);
cfg.MergeMode = true;
}
#endif
// Add main font
resolved_font_path = _font_path.empty() ? _default_font_path : _font_path;
{
if (!add_font_from_file(resolved_font_path, cfg, glyph_ranges, ec))
{
log::message(log::level::error, "Failed to load font from '%s' with error code %d!", resolved_font_path.u8string().c_str(), ec.value());
resolved_font_path.clear();
}
// Use default font if custom font failed to load
if (resolved_font_path.empty())
atlas->AddFontDefault(&cfg);
// Merge icons into main font
cfg.MergeMode = true;
cfg.PixelSnapH = true;
// This need to be static so that it doesn't fall out of scope before the atlas is built below
static constexpr ImWchar icon_ranges[] = { ICON_MIN_FK, ICON_MAX_FK, 0 }; // Zero-terminated list
atlas->AddFontFromMemoryCompressedBase85TTF(FONT_ICON_BUFFER_NAME_FK, cfg.SizePixels, &cfg, icon_ranges);
}
// Add editor font
resolved_font_path = _editor_font_path.empty() ? _default_editor_font_path : _editor_font_path;
if (resolved_font_path != _font_path || _editor_font_size != _font_size)
{
cfg = ImFontConfig();
cfg.SizePixels = static_cast<float>(_editor_font_size);
if (!add_font_from_file(resolved_font_path, cfg, glyph_ranges, ec))
{
log::message(log::level::error, "Failed to load editor font from '%s' with error code %d!", resolved_font_path.u8string().c_str(), ec.value());
resolved_font_path.clear();
}
if (resolved_font_path.empty())
atlas->AddFontDefault(&cfg);
}
if (atlas->Build())
{
#if RESHADE_VERBOSE_LOG
log::message(log::level::debug, "Font atlas size: %dx%d", atlas->TexWidth, atlas->TexHeight);
#endif
}
else
{
log::message(log::level::error, "Failed to build font atlas!");
_font_path.clear();
_latin_font_path.clear();
_editor_font_path.clear();
atlas->Clear();
// If unable to build font atlas due to an invalid custom font, revert to the default font
for (int i = 0; i < (_editor_font_size != _font_size ? 2 : 1); ++i)
{
cfg = ImFontConfig();
cfg.SizePixels = static_cast<float>(i == 0 ? _font_size : _editor_font_size);
atlas->AddFontDefault(&cfg);
}
}
ImGui::SetCurrentContext(backup_context);
_show_splash = true;
int width, height;
unsigned char *pixels;
// This will also build the font atlas again if that previously failed above
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::message(log::level::error, "Failed to create front atlas resource!");
return;
}
// Texture data is now uploaded, so can free the memory
atlas->ClearTexData();
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::message(log::level::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;
const auto config_get = [&config](const std::string §ion, const std::string &key, auto &values) {
if (config.get(section, key, values))
return true;
// Fall back to global configuration when an entry does not exist in the local configuration
return global_config().get(section, key, values);
};
config_get("INPUT", "KeyOverlay", _overlay_key_data);
config_get("INPUT", "KeyFPS", _fps_key_data);
config_get("INPUT", "KeyFrameTime", _frametime_key_data);
config_get("INPUT", "InputProcessing", _input_processing_mode);
#if RESHADE_LOCALIZATION
config_get("OVERLAY", "Language", _selected_language);
#endif
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", "ShowPresetName", _show_preset_name);
config.get("OVERLAY", "ShowScreenshotMessage", _show_screenshot_message);
#if RESHADE_FX
if (!global_config().get("OVERLAY", "TutorialProgress", _tutorial_index))
config.get("OVERLAY", "TutorialProgress", _tutorial_index);
config.get("OVERLAY", "VariableListHeight", _variable_editor_height);
config.get("OVERLAY", "VariableListUseTabs", _variable_editor_tabs);
config.get("OVERLAY", "AutoSavePreset", _auto_save_preset);
config.get("OVERLAY", "ShowPresetTransitionMessage", _show_preset_transition_message);
#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_path);
config.get("STYLE", "EditorFontSize", _editor_font_size);
config.get("STYLE", "EditorStyleIndex", _editor_style_index);
config.get("STYLE", "Font", _font_path);
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", "LatinFont", _latin_font_path);
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);
config.get("STYLE", "HdrOverlayBrightness", _hdr_overlay_brightness);
config.get("STYLE", "HdrOverlayOverwriteColorSpaceTo", reinterpret_cast<int &>(_hdr_overlay_overwrite_color_space));
// 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)
{
if (std::vector<std::string> lines;
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", "KeyFPS", _fps_key_data);
config.set("INPUT", "KeyFrametime", _frametime_key_data);
config.set("INPUT", "InputProcessing", _input_processing_mode);
#if RESHADE_LOCALIZATION
config.set("OVERLAY", "Language", _selected_language);
#endif
config.set("OVERLAY", "ClockFormat", _clock_format);
config.set("OVERLAY", "FPSPosition", _fps_pos);
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", "ShowPresetName", _show_preset_name);
config.set("OVERLAY", "ShowScreenshotMessage", _show_screenshot_message);
#if RESHADE_FX
global_config().set("OVERLAY", "TutorialProgress", _tutorial_index);
config.set("OVERLAY", "TutorialProgress", _tutorial_index);
config.set("OVERLAY", "VariableListHeight", _variable_editor_height);
config.set("OVERLAY", "VariableListUseTabs", _variable_editor_tabs);
config.set("OVERLAY", "AutoSavePreset", _auto_save_preset);
config.set("OVERLAY", "ShowPresetTransitionMessage", _show_preset_transition_message);
#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_path);
config.set("STYLE", "EditorFontSize", _editor_font_size);
config.set("STYLE", "EditorStyleIndex", _editor_style_index);
config.set("STYLE", "Font", _font_path);
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", "LatinFont", _latin_font_path);
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);
config.set("STYLE", "HdrOverlayBrightness", _hdr_overlay_brightness);
config.set("STYLE", "HdrOverlayOverwriteColorSpaceTo", static_cast<int>(_hdr_overlay_overwrite_color_space));
// 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);
bool show_overlay = _show_overlay;
api::input_source show_overlay_source = api::input_source::keyboard;
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 (!_ignore_shortcuts)
{
if (_input->is_key_pressed(_fps_key_data, _force_shortcut_modifiers))
_show_fps = _show_fps ? 0 : 1;
if (_input->is_key_pressed(_frametime_key_data, _force_shortcut_modifiers))
_show_frametime = _show_frametime ? 0 : 1;
}
}
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;
show_overlay_source = api::input_source::gamepad;
}
}
if (show_overlay != _show_overlay)
open_overlay(show_overlay, show_overlay_source);
#if RESHADE_FX
const bool show_splash_window = _show_splash && (is_loading() || (_reload_count <= 1 && (_last_present_time - _last_reload_time) < std::chrono::seconds(5)) || (!_show_overlay && _tutorial_index == 0 && _input != nullptr));
#else
const bool show_splash_window = _show_splash && (_last_present_time - _last_reload_time) < std::chrono::seconds(5);
#endif
// 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_successful) && !_should_save_screenshot && (_last_present_time - _last_screenshot_time) < std::chrono::seconds(_last_screenshot_save_successful ? 3 : 5);
#if RESHADE_FX
const bool show_preset_transition_message = _show_preset_transition_message && _is_in_preset_transition;
#else
const bool show_preset_transition_message = false;
#endif
const bool show_message_window = show_screenshot_message || show_preset_transition_message || !_preset_save_successful;
const bool show_clock = _show_clock == 1 || (_show_overlay && _show_clock > 1);
const bool show_fps = _show_fps == 1 || (_show_overlay && _show_fps > 1);
const bool show_frametime = _show_frametime == 1 || (_show_overlay && _show_frametime > 1);
const bool show_preset_name = _show_preset_name == 1 || (_show_overlay && _show_preset_name > 1);
bool show_statistics_window = show_clock || show_fps || show_frametime || show_preset_name;
#if RESHADE_ADDON
for (const addon_info &info : addon_loaded_info)
{
for (const addon_info::overlay_callback &widget : info.overlay_callbacks)
{
if (widget.title == "OSD")
{
show_statistics_window = true;
break;
}
}
}
#endif
_ignore_shortcuts = false;
_block_input_next_frame = false;
#if RESHADE_FX
_gather_gpu_statistics = false;
_effects_expanded_state &= 2;
#endif
if (!show_splash_window && !show_message_window && !show_statistics_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);
_input->immobilize_cursor(false);
}
return; // Early-out to avoid costly ImGui calls when no GUI elements are on the screen
}
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.AddMousePosEvent(
_input->mouse_position_x() * (imgui_io.DisplaySize.x / max_position[0]),
_input->mouse_position_y() * (imgui_io.DisplaySize.y / max_position[1]));
// Add wheel delta to the current absolute mouse wheel position
imgui_io.AddMouseWheelEvent(0.0f, _input->mouse_wheel_delta());
// Update all the button states
constexpr std::pair<ImGuiKey, unsigned int> key_mappings[] = {
{ ImGuiKey_Tab, 0x09 /* VK_TAB */ },
{ ImGuiKey_LeftArrow, 0x25 /* VK_LEFT */ },
{ ImGuiKey_RightArrow, 0x27 /* VK_RIGHT */ },
{ ImGuiKey_UpArrow, 0x26 /* VK_UP */ },
{ ImGuiKey_DownArrow, 0x28 /* VK_DOWN */ },
{ ImGuiKey_PageUp, 0x21 /* VK_PRIOR */ },
{ ImGuiKey_PageDown, 0x22 /* VK_NEXT */ },
{ ImGuiKey_End, 0x23 /* VK_END */ },
{ ImGuiKey_Home, 0x24 /* VK_HOME */ },
{ ImGuiKey_Insert, 0x2D /* VK_INSERT */ },
{ ImGuiKey_Delete, 0x2E /* VK_DELETE */ },
{ ImGuiKey_Backspace, 0x08 /* VK_BACK */ },
{ ImGuiKey_Space, 0x20 /* VK_SPACE */ },
{ ImGuiKey_Enter, 0x0D /* VK_RETURN */ },
{ ImGuiKey_Escape, 0x1B /* VK_ESCAPE */ },
{ ImGuiKey_LeftCtrl, 0xA2 /* VK_LCONTROL */ },
{ ImGuiKey_LeftShift, 0xA0 /* VK_LSHIFT */ },
{ ImGuiKey_LeftAlt, 0xA4 /* VK_LMENU */ },
{ ImGuiKey_LeftSuper, 0x5B /* VK_LWIN */ },
{ ImGuiKey_RightCtrl, 0xA3 /* VK_RCONTROL */ },
{ ImGuiKey_RightShift, 0xA1 /* VK_RSHIFT */ },
{ ImGuiKey_RightAlt, 0xA5 /* VK_RMENU */ },
{ ImGuiKey_RightSuper, 0x5C /* VK_RWIN */ },
{ ImGuiKey_Menu, 0x5D /* VK_APPS */ },
{ ImGuiKey_0, '0' },
{ ImGuiKey_1, '1' },
{ ImGuiKey_2, '2' },
{ ImGuiKey_3, '3' },
{ ImGuiKey_4, '4' },
{ ImGuiKey_5, '5' },
{ ImGuiKey_6, '6' },
{ ImGuiKey_7, '7' },
{ ImGuiKey_8, '8' },
{ ImGuiKey_9, '9' },
{ ImGuiKey_A, 'A' },
{ ImGuiKey_B, 'B' },
{ ImGuiKey_C, 'C' },
{ ImGuiKey_D, 'D' },
{ ImGuiKey_E, 'E' },
{ ImGuiKey_F, 'F' },
{ ImGuiKey_G, 'G' },
{ ImGuiKey_H, 'H' },
{ ImGuiKey_I, 'I' },
{ ImGuiKey_J, 'J' },
{ ImGuiKey_K, 'K' },
{ ImGuiKey_L, 'L' },