Code cleanup and optimization for writing the skin settings individually.

This commit is contained in:
spx 2011-08-06 10:43:14 +00:00
parent d300d469b0
commit 5cb6b0f71b
2 changed files with 116 additions and 76 deletions

View File

@ -572,7 +572,7 @@ void CMeterWindow::MoveWindow(int x, int y)
if (m_SavePosition) if (m_SavePosition)
{ {
WriteConfig(); WriteConfig(SETTING_WINDOWPOSITION);
} }
} }
@ -1889,6 +1889,7 @@ void CMeterWindow::ScreenToWindow()
*/ */
void CMeterWindow::ReadConfig() void CMeterWindow::ReadConfig()
{ {
WCHAR buffer[32];
const std::wstring& iniFile = m_Rainmeter->GetIniFile(); const std::wstring& iniFile = m_Rainmeter->GetIniFile();
const WCHAR* section = L"Rainmeter"; const WCHAR* section = L"Rainmeter";
@ -1938,45 +1939,33 @@ void CMeterWindow::ReadConfig()
} }
// Check if the window position should be read as a formula // Check if the window position should be read as a formula
double value;
if (!m_WindowX.empty() && m_WindowX[0] == L'(' && m_WindowX[m_WindowX.size() - 1] == L')') if (!m_WindowX.empty() && m_WindowX[0] == L'(' && m_WindowX[m_WindowX.size() - 1] == L')')
{ {
double value = parser.ReadFormula(section, L"WindowX", 0.0); if (!parser.ReadFormula(m_WindowX, &value))
WCHAR buffer[32]; {
value = 0.0;
}
_snwprintf_s(buffer, _TRUNCATE, L"%i", (int)value); _snwprintf_s(buffer, _TRUNCATE, L"%i", (int)value);
m_WindowX = buffer; m_WindowX = buffer;
} }
if (!m_WindowY.empty() && m_WindowY[0] == L'(' && m_WindowY[m_WindowY.size() - 1] == L')') if (!m_WindowY.empty() && m_WindowY[0] == L'(' && m_WindowY[m_WindowY.size() - 1] == L')')
{ {
double value = parser.ReadFormula(section, L"WindowY", 0.0); if (!parser.ReadFormula(m_WindowY, &value))
WCHAR buffer[32]; {
value = 0.0;
}
_snwprintf_s(buffer, _TRUNCATE, L"%i", (int)value); _snwprintf_s(buffer, _TRUNCATE, L"%i", (int)value);
m_WindowY = buffer; m_WindowY = buffer;
} }
int zPos = parser.ReadInt(section, L"AlwaysOnTop", m_WindowZPosition); int zPos = parser.ReadInt(section, L"AlwaysOnTop", m_WindowZPosition);
if (zPos == -1) m_WindowZPosition = (zPos >= ZPOSITION_ONDESKTOP && zPos <= ZPOSITION_ONTOPMOST) ? (ZPOSITION)zPos : ZPOSITION_NORMAL;
{
m_WindowZPosition = ZPOSITION_ONBOTTOM; int hideMode = parser.ReadInt(section, L"HideOnMouseOver", m_WindowHide);
} m_WindowHide = (hideMode >= HIDEMODE_NONE && hideMode <= HIDEMODE_FADEOUT) ? (HIDEMODE)hideMode : HIDEMODE_NONE;
else if (zPos == -2)
{
m_WindowZPosition = ZPOSITION_ONDESKTOP;
}
else if (zPos == 1)
{
m_WindowZPosition = ZPOSITION_ONTOP;
}
else if (zPos == 2)
{
m_WindowZPosition = ZPOSITION_ONTOPMOST;
}
else
{
m_WindowZPosition = ZPOSITION_NORMAL;
}
m_WindowDraggable = 0!=parser.ReadInt(section, L"Draggable", m_WindowDraggable); m_WindowDraggable = 0!=parser.ReadInt(section, L"Draggable", m_WindowDraggable);
m_WindowHide = (HIDEMODE)parser.ReadInt(section, L"HideOnMouseOver", m_WindowHide);
m_WindowStartHidden = 0!=parser.ReadInt(section, L"StartHidden", m_WindowStartHidden); m_WindowStartHidden = 0!=parser.ReadInt(section, L"StartHidden", m_WindowStartHidden);
m_SavePosition = 0!=parser.ReadInt(section, L"SavePosition", m_SavePosition); m_SavePosition = 0!=parser.ReadInt(section, L"SavePosition", m_SavePosition);
m_SnapEdges = 0!=parser.ReadInt(section, L"SnapEdges", m_SnapEdges); m_SnapEdges = 0!=parser.ReadInt(section, L"SnapEdges", m_SnapEdges);
@ -2008,13 +1997,16 @@ void CMeterWindow::ReadConfig()
** Writes the new settings to the config ** Writes the new settings to the config
** **
*/ */
void CMeterWindow::WriteConfig() void CMeterWindow::WriteConfig(INT setting)
{ {
WCHAR buffer[32];
const WCHAR* iniFile = m_Rainmeter->GetIniFile().c_str(); const WCHAR* iniFile = m_Rainmeter->GetIniFile().c_str();
const WCHAR* section = m_SkinName.c_str();
if (*iniFile) if (*iniFile)
{
WCHAR buffer[32];
const WCHAR* section = m_SkinName.c_str();
if (setting & SETTING_WINDOWPOSITION)
{ {
// If position needs to be save, do so. // If position needs to be save, do so.
if (m_SavePosition) if (m_SavePosition)
@ -2023,31 +2015,62 @@ void CMeterWindow::WriteConfig()
WritePrivateProfileString(section, L"WindowX", m_WindowX.c_str(), iniFile); WritePrivateProfileString(section, L"WindowX", m_WindowX.c_str(), iniFile);
WritePrivateProfileString(section, L"WindowY", m_WindowY.c_str(), iniFile); WritePrivateProfileString(section, L"WindowY", m_WindowY.c_str(), iniFile);
} }
}
if (setting & SETTING_ALPHAVALUE)
{
_snwprintf_s(buffer, _TRUNCATE, L"%i", m_AlphaValue); _snwprintf_s(buffer, _TRUNCATE, L"%i", m_AlphaValue);
WritePrivateProfileString(section, L"AlphaValue", buffer, iniFile); WritePrivateProfileString(section, L"AlphaValue", buffer, iniFile);
}
if (setting & SETTING_FADEDURATION)
{
_snwprintf_s(buffer, _TRUNCATE, L"%i", m_FadeDuration); _snwprintf_s(buffer, _TRUNCATE, L"%i", m_FadeDuration);
WritePrivateProfileString(section, L"FadeDuration", buffer, iniFile); WritePrivateProfileString(section, L"FadeDuration", buffer, iniFile);
}
_snwprintf_s(buffer, _TRUNCATE, L"%i", m_ClickThrough); if (setting & SETTING_CLICKTHROUGH)
WritePrivateProfileString(section, L"ClickThrough", buffer, iniFile); {
_snwprintf_s(buffer, _TRUNCATE, L"%i", m_WindowDraggable); WritePrivateProfileString(section, L"ClickThrough", m_ClickThrough ? L"1" : L"0", iniFile);
WritePrivateProfileString(section, L"Draggable", buffer, iniFile); }
if (setting & SETTING_WINDOWDRAGGABLE)
{
WritePrivateProfileString(section, L"Draggable", m_WindowDraggable ? L"1" : L"0", iniFile);
}
if (setting & SETTING_HIDEONMOUSEOVER)
{
_snwprintf_s(buffer, _TRUNCATE, L"%i", m_WindowHide); _snwprintf_s(buffer, _TRUNCATE, L"%i", m_WindowHide);
WritePrivateProfileString(section, L"HideOnMouseOver", buffer, iniFile); WritePrivateProfileString(section, L"HideOnMouseOver", buffer, iniFile);
_snwprintf_s(buffer, _TRUNCATE, L"%i", m_SavePosition); }
WritePrivateProfileString(section, L"SavePosition", buffer, iniFile);
_snwprintf_s(buffer, _TRUNCATE, L"%i", m_SnapEdges);
WritePrivateProfileString(section, L"SnapEdges", buffer, iniFile);
_snwprintf_s(buffer, _TRUNCATE, L"%i", m_KeepOnScreen);
WritePrivateProfileString(section, L"KeepOnScreen", buffer, iniFile);
_snwprintf_s(buffer, _TRUNCATE, L"%i", m_AutoSelectScreen);
WritePrivateProfileString(section, L"AutoSelectScreen", buffer, iniFile);
if (setting & SETTING_SAVEPOSITION)
{
WritePrivateProfileString(section, L"SavePosition", m_SavePosition ? L"1" : L"0", iniFile);
}
if (setting & SETTING_SNAPEDGES)
{
WritePrivateProfileString(section, L"SnapEdges", m_SnapEdges ? L"1" : L"0", iniFile);
}
if (setting & SETTING_KEEPONSCREEN)
{
WritePrivateProfileString(section, L"KeepOnScreen", m_KeepOnScreen ? L"1" : L"0", iniFile);
}
if (setting & SETTING_AUTOSELECTSCREEN)
{
WritePrivateProfileString(section, L"AutoSelectScreen", m_AutoSelectScreen ? L"1" : L"0", iniFile);
}
if (setting & SETTING_ALWAYSONTOP)
{
_snwprintf_s(buffer, _TRUNCATE, L"%i", m_WindowZPosition); _snwprintf_s(buffer, _TRUNCATE, L"%i", m_WindowZPosition);
WritePrivateProfileString(section, L"AlwaysOnTop", buffer, iniFile); WritePrivateProfileString(section, L"AlwaysOnTop", buffer, iniFile);
} }
}
} }
@ -3641,27 +3664,27 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
else if (wParam == ID_CONTEXT_SKINMENU_VERYTOPMOST) else if (wParam == ID_CONTEXT_SKINMENU_VERYTOPMOST)
{ {
ChangeZPos(ZPOSITION_ONTOPMOST); ChangeZPos(ZPOSITION_ONTOPMOST);
WriteConfig(); WriteConfig(SETTING_ALWAYSONTOP);
} }
else if (wParam == ID_CONTEXT_SKINMENU_TOPMOST) else if (wParam == ID_CONTEXT_SKINMENU_TOPMOST)
{ {
ChangeZPos(ZPOSITION_ONTOP); ChangeZPos(ZPOSITION_ONTOP);
WriteConfig(); WriteConfig(SETTING_ALWAYSONTOP);
} }
else if (wParam == ID_CONTEXT_SKINMENU_BOTTOM) else if (wParam == ID_CONTEXT_SKINMENU_BOTTOM)
{ {
ChangeZPos(ZPOSITION_ONBOTTOM); ChangeZPos(ZPOSITION_ONBOTTOM);
WriteConfig(); WriteConfig(SETTING_ALWAYSONTOP);
} }
else if (wParam == ID_CONTEXT_SKINMENU_NORMAL) else if (wParam == ID_CONTEXT_SKINMENU_NORMAL)
{ {
ChangeZPos(ZPOSITION_NORMAL); ChangeZPos(ZPOSITION_NORMAL);
WriteConfig(); WriteConfig(SETTING_ALWAYSONTOP);
} }
else if (wParam == ID_CONTEXT_SKINMENU_ONDESKTOP) else if (wParam == ID_CONTEXT_SKINMENU_ONDESKTOP)
{ {
ChangeZPos(ZPOSITION_ONDESKTOP); ChangeZPos(ZPOSITION_ONDESKTOP);
WriteConfig(); WriteConfig(SETTING_ALWAYSONTOP);
} }
else if (wParam == ID_CONTEXT_SKINMENU_KEEPONSCREEN) else if (wParam == ID_CONTEXT_SKINMENU_KEEPONSCREEN)
{ {
@ -3685,7 +3708,7 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
m_WindowHide = HIDEMODE_NONE; m_WindowHide = HIDEMODE_NONE;
} }
WriteConfig(); WriteConfig(SETTING_HIDEONMOUSEOVER);
UpdateTransparency(m_AlphaValue, false); UpdateTransparency(m_AlphaValue, false);
} }
else if (wParam == ID_CONTEXT_SKINMENU_TRANSPARENCY_FADEIN) else if (wParam == ID_CONTEXT_SKINMENU_TRANSPARENCY_FADEIN)
@ -3698,7 +3721,7 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
m_WindowHide = HIDEMODE_NONE; m_WindowHide = HIDEMODE_NONE;
} }
WriteConfig(); WriteConfig(SETTING_HIDEONMOUSEOVER);
UpdateTransparency(m_AlphaValue, false); UpdateTransparency(m_AlphaValue, false);
} }
else if (wParam == ID_CONTEXT_SKINMENU_TRANSPARENCY_FADEOUT) else if (wParam == ID_CONTEXT_SKINMENU_TRANSPARENCY_FADEOUT)
@ -3711,7 +3734,7 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
m_WindowHide = HIDEMODE_NONE; m_WindowHide = HIDEMODE_NONE;
} }
WriteConfig(); WriteConfig(SETTING_HIDEONMOUSEOVER);
UpdateTransparency(m_AlphaValue, false); UpdateTransparency(m_AlphaValue, false);
} }
else if (wParam == ID_CONTEXT_SKINMENU_REMEMBERPOSITION) else if (wParam == ID_CONTEXT_SKINMENU_REMEMBERPOSITION)
@ -3725,7 +3748,7 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
else if (wParam >= ID_CONTEXT_SKINMENU_TRANSPARENCY_0 && wParam <= ID_CONTEXT_SKINMENU_TRANSPARENCY_90) else if (wParam >= ID_CONTEXT_SKINMENU_TRANSPARENCY_0 && wParam <= ID_CONTEXT_SKINMENU_TRANSPARENCY_90)
{ {
m_AlphaValue = (int)(255.0 - (wParam - ID_CONTEXT_SKINMENU_TRANSPARENCY_0) * (230.0 / (ID_CONTEXT_SKINMENU_TRANSPARENCY_90 - ID_CONTEXT_SKINMENU_TRANSPARENCY_0))); m_AlphaValue = (int)(255.0 - (wParam - ID_CONTEXT_SKINMENU_TRANSPARENCY_0) * (230.0 / (ID_CONTEXT_SKINMENU_TRANSPARENCY_90 - ID_CONTEXT_SKINMENU_TRANSPARENCY_0)));
WriteConfig(); WriteConfig(SETTING_ALPHAVALUE);
UpdateTransparency(m_AlphaValue, false); UpdateTransparency(m_AlphaValue, false);
} }
else if (wParam == ID_CONTEXT_CLOSESKIN) else if (wParam == ID_CONTEXT_CLOSESKIN)
@ -3740,7 +3763,7 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
if (m_SavePosition) if (m_SavePosition)
{ {
WriteConfig(); WriteConfig(SETTING_WINDOWPOSITION);
} }
} }
else if (wParam == ID_CONTEXT_SKINMENU_FROMBOTTOM) else if (wParam == ID_CONTEXT_SKINMENU_FROMBOTTOM)
@ -3751,7 +3774,7 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
if (m_SavePosition) if (m_SavePosition)
{ {
WriteConfig(); WriteConfig(SETTING_WINDOWPOSITION);
} }
} }
else if (wParam == ID_CONTEXT_SKINMENU_XPERCENTAGE) else if (wParam == ID_CONTEXT_SKINMENU_XPERCENTAGE)
@ -3762,7 +3785,7 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
if (m_SavePosition) if (m_SavePosition)
{ {
WriteConfig(); WriteConfig(SETTING_WINDOWPOSITION);
} }
} }
else if (wParam == ID_CONTEXT_SKINMENU_YPERCENTAGE) else if (wParam == ID_CONTEXT_SKINMENU_YPERCENTAGE)
@ -3773,7 +3796,7 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
if (m_SavePosition) if (m_SavePosition)
{ {
WriteConfig(); WriteConfig(SETTING_WINDOWPOSITION);
} }
} }
else if (wParam == ID_CONTEXT_SKINMENU_MONITOR_AUTOSELECT) else if (wParam == ID_CONTEXT_SKINMENU_MONITOR_AUTOSELECT)
@ -3782,7 +3805,7 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
ScreenToWindow(); ScreenToWindow();
WriteConfig(); WriteConfig(SETTING_WINDOWPOSITION | SETTING_AUTOSELECTSCREEN);
} }
else if (wParam == ID_CONTEXT_SKINMENU_MONITOR_PRIMARY || wParam >= ID_MONITOR_FIRST && wParam <= ID_MONITOR_LAST) else if (wParam == ID_CONTEXT_SKINMENU_MONITOR_PRIMARY || wParam >= ID_MONITOR_FIRST && wParam <= ID_MONITOR_LAST)
{ {
@ -3815,7 +3838,7 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
m_Parser.ResetMonitorVariables(this); // Set present monitor variables m_Parser.ResetMonitorVariables(this); // Set present monitor variables
ScreenToWindow(); ScreenToWindow();
WriteConfig(); WriteConfig(SETTING_WINDOWPOSITION | SETTING_AUTOSELECTSCREEN);
} }
} }
else else
@ -3850,7 +3873,7 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
void CMeterWindow::SetClickThrough(bool b) void CMeterWindow::SetClickThrough(bool b)
{ {
m_ClickThrough = b; m_ClickThrough = b;
WriteConfig(); WriteConfig(SETTING_CLICKTHROUGH);
if (!m_ClickThrough) if (!m_ClickThrough)
{ {
@ -3877,7 +3900,7 @@ void CMeterWindow::SetClickThrough(bool b)
void CMeterWindow::SetKeepOnScreen(bool b) void CMeterWindow::SetKeepOnScreen(bool b)
{ {
m_KeepOnScreen = b; m_KeepOnScreen = b;
WriteConfig(); WriteConfig(SETTING_KEEPONSCREEN);
if (m_KeepOnScreen) if (m_KeepOnScreen)
{ {
@ -3900,7 +3923,7 @@ void CMeterWindow::SetKeepOnScreen(bool b)
void CMeterWindow::SetWindowDraggable(bool b) void CMeterWindow::SetWindowDraggable(bool b)
{ {
m_WindowDraggable = b; m_WindowDraggable = b;
WriteConfig(); WriteConfig(SETTING_WINDOWDRAGGABLE);
} }
/* /*
@ -3912,7 +3935,7 @@ void CMeterWindow::SetWindowDraggable(bool b)
void CMeterWindow::SetSavePosition(bool b) void CMeterWindow::SetSavePosition(bool b)
{ {
m_SavePosition = b; m_SavePosition = b;
WriteConfig(); WriteConfig(SETTING_WINDOWPOSITION | SETTING_SAVEPOSITION);
} }
/* /*
@ -3924,7 +3947,7 @@ void CMeterWindow::SetSavePosition(bool b)
void CMeterWindow::SetSnapEdges(bool b) void CMeterWindow::SetSnapEdges(bool b)
{ {
m_SnapEdges = b; m_SnapEdges = b;
WriteConfig(); WriteConfig(SETTING_SNAPEDGES);
} }
/* /*
@ -3956,7 +3979,7 @@ LRESULT CMeterWindow::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
// Write the new place of the window to config file // Write the new place of the window to config file
if (m_SavePosition) if (m_SavePosition)
{ {
WriteConfig(); WriteConfig(SETTING_WINDOWPOSITION);
} }
POINT pos; POINT pos;

View File

@ -284,6 +284,23 @@ protected:
LRESULT OnDisplayChange(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnDisplayChange(UINT uMsg, WPARAM wParam, LPARAM lParam);
private: private:
enum SETTING
{
SETTING_WINDOWPOSITION = 0x00000001,
SETTING_ALPHAVALUE = 0x00000002,
SETTING_FADEDURATION = 0x00000004,
SETTING_CLICKTHROUGH = 0x00000008,
SETTING_WINDOWDRAGGABLE = 0x00000010,
SETTING_HIDEONMOUSEOVER = 0x00000020,
SETTING_SAVEPOSITION = 0x00000040,
SETTING_SNAPEDGES = 0x00000080,
SETTING_KEEPONSCREEN = 0x00000100,
SETTING_AUTOSELECTSCREEN = 0x00000200,
SETTING_ALWAYSONTOP = 0x00000400,
SETTING_ALL = 0xFFFFFFFF
};
bool HitTest(int x, int y); bool HitTest(int x, int y);
void CreateRegion(bool clear); void CreateRegion(bool clear);
@ -299,7 +316,7 @@ private:
void Update(bool nodraw); void Update(bool nodraw);
void UpdateTransparency(int alpha, bool reset); void UpdateTransparency(int alpha, bool reset);
void ReadConfig(); void ReadConfig();
void WriteConfig(); void WriteConfig(INT setting = SETTING_ALL);
bool ReadSkin(); bool ReadSkin();
void InitializeMeasures(); void InitializeMeasures();
void InitializeMeters(); void InitializeMeters();