From 2b45f7301d08da4255d5d651ad0cafeb7ccdee06 Mon Sep 17 00:00:00 2001 From: spx Date: Tue, 27 Nov 2012 17:45:53 +0900 Subject: [PATCH] Code cleanup --- Library/MeterWindow.cpp | 150 ++++++++++++++++++++-------------------- Library/MeterWindow.h | 1 + 2 files changed, 75 insertions(+), 76 deletions(-) diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 98064816..ee126b66 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -181,41 +181,7 @@ CMeterWindow::~CMeterWindow() Rainmeter->ExecuteCommand(m_OnCloseAction.c_str(), this); } - // Kill the timer - KillTimer(m_Window, TIMER_METER); - KillTimer(m_Window, TIMER_MOUSE); - KillTimer(m_Window, TIMER_FADE); - KillTimer(m_Window, TIMER_TRANSITION); - - UnregisterMouseInput(); - - // Destroy the meters - std::vector::iterator j = m_Meters.begin(); - for ( ; j != m_Meters.end(); ++j) - { - delete (*j); - } - - // Destroy the measures - std::vector::iterator i = m_Measures.begin(); - for ( ; i != m_Measures.end(); ++i) - { - delete (*i); - } - - delete m_Background; - delete m_DoubleBuffer; - if (m_DIBSectionBuffer) DeleteObject(m_DIBSectionBuffer); - - if (m_BlurRegion) DeleteObject(m_BlurRegion); - - if (m_Window) DestroyWindow(m_Window); - - if (m_FontCollection) - { - CMeterString::FreeFontCache(m_FontCollection); - delete m_FontCollection; - } + Dispose(false); --c_InstanceCount; @@ -236,6 +202,78 @@ CMeterWindow::~CMeterWindow() } } +/* +** Kills timers/hooks and disposes buffers +** +*/ +void CMeterWindow::Dispose(bool refresh) +{ + // Kill the timer/hook + KillTimer(m_Window, TIMER_METER); + KillTimer(m_Window, TIMER_MOUSE); + KillTimer(m_Window, TIMER_FADE); + KillTimer(m_Window, TIMER_TRANSITION); + + UnregisterMouseInput(); + + m_ActiveTransition = false; + + m_MouseOver = false; + SetMouseLeaveEvent(true); + + // Destroy the meters + for (auto j = m_Meters.begin(); j != m_Meters.end(); ++j) + { + delete (*j); + } + m_Meters.clear(); + + // Destroy the measures + for (auto i = m_Measures.begin(); i != m_Measures.end(); ++i) + { + delete (*i); + } + m_Measures.clear(); + + delete m_Background; + m_Background = NULL; + + m_BackgroundSize.cx = m_BackgroundSize.cy = 0; + m_BackgroundName.clear(); + + if (m_BlurRegion) + { + DeleteObject(m_BlurRegion); + m_BlurRegion = NULL; + } + + if (m_FontCollection) + { + CMeterString::FreeFontCache(m_FontCollection); + delete m_FontCollection; + m_FontCollection = NULL; + } + + if (!refresh) + { + // Destroy double buffers and window + delete m_DoubleBuffer; + m_DoubleBuffer = NULL; + + if (m_DIBSectionBuffer) + { + DeleteObject(m_DIBSectionBuffer); + m_DIBSectionBuffer = NULL; + } + + if (m_Window) + { + DestroyWindow(m_Window); + m_Window = NULL; + } + } +} + /* ** Initializes the window, creates the class and the window. ** @@ -374,47 +412,7 @@ void CMeterWindow::Refresh(bool init, bool all) if (!init) { - // First destroy everything - 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); - - std::vector::iterator i = m_Measures.begin(); - for ( ; i != m_Measures.end(); ++i) - { - delete (*i); - } - m_Measures.clear(); - - std::vector::iterator j = m_Meters.begin(); - for ( ; j != m_Meters.end(); ++j) - { - delete (*j); - } - m_Meters.clear(); - - delete m_Background; - m_Background = NULL; - - m_BackgroundSize.cx = m_BackgroundSize.cy = 0; - - m_BackgroundName.erase(); - - if (m_BlurRegion) DeleteObject(m_BlurRegion); - m_BlurRegion = NULL; - - if (m_FontCollection) - { - CMeterString::FreeFontCache(m_FontCollection); - delete m_FontCollection; - m_FontCollection = NULL; - } + Dispose(true); } ZPOSITION oldZPos = m_WindowZPosition; diff --git a/Library/MeterWindow.h b/Library/MeterWindow.h index ca32b55a..8039629e 100644 --- a/Library/MeterWindow.h +++ b/Library/MeterWindow.h @@ -346,6 +346,7 @@ private: void ShowBlur(); void HideBlur(); + void Dispose(bool refresh); void CreateDoubleBuffer(int cx, int cy); CConfigParser m_Parser;