2013-04-18 03:09:55 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2009-02-23 06:15:48 +00:00
|
|
|
|
|
|
|
#include <list>
|
2014-02-17 10:18:15 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/Timer.h"
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
|
|
|
|
#include "VideoCommon/OnScreenDisplay.h"
|
|
|
|
#include "VideoCommon/RenderBase.h"
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2013-04-13 05:48:53 +00:00
|
|
|
|
2009-02-23 06:15:48 +00:00
|
|
|
namespace OSD
|
|
|
|
{
|
|
|
|
|
2013-08-24 00:13:54 +00:00
|
|
|
struct Message
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2014-02-09 23:29:13 +00:00
|
|
|
Message() {}
|
|
|
|
Message(const std::string& s, u32 ts) : str(s), timestamp(ts) {}
|
2013-04-24 13:21:54 +00:00
|
|
|
|
2013-08-24 00:13:54 +00:00
|
|
|
std::string str;
|
|
|
|
u32 timestamp;
|
2013-04-13 05:48:53 +00:00
|
|
|
};
|
2013-04-24 13:21:54 +00:00
|
|
|
|
2013-08-24 00:13:54 +00:00
|
|
|
static std::multimap<CallbackType, Callback> s_callbacks;
|
|
|
|
static std::list<Message> s_msgList;
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2013-08-23 23:41:17 +00:00
|
|
|
void AddMessage(const std::string& str, u32 ms)
|
|
|
|
{
|
2013-08-24 00:13:54 +00:00
|
|
|
s_msgList.push_back(Message(str, Common::Timer::GetTimeMs() + ms));
|
2013-08-23 23:41:17 +00:00
|
|
|
}
|
|
|
|
|
2009-02-23 06:15:48 +00:00
|
|
|
void DrawMessages()
|
|
|
|
{
|
2014-03-10 11:30:55 +00:00
|
|
|
if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bOnScreenDisplayMessages)
|
2013-04-24 13:21:54 +00:00
|
|
|
return;
|
2012-11-16 20:16:50 +00:00
|
|
|
|
2013-08-24 00:13:54 +00:00
|
|
|
int left = 25, top = 15;
|
|
|
|
auto it = s_msgList.begin();
|
|
|
|
while (it != s_msgList.end())
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2013-08-24 00:13:54 +00:00
|
|
|
int time_left = (int)(it->timestamp - Common::Timer::GetTimeMs());
|
|
|
|
u32 alpha = 255;
|
|
|
|
|
|
|
|
if (time_left < 1024)
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2013-08-24 00:13:54 +00:00
|
|
|
alpha = time_left >> 2;
|
|
|
|
if (time_left < 0)
|
|
|
|
alpha = 0;
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
2013-08-24 00:13:54 +00:00
|
|
|
|
|
|
|
alpha <<= 24;
|
|
|
|
|
2014-03-12 19:33:41 +00:00
|
|
|
g_renderer->RenderText(it->str, left + 1, top + 1, 0x000000 | alpha);
|
|
|
|
g_renderer->RenderText(it->str, left, top, 0xffff30 | alpha);
|
2013-08-24 00:13:54 +00:00
|
|
|
top += 15;
|
|
|
|
|
|
|
|
if (time_left <= 0)
|
|
|
|
it = s_msgList.erase(it);
|
|
|
|
else
|
|
|
|
++it;
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-02 04:40:27 +00:00
|
|
|
void ClearMessages()
|
|
|
|
{
|
2013-08-24 00:13:54 +00:00
|
|
|
s_msgList.clear();
|
2011-02-02 04:40:27 +00:00
|
|
|
}
|
|
|
|
|
2013-04-13 05:48:53 +00:00
|
|
|
// On-Screen Display Callbacks
|
2013-08-24 00:13:54 +00:00
|
|
|
void AddCallback(CallbackType type, Callback cb)
|
2013-04-13 05:48:53 +00:00
|
|
|
{
|
2013-08-24 00:13:54 +00:00
|
|
|
s_callbacks.insert(std::pair<CallbackType, Callback>(type, cb));
|
2013-04-13 05:48:53 +00:00
|
|
|
}
|
|
|
|
|
2013-08-24 00:13:54 +00:00
|
|
|
void DoCallbacks(CallbackType type)
|
2013-04-13 05:48:53 +00:00
|
|
|
{
|
2013-08-24 00:13:54 +00:00
|
|
|
auto it_bounds = s_callbacks.equal_range(type);
|
|
|
|
for (auto it = it_bounds.first; it != it_bounds.second; ++it)
|
2013-04-24 13:21:54 +00:00
|
|
|
{
|
2013-08-24 00:13:54 +00:00
|
|
|
it->second();
|
2013-04-24 13:21:54 +00:00
|
|
|
}
|
2013-09-23 06:43:18 +00:00
|
|
|
|
|
|
|
// Wipe all callbacks on shutdown
|
|
|
|
if (type == OSD_SHUTDOWN)
|
|
|
|
s_callbacks.clear();
|
2013-04-13 05:48:53 +00:00
|
|
|
}
|
|
|
|
|
2009-02-23 06:15:48 +00:00
|
|
|
} // namespace
|