From 9d5c6c55fe1148c6dc5418a824d2bc84e83d2a76 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 1 Jan 2015 13:23:34 -0500 Subject: [PATCH] OnScreenDisplay: Allow for different colored messages --- Source/Core/VideoCommon/OnScreenDisplay.cpp | 29 +++++++++------------ Source/Core/VideoCommon/OnScreenDisplay.h | 4 +-- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Source/Core/VideoCommon/OnScreenDisplay.cpp b/Source/Core/VideoCommon/OnScreenDisplay.cpp index b25f461336..92b94194d6 100644 --- a/Source/Core/VideoCommon/OnScreenDisplay.cpp +++ b/Source/Core/VideoCommon/OnScreenDisplay.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include #include #include #include @@ -21,18 +22,21 @@ namespace OSD struct Message { Message() {} - Message(const std::string& s, u32 ts) : str(s), timestamp(ts) {} + Message(const std::string& s, u32 ts, u32 rgba) : m_str(s), m_timestamp(ts), m_rgba(rgba) + { + } - std::string str; - u32 timestamp; + std::string m_str; + u32 m_timestamp; + u32 m_rgba; }; static std::multimap s_callbacks; static std::list s_msgList; -void AddMessage(const std::string& str, u32 ms) +void AddMessage(const std::string& str, u32 ms, u32 rgba) { - s_msgList.push_back(Message(str, Common::Timer::GetTimeMs() + ms)); + s_msgList.emplace_back(str, Common::Timer::GetTimeMs() + ms, rgba); } void DrawMessages() @@ -44,19 +48,12 @@ void DrawMessages() auto it = s_msgList.begin(); while (it != s_msgList.end()) { - int time_left = (int)(it->timestamp - Common::Timer::GetTimeMs()); - u32 alpha = 255; + int time_left = (int)(it->m_timestamp - Common::Timer::GetTimeMs()); + float alpha = std::max(1.0f, std::min(0.0f, time_left / 1024.0f)); + u32 color = (it->m_rgba & 0xFFFFFF) | ((u32)((it->m_rgba >> 24) * alpha) << 24); - if (time_left < 1024) - { - alpha = time_left >> 2; - if (time_left < 0) - alpha = 0; - } + g_renderer->RenderText(it->m_str, left, top, color); - alpha <<= 24; - - g_renderer->RenderText(it->str, left, top, 0xffff30 | alpha); top += 15; if (time_left <= 0) diff --git a/Source/Core/VideoCommon/OnScreenDisplay.h b/Source/Core/VideoCommon/OnScreenDisplay.h index eb7302c57f..90b13968d4 100644 --- a/Source/Core/VideoCommon/OnScreenDisplay.h +++ b/Source/Core/VideoCommon/OnScreenDisplay.h @@ -11,8 +11,8 @@ namespace OSD { -// On-screen message display -void AddMessage(const std::string& str, u32 ms = 2000); +// On-screen message display (colored yellow by default) +void AddMessage(const std::string& str, u32 ms = 2000, u32 rgba = 0xFFFFFF30); void DrawMessages(); // draw the current messages on the screen. Only call once per frame. void ClearMessages();