Merge pull request #1803 from lioncash/rgb
OnScreenDisplay: Allow for different colored messages
This commit is contained in:
commit
405444d4fe
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under GPLv2
|
// Licensed under GPLv2
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -21,18 +22,21 @@ namespace OSD
|
||||||
struct Message
|
struct Message
|
||||||
{
|
{
|
||||||
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;
|
std::string m_str;
|
||||||
u32 timestamp;
|
u32 m_timestamp;
|
||||||
|
u32 m_rgba;
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::multimap<CallbackType, Callback> s_callbacks;
|
static std::multimap<CallbackType, Callback> s_callbacks;
|
||||||
static std::list<Message> s_msgList;
|
static std::list<Message> 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()
|
void DrawMessages()
|
||||||
|
@ -44,19 +48,12 @@ void DrawMessages()
|
||||||
auto it = s_msgList.begin();
|
auto it = s_msgList.begin();
|
||||||
while (it != s_msgList.end())
|
while (it != s_msgList.end())
|
||||||
{
|
{
|
||||||
int time_left = (int)(it->timestamp - Common::Timer::GetTimeMs());
|
int time_left = (int)(it->m_timestamp - Common::Timer::GetTimeMs());
|
||||||
u32 alpha = 255;
|
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)
|
g_renderer->RenderText(it->m_str, left, top, color);
|
||||||
{
|
|
||||||
alpha = time_left >> 2;
|
|
||||||
if (time_left < 0)
|
|
||||||
alpha = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
alpha <<= 24;
|
|
||||||
|
|
||||||
g_renderer->RenderText(it->str, left, top, 0xffff30 | alpha);
|
|
||||||
top += 15;
|
top += 15;
|
||||||
|
|
||||||
if (time_left <= 0)
|
if (time_left <= 0)
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
|
|
||||||
namespace OSD
|
namespace OSD
|
||||||
{
|
{
|
||||||
// On-screen message display
|
// On-screen message display (colored yellow by default)
|
||||||
void AddMessage(const std::string& str, u32 ms = 2000);
|
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 DrawMessages(); // draw the current messages on the screen. Only call once per frame.
|
||||||
void ClearMessages();
|
void ClearMessages();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue