diff --git a/src/Cafe/HW/Latte/Core/LatteOverlay.cpp b/src/Cafe/HW/Latte/Core/LatteOverlay.cpp index 9801c1d3..f3e7f8bc 100644 --- a/src/Cafe/HW/Latte/Core/LatteOverlay.cpp +++ b/src/Cafe/HW/Latte/Core/LatteOverlay.cpp @@ -66,11 +66,11 @@ struct OverlayList const auto kPopupFlags = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav; const float kBackgroundAlpha = 0.65f; -void LatteOverlay_renderOverlay(ImVec2& position, ImVec2& pivot, sint32 direction) +void LatteOverlay_renderOverlay(ImVec2& position, ImVec2& pivot, sint32 direction, float fontSize, bool pad) { auto& config = GetConfig(); - - const auto font = ImGui_GetFont(14.0f * (float)config.overlay.text_scale / 100.0f); + + const auto font = ImGui_GetFont(fontSize); ImGui::PushFont(font); const ImVec4 color = ImGui::ColorConvertU32ToFloat4(config.overlay.text_color); @@ -80,7 +80,7 @@ void LatteOverlay_renderOverlay(ImVec2& position, ImVec2& pivot, sint32 directio { ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot); ImGui::SetNextWindowBgAlpha(kBackgroundAlpha); - if (ImGui::Begin("Stats overlay", nullptr, kPopupFlags)) + if (ImGui_BeginPadDistinct("Stats overlay", nullptr, kPopupFlags, pad)) { if (config.overlay.fps) ImGui::Text("FPS: %.2lf", g_state.fps); @@ -117,11 +117,11 @@ void LatteOverlay_renderOverlay(ImVec2& position, ImVec2& pivot, sint32 directio ImGui::PopFont(); } -void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 direction) +void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 direction, float fontSize, bool pad) { auto& config = GetConfig(); - const auto font = ImGui_GetFont(14.0f * (float)config.notification.text_scale / 100.0f); + const auto font = ImGui_GetFont(fontSize); ImGui::PushFont(font); const ImVec4 color = ImGui::ColorConvertU32ToFloat4(config.notification.text_color); @@ -141,7 +141,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di // active account ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot); ImGui::SetNextWindowBgAlpha(kBackgroundAlpha); - if (ImGui::Begin("Active account", nullptr, kPopupFlags)) + if (ImGui_BeginPadDistinct("Active account", nullptr, kPopupFlags, pad)) { ImGui::TextUnformatted((const char*)ICON_FA_USER); ImGui::SameLine(); @@ -179,7 +179,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di { ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot); ImGui::SetNextWindowBgAlpha(kBackgroundAlpha); - if (ImGui::Begin("Controller profile names", nullptr, kPopupFlags)) + if (ImGui_BeginPadDistinct("Controller profile names", nullptr, kPopupFlags, pad)) { auto it = profiles.cbegin(); ImGui::TextUnformatted((const char*)ICON_FA_GAMEPAD); @@ -227,7 +227,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di { ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot); ImGui::SetNextWindowBgAlpha(kBackgroundAlpha); - if (ImGui::Begin("Friends overlay", nullptr, kPopupFlags)) + if (ImGui_BeginPadDistinct("Friends overlay", nullptr, kPopupFlags, pad)) { const auto tick = tick_cached(); for (auto it = s_friend_list.cbegin(); it != s_friend_list.cend();) @@ -274,7 +274,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot); ImGui::SetNextWindowBgAlpha(kBackgroundAlpha); - if (ImGui::Begin("Low battery overlay", nullptr, kPopupFlags)) + if (ImGui_BeginPadDistinct("Low battery overlay", nullptr, kPopupFlags, pad)) { auto it = batteries.cbegin(); ImGui::TextUnformatted((const char*)(s_blink_state ? ICON_FA_BATTERY_EMPTY : ICON_FA_BATTERY_QUARTER)); @@ -322,7 +322,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di { ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot); ImGui::SetNextWindowBgAlpha(kBackgroundAlpha); - if (ImGui::Begin("Compiling shaders overlay", nullptr, kPopupFlags)) + if (ImGui_BeginPadDistinct("Compiling shaders overlay", nullptr, kPopupFlags, pad)) { ImRotateStart(); ImGui::TextUnformatted((const char*)ICON_FA_SPINNER); @@ -377,7 +377,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di { ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot); ImGui::SetNextWindowBgAlpha(kBackgroundAlpha); - if (ImGui::Begin("Compiling pipeline overlay", nullptr, kPopupFlags)) + if (ImGui_BeginPadDistinct("Compiling pipeline overlay", nullptr, kPopupFlags, pad)) { ImRotateStart(); ImGui::TextUnformatted((const char*)ICON_FA_SPINNER); @@ -446,7 +446,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di { ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot); ImGui::SetNextWindowBgAlpha(kBackgroundAlpha); - if (ImGui::Begin("Misc notifications", nullptr, kPopupFlags)) + if (ImGui_BeginPadDistinct("Misc notifications", nullptr, kPopupFlags, pad)) { const auto tick = tick_cached(); for (auto it = s_misc_notifications.cbegin(); it != s_misc_notifications.cend();) @@ -521,12 +521,18 @@ void LatteOverlay_render(bool pad_view) return; const Vector2f window_size{ (float)w,(float)h }; - + + float fontDPIScale = !pad_view ? gui_getWindowDPIScale() : gui_getPadDPIScale(); + + float overlayFontSize = 14.0f * (float)config.overlay.text_scale / 100.0f * fontDPIScale; + // test if fonts are already precached - if (!ImGui_GetFont(14.0f * (float)config.overlay.text_scale / 100.0f)) + if (!ImGui_GetFont(overlayFontSize)) return; + + float notificationsFontSize = 14.0f * (float)config.notification.text_scale / 100.0f * fontDPIScale; - if (!ImGui_GetFont(14.0f * (float)config.notification.text_scale / 100.0f)) + if (!ImGui_GetFont(notificationsFontSize)) return; ImVec2 position{}, pivot{}; @@ -535,7 +541,7 @@ void LatteOverlay_render(bool pad_view) if (config.overlay.position != ScreenPosition::kDisabled) { LatteOverlay_translateScreenPosition(config.overlay.position, window_size, position, pivot, direction); - LatteOverlay_renderOverlay(position, pivot, direction); + LatteOverlay_renderOverlay(position, pivot, direction, overlayFontSize, pad_view); } @@ -544,7 +550,7 @@ void LatteOverlay_render(bool pad_view) if(config.overlay.position != config.notification.position) LatteOverlay_translateScreenPosition(config.notification.position, window_size, position, pivot, direction); - LatteOverlay_RenderNotifications(position, pivot, direction); + LatteOverlay_RenderNotifications(position, pivot, direction, notificationsFontSize, pad_view); } } diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 7b17823d..23b30186 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1523,6 +1523,7 @@ void MainWindow::OnSizeEvent(wxSizeEvent& event) g_window_info.height = client_size.GetHeight(); g_window_info.phys_width = ToPhys(client_size.GetWidth()); g_window_info.phys_height = ToPhys(client_size.GetHeight()); + g_window_info.dpi_scale = GetDPIScaleFactor(); if (m_debugger_window && m_debugger_window->IsShown()) m_debugger_window->OnParentMove(GetPosition(), event.GetSize()); @@ -1540,6 +1541,7 @@ void MainWindow::OnDPIChangedEvent(wxDPIChangedEvent& event) g_window_info.height = client_size.GetHeight(); g_window_info.phys_width = ToPhys(client_size.GetWidth()); g_window_info.phys_height = ToPhys(client_size.GetHeight()); + g_window_info.dpi_scale = GetDPIScaleFactor(); } void MainWindow::OnMove(wxMoveEvent& event) diff --git a/src/gui/PadViewFrame.cpp b/src/gui/PadViewFrame.cpp index 2704eebe..d11ea4d3 100644 --- a/src/gui/PadViewFrame.cpp +++ b/src/gui/PadViewFrame.cpp @@ -103,6 +103,7 @@ void PadViewFrame::OnSizeEvent(wxSizeEvent& event) g_window_info.pad_height = client_size.GetHeight(); g_window_info.phys_pad_width = ToPhys(client_size.GetWidth()); g_window_info.phys_pad_height = ToPhys(client_size.GetHeight()); + g_window_info.pad_dpi_scale = GetDPIScaleFactor(); event.Skip(); } @@ -115,6 +116,7 @@ void PadViewFrame::OnDPIChangedEvent(wxDPIChangedEvent& event) g_window_info.pad_height = client_size.GetHeight(); g_window_info.phys_pad_width = ToPhys(client_size.GetWidth()); g_window_info.phys_pad_height = ToPhys(client_size.GetHeight()); + g_window_info.pad_dpi_scale = GetDPIScaleFactor(); } void PadViewFrame::OnMoveEvent(wxMoveEvent& event) diff --git a/src/gui/guiWrapper.cpp b/src/gui/guiWrapper.cpp index 6d1aed13..e1cef1fe 100644 --- a/src/gui/guiWrapper.cpp +++ b/src/gui/guiWrapper.cpp @@ -143,7 +143,6 @@ void gui_getWindowSize(int& w, int& h) h = g_window_info.height; } - void gui_getPadWindowSize(int& w, int& h) { if (g_window_info.pad_open) @@ -178,6 +177,16 @@ void gui_getPadWindowPhysSize(int& w, int& h) } } +double gui_getWindowDPIScale() +{ + return g_window_info.dpi_scale; +} + +double gui_getPadDPIScale() +{ + return g_window_info.pad_open ? g_window_info.pad_dpi_scale.load() : 1.0; +} + bool gui_isPadWindowOpen() { return g_window_info.pad_open; diff --git a/src/gui/guiWrapper.h b/src/gui/guiWrapper.h index fd5eceea..5b64dc02 100644 --- a/src/gui/guiWrapper.h +++ b/src/gui/guiWrapper.h @@ -57,10 +57,12 @@ struct WindowInfo std::atomic_int32_t width, height; // client size of main window std::atomic_int32_t phys_width, phys_height; // client size of main window in physical pixels + std::atomic dpi_scale; std::atomic_bool pad_open; // if separate pad view is open std::atomic_int32_t pad_width, pad_height; // client size of pad window std::atomic_int32_t phys_pad_width, phys_pad_height; // client size of pad window in physical pixels + std::atomic pad_dpi_scale; std::atomic_bool pad_maximized = false; std::atomic_int32_t restored_pad_x = -1, restored_pad_y = -1; @@ -118,6 +120,8 @@ void gui_getWindowSize(int& w, int& h); void gui_getPadWindowSize(int& w, int& h); void gui_getWindowPhysSize(int& w, int& h); void gui_getPadWindowPhysSize(int& w, int& h); +double gui_getWindowDPIScale(); +double gui_getPadDPIScale(); bool gui_isPadWindowOpen(); bool gui_isKeyDown(uint32 key); bool gui_isKeyDown(PlatformKeyCodes key); diff --git a/src/imgui/imgui_extension.cpp b/src/imgui/imgui_extension.cpp index 15e0de82..5efef9e1 100644 --- a/src/imgui/imgui_extension.cpp +++ b/src/imgui/imgui_extension.cpp @@ -50,6 +50,14 @@ extern char const g_fontawesome_data[]; std::unordered_map g_imgui_fonts; std::stack g_font_requests; +bool ImGui_BeginPadDistinct(const char* name, bool* p_open, ImGuiWindowFlags flags, bool pad) +{ + std::string distinctName = name; + if (pad) + distinctName += "##pad"; + return ImGui::Begin(distinctName.c_str(), p_open, flags); +} + void ImGui_PrecacheFonts() { while (!g_font_requests.empty()) diff --git a/src/imgui/imgui_extension.h b/src/imgui/imgui_extension.h index cbc35e69..de3bb5ac 100644 --- a/src/imgui/imgui_extension.h +++ b/src/imgui/imgui_extension.h @@ -9,6 +9,8 @@ inline ImVec2 operator-(const ImVec2& l, const ImVec2& r) { return{ l.x - r.x, l inline bool operator<(const ImVec2& lhs, const ImVec2& rhs) { return lhs.x < rhs.x; } inline bool operator>=(const ImVec2& lhs, const ImVec2& rhs) { return lhs.x >= rhs.x; } +bool ImGui_BeginPadDistinct(const char* name, bool* p_open, ImGuiWindowFlags flags, bool pad); + void ImGui_PrecacheFonts(); ImFont* ImGui_GetFont(float size); void ImGui_UpdateWindowInformation(bool mainWindow); \ No newline at end of file