From 49ceff71a2a4f2642fbac8a32bfd6f047eb1cc54 Mon Sep 17 00:00:00 2001 From: Vinicius Rangel Date: Fri, 4 Oct 2024 00:44:36 -0300 Subject: [PATCH] Devtools fixes1 (#1228) * imgui: fix nav with dock & fps display disabled by default * devtools: change basic fps scale * imgui: scale font with display dpi --- src/core/devtools/layer.cpp | 24 ++++++++++++++++++++---- src/imgui/renderer/imgui_core.cpp | 15 +++++++++++++-- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/core/devtools/layer.cpp b/src/core/devtools/layer.cpp index 7e25f109..0c7e85e4 100644 --- a/src/core/devtools/layer.cpp +++ b/src/core/devtools/layer.cpp @@ -18,6 +18,8 @@ using namespace Core::Devtools; using L = Core::Devtools::Layer; static bool show_simple_fps = false; +static float fps_scale = 1.0f; + static bool show_advanced_debug = false; static int dump_frame_count = 1; @@ -149,8 +151,9 @@ void L::SetupSettings() { }; handler.ReadLineFn = [](ImGuiContext*, ImGuiSettingsHandler*, void*, const char* line) { int v; - if (sscanf(line, "show_simple_fps=%d", &v) == 1) { - show_simple_fps = v != 0; + float f; + if (sscanf(line, "fps_scale=%f", &f) == 1) { + fps_scale = f; } else if (sscanf(line, "show_advanced_debug=%d", &v) == 1) { show_advanced_debug = v != 0; } else if (sscanf(line, "show_frame_graph=%d", &v) == 1) { @@ -161,7 +164,7 @@ void L::SetupSettings() { }; handler.WriteAllFn = [](ImGuiContext*, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf) { buf->appendf("[%s][Data]\n", handler->TypeName); - buf->appendf("show_simple_fps=%d\n", show_simple_fps); + buf->appendf("fps_scale=%f\n", fps_scale); buf->appendf("show_advanced_debug=%d\n", show_advanced_debug); buf->appendf("show_frame_graph=%d\n", frame_graph.is_open); buf->appendf("dump_frame_count=%d\n", dump_frame_count); @@ -193,11 +196,24 @@ void L::Draw() { } if (show_simple_fps) { - SetWindowPos("Video Info", {999999.0f, 0.0f}, ImGuiCond_FirstUseEver); if (Begin("Video Info", nullptr, ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDocking)) { + SetWindowPos("Video Info", {999999.0f, 0.0f}, ImGuiCond_FirstUseEver); + if (BeginPopupContextWindow()) { +#define M(label, value) \ + if (MenuItem(label, nullptr, fps_scale == value)) \ + fps_scale = value + M("0.5x", 0.5f); + M("1.0x", 1.0f); + M("1.5x", 1.5f); + M("2.0x", 2.0f); + M("2.5x", 2.5f); + EndPopup(); +#undef M + } KeepWindowInside(); + SetWindowFontScale(fps_scale); DrawSimple(); } End(); diff --git a/src/imgui/renderer/imgui_core.cpp b/src/imgui/renderer/imgui_core.cpp index feda54a8..2473f371 100644 --- a/src/imgui/renderer/imgui_core.cpp +++ b/src/imgui/renderer/imgui_core.cpp @@ -35,6 +35,7 @@ std::deque>& GetChangeLayers() { } static std::mutex change_layers_mutex{}; +static ImGuiID dock_id; namespace ImGui { @@ -106,6 +107,14 @@ void Initialize(const ::Vulkan::Instance& instance, const Frontend::WindowSDL& w Vulkan::Init(vk_info); TextureManager::StartWorker(); + + char label[32]; + ImFormatString(label, IM_ARRAYSIZE(label), "WindowOverViewport_%08X", GetMainViewport()->ID); + dock_id = ImHashStr(label); + + if (const auto dpi = SDL_GetWindowDisplayScale(window.GetSdlWindow()); dpi > 0.0f) { + GetIO().FontGlobalScale = dpi; + } } void OnResize() { @@ -147,8 +156,10 @@ bool ProcessEvent(SDL_Event* event) { case SDL_EVENT_GAMEPAD_BUTTON_DOWN: case SDL_EVENT_GAMEPAD_AXIS_MOTION: case SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN: - case SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION: - return GetIO().NavActive; + case SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION: { + const auto& io = GetIO(); + return io.NavActive && io.Ctx->NavWindow != nullptr && io.Ctx->NavWindow->ID != dock_id; + } default: return false; }