From ed0c4b7a9e19f922f34bb996236e8e910ebb0263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 20 Jun 2023 15:07:01 +0200 Subject: [PATCH] Rename OSD "Message" to "Entry" since it can soon be multiple other things (progress bar, etc). --- Common/System/Request.cpp | 21 ++++++++++----------- Common/System/System.h | 16 ++++++++++------ UI/OnScreenDisplay.cpp | 22 +++++++++++++++++----- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/Common/System/Request.cpp b/Common/System/Request.cpp index a2892f0836..eff9b60027 100644 --- a/Common/System/Request.cpp +++ b/Common/System/Request.cpp @@ -11,18 +11,18 @@ void OnScreenDisplay::Update() { std::lock_guard guard(mutex_); double now = time_now_d(); - for (auto iter = messages_.begin(); iter != messages_.end(); ) { + for (auto iter = entries_.begin(); iter != entries_.end(); ) { if (now >= iter->endTime) { - iter = messages_.erase(iter); + iter = entries_.erase(iter); } else { iter++; } } } -std::vector OnScreenDisplay::Messages() { +std::vector OnScreenDisplay::Entries() { std::lock_guard guard(mutex_); - return messages_; + return entries_; // makes a copy. } void OnScreenDisplay::Show(OSDType type, const std::string &text, float duration_s, const char *id) { @@ -48,23 +48,23 @@ void OnScreenDisplay::Show(OSDType type, const std::string &text, float duration double now = time_now_d(); std::lock_guard guard(mutex_); if (id) { - for (auto iter = messages_.begin(); iter != messages_.end(); ++iter) { + for (auto iter = entries_.begin(); iter != entries_.end(); ++iter) { if (iter->id && !strcmp(iter->id, id)) { - Message msg = *iter; + Entry msg = *iter; msg.endTime = now + duration_s; msg.text = text; - messages_.erase(iter); - messages_.insert(messages_.begin(), msg); + entries_.erase(iter); + entries_.insert(entries_.begin(), msg); return; } } } - Message msg; + Entry msg; msg.text = text; msg.endTime = now + duration_s; msg.id = id; - messages_.insert(messages_.begin(), msg); + entries_.insert(entries_.begin(), msg); } void OnScreenDisplay::ShowOnOff(const std::string &message, bool on, float duration_s) { @@ -72,7 +72,6 @@ void OnScreenDisplay::ShowOnOff(const std::string &message, bool on, float durat Show(OSDType::MESSAGE_INFO, message + ": " + (on ? "on" : "off"), duration_s); } - const char *RequestTypeAsString(SystemRequestType type) { switch (type) { case SystemRequestType::INPUT_TEXT_MODAL: return "INPUT_TEXT_MODAL"; diff --git a/Common/System/System.h b/Common/System/System.h index 065ad62dfd..943145e28a 100644 --- a/Common/System/System.h +++ b/Common/System/System.h @@ -224,26 +224,30 @@ enum class OSDType { // PROGRESS_INDETERMINATE, }; -// Data holder. This one is currently global. +// Data holder for on-screen messages. class OnScreenDisplay { public: - // If you specify 0 duration, a duration will be chosen automatically depending on type. + // If you specify 0.0f as duration, a duration will be chosen automatically depending on type. void Show(OSDType type, const std::string &message, float duration_s = 0.0f, const char *id = nullptr); void ShowOnOff(const std::string &message, bool on, float duration_s = 0.0f); - bool IsEmpty() const { return messages_.empty(); } + bool IsEmpty() const { return entries_.empty(); } // Shortcut to skip rendering. + + // Call this every frame, cleans up old entries. void Update(); - struct Message { + struct Entry { + OSDType type; std::string text; const char *id; double endTime; double duration; + float progress; }; - std::vector Messages(); + std::vector Entries(); private: - std::vector messages_; + std::vector entries_; std::mutex mutex_; }; diff --git a/UI/OnScreenDisplay.cpp b/UI/OnScreenDisplay.cpp index 4bcc2bd4f1..5522ea343e 100644 --- a/UI/OnScreenDisplay.cpp +++ b/UI/OnScreenDisplay.cpp @@ -15,6 +15,18 @@ #include "Common/Net/HTTPClient.h" #include "Core/Config.h" +static uint32_t GetOSDBackgroundColor(OSDType type) { + // Colors from Infima + switch (type) { + case OSDType::MESSAGE_ERROR: + case OSDType::MESSAGE_ERROR_DUMP: return 0xd53035; // danger-darker + case OSDType::MESSAGE_WARNING: return 0xd99e00; // warning-darker + case OSDType::MESSAGE_INFO: return 0x606770; // gray-700 + case OSDType::MESSAGE_SUCCESS: return 0x008b00; + default: return 0x606770; + } +} + void OnScreenMessagesView::Draw(UIContext &dc) { if (!g_Config.bShowOnScreenMessages) { return; @@ -26,9 +38,9 @@ void OnScreenMessagesView::Draw(UIContext &dc) { float y = 10.0f; // Then draw them all. - const std::vector messages = g_OSD.Messages(); + const std::vector entries = g_OSD.Entries(); double now = time_now_d(); - for (auto iter = messages.begin(); iter != messages.end(); ++iter) { + for (auto iter = entries.begin(); iter != entries.end(); ++iter) { float alpha = (iter->endTime - now) * 4.0f; if (alpha > 1.0) alpha = 1.0f; if (alpha < 0.0) alpha = 0.0f; @@ -86,9 +98,9 @@ void OnScreenMessagesView::Draw(UIContext &dc) { std::string OnScreenMessagesView::DescribeText() const { std::stringstream ss; - const auto &messages = g_OSD.Messages(); - for (auto iter = messages.begin(); iter != messages.end(); ++iter) { - if (iter != messages.begin()) { + const auto &entries = g_OSD.Entries(); + for (auto iter = entries.begin(); iter != entries.end(); ++iter) { + if (iter != entries.begin()) { ss << "\n"; } ss << iter->text;