| 
									
										
										
										
											2015-05-24 06:55:12 +02:00
										 |  |  | // Copyright 2009 Dolphin Emulator Project
 | 
					
						
							| 
									
										
										
										
											2015-05-18 01:08:10 +02:00
										 |  |  | // Licensed under GPLv2+
 | 
					
						
							| 
									
										
										
										
											2013-04-17 23:09:55 -04:00
										 |  |  | // Refer to the license.txt file included.
 | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-01 13:23:34 -05:00
										 |  |  | #include <algorithm>
 | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | #include <list>
 | 
					
						
							| 
									
										
										
										
											2014-02-17 05:18:15 -05:00
										 |  |  | #include <map>
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-07 20:06:58 -05:00
										 |  |  | #include "Common/CommonTypes.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-17 05:18:15 -05:00
										 |  |  | #include "Common/Timer.h"
 | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-17 05:18:15 -05:00
										 |  |  | #include "Core/ConfigManager.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "VideoCommon/OnScreenDisplay.h"
 | 
					
						
							|  |  |  | #include "VideoCommon/RenderBase.h"
 | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-13 00:48:53 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | namespace OSD | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-24 02:13:54 +02:00
										 |  |  | struct Message | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-09 18:29:13 -05:00
										 |  |  | 	Message() {} | 
					
						
							| 
									
										
										
										
											2015-01-01 13:23:34 -05:00
										 |  |  | 	Message(const std::string& s, u32 ts, u32 rgba) : m_str(s), m_timestamp(ts), m_rgba(rgba) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-04-24 09:21:54 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-01 13:23:34 -05:00
										 |  |  | 	std::string m_str; | 
					
						
							|  |  |  | 	u32 m_timestamp; | 
					
						
							|  |  |  | 	u32 m_rgba; | 
					
						
							| 
									
										
										
										
											2013-04-13 00:48:53 -05:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-04-24 09:21:54 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-24 02:13:54 +02:00
										 |  |  | static std::multimap<CallbackType, Callback> s_callbacks; | 
					
						
							|  |  |  | static std::list<Message> s_msgList; | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-01 13:23:34 -05:00
										 |  |  | void AddMessage(const std::string& str, u32 ms, u32 rgba) | 
					
						
							| 
									
										
										
										
											2013-08-24 01:41:17 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-01-01 13:23:34 -05:00
										 |  |  | 	s_msgList.emplace_back(str, Common::Timer::GetTimeMs() + ms, rgba); | 
					
						
							| 
									
										
										
										
											2013-08-24 01:41:17 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | void DrawMessages() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-12 13:56:53 +02:00
										 |  |  | 	if (!SConfig::GetInstance().bOnScreenDisplayMessages) | 
					
						
							| 
									
										
										
										
											2013-04-24 09:21:54 -04:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2012-11-16 15:16:50 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-24 02:13:54 +02:00
										 |  |  | 	int left = 25, top = 15; | 
					
						
							|  |  |  | 	auto it = s_msgList.begin(); | 
					
						
							|  |  |  | 	while (it != s_msgList.end()) | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-01-01 13:23:34 -05:00
										 |  |  | 		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); | 
					
						
							| 
									
										
										
										
											2013-08-24 02:13:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-01 13:23:34 -05:00
										 |  |  | 		g_renderer->RenderText(it->m_str, left, top, color); | 
					
						
							| 
									
										
										
										
											2013-08-24 02:13:54 +02: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 02:13:54 +02:00
										 |  |  | 	s_msgList.clear(); | 
					
						
							| 
									
										
										
										
											2011-02-02 04:40:27 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-13 00:48:53 -05:00
										 |  |  | // On-Screen Display Callbacks
 | 
					
						
							| 
									
										
										
										
											2013-08-24 02:13:54 +02:00
										 |  |  | void AddCallback(CallbackType type, Callback cb) | 
					
						
							| 
									
										
										
										
											2013-04-13 00:48:53 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-28 19:08:28 -04:00
										 |  |  | 	s_callbacks.emplace(type, cb); | 
					
						
							| 
									
										
										
										
											2013-04-13 00:48:53 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-24 02:13:54 +02:00
										 |  |  | void DoCallbacks(CallbackType type) | 
					
						
							| 
									
										
										
										
											2013-04-13 00:48:53 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-08-24 02:13:54 +02:00
										 |  |  | 	auto it_bounds = s_callbacks.equal_range(type); | 
					
						
							|  |  |  | 	for (auto it = it_bounds.first; it != it_bounds.second; ++it) | 
					
						
							| 
									
										
										
										
											2013-04-24 09:21:54 -04:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2013-08-24 02:13:54 +02:00
										 |  |  | 		it->second(); | 
					
						
							| 
									
										
										
										
											2013-04-24 09:21:54 -04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-09-23 01:43:18 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Wipe all callbacks on shutdown
 | 
					
						
							|  |  |  | 	if (type == OSD_SHUTDOWN) | 
					
						
							|  |  |  | 		s_callbacks.clear(); | 
					
						
							| 
									
										
										
										
											2013-04-13 00:48:53 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | }  // namespace
 |