diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index 6e345be35..3c95ba85d 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -931,6 +931,40 @@ void CommonHostInterface::ClearOSDMessages() m_osd_messages.clear(); } +bool CommonHostInterface::EnumerateOSDMessages(std::function callback) +{ + std::unique_lock lock(m_osd_messages_lock); + if (m_osd_messages.empty()) + return true; + + bool result = true; + auto iter = m_osd_messages.begin(); + while (iter != m_osd_messages.end()) + { + const OSDMessage& msg = *iter; + const double time = msg.time.GetTimeSeconds(); + const float time_remaining = static_cast(msg.duration - time); + if (time_remaining <= 0.0f) + { + iter = m_osd_messages.erase(iter); + continue; + } + + if (!g_settings.display_show_osd_messages) + { + ++iter; + continue; + } + + if (!callback(iter->text, time_remaining)) + return false; + + ++iter; + } + + return true; +} + void CommonHostInterface::DrawOSDMessages() { constexpr ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoInputs | diff --git a/src/frontend-common/common_host_interface.h b/src/frontend-common/common_host_interface.h index 2ebdf9d26..efd81cdce 100644 --- a/src/frontend-common/common_host_interface.h +++ b/src/frontend-common/common_host_interface.h @@ -130,6 +130,7 @@ public: /// Adds OSD messages, duration is in seconds. void AddOSDMessage(std::string message, float duration = 2.0f) override; + bool EnumerateOSDMessages(std::function callback); void ClearOSDMessages(); /// Displays a loading screen with the logo, rendered with ImGui. Use when executing possibly-time-consuming tasks