mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-15 22:09:19 -07:00
91 lines
1.7 KiB
C++
91 lines
1.7 KiB
C++
// Copyright 2009 Dolphin Emulator Project
|
|
// Licensed under GPLv2+
|
|
// Refer to the license.txt file included.
|
|
|
|
#include <algorithm>
|
|
#include <list>
|
|
#include <map>
|
|
#include <string>
|
|
|
|
#include "Common/CommonTypes.h"
|
|
#include "Common/Timer.h"
|
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "VideoCommon/OnScreenDisplay.h"
|
|
#include "VideoCommon/RenderBase.h"
|
|
|
|
|
|
namespace OSD
|
|
{
|
|
|
|
struct Message
|
|
{
|
|
Message() {}
|
|
Message(const std::string& s, u32 ts, u32 rgba) : m_str(s), m_timestamp(ts), m_rgba(rgba)
|
|
{
|
|
}
|
|
|
|
std::string m_str;
|
|
u32 m_timestamp;
|
|
u32 m_rgba;
|
|
};
|
|
|
|
static std::multimap<CallbackType, Callback> s_callbacks;
|
|
static std::list<Message> s_msgList;
|
|
|
|
void AddMessage(const std::string& str, u32 ms, u32 rgba)
|
|
{
|
|
s_msgList.emplace_back(str, Common::Timer::GetTimeMs() + ms, rgba);
|
|
}
|
|
|
|
void DrawMessages()
|
|
{
|
|
if (!SConfig::GetInstance().bOnScreenDisplayMessages)
|
|
return;
|
|
|
|
int left = 25, top = 15;
|
|
auto it = s_msgList.begin();
|
|
while (it != s_msgList.end())
|
|
{
|
|
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);
|
|
|
|
g_renderer->RenderText(it->m_str, left, top, color);
|
|
|
|
top += 15;
|
|
|
|
if (time_left <= 0)
|
|
it = s_msgList.erase(it);
|
|
else
|
|
++it;
|
|
}
|
|
}
|
|
|
|
void ClearMessages()
|
|
{
|
|
s_msgList.clear();
|
|
}
|
|
|
|
// On-Screen Display Callbacks
|
|
void AddCallback(CallbackType type, Callback cb)
|
|
{
|
|
s_callbacks.emplace(type, cb);
|
|
}
|
|
|
|
void DoCallbacks(CallbackType type)
|
|
{
|
|
auto it_bounds = s_callbacks.equal_range(type);
|
|
for (auto it = it_bounds.first; it != it_bounds.second; ++it)
|
|
{
|
|
it->second();
|
|
}
|
|
|
|
// Wipe all callbacks on shutdown
|
|
if (type == CallbackType::Shutdown)
|
|
s_callbacks.clear();
|
|
}
|
|
|
|
} // namespace
|