diff --git a/Library/Library.vcxproj b/Library/Library.vcxproj
index 25190616..3774f52c 100644
--- a/Library/Library.vcxproj
+++ b/Library/Library.vcxproj
@@ -194,6 +194,9 @@
Use
+
+ Use
+
Create
diff --git a/Library/Library.vcxproj.filters b/Library/Library.vcxproj.filters
index 73eac537..241c76b7 100644
--- a/Library/Library.vcxproj.filters
+++ b/Library/Library.vcxproj.filters
@@ -321,6 +321,9 @@
Source Files
+
+ Source Files
+
Common
diff --git a/Library/Measure.cpp b/Library/Measure.cpp
index c6eaebe2..088f86cf 100644
--- a/Library/Measure.cpp
+++ b/Library/Measure.cpp
@@ -69,7 +69,7 @@ extern CRainmeter* Rainmeter;
** The constructor
**
*/
-CMeasure::CMeasure(CMeterWindow* meterWindow, const WCHAR* name) : CSection(name), m_MeterWindow(meterWindow),
+CMeasure::CMeasure(CMeterWindow* meterWindow, const WCHAR* name) : CSection(meterWindow, name),
m_Invert(false),
m_LogMaxValue(false),
m_MinValue(),
@@ -87,8 +87,8 @@ CMeasure::CMeasure(CMeterWindow* meterWindow, const WCHAR* name) : CSection(name
m_IfBelowCommitted(false),
m_Disabled(false),
m_Initialized(false),
- m_OldValue(0.0),
- m_OldStringValue(L"")
+ m_OldValue(),
+ m_OldValueInitialized(false)
{
}
@@ -728,6 +728,36 @@ void CMeasure::RemoveTrailingZero(WCHAR* str, int strLen)
}
}
+/*
+** Execute OnChangeAction if action is set
+**
+*/
+void CMeasure::DoChangeAction()
+{
+ if (!m_OldValueInitialized)
+ {
+ double newValue = GetValue();
+ const WCHAR* newStringValue = GetStringValue(AUTOSCALE_OFF, 1, -1, false);
+
+ m_OldValue = newValue;
+ m_OldStringValue = newStringValue;
+ m_OldValueInitialized = true;
+ }
+ else if (!m_OnChangeAction.empty())
+ {
+ double newValue = GetValue();
+ const WCHAR* newStringValue = GetStringValue(AUTOSCALE_OFF, 1, -1, false);
+
+ if (m_OldValue != newValue || wcscmp(m_OldStringValue.c_str(), newStringValue) != 0)
+ {
+ m_OldValue = newValue;
+ m_OldStringValue = newStringValue;
+
+ Rainmeter->ExecuteCommand(m_OnChangeAction.c_str(), m_MeterWindow);
+ }
+ }
+}
+
/*
** Creates the given measure. This is the factory method for the measures.
** If new measures are implemented this method needs to be updated.
diff --git a/Library/Measure.h b/Library/Measure.h
index 59a18e7a..7c7d5a02 100644
--- a/Library/Measure.h
+++ b/Library/Measure.h
@@ -68,10 +68,7 @@ public:
static void RemoveTrailingZero(WCHAR* str, int strLen);
const std::wstring& GetOnChangeAction() { return m_OnChangeAction; }
- void SetOldValue(double value) { m_OldValue = value; }
- double GetOldValue() { return m_OldValue; }
- void SetOldStringValue(std::wstring value) { m_OldStringValue = value; }
- const std::wstring& GetOldStringValue() { return m_OldStringValue; }
+ void DoChangeAction();
CMeterWindow* GetMeterWindow() { return m_MeterWindow; }
@@ -119,8 +116,7 @@ protected:
std::wstring m_OnChangeAction;
double m_OldValue;
std::wstring m_OldStringValue;
-
- CMeterWindow* m_MeterWindow;
+ bool m_OldValueInitialized;
};
#endif
diff --git a/Library/Meter.cpp b/Library/Meter.cpp
index 217ecc6a..82378f8e 100644
--- a/Library/Meter.cpp
+++ b/Library/Meter.cpp
@@ -39,7 +39,7 @@ extern CRainmeter* Rainmeter;
** The constructor
**
*/
-CMeter::CMeter(CMeterWindow* meterWindow, const WCHAR* name) : CSection(name), m_MeterWindow(meterWindow),
+CMeter::CMeter(CMeterWindow* meterWindow, const WCHAR* name) : CSection(meterWindow, name),
m_X(),
m_Y(),
m_W(0),
diff --git a/Library/Meter.h b/Library/Meter.h
index 97657ca2..d082f8c7 100644
--- a/Library/Meter.h
+++ b/Library/Meter.h
@@ -150,8 +150,6 @@ protected:
Gdiplus::REAL m_SolidAngle;
bool m_AntiAlias;
bool m_Initialized;
-
- CMeterWindow* m_MeterWindow;
};
#endif
diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp
index a591f104..c5011d3d 100644
--- a/Library/MeterWindow.cpp
+++ b/Library/MeterWindow.cpp
@@ -1228,7 +1228,7 @@ void CMeterWindow::UpdateMeter(const std::wstring& name, bool group)
{
if (UpdateMeter((*j), bActiveTransition, true))
{
- DoUpdateAction((*j));
+ (*j)->DoUpdateAction();
}
SetResizeWindowMode(RESIZEMODE_CHECK); // Need to recalculate the window size
@@ -1354,8 +1354,8 @@ void CMeterWindow::UpdateMeasure(const std::wstring& name, bool group)
if (UpdateMeasure((*i), true))
{
- DoUpdateAction((*i));
- //DoChangeAction((*i), false); // TODO: Check that this is the first update or not
+ (*i)->DoUpdateAction();
+ (*i)->DoChangeAction();
}
if (!group) return;
@@ -2678,6 +2678,11 @@ void CMeterWindow::Update(bool refresh)
{
++m_UpdateCounter;
+#ifdef DEBUG_PERF_UPDATE
+ _QPC(s1);
+ __int64 e1;
+#endif
+
if (!m_Measures.empty())
{
// Pre-updates
@@ -2687,20 +2692,34 @@ void CMeterWindow::Update(bool refresh)
CMeasureNet::UpdateStats();
}
+#ifdef DEBUG_PERF_UPDATE
+ e1 = QPC();
+#endif
+
// Update all measures
std::vector::const_iterator i = m_Measures.begin();
for ( ; i != m_Measures.end(); ++i)
{
if (UpdateMeasure((*i), refresh))
{
- DoUpdateAction((*i));
- DoChangeAction((*i), refresh);
+ (*i)->DoUpdateAction();
+ (*i)->DoChangeAction();
}
}
}
+#ifdef DEBUG_PERF_UPDATE
+ else
+ {
+ e1 = QPC();
+ }
+#endif
CDialogAbout::UpdateMeasures(this);
+#ifdef DEBUG_PERF_UPDATE
+ _QPC(e2);
+#endif
+
// Update all meters
bool bActiveTransition = false;
bool bUpdate = false;
@@ -2711,10 +2730,16 @@ void CMeterWindow::Update(bool refresh)
{
bUpdate = true;
- DoUpdateAction((*j));
+ (*j)->DoUpdateAction();
}
}
+#ifdef DEBUG_PERF_UPDATE
+ _QPC(e3);
+ double q1 = QPCms(s1,e1), q2 = QPCms(e1,e2), q3 = QPCms(e2,e3);
+ DebugString(L"Update: %.5f [ms] (PreUpdate: %.5f / Measure: %.5f / Meter: %.5f) :: %s", q1 + q2 + q3, q1, q2, q3, m_FolderPath.c_str());
+#endif
+
// Redraw all meters
if (bUpdate || m_ResizeWindow || refresh)
{
@@ -2741,40 +2766,6 @@ void CMeterWindow::Update(bool refresh)
}
}
-void CMeterWindow::DoUpdateAction(CSection* section)
-{
- const std::wstring& updateAction = section->GetOnUpdateAction();
- if (!updateAction.empty())
- {
- Rainmeter->ExecuteCommand(updateAction.c_str(), this);
- }
-}
-
-void CMeterWindow::DoChangeAction(CMeasure* measure, bool first)
-{
- const std::wstring& changeAction = measure->GetOnChangeAction();
- if (first)
- {
- double newValue = measure->GetValue();
- const WCHAR* newStringValue = measure->GetStringValue(AUTOSCALE_OFF, 1, -1, false);
-
- measure->SetOldValue(newValue);
- measure->SetOldStringValue(newStringValue);
- }
- else if (!changeAction.empty())
- {
- double newValue = measure->GetValue();
- const WCHAR* newStringValue = measure->GetStringValue(AUTOSCALE_OFF, 1, -1, false);
-
- if (measure->GetOldValue() != newValue || wcscmp(measure->GetOldStringValue().c_str(), newStringValue) != 0)
- {
- measure->SetOldValue(newValue);
- measure->SetOldStringValue(newStringValue);
- Rainmeter->ExecuteCommand(changeAction.c_str(), this);
- }
- }
-}
-
/*
** Updates the window contents
**
diff --git a/Library/MeterWindow.h b/Library/MeterWindow.h
index af8699ae..cf242f38 100644
--- a/Library/MeterWindow.h
+++ b/Library/MeterWindow.h
@@ -25,7 +25,6 @@
#include
#include
#include "ConfigParser.h"
-#include "Section.h"
#include "Group.h"
#include "Mouse.h"
@@ -318,8 +317,6 @@ private:
bool UpdateMeasure(CMeasure* measure, bool force);
bool UpdateMeter(CMeter* meter, bool& bActiveTransition, bool force);
void Update(bool refresh);
- void DoUpdateAction(CSection* section);
- void DoChangeAction(CMeasure* measure, bool first);
void UpdateWindow(int alpha, bool reset);
void ReadOptions();
void WriteOptions(INT setting = OPTION_ALL);
diff --git a/Library/Section.cpp b/Library/Section.cpp
new file mode 100644
index 00000000..b2168cc6
--- /dev/null
+++ b/Library/Section.cpp
@@ -0,0 +1,54 @@
+/*
+ Copyright (C) 2013 spx
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#include "StdAfx.h"
+#include "Section.h"
+#include "Rainmeter.h"
+
+extern CRainmeter* Rainmeter;
+
+/*
+** The constructor
+**
+*/
+CSection::CSection(CMeterWindow* meterWindow, const WCHAR* name) : m_MeterWindow(meterWindow), m_Name(name),
+ m_DynamicVariables(false),
+ m_UpdateDivider(1),
+ m_UpdateCounter(1)
+{
+}
+
+/*
+** The destructor
+**
+*/
+CSection::~CSection()
+{
+}
+
+/*
+** Execute OnUpdateAction if action is set
+**
+*/
+void CSection::DoUpdateAction()
+{
+ if (!m_OnUpdateAction.empty())
+ {
+ Rainmeter->ExecuteCommand(m_OnUpdateAction.c_str(), m_MeterWindow);
+ }
+}
diff --git a/Library/Section.h b/Library/Section.h
index 1bcd0929..211cea6d 100644
--- a/Library/Section.h
+++ b/Library/Section.h
@@ -23,10 +23,12 @@
#include
#include "Group.h"
+class CMeterWindow;
+
class CSection : public CGroup
{
public:
- virtual ~CSection() {};
+ virtual ~CSection();
virtual UINT GetTypeID() = 0;
@@ -41,9 +43,10 @@ public:
int GetUpdateDivider() const { return m_UpdateDivider; }
const std::wstring& GetOnUpdateAction() { return m_OnUpdateAction; }
+ void DoUpdateAction();
protected:
- CSection(const WCHAR* name) : m_Name(name), m_DynamicVariables(false), m_UpdateDivider(1), m_UpdateCounter(1) {}
+ CSection(CMeterWindow* meterWindow, const WCHAR* name);
const std::wstring m_Name; // Name of this Section
@@ -52,6 +55,8 @@ protected:
int m_UpdateCounter; // Current update counter
std::wstring m_OnUpdateAction;
+
+ CMeterWindow* m_MeterWindow;
};
#endif