mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-26 15:45:42 +00:00
HostInterface: Add keyed OSD messages
This commit is contained in:
parent
c346dfe8a4
commit
7522304360
|
@ -229,11 +229,6 @@ bool HostInterface::ConfirmFormattedMessage(const char* format, ...)
|
|||
return ConfirmMessage(message.c_str());
|
||||
}
|
||||
|
||||
void HostInterface::AddOSDMessage(std::string message, float duration /* = 2.0f */)
|
||||
{
|
||||
Log_InfoPrintf("OSD: %s", message.c_str());
|
||||
}
|
||||
|
||||
void HostInterface::AddFormattedOSDMessage(float duration, const char* format, ...)
|
||||
{
|
||||
std::va_list ap;
|
||||
|
@ -244,6 +239,16 @@ void HostInterface::AddFormattedOSDMessage(float duration, const char* format, .
|
|||
AddOSDMessage(std::move(message), duration);
|
||||
}
|
||||
|
||||
void HostInterface::AddKeyedFormattedOSDMessage(std::string key, float duration, const char* format, ...)
|
||||
{
|
||||
std::va_list ap;
|
||||
va_start(ap, format);
|
||||
std::string message = StringUtil::StdStringFromFormatV(format, ap);
|
||||
va_end(ap);
|
||||
|
||||
AddKeyedOSDMessage(std::move(key), std::move(message), duration);
|
||||
}
|
||||
|
||||
std::string HostInterface::GetBIOSDirectory()
|
||||
{
|
||||
std::string dir = GetStringSettingValue("BIOS", "SearchDirectory", "");
|
||||
|
|
|
@ -70,8 +70,11 @@ public:
|
|||
bool ConfirmFormattedMessage(const char* format, ...) printflike(2, 3);
|
||||
|
||||
/// Adds OSD messages, duration is in seconds.
|
||||
virtual void AddOSDMessage(std::string message, float duration = 2.0f);
|
||||
virtual void AddOSDMessage(std::string message, float duration = 2.0f) = 0;
|
||||
virtual void AddKeyedOSDMessage(std::string key, std::string message, float duration = 2.0f) = 0;
|
||||
virtual void RemoveKeyedOSDMessage(std::string key) = 0;
|
||||
void AddFormattedOSDMessage(float duration, const char* format, ...) printflike(3, 4);
|
||||
void AddKeyedFormattedOSDMessage(std::string key, float duration, const char* format, ...) printflike(3, 4);
|
||||
|
||||
/// Returns the base user directory path.
|
||||
ALWAYS_INLINE const std::string& GetUserDirectory() const { return m_user_directory; }
|
||||
|
|
|
@ -77,6 +77,13 @@ void RegTestHostInterface::AddOSDMessage(std::string message, float duration /*=
|
|||
Log_InfoPrintf("OSD: %s", message.c_str());
|
||||
}
|
||||
|
||||
void RegTestHostInterface::AddKeyedOSDMessage(std::string key, std::string message, float duration /* = 2.0f */)
|
||||
{
|
||||
Log_InfoPrintf("OSD: %s", message.c_str());
|
||||
}
|
||||
|
||||
void RegTestHostInterface::RemoveKeyedOSDMessage(std::string key) {}
|
||||
|
||||
void RegTestHostInterface::DisplayLoadingScreen(const char* message, int progress_min /*= -1*/,
|
||||
int progress_max /*= -1*/, int progress_value /*= -1*/)
|
||||
{
|
||||
|
|
|
@ -17,6 +17,8 @@ public:
|
|||
bool ConfirmMessage(const char* message) override;
|
||||
|
||||
void AddOSDMessage(std::string message, float duration = 2.0f) override;
|
||||
void AddKeyedOSDMessage(std::string key, std::string message, float duration = 2.0f) override;
|
||||
void RemoveKeyedOSDMessage(std::string key) override;
|
||||
void DisplayLoadingScreen(const char* message, int progress_min = -1, int progress_max = -1,
|
||||
int progress_value = -1) override;
|
||||
void GetGameInfo(const char* path, CDImage* image, std::string* code, std::string* title) override;
|
||||
|
|
|
@ -1389,6 +1389,27 @@ void CommonHostInterface::AddOSDMessage(std::string message, float duration /*=
|
|||
m_osd_posted_messages.push_back(std::move(msg));
|
||||
}
|
||||
|
||||
void CommonHostInterface::AddKeyedOSDMessage(std::string key, std::string message, float duration /*= 2.0f*/)
|
||||
{
|
||||
OSDMessage msg;
|
||||
msg.key = std::move(key);
|
||||
msg.text = std::move(message);
|
||||
msg.duration = duration;
|
||||
|
||||
std::unique_lock<std::mutex> lock(m_osd_messages_lock);
|
||||
m_osd_posted_messages.push_back(std::move(msg));
|
||||
}
|
||||
|
||||
void CommonHostInterface::RemoveKeyedOSDMessage(std::string key)
|
||||
{
|
||||
OSDMessage msg;
|
||||
msg.key = std::move(key);
|
||||
msg.duration = 0.0f;
|
||||
|
||||
std::unique_lock<std::mutex> lock(m_osd_messages_lock);
|
||||
m_osd_posted_messages.push_back(std::move(msg));
|
||||
}
|
||||
|
||||
void CommonHostInterface::ClearOSDMessages()
|
||||
{
|
||||
{
|
||||
|
@ -1425,7 +1446,23 @@ void CommonHostInterface::AcquirePendingOSDMessages()
|
|||
break;
|
||||
|
||||
if (g_settings.display_show_osd_messages)
|
||||
m_osd_active_messages.push_back(std::move(m_osd_posted_messages.front()));
|
||||
{
|
||||
OSDMessage& new_msg = m_osd_posted_messages.front();
|
||||
std::deque<OSDMessage>::iterator iter;
|
||||
if (!new_msg.key.empty() && (iter = std::find_if(m_osd_active_messages.begin(), m_osd_active_messages.end(),
|
||||
[&new_msg](const OSDMessage& other) {
|
||||
return new_msg.key == other.key;
|
||||
})) != m_osd_active_messages.end())
|
||||
{
|
||||
iter->text = std::move(new_msg.text);
|
||||
iter->duration = new_msg.duration;
|
||||
iter->time = new_msg.time;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_osd_active_messages.push_back(std::move(new_msg));
|
||||
}
|
||||
}
|
||||
|
||||
m_osd_posted_messages.pop_front();
|
||||
|
||||
|
|
|
@ -223,6 +223,8 @@ public:
|
|||
|
||||
/// Adds OSD messages, duration is in seconds.
|
||||
void AddOSDMessage(std::string message, float duration = 2.0f) override;
|
||||
void AddKeyedOSDMessage(std::string key, std::string message, float duration = 2.0f) override;
|
||||
void RemoveKeyedOSDMessage(std::string key) override;
|
||||
void ClearOSDMessages();
|
||||
|
||||
/// async message queue bookeeping for. Should be called on UI thread.
|
||||
|
@ -353,6 +355,7 @@ protected:
|
|||
|
||||
struct OSDMessage
|
||||
{
|
||||
std::string key;
|
||||
std::string text;
|
||||
Common::Timer time;
|
||||
float duration;
|
||||
|
|
Loading…
Reference in a new issue