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>
|
|
|
|
|
|
|
|
#include "Common.h"
|
|
|
|
|
2012-11-16 20:16:50 +00:00
|
|
|
#include "ConfigManager.h"
|
2009-02-23 06:15:48 +00:00
|
|
|
#include "OnScreenDisplay.h"
|
2010-11-18 02:21:26 +00:00
|
|
|
#include "RenderBase.h"
|
2009-02-23 06:15:48 +00:00
|
|
|
#include "Timer.h"
|
|
|
|
|
2013-04-13 05:48:53 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2009-02-23 06:15:48 +00:00
|
|
|
namespace OSD
|
|
|
|
{
|
|
|
|
|
|
|
|
struct MESSAGE
|
|
|
|
{
|
|
|
|
MESSAGE() {}
|
2013-04-24 13:21:54 +00:00
|
|
|
MESSAGE(const char* p, u32 dw)
|
|
|
|
{
|
2009-02-23 06:15:48 +00:00
|
|
|
strncpy(str, p, 255);
|
|
|
|
str[255] = '\0';
|
|
|
|
dwTimeStamp = dw;
|
|
|
|
}
|
|
|
|
char str[256];
|
|
|
|
u32 dwTimeStamp;
|
|
|
|
};
|
|
|
|
|
2013-04-13 05:54:11 +00:00
|
|
|
class OSDCALLBACK
|
2013-04-13 05:48:53 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
CallbackPtr m_functionptr;
|
|
|
|
CallbackType m_type;
|
|
|
|
u32 m_data;
|
|
|
|
public:
|
2013-04-13 05:54:11 +00:00
|
|
|
OSDCALLBACK(CallbackType OnType, CallbackPtr FuncPtr, u32 UserData)
|
2013-04-13 05:48:53 +00:00
|
|
|
{
|
|
|
|
m_type = OnType;
|
|
|
|
m_functionptr = FuncPtr;
|
|
|
|
m_data = UserData;
|
|
|
|
}
|
|
|
|
void Call()
|
|
|
|
{
|
|
|
|
m_functionptr(m_data);
|
|
|
|
}
|
2013-04-24 13:21:54 +00:00
|
|
|
|
2013-04-13 05:48:53 +00:00
|
|
|
CallbackType Type() { return m_type; }
|
|
|
|
};
|
2013-04-24 13:21:54 +00:00
|
|
|
|
2013-04-13 05:54:11 +00:00
|
|
|
std::vector<OSDCALLBACK> m_callbacks;
|
2009-02-23 06:15:48 +00:00
|
|
|
static std::list<MESSAGE> s_listMsgs;
|
|
|
|
|
|
|
|
void AddMessage(const char* pstr, u32 ms)
|
|
|
|
{
|
2010-01-21 21:27:52 +00:00
|
|
|
s_listMsgs.push_back(MESSAGE(pstr, Common::Timer::GetTimeMs() + ms));
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
2013-08-23 23:41:17 +00:00
|
|
|
void AddMessage(const std::string& str, u32 ms)
|
|
|
|
{
|
|
|
|
AddMessage(str.c_str(), ms);
|
|
|
|
}
|
|
|
|
|
2009-02-23 06:15:48 +00:00
|
|
|
void DrawMessages()
|
|
|
|
{
|
2013-04-24 13:21:54 +00:00
|
|
|
if(!SConfig::GetInstance().m_LocalCoreStartupParameter.bOnScreenDisplayMessages)
|
|
|
|
return;
|
2012-11-16 20:16:50 +00:00
|
|
|
|
2009-02-23 06:15:48 +00:00
|
|
|
if (s_listMsgs.size() > 0)
|
|
|
|
{
|
|
|
|
int left = 25, top = 15;
|
|
|
|
std::list<MESSAGE>::iterator it = s_listMsgs.begin();
|
|
|
|
while (it != s_listMsgs.end())
|
|
|
|
{
|
2010-01-21 21:27:52 +00:00
|
|
|
int time_left = (int)(it->dwTimeStamp - Common::Timer::GetTimeMs());
|
2009-02-23 06:15:48 +00:00
|
|
|
int alpha = 255;
|
|
|
|
|
|
|
|
if (time_left < 1024)
|
|
|
|
{
|
|
|
|
alpha = time_left >> 2;
|
2013-04-24 13:21:54 +00:00
|
|
|
if (time_left < 0)
|
|
|
|
alpha = 0;
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
alpha <<= 24;
|
|
|
|
|
2010-11-18 02:21:26 +00:00
|
|
|
g_renderer->RenderText(it->str, left+1, top+1, 0x000000|alpha);
|
|
|
|
g_renderer->RenderText(it->str, left, top, 0xffff30|alpha);
|
2009-02-23 06:15:48 +00:00
|
|
|
top += 15;
|
|
|
|
|
|
|
|
if (time_left <= 0)
|
|
|
|
it = s_listMsgs.erase(it);
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-02 04:40:27 +00:00
|
|
|
void ClearMessages()
|
|
|
|
{
|
|
|
|
std::list<MESSAGE>::iterator it = s_listMsgs.begin();
|
2013-04-24 13:21:54 +00:00
|
|
|
|
|
|
|
while (it != s_listMsgs.end())
|
|
|
|
{
|
2011-02-02 04:40:27 +00:00
|
|
|
it = s_listMsgs.erase(it);
|
2013-04-24 13:21:54 +00:00
|
|
|
}
|
2011-02-02 04:40:27 +00:00
|
|
|
}
|
|
|
|
|
2013-04-13 05:48:53 +00:00
|
|
|
// On-Screen Display Callbacks
|
|
|
|
void AddCallback(CallbackType OnType, CallbackPtr FuncPtr, u32 UserData)
|
|
|
|
{
|
2013-04-13 05:54:11 +00:00
|
|
|
m_callbacks.push_back(OSDCALLBACK(OnType, FuncPtr, UserData));
|
2013-04-13 05:48:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DoCallbacks(CallbackType OnType)
|
|
|
|
{
|
|
|
|
for (auto it = m_callbacks.begin(); it != m_callbacks.end(); ++it)
|
2013-04-24 13:21:54 +00:00
|
|
|
{
|
2013-04-13 05:48:53 +00:00
|
|
|
if (it->Type() == OnType)
|
|
|
|
it->Call();
|
2013-04-24 13:21:54 +00:00
|
|
|
}
|
2013-04-13 05:48:53 +00:00
|
|
|
}
|
|
|
|
|
2009-02-23 06:15:48 +00:00
|
|
|
} // namespace
|