1 #pragma once
2 
3 #include "stdafx.h"
4 #include <chrono>
5 
6 class ToastInfo;
7 
8 class IMessageManager
9 {
10 public:
11 	virtual void DisplayMessage(string title, string message) = 0;
12 };
13 
14 class ToastInfo
15 {
16 private:
17 	string _title;
18 	string _message;
19 	uint64_t _endTime;
20 	uint64_t _startTime;
21 
GetCurrentTime()22 	uint64_t GetCurrentTime()
23 	{
24 		return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
25 	}
26 
27 public:
ToastInfo(string title,string message,int displayDuration)28 	ToastInfo(string title, string message, int displayDuration)
29 	{
30 		_title = title;
31 		_message = message;
32 		_startTime = GetCurrentTime();
33 		_endTime = _startTime + displayDuration;
34 	}
35 
GetToastTitle()36 	string GetToastTitle()
37 	{
38 		return _title;
39 	}
40 
GetToastMessage()41 	string GetToastMessage()
42 	{
43 		return _message;
44 	}
45 
GetOpacity()46 	float GetOpacity()
47 	{
48 		uint64_t currentTime = GetCurrentTime();
49 		if(currentTime - _startTime < 200) {
50 			return (currentTime - _startTime) * 5.0f / 1000.0f;
51 		} else if(_endTime - currentTime < 200) {
52 			return (_endTime - currentTime) * 5.0f / 1000.0f;
53 		} else if(currentTime >= _endTime) {
54 			return 0.0f;
55 		} else {
56 			return 1.0f;
57 		}
58 	}
59 
IsToastExpired()60 	bool IsToastExpired()
61 	{
62 		return _endTime < GetCurrentTime();
63 	}
64 };