ImGuiManager: Fix changing global scale through FSUI
This commit is contained in:
parent
bcda86d782
commit
5480e42cd1
|
@ -249,7 +249,7 @@ bool Host::CreateGPUDevice(RenderAPI api)
|
|||
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.");
|
||||
g_gpu_device->Destroy();
|
||||
|
|
|
@ -3690,8 +3690,13 @@ void System::CheckForSettingsChanges(const Settings& old_settings)
|
|||
PostProcessing::UpdateSettings();
|
||||
}
|
||||
|
||||
if (g_gpu_device && g_settings.display_osd_scale != old_settings.display_osd_scale)
|
||||
ImGuiManager::SetGlobalScale(g_settings.display_osd_scale / 100.0f);
|
||||
if (g_gpu_device)
|
||||
{
|
||||
if (g_settings.display_osd_scale != old_settings.display_osd_scale)
|
||||
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;
|
||||
for (u32 i = 0; i < NUM_CONTROLLER_AND_CARD_PORTS; i++)
|
||||
|
|
|
@ -90,6 +90,8 @@ struct OSDMessage
|
|||
static std::deque<OSDMessage> s_osd_active_messages;
|
||||
static std::deque<OSDMessage> s_osd_posted_messages;
|
||||
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 = {};
|
||||
|
||||
|
@ -107,11 +109,24 @@ void ImGuiManager::SetFontRange(const u16* range)
|
|||
|
||||
void ImGuiManager::SetGlobalScale(float global_scale)
|
||||
{
|
||||
if (s_global_prescale == global_scale)
|
||||
return;
|
||||
|
||||
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())
|
||||
{
|
||||
|
@ -121,6 +136,7 @@ bool ImGuiManager::Initialize(float global_scale)
|
|||
|
||||
s_global_prescale = global_scale;
|
||||
s_global_scale = std::max(g_gpu_device->GetWindowScale() * global_scale, 1.0f);
|
||||
s_show_osd_messages = show_osd_messages;
|
||||
|
||||
ImGui::CreateContext();
|
||||
|
||||
|
@ -181,10 +197,11 @@ void ImGuiManager::WindowResized()
|
|||
|
||||
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
|
||||
ImGui::EndFrame();
|
||||
|
||||
UpdateScale();
|
||||
|
||||
NewFrame();
|
||||
}
|
||||
|
||||
|
@ -196,9 +213,6 @@ void ImGuiManager::UpdateScale()
|
|||
if (scale == s_global_scale && (!HasFullscreenFonts() || !ImGuiFullscreen::UpdateLayoutScale()))
|
||||
return;
|
||||
|
||||
// This is assumed to be called mid-frame.
|
||||
ImGui::EndFrame();
|
||||
|
||||
s_global_scale = scale;
|
||||
|
||||
ImGui::GetStyle() = ImGuiStyle();
|
||||
|
@ -211,8 +225,6 @@ void ImGuiManager::UpdateScale()
|
|||
|
||||
if (!g_gpu_device->UpdateImGuiFontTexture())
|
||||
Panic("Failed to recreate font texture after scale+resize");
|
||||
|
||||
NewFrame();
|
||||
}
|
||||
|
||||
void ImGuiManager::NewFrame()
|
||||
|
@ -220,6 +232,12 @@ void ImGuiManager::NewFrame()
|
|||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.DeltaTime = static_cast<float>(s_last_render_time.GetTimeSecondsAndReset());
|
||||
|
||||
if (s_global_prescale_changed)
|
||||
{
|
||||
s_global_prescale_changed = false;
|
||||
UpdateScale();
|
||||
}
|
||||
|
||||
ImGui::NewFrame();
|
||||
|
||||
// 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
|
||||
Log_InfoPrintf("OSD: %s", message.c_str());
|
||||
|
||||
if (!s_show_osd_messages)
|
||||
return;
|
||||
|
||||
OSDMessage msg;
|
||||
msg.key = std::move(key);
|
||||
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)
|
||||
{
|
||||
if (!s_show_osd_messages)
|
||||
return;
|
||||
|
||||
OSDMessage msg;
|
||||
msg.key = std::move(key);
|
||||
msg.duration = 0.0f;
|
||||
|
|
|
@ -21,8 +21,11 @@ void SetFontRange(const u16* range);
|
|||
/// Changes the global scale.
|
||||
void SetGlobalScale(float global_scale);
|
||||
|
||||
/// Changes whether OSD messages are silently dropped.
|
||||
void SetShowOSDMessages(bool enable);
|
||||
|
||||
/// Initializes ImGui, creates fonts, etc.
|
||||
bool Initialize(float global_scale);
|
||||
bool Initialize(float global_scale, bool show_osd_messages);
|
||||
|
||||
/// Frees all ImGui resources.
|
||||
void Shutdown();
|
||||
|
|
Loading…
Reference in New Issue