diff options
| author | Jules Blok <jules.blok@gmail.com> | 2015-06-10 00:00:12 +0200 |
|---|---|---|
| committer | Jules Blok <jules.blok@gmail.com> | 2015-06-10 00:00:12 +0200 |
| commit | 7dfced21a2e5aac7195e0e1ad76468e30306766b (patch) | |
| tree | bd671b639d3d911460b767caabad8fc8a759a6bf /Source/Core/VideoCommon/OnScreenDisplay.cpp | |
| parent | c25be031fc1031d795157d8344b87b7841145197 (diff) | |
| parent | 7b0a65e295c784f9d573f2ef52d4e2a7b9bb2889 (diff) | |
Merge branch 'master' into stable
Diffstat (limited to 'Source/Core/VideoCommon/OnScreenDisplay.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/OnScreenDisplay.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/Source/Core/VideoCommon/OnScreenDisplay.cpp b/Source/Core/VideoCommon/OnScreenDisplay.cpp new file mode 100644 index 0000000000..2f59cf50dd --- /dev/null +++ b/Source/Core/VideoCommon/OnScreenDisplay.cpp @@ -0,0 +1,90 @@ +// 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().m_LocalCoreStartupParameter.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.insert(std::pair<CallbackType, Callback>(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 == OSD_SHUTDOWN) + s_callbacks.clear(); +} + +} // namespace |
