2014-07-06 23:54:47 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2015-07-02 03:17:14 +00:00
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
class ToastInfo;
|
2014-07-06 23:54:47 +00:00
|
|
|
|
|
|
|
class IMessageManager
|
|
|
|
{
|
|
|
|
public:
|
2015-07-11 12:27:22 +00:00
|
|
|
virtual void DisplayMessage(string title, string message) = 0;
|
2015-07-02 03:17:14 +00:00
|
|
|
virtual void DisplayToast(shared_ptr<ToastInfo> toast) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ToastInfo
|
|
|
|
{
|
|
|
|
private:
|
2015-07-11 12:27:22 +00:00
|
|
|
string _title;
|
|
|
|
string _message;
|
2015-07-02 03:17:14 +00:00
|
|
|
uint8_t* _icon;
|
|
|
|
uint32_t _iconSize;
|
|
|
|
uint64_t _endTime;
|
|
|
|
uint64_t _startTime;
|
|
|
|
|
2015-07-11 12:27:22 +00:00
|
|
|
uint8_t* ReadFile(string filename, uint32_t &fileSize)
|
2015-07-02 03:17:14 +00:00
|
|
|
{
|
|
|
|
ifstream file(filename, ios::in | ios::binary);
|
|
|
|
if(file) {
|
|
|
|
file.seekg(0, ios::end);
|
|
|
|
fileSize = (uint32_t)file.tellg();
|
|
|
|
file.seekg(0, ios::beg);
|
|
|
|
|
|
|
|
uint8_t* buffer = new uint8_t[fileSize];
|
|
|
|
file.read((char*)buffer, fileSize);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t GetCurrentTime()
|
|
|
|
{
|
|
|
|
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2015-07-11 12:27:22 +00:00
|
|
|
ToastInfo(string title, string message, int displayDuration, string iconFile)
|
2015-07-02 03:17:14 +00:00
|
|
|
{
|
|
|
|
_title = title;
|
|
|
|
_message = message;
|
|
|
|
|
|
|
|
_icon = ReadFile(iconFile, _iconSize);
|
|
|
|
|
|
|
|
_startTime = GetCurrentTime();
|
|
|
|
_endTime = _startTime + displayDuration;
|
|
|
|
}
|
|
|
|
|
2015-07-11 12:27:22 +00:00
|
|
|
ToastInfo(string title, string message, int displayDuration, uint8_t* iconData, uint32_t iconSize)
|
2015-07-02 03:17:14 +00:00
|
|
|
{
|
|
|
|
_title = title;
|
|
|
|
_message = message;
|
|
|
|
|
|
|
|
_iconSize = iconSize;
|
|
|
|
_icon = new uint8_t[iconSize];
|
|
|
|
memcpy(_icon, iconData, iconSize);
|
|
|
|
|
|
|
|
_startTime = GetCurrentTime();
|
|
|
|
_endTime = _startTime + displayDuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
~ToastInfo()
|
|
|
|
{
|
|
|
|
if(_icon) {
|
|
|
|
delete _icon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-11 12:27:22 +00:00
|
|
|
string GetToastTitle()
|
2015-07-02 03:17:14 +00:00
|
|
|
{
|
|
|
|
return _title;
|
|
|
|
}
|
|
|
|
|
2015-07-11 12:27:22 +00:00
|
|
|
string GetToastMessage()
|
2015-07-02 03:17:14 +00:00
|
|
|
{
|
|
|
|
return _message;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t* GetToastIcon()
|
|
|
|
{
|
|
|
|
return _icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t GetIconSize()
|
|
|
|
{
|
|
|
|
return _iconSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasIcon()
|
|
|
|
{
|
|
|
|
return _iconSize > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
float GetOpacity()
|
|
|
|
{
|
|
|
|
uint64_t currentTime = GetCurrentTime();
|
2016-02-06 23:33:24 +00:00
|
|
|
if(currentTime - _startTime < 200) {
|
|
|
|
return (currentTime - _startTime) * 5.0f / 1000.0f;
|
|
|
|
} else if(_endTime - currentTime < 200) {
|
|
|
|
return (_endTime - currentTime) * 5.0f / 1000.0f;
|
2015-07-02 03:17:14 +00:00
|
|
|
} else {
|
|
|
|
return 1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsToastExpired()
|
|
|
|
{
|
|
|
|
return _endTime < GetCurrentTime();
|
|
|
|
}
|
2014-07-06 23:54:47 +00:00
|
|
|
};
|