ImGuiManager: Fix changing global scale through FSUI

This commit is contained in:
Stenzek 2023-09-02 19:40:23 +10:00
parent bcda86d782
commit 5480e42cd1
4 changed files with 45 additions and 13 deletions

View file

@ -249,7 +249,7 @@ bool Host::CreateGPUDevice(RenderAPI api)
return false; return false;
} }
if (!ImGuiManager::Initialize(g_settings.display_osd_scale / 100.0f)) if (!ImGuiManager::Initialize(g_settings.display_osd_scale / 100.0f, g_settings.display_show_osd_messages))
{ {
Log_ErrorPrintf("Failed to initialize ImGuiManager."); Log_ErrorPrintf("Failed to initialize ImGuiManager.");
g_gpu_device->Destroy(); g_gpu_device->Destroy();

View file

@ -3690,8 +3690,13 @@ void System::CheckForSettingsChanges(const Settings& old_settings)
PostProcessing::UpdateSettings(); PostProcessing::UpdateSettings();
} }
if (g_gpu_device && g_settings.display_osd_scale != old_settings.display_osd_scale) if (g_gpu_device)
{
if (g_settings.display_osd_scale != old_settings.display_osd_scale)
ImGuiManager::SetGlobalScale(g_settings.display_osd_scale / 100.0f); ImGuiManager::SetGlobalScale(g_settings.display_osd_scale / 100.0f);
if (g_settings.display_show_osd_messages != old_settings.display_show_osd_messages)
ImGuiManager::SetShowOSDMessages(g_settings.display_show_osd_messages);
}
bool controllers_updated = false; bool controllers_updated = false;
for (u32 i = 0; i < NUM_CONTROLLER_AND_CARD_PORTS; i++) for (u32 i = 0; i < NUM_CONTROLLER_AND_CARD_PORTS; i++)

View file

@ -90,6 +90,8 @@ struct OSDMessage
static std::deque<OSDMessage> s_osd_active_messages; static std::deque<OSDMessage> s_osd_active_messages;
static std::deque<OSDMessage> s_osd_posted_messages; static std::deque<OSDMessage> s_osd_posted_messages;
static std::mutex s_osd_messages_lock; static std::mutex s_osd_messages_lock;
static bool s_show_osd_messages = true;
static bool s_global_prescale_changed = false;
static std::array<ImGuiManager::SoftwareCursor, InputManager::MAX_SOFTWARE_CURSORS> s_software_cursors = {}; static std::array<ImGuiManager::SoftwareCursor, InputManager::MAX_SOFTWARE_CURSORS> s_software_cursors = {};
@ -107,11 +109,24 @@ void ImGuiManager::SetFontRange(const u16* range)
void ImGuiManager::SetGlobalScale(float global_scale) void ImGuiManager::SetGlobalScale(float global_scale)
{ {
if (s_global_prescale == global_scale)
return;
s_global_prescale = global_scale; s_global_prescale = global_scale;
UpdateScale(); s_global_prescale_changed = true;
} }
bool ImGuiManager::Initialize(float global_scale) void ImGuiManager::SetShowOSDMessages(bool enable)
{
if (s_show_osd_messages == enable)
return;
s_show_osd_messages = enable;
if (!enable)
Host::ClearOSDMessages();
}
bool ImGuiManager::Initialize(float global_scale, bool show_osd_messages)
{ {
if (!LoadFontData()) if (!LoadFontData())
{ {
@ -121,6 +136,7 @@ bool ImGuiManager::Initialize(float global_scale)
s_global_prescale = global_scale; s_global_prescale = global_scale;
s_global_scale = std::max(g_gpu_device->GetWindowScale() * global_scale, 1.0f); s_global_scale = std::max(g_gpu_device->GetWindowScale() * global_scale, 1.0f);
s_show_osd_messages = show_osd_messages;
ImGui::CreateContext(); ImGui::CreateContext();
@ -181,10 +197,11 @@ void ImGuiManager::WindowResized()
ImGui::GetIO().DisplaySize = ImVec2(static_cast<float>(new_width), static_cast<float>(new_height)); ImGui::GetIO().DisplaySize = ImVec2(static_cast<float>(new_width), static_cast<float>(new_height));
UpdateScale();
// restart imgui frame on the new window size to pick it up, otherwise we draw to the old size // restart imgui frame on the new window size to pick it up, otherwise we draw to the old size
ImGui::EndFrame(); ImGui::EndFrame();
UpdateScale();
NewFrame(); NewFrame();
} }
@ -196,9 +213,6 @@ void ImGuiManager::UpdateScale()
if (scale == s_global_scale && (!HasFullscreenFonts() || !ImGuiFullscreen::UpdateLayoutScale())) if (scale == s_global_scale && (!HasFullscreenFonts() || !ImGuiFullscreen::UpdateLayoutScale()))
return; return;
// This is assumed to be called mid-frame.
ImGui::EndFrame();
s_global_scale = scale; s_global_scale = scale;
ImGui::GetStyle() = ImGuiStyle(); ImGui::GetStyle() = ImGuiStyle();
@ -211,8 +225,6 @@ void ImGuiManager::UpdateScale()
if (!g_gpu_device->UpdateImGuiFontTexture()) if (!g_gpu_device->UpdateImGuiFontTexture())
Panic("Failed to recreate font texture after scale+resize"); Panic("Failed to recreate font texture after scale+resize");
NewFrame();
} }
void ImGuiManager::NewFrame() void ImGuiManager::NewFrame()
@ -220,6 +232,12 @@ void ImGuiManager::NewFrame()
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
io.DeltaTime = static_cast<float>(s_last_render_time.GetTimeSecondsAndReset()); io.DeltaTime = static_cast<float>(s_last_render_time.GetTimeSecondsAndReset());
if (s_global_prescale_changed)
{
s_global_prescale_changed = false;
UpdateScale();
}
ImGui::NewFrame(); ImGui::NewFrame();
// Disable nav input on the implicit (Debug##Default) window. Otherwise we end up requesting keyboard // Disable nav input on the implicit (Debug##Default) window. Otherwise we end up requesting keyboard
@ -587,6 +605,9 @@ void Host::AddKeyedOSDMessage(std::string key, std::string message, float durati
else else
Log_InfoPrintf("OSD: %s", message.c_str()); Log_InfoPrintf("OSD: %s", message.c_str());
if (!s_show_osd_messages)
return;
OSDMessage msg; OSDMessage msg;
msg.key = std::move(key); msg.key = std::move(key);
msg.text = std::move(message); msg.text = std::move(message);
@ -622,6 +643,9 @@ void Host::AddKeyedFormattedOSDMessage(std::string key, float duration, const ch
void Host::RemoveKeyedOSDMessage(std::string key) void Host::RemoveKeyedOSDMessage(std::string key)
{ {
if (!s_show_osd_messages)
return;
OSDMessage msg; OSDMessage msg;
msg.key = std::move(key); msg.key = std::move(key);
msg.duration = 0.0f; msg.duration = 0.0f;

View file

@ -21,8 +21,11 @@ void SetFontRange(const u16* range);
/// Changes the global scale. /// Changes the global scale.
void SetGlobalScale(float global_scale); void SetGlobalScale(float global_scale);
/// Changes whether OSD messages are silently dropped.
void SetShowOSDMessages(bool enable);
/// Initializes ImGui, creates fonts, etc. /// Initializes ImGui, creates fonts, etc.
bool Initialize(float global_scale); bool Initialize(float global_scale, bool show_osd_messages);
/// Frees all ImGui resources. /// Frees all ImGui resources.
void Shutdown(); void Shutdown();