From 153b466abd667743a07a47194c970b540a059ef3 Mon Sep 17 00:00:00 2001 From: spx Date: Thu, 3 Nov 2011 09:27:07 +0000 Subject: [PATCH] - Fixed negative W/H issue: http://rainmeter.net/forum/viewtopic.php?t=8614&p=59732#p59732 - Code cleanup. --- Library/Meter.cpp | 2 - Library/MeterLine.cpp | 15 +++-- Library/MeterWindow.cpp | 118 ++++++++++++++++++++++------------------ Library/TrayWindow.cpp | 17 ++++-- 4 files changed, 88 insertions(+), 64 deletions(-) diff --git a/Library/Meter.cpp b/Library/Meter.cpp index 35152d45..7dc5dbc9 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -360,11 +360,9 @@ void CMeter::ReadConfig(CConfigParser& parser, const WCHAR* section) } m_W = (int)parser.ReadFormula(section, L"W", 1.0); - m_W = max(m_W, 0); m_WDefined = parser.GetLastValueDefined(); m_H = (int)parser.ReadFormula(section, L"H", 1.0); - m_H = max(m_H, 0); m_HDefined = parser.GetLastValueDefined(); if (!m_Initialized) diff --git a/Library/MeterLine.cpp b/Library/MeterLine.cpp index 42edcabc..e1a18121 100644 --- a/Library/MeterLine.cpp +++ b/Library/MeterLine.cpp @@ -71,7 +71,10 @@ void CMeterLine::Initialize() { m_AllValues.push_back(std::vector()); - m_AllValues.back().assign(m_W, 0.0); + if (m_W > 0) + { + m_AllValues.back().assign(m_W, 0.0); + } } } else @@ -80,13 +83,17 @@ void CMeterLine::Initialize() } } - if (num != (size_t)m_W) + if (m_W < 0 || num != (size_t)m_W) { if (m_CurrentPos >= m_W) m_CurrentPos = 0; + num = (m_W < 0) ? 0 : m_W; for (size_t i = 0; i < allValuesSize; ++i) { - m_AllValues[i].resize(m_W, 0.0); + if (num != m_AllValues[i].size()) + { + m_AllValues[i].resize(num, 0.0); + } } } } @@ -208,7 +215,7 @@ bool CMeterLine::Update() */ bool CMeterLine::Draw(Graphics& graphics) { - if (!CMeter::Draw(graphics) || m_W == 0) return false; + if (!CMeter::Draw(graphics) || m_W <= 0) return false; double maxValue = 0.0; int counter = 0; diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index b81a9359..63c1328a 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -39,13 +39,23 @@ using namespace Gdiplus; -#define METERTIMER 1 -#define MOUSETIMER 2 -#define FADETIMER 3 -#define TRANSITIONTIMER 4 - #define SNAPDISTANCE 10 +enum TIMER +{ + TIMER_METER = 1, + TIMER_MOUSE = 2, + TIMER_FADE = 3, + TIMER_TRANSITION = 4 +}; +enum INTERVAL +{ + INTERVAL_METER = 1000, + INTERVAL_MOUSE = 500, + INTERVAL_FADE = 10, + INTERVAL_TRANSITION = 100 +}; + int CMeterWindow::c_InstanceCount = 0; HINSTANCE CMeterWindow::c_DwmInstance = NULL; @@ -95,8 +105,8 @@ CMeterWindow::CMeterWindow(const std::wstring& path, const std::wstring& config, m_AnchorScreenX(), m_AnchorScreenY(), m_WindowDraggable(true), - m_WindowUpdate(1000), - m_TransitionUpdate(100), + m_WindowUpdate(INTERVAL_METER), + m_TransitionUpdate(INTERVAL_TRANSITION), m_ActiveTransition(false), m_HasNetMeasures(false), m_HasButtons(false), @@ -160,10 +170,10 @@ CMeterWindow::~CMeterWindow() WriteConfig(); // Kill the timer - KillTimer(m_Window, METERTIMER); - KillTimer(m_Window, MOUSETIMER); - KillTimer(m_Window, FADETIMER); - KillTimer(m_Window, TRANSITIONTIMER); + KillTimer(m_Window, TIMER_METER); + KillTimer(m_Window, TIMER_MOUSE); + KillTimer(m_Window, TIMER_FADE); + KillTimer(m_Window, TIMER_TRANSITION); // Destroy the meters std::list::iterator j = m_Meters.begin(); @@ -333,10 +343,12 @@ void CMeterWindow::Refresh(bool init, bool all) // WriteConfig(); //Not clear why this is needed and it messes up resolution changes // Kill the timer - KillTimer(m_Window, METERTIMER); - KillTimer(m_Window, MOUSETIMER); - KillTimer(m_Window, FADETIMER); - KillTimer(m_Window, TRANSITIONTIMER); + KillTimer(m_Window, TIMER_METER); + KillTimer(m_Window, TIMER_MOUSE); + KillTimer(m_Window, TIMER_FADE); + KillTimer(m_Window, TIMER_TRANSITION); + + m_ActiveTransition = false; m_MouseOver = false; SetMouseLeaveEvent(true); @@ -426,13 +438,13 @@ void CMeterWindow::Refresh(bool init, bool all) // Start the timers if (m_WindowUpdate >= 0) { - if (0 == SetTimer(m_Window, METERTIMER, m_WindowUpdate, NULL)) + if (0 == SetTimer(m_Window, TIMER_METER, m_WindowUpdate, NULL)) { throw CError(L"Unable to set timer!", __LINE__, __FILE__); } } - if (0 == SetTimer(m_Window, MOUSETIMER, 500, NULL)) // Mouse position is checked twice per sec + if (0 == SetTimer(m_Window, TIMER_MOUSE, INTERVAL_MOUSE, NULL)) // Mouse position is checked twice per sec { throw CError(L"Unable to set timer!", __LINE__, __FILE__); } @@ -681,12 +693,12 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const WCHAR* arg) break; case BANG_UPDATE: - KillTimer(m_Window, METERTIMER); // Kill timer temporarily + KillTimer(m_Window, TIMER_METER); // Kill timer temporarily Update(false); CDialogAbout::UpdateMeasures(m_SkinName.c_str()); if (m_WindowUpdate >= 0) { - SetTimer(m_Window, METERTIMER, m_WindowUpdate, NULL); + SetTimer(m_Window, TIMER_METER, m_WindowUpdate, NULL); } break; @@ -2111,8 +2123,8 @@ bool CMeterWindow::ReadSkin() m_MouseLeaveAction = m_Parser.ReadString(L"Rainmeter", L"MouseLeaveAction", L"", false); m_OnRefreshAction = m_Parser.ReadString(L"Rainmeter", L"OnRefreshAction", L"", false); - m_WindowUpdate = m_Parser.ReadInt(L"Rainmeter", L"Update", 1000); - m_TransitionUpdate = m_Parser.ReadInt(L"Rainmeter", L"TransitionUpdate", 100); + m_WindowUpdate = m_Parser.ReadInt(L"Rainmeter", L"Update", INTERVAL_METER); + m_TransitionUpdate = m_Parser.ReadInt(L"Rainmeter", L"TransitionUpdate", INTERVAL_TRANSITION); m_MouseActionCursor = 0 != m_Parser.ReadInt(L"Rainmeter", L"MouseActionCursor", 1); m_ToolTipHidden = 0 != m_Parser.ReadInt(L"Rainmeter", L"ToolTipHidden", 0); @@ -2789,12 +2801,12 @@ void CMeterWindow::PostUpdate(bool bActiveTransition) // Start/stop the transition timer if necessary if (bActiveTransition && !m_ActiveTransition) { - SetTimer(m_Window, TRANSITIONTIMER, m_TransitionUpdate, NULL); + SetTimer(m_Window, TIMER_TRANSITION, m_TransitionUpdate, NULL); m_ActiveTransition = true; } else if (m_ActiveTransition && !bActiveTransition) { - KillTimer(m_Window, TRANSITIONTIMER); + KillTimer(m_Window, TIMER_TRANSITION); m_ActiveTransition = false; } } @@ -3030,37 +3042,12 @@ LRESULT CMeterWindow::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam) */ LRESULT CMeterWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam) { - if (wParam == METERTIMER) + if (wParam == TIMER_METER) { Update(false); CDialogAbout::UpdateMeasures(m_SkinName.c_str()); } - else if (wParam == TRANSITIONTIMER) - { - // Redraw only if there is active transition still going - bool bActiveTransition = false; - std::list::const_iterator j = m_Meters.begin(); - for ( ; j != m_Meters.end(); ++j) - { - if ((*j)->HasActiveTransition()) - { - bActiveTransition = true; - break; - } - } - - if (bActiveTransition) - { - Redraw(); - } - else - { - // Stop the transition timer - KillTimer(m_Window, TRANSITIONTIMER); - m_ActiveTransition = false; - } - } - else if (wParam == MOUSETIMER) + else if (wParam == TIMER_MOUSE) { if (!m_Rainmeter->IsMenuActive() && !m_Dragging) { @@ -3101,7 +3088,32 @@ LRESULT CMeterWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam) } } } - else if (wParam == FADETIMER) + else if (wParam == TIMER_TRANSITION) + { + // Redraw only if there is active transition still going + bool bActiveTransition = false; + std::list::const_iterator j = m_Meters.begin(); + for ( ; j != m_Meters.end(); ++j) + { + if ((*j)->HasActiveTransition()) + { + bActiveTransition = true; + break; + } + } + + if (bActiveTransition) + { + Redraw(); + } + else + { + // Stop the transition timer + KillTimer(m_Window, TIMER_TRANSITION); + m_ActiveTransition = false; + } + } + else if (wParam == TIMER_FADE) { ULONGLONG ticks = CSystem::GetTickCount64(); if (m_FadeStartTime == 0) @@ -3111,7 +3123,7 @@ LRESULT CMeterWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam) if (ticks - m_FadeStartTime > (ULONGLONG)m_FadeDuration) { - KillTimer(m_Window, FADETIMER); + KillTimer(m_Window, TIMER_FADE); m_FadeStartTime = 0; if (m_FadeEndValue == 0) { @@ -3174,7 +3186,7 @@ void CMeterWindow::FadeWindow(int from, int to) } } - SetTimer(m_Window, FADETIMER, 10, NULL); + SetTimer(m_Window, TIMER_FADE, INTERVAL_FADE, NULL); } } diff --git a/Library/TrayWindow.cpp b/Library/TrayWindow.cpp index f22558de..b8ca7957 100644 --- a/Library/TrayWindow.cpp +++ b/Library/TrayWindow.cpp @@ -28,14 +28,21 @@ #include "RainmeterQuery.h" #include "../Version.h" -#define TRAYTIMER 3 - #define RAINMETER_OFFICIAL L"http://rainmeter.net/cms/" #define RAINMETER_MANUAL L"http://rainmeter.net/cms/Manual" #define RAINMETER_MANUALBETA L"http://rainmeter.net/cms/Manual_beta" #define ZPOS_FLAGS (SWP_NOMOVE | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOSENDCHANGING) +enum TIMER +{ + TIMER_TRAY = 3 +}; +enum INTERVAL +{ + INTERVAL_TRAY = 1000 +}; + const UINT WM_TASKBARCREATED = ::RegisterWindowMessage(L"TaskbarCreated"); extern CRainmeter* Rainmeter; @@ -79,7 +86,7 @@ CTrayWindow::CTrayWindow(HINSTANCE instance) : m_Instance(instance), CTrayWindow::~CTrayWindow() { - KillTimer(m_Window, TRAYTIMER); + KillTimer(m_Window, TIMER_TRAY); RemoveTrayIcon(); delete m_Bitmap; @@ -263,7 +270,7 @@ HICON CTrayWindow::CreateTrayIcon(double value) void CTrayWindow::ReadConfig(CConfigParser& parser) { // Clear old Settings - KillTimer(m_Window, TRAYTIMER); + KillTimer(m_Window, TIMER_TRAY); delete m_Measure; m_Measure = NULL; @@ -374,7 +381,7 @@ void CTrayWindow::ReadConfig(CConfigParser& parser) if (m_Measure) { - SetTimer(m_Window, TRAYTIMER, 1000, NULL); // Update the tray once per sec + SetTimer(m_Window, TIMER_TRAY, INTERVAL_TRAY, NULL); // Update the tray once per sec } } else