mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Cosmetics
This commit is contained in:
parent
2974b2a91e
commit
c6f7116031
@ -50,16 +50,16 @@ extern CRainmeter* Rainmeter;
|
|||||||
using namespace Gdiplus;
|
using namespace Gdiplus;
|
||||||
|
|
||||||
CTrayWindow::CTrayWindow(HINSTANCE instance) : m_Instance(instance),
|
CTrayWindow::CTrayWindow(HINSTANCE instance) : m_Instance(instance),
|
||||||
m_TrayIcon(),
|
m_Icon(),
|
||||||
m_Measure(),
|
m_Measure(),
|
||||||
m_MeterType(TRAY_METER_TYPE_HISTOGRAM),
|
m_MeterType(TRAY_METER_TYPE_HISTOGRAM),
|
||||||
m_TrayColor1(0, 100, 0),
|
m_Color1(0, 100, 0),
|
||||||
m_TrayColor2(0, 255, 0),
|
m_Color2(0, 255, 0),
|
||||||
m_Bitmap(),
|
m_Bitmap(),
|
||||||
m_TrayValues(),
|
m_Values(),
|
||||||
m_TrayPos(),
|
m_Pos(),
|
||||||
m_Notification(TRAY_NOTIFICATION_NONE),
|
m_Notification(TRAY_NOTIFICATION_NONE),
|
||||||
m_TrayIconEnabled(true)
|
m_IconEnabled(true)
|
||||||
{
|
{
|
||||||
WNDCLASS wc = {0};
|
WNDCLASS wc = {0};
|
||||||
wc.lpfnWndProc = (WNDPROC)WndProc;
|
wc.lpfnWndProc = (WNDPROC)WndProc;
|
||||||
@ -94,33 +94,33 @@ CTrayWindow::~CTrayWindow()
|
|||||||
delete m_Bitmap;
|
delete m_Bitmap;
|
||||||
delete m_Measure;
|
delete m_Measure;
|
||||||
|
|
||||||
for (size_t i = 0, isize = m_TrayIcons.size(); i < isize; ++i)
|
for (size_t i = 0, isize = m_Icons.size(); i < isize; ++i)
|
||||||
{
|
{
|
||||||
DestroyIcon(m_TrayIcons[i]);
|
DestroyIcon(m_Icons[i]);
|
||||||
}
|
}
|
||||||
m_TrayIcons.clear();
|
m_Icons.clear();
|
||||||
|
|
||||||
if (m_Window) DestroyWindow(m_Window);
|
if (m_Window) DestroyWindow(m_Window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTrayWindow::AddTrayIcon()
|
void CTrayWindow::AddTrayIcon()
|
||||||
{
|
{
|
||||||
if (m_TrayIcon)
|
if (m_Icon)
|
||||||
{
|
{
|
||||||
DestroyIcon(m_TrayIcon);
|
DestroyIcon(m_Icon);
|
||||||
m_TrayIcon = NULL;
|
m_Icon = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_TrayIcon = CreateTrayIcon(0);
|
m_Icon = CreateTrayIcon(0);
|
||||||
|
|
||||||
if (m_TrayIcon)
|
if (m_Icon)
|
||||||
{
|
{
|
||||||
NOTIFYICONDATA tnid = {sizeof(NOTIFYICONDATA)};
|
NOTIFYICONDATA tnid = {sizeof(NOTIFYICONDATA)};
|
||||||
tnid.hWnd = m_Window;
|
tnid.hWnd = m_Window;
|
||||||
tnid.uID = IDI_TRAY;
|
tnid.uID = IDI_TRAY;
|
||||||
tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
|
tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
|
||||||
tnid.uCallbackMessage = WM_TRAY_NOTIFYICON;
|
tnid.uCallbackMessage = WM_TRAY_NOTIFYICON;
|
||||||
tnid.hIcon = m_TrayIcon;
|
tnid.hIcon = m_Icon;
|
||||||
wcsncpy_s(tnid.szTip, L"Rainmeter", _TRUNCATE);
|
wcsncpy_s(tnid.szTip, L"Rainmeter", _TRUNCATE);
|
||||||
|
|
||||||
Shell_NotifyIcon(NIM_ADD, &tnid);
|
Shell_NotifyIcon(NIM_ADD, &tnid);
|
||||||
@ -129,7 +129,7 @@ void CTrayWindow::AddTrayIcon()
|
|||||||
|
|
||||||
void CTrayWindow::RemoveTrayIcon()
|
void CTrayWindow::RemoveTrayIcon()
|
||||||
{
|
{
|
||||||
if (m_TrayIcon)
|
if (m_Icon)
|
||||||
{
|
{
|
||||||
NOTIFYICONDATA tnid = {sizeof(NOTIFYICONDATA)};
|
NOTIFYICONDATA tnid = {sizeof(NOTIFYICONDATA)};
|
||||||
tnid.hWnd = m_Window;
|
tnid.hWnd = m_Window;
|
||||||
@ -138,26 +138,26 @@ void CTrayWindow::RemoveTrayIcon()
|
|||||||
|
|
||||||
Shell_NotifyIcon(NIM_DELETE, &tnid);
|
Shell_NotifyIcon(NIM_DELETE, &tnid);
|
||||||
|
|
||||||
DestroyIcon(m_TrayIcon);
|
DestroyIcon(m_Icon);
|
||||||
m_TrayIcon = NULL;
|
m_Icon = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTrayWindow::ModifyTrayIcon(double value)
|
void CTrayWindow::ModifyTrayIcon(double value)
|
||||||
{
|
{
|
||||||
if (m_TrayIcon)
|
if (m_Icon)
|
||||||
{
|
{
|
||||||
DestroyIcon(m_TrayIcon);
|
DestroyIcon(m_Icon);
|
||||||
m_TrayIcon = NULL;
|
m_Icon = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_TrayIcon = CreateTrayIcon(value);
|
m_Icon = CreateTrayIcon(value);
|
||||||
|
|
||||||
NOTIFYICONDATA tnid = {sizeof(NOTIFYICONDATA)};
|
NOTIFYICONDATA tnid = {sizeof(NOTIFYICONDATA)};
|
||||||
tnid.hWnd = m_Window;
|
tnid.hWnd = m_Window;
|
||||||
tnid.uID = IDI_TRAY;
|
tnid.uID = IDI_TRAY;
|
||||||
tnid.uFlags = NIF_ICON;
|
tnid.uFlags = NIF_ICON;
|
||||||
tnid.hIcon = m_TrayIcon;
|
tnid.hIcon = m_Icon;
|
||||||
|
|
||||||
Shell_NotifyIcon(NIM_MODIFY, &tnid);
|
Shell_NotifyIcon(NIM_MODIFY, &tnid);
|
||||||
}
|
}
|
||||||
@ -168,8 +168,8 @@ HICON CTrayWindow::CreateTrayIcon(double value)
|
|||||||
{
|
{
|
||||||
if (m_MeterType == TRAY_METER_TYPE_HISTOGRAM)
|
if (m_MeterType == TRAY_METER_TYPE_HISTOGRAM)
|
||||||
{
|
{
|
||||||
m_TrayValues[m_TrayPos] = value;
|
m_Values[m_Pos] = value;
|
||||||
m_TrayPos = (m_TrayPos + 1) % TRAYICON_SIZE;
|
m_Pos = (m_Pos + 1) % TRAYICON_SIZE;
|
||||||
|
|
||||||
Bitmap trayBitmap(TRAYICON_SIZE, TRAYICON_SIZE);
|
Bitmap trayBitmap(TRAYICON_SIZE, TRAYICON_SIZE);
|
||||||
Graphics graphics(&trayBitmap);
|
Graphics graphics(&trayBitmap);
|
||||||
@ -184,31 +184,31 @@ HICON CTrayWindow::CreateTrayIcon(double value)
|
|||||||
for (int i = 0; i < TRAYICON_SIZE; ++i)
|
for (int i = 0; i < TRAYICON_SIZE; ++i)
|
||||||
{
|
{
|
||||||
points[i + 1].X = i;
|
points[i + 1].X = i;
|
||||||
points[i + 1].Y = (int)(TRAYICON_SIZE * (1.0 - m_TrayValues[(m_TrayPos + i) % TRAYICON_SIZE]));
|
points[i + 1].Y = (int)(TRAYICON_SIZE * (1.0 - m_Values[(m_Pos + i) % TRAYICON_SIZE]));
|
||||||
}
|
}
|
||||||
|
|
||||||
SolidBrush brush(m_TrayColor1);
|
SolidBrush brush(m_Color1);
|
||||||
graphics.FillRectangle(&brush, 0, 0, TRAYICON_SIZE, TRAYICON_SIZE);
|
graphics.FillRectangle(&brush, 0, 0, TRAYICON_SIZE, TRAYICON_SIZE);
|
||||||
|
|
||||||
SolidBrush brush2(m_TrayColor2);
|
SolidBrush brush2(m_Color2);
|
||||||
graphics.FillPolygon(&brush2, points, TRAYICON_SIZE + 2);
|
graphics.FillPolygon(&brush2, points, TRAYICON_SIZE + 2);
|
||||||
|
|
||||||
HICON icon;
|
HICON icon;
|
||||||
trayBitmap.GetHICON(&icon);
|
trayBitmap.GetHICON(&icon);
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
else if (m_MeterType == TRAY_METER_TYPE_BITMAP && (m_Bitmap || !m_TrayIcons.empty()))
|
else if (m_MeterType == TRAY_METER_TYPE_BITMAP && (m_Bitmap || !m_Icons.empty()))
|
||||||
{
|
{
|
||||||
if (!m_TrayIcons.empty())
|
if (!m_Icons.empty())
|
||||||
{
|
{
|
||||||
size_t frame = 0;
|
size_t frame = 0;
|
||||||
size_t frameCount = m_TrayIcons.size();
|
size_t frameCount = m_Icons.size();
|
||||||
|
|
||||||
// Select the correct frame linearly
|
// Select the correct frame linearly
|
||||||
frame = (size_t)(value * frameCount);
|
frame = (size_t)(value * frameCount);
|
||||||
frame = min((frameCount - 1), frame);
|
frame = min((frameCount - 1), frame);
|
||||||
|
|
||||||
return CopyIcon(m_TrayIcons[frame]);
|
return CopyIcon(m_Icons[frame]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -317,18 +317,18 @@ void CTrayWindow::ReadConfig(CConfigParser& parser)
|
|||||||
delete m_Bitmap;
|
delete m_Bitmap;
|
||||||
m_Bitmap = NULL;
|
m_Bitmap = NULL;
|
||||||
|
|
||||||
std::vector<HICON>::const_iterator iter = m_TrayIcons.begin();
|
std::vector<HICON>::const_iterator iter = m_Icons.begin();
|
||||||
for ( ; iter != m_TrayIcons.end(); ++iter)
|
for ( ; iter != m_Icons.end(); ++iter)
|
||||||
{
|
{
|
||||||
DestroyIcon((*iter));
|
DestroyIcon((*iter));
|
||||||
}
|
}
|
||||||
m_TrayIcons.clear();
|
m_Icons.clear();
|
||||||
|
|
||||||
m_MeterType = TRAY_METER_TYPE_NONE;
|
m_MeterType = TRAY_METER_TYPE_NONE;
|
||||||
|
|
||||||
// Read tray settings
|
// Read tray settings
|
||||||
m_TrayIconEnabled = 0!=parser.ReadInt(L"Rainmeter", L"TrayIcon", 1);
|
m_IconEnabled = 0!=parser.ReadInt(L"Rainmeter", L"TrayIcon", 1);
|
||||||
if (m_TrayIconEnabled)
|
if (m_IconEnabled)
|
||||||
{
|
{
|
||||||
const std::wstring& measureName = parser.ReadString(L"TrayMeasure", L"Measure", L"");
|
const std::wstring& measureName = parser.ReadString(L"TrayMeasure", L"Measure", L"");
|
||||||
|
|
||||||
@ -363,8 +363,8 @@ void CTrayWindow::ReadConfig(CConfigParser& parser)
|
|||||||
else if (_wcsicmp(type, L"HISTOGRAM") == 0)
|
else if (_wcsicmp(type, L"HISTOGRAM") == 0)
|
||||||
{
|
{
|
||||||
m_MeterType = TRAY_METER_TYPE_HISTOGRAM;
|
m_MeterType = TRAY_METER_TYPE_HISTOGRAM;
|
||||||
m_TrayColor1 = parser.ReadColor(L"TrayMeasure", L"TrayColor1", Color::MakeARGB(255, 0, 100, 0));
|
m_Color1 = parser.ReadColor(L"TrayMeasure", L"TrayColor1", Color::MakeARGB(255, 0, 100, 0));
|
||||||
m_TrayColor2 = parser.ReadColor(L"TrayMeasure", L"TrayColor2", Color::MakeARGB(255, 0, 255, 0));
|
m_Color2 = parser.ReadColor(L"TrayMeasure", L"TrayColor2", Color::MakeARGB(255, 0, 255, 0));
|
||||||
}
|
}
|
||||||
else if (_wcsicmp(type, L"BITMAP") == 0)
|
else if (_wcsicmp(type, L"BITMAP") == 0)
|
||||||
{
|
{
|
||||||
@ -389,13 +389,13 @@ void CTrayWindow::ReadConfig(CConfigParser& parser)
|
|||||||
_snwprintf_s(buffer, _TRUNCATE, imagePath, count++);
|
_snwprintf_s(buffer, _TRUNCATE, imagePath, count++);
|
||||||
|
|
||||||
hIcon = (HICON)LoadImage(NULL, buffer, IMAGE_ICON, TRAYICON_SIZE, TRAYICON_SIZE, LR_LOADFROMFILE);
|
hIcon = (HICON)LoadImage(NULL, buffer, IMAGE_ICON, TRAYICON_SIZE, TRAYICON_SIZE, LR_LOADFROMFILE);
|
||||||
if (hIcon) m_TrayIcons.push_back(hIcon);
|
if (hIcon) m_Icons.push_back(hIcon);
|
||||||
if (wcscmp(imagePath, buffer) == 0) break;
|
if (wcscmp(imagePath, buffer) == 0) break;
|
||||||
}
|
}
|
||||||
while(hIcon != NULL);
|
while(hIcon != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_TrayIcons.empty())
|
if (m_Icons.empty())
|
||||||
{
|
{
|
||||||
// No icons found so load as bitmap
|
// No icons found so load as bitmap
|
||||||
delete m_Bitmap;
|
delete m_Bitmap;
|
||||||
|
@ -46,7 +46,7 @@ public:
|
|||||||
|
|
||||||
void ReadConfig(CConfigParser& parser);
|
void ReadConfig(CConfigParser& parser);
|
||||||
HWND GetWindow() { return m_Window; }
|
HWND GetWindow() { return m_Window; }
|
||||||
bool IsTrayIconEnabled() { return m_TrayIconEnabled; }
|
bool IsTrayIconEnabled() { return m_IconEnabled; }
|
||||||
|
|
||||||
void ShowWelcomeNotification();
|
void ShowWelcomeNotification();
|
||||||
void ShowUpdateNotification(const WCHAR* newVersion);
|
void ShowUpdateNotification(const WCHAR* newVersion);
|
||||||
@ -69,24 +69,24 @@ private:
|
|||||||
|
|
||||||
void ShowNotification(TRAY_NOTIFICATION id, const WCHAR* title, const WCHAR* text);
|
void ShowNotification(TRAY_NOTIFICATION id, const WCHAR* title, const WCHAR* text);
|
||||||
|
|
||||||
HICON m_TrayIcon;
|
HICON m_Icon;
|
||||||
HWND m_Window;
|
HWND m_Window;
|
||||||
HINSTANCE m_Instance;
|
HINSTANCE m_Instance;
|
||||||
CMeasure* m_Measure;
|
CMeasure* m_Measure;
|
||||||
|
|
||||||
TRAY_METER_TYPE m_MeterType;
|
TRAY_METER_TYPE m_MeterType;
|
||||||
Gdiplus::Color m_TrayColor1;
|
Gdiplus::Color m_Color1;
|
||||||
Gdiplus::Color m_TrayColor2;
|
Gdiplus::Color m_Color2;
|
||||||
Gdiplus::Bitmap* m_Bitmap;
|
Gdiplus::Bitmap* m_Bitmap;
|
||||||
|
|
||||||
std::vector<HICON> m_TrayIcons;
|
std::vector<HICON> m_Icons;
|
||||||
|
|
||||||
double m_TrayValues[TRAYICON_SIZE];
|
double m_Values[TRAYICON_SIZE];
|
||||||
int m_TrayPos;
|
int m_Pos;
|
||||||
|
|
||||||
TRAY_NOTIFICATION m_Notification;
|
TRAY_NOTIFICATION m_Notification;
|
||||||
|
|
||||||
bool m_TrayIconEnabled;
|
bool m_IconEnabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user