CommonHostInterface: Add enumerator for OSD messages
This commit is contained in:
parent
96a36f4850
commit
556cd6d168
|
@ -931,6 +931,40 @@ void CommonHostInterface::ClearOSDMessages()
|
|||
m_osd_messages.clear();
|
||||
}
|
||||
|
||||
bool CommonHostInterface::EnumerateOSDMessages(std::function<bool(const std::string&, float)> callback)
|
||||
{
|
||||
std::unique_lock<std::mutex> 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<float>(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 |
|
||||
|
|
|
@ -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<bool(const std::string&, float)> callback);
|
||||
void ClearOSDMessages();
|
||||
|
||||
/// Displays a loading screen with the logo, rendered with ImGui. Use when executing possibly-time-consuming tasks
|
||||
|
|
Loading…
Reference in New Issue