diff --git a/Library/Group.cpp b/Library/Group.cpp index e9e914d8..e2c81167 100644 --- a/Library/Group.cpp +++ b/Library/Group.cpp @@ -44,12 +44,12 @@ void CGroup::InitializeGroup(const std::wstring& groups) } } -bool CGroup::BelongsToGroup(const std::wstring& group) +bool CGroup::BelongsToGroup(const std::wstring& group) const { return (m_Groups.find(CreateGroup(group)) != m_Groups.end()); } -std::wstring CGroup::CreateGroup(const std::wstring& str) +std::wstring CGroup::CreateGroup(const std::wstring& str) const { std::wstring strTmp; diff --git a/Library/Group.h b/Library/Group.h index 6ff47b8d..e956bc77 100644 --- a/Library/Group.h +++ b/Library/Group.h @@ -25,16 +25,17 @@ class CGroup { public: - bool BelongsToGroup(const std::wstring& group); + virtual ~CGroup() {} + + bool BelongsToGroup(const std::wstring& group) const; protected: CGroup() {} - virtual ~CGroup() {} void InitializeGroup(const std::wstring& groups); private: - std::wstring CreateGroup(const std::wstring& str); + std::wstring CreateGroup(const std::wstring& str) const; std::unordered_set m_Groups; std::wstring m_OldGroups; diff --git a/Library/Library.vcxproj b/Library/Library.vcxproj index aca8ac57..85d22742 100644 --- a/Library/Library.vcxproj +++ b/Library/Library.vcxproj @@ -436,6 +436,7 @@ + diff --git a/Library/Library.vcxproj.filters b/Library/Library.vcxproj.filters index 3e815360..23fa0d1d 100644 --- a/Library/Library.vcxproj.filters +++ b/Library/Library.vcxproj.filters @@ -551,6 +551,9 @@ Header Files + + Header Files + diff --git a/Library/Measure.cpp b/Library/Measure.cpp index 25d9927e..aefe670c 100644 --- a/Library/Measure.cpp +++ b/Library/Measure.cpp @@ -69,8 +69,7 @@ extern CRainmeter* Rainmeter; ** The constructor ** */ -CMeasure::CMeasure(CMeterWindow* meterWindow, const WCHAR* name) : m_MeterWindow(meterWindow), m_Name(name), - m_DynamicVariables(false), +CMeasure::CMeasure(CMeterWindow* meterWindow, const WCHAR* name) : CSection(name), m_MeterWindow(meterWindow), m_Invert(false), m_LogMaxValue(false), m_MinValue(), @@ -87,8 +86,6 @@ CMeasure::CMeasure(CMeterWindow* meterWindow, const WCHAR* name) : m_MeterWindow m_IfAboveCommitted(false), m_IfBelowCommitted(false), m_Disabled(false), - m_UpdateDivider(1), - m_UpdateCounter(1), m_Initialized(false) { } diff --git a/Library/Measure.h b/Library/Measure.h index c4e005e5..92c60be9 100644 --- a/Library/Measure.h +++ b/Library/Measure.h @@ -23,7 +23,7 @@ #include #include #include "Litestep.h" -#include "Group.h" +#include "Section.h" enum AUTOSCALE { @@ -41,29 +41,20 @@ class CMeter; class CMeterWindow; class CConfigParser; -class CMeasure : public CGroup +class CMeasure : public CSection { public: - CMeasure(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeasure(); - virtual UINT GetTypeID() = 0; - void ReadOptions(CConfigParser& parser) { ReadOptions(parser, GetName()); } virtual void Initialize(); bool Update(); - const WCHAR* GetName() { return m_Name.c_str(); } - const std::wstring& GetOriginalName() { return m_Name; } - void Disable(); void Enable(); bool IsDisabled() { return m_Disabled; } - bool HasDynamicVariables() { return m_DynamicVariables; } - void SetDynamicVariables(bool b) { m_DynamicVariables = b; } - virtual void Command(const std::wstring& command); double GetValue(); @@ -72,10 +63,6 @@ public: double GetMinValue() { return m_MinValue; } double GetMaxValue() { return m_MaxValue; } - void ResetUpdateCounter() { m_UpdateCounter = m_UpdateDivider; } - int GetUpdateCounter() { return m_UpdateCounter; } - int GetUpdateDivider() { return m_UpdateDivider; } - virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual); static void GetScaledValue(AUTOSCALE autoScale, int decimals, double theValue, WCHAR* buffer, size_t sizeInWords); static void RemoveTrailingZero(WCHAR* str, int strLen); @@ -85,6 +72,8 @@ public: static CMeasure* Create(const WCHAR* measure, CMeterWindow* meterWindow, const WCHAR* name); protected: + CMeasure(CMeterWindow* meterWindow, const WCHAR* name); + virtual void ReadOptions(CConfigParser& parser, const WCHAR* section); virtual void UpdateValue() = 0; @@ -93,13 +82,11 @@ protected: const WCHAR* CheckSubstitute(const WCHAR* buffer); bool MakePlainSubstitute(std::wstring& str, size_t index); - bool m_DynamicVariables; // If true, the measure contains dynamic variables bool m_Invert; // If true, the value should be inverted bool m_LogMaxValue; // If true, The maximum & minimum values are logged double m_MinValue; // The minimum value (so far) double m_MaxValue; // The maximum value (so far) double m_Value; // The current value - const std::wstring m_Name; // Name of this Measure std::vector m_Substitute; // Vec of substitute strings bool m_RegExpSubstitute; @@ -122,8 +109,6 @@ protected: bool m_IfAboveCommitted; // True when the IfAbove action is executed bool m_IfBelowCommitted; // True when the IfBelow action is executed bool m_Disabled; // Status of the measure - int m_UpdateDivider; // Divider for the update - int m_UpdateCounter; // Current update counter bool m_Initialized; CMeterWindow* m_MeterWindow; diff --git a/Library/Meter.cpp b/Library/Meter.cpp index 3321e9b3..3b239cad 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) : m_MeterWindow(meterWindow), m_Name(name), +CMeter::CMeter(CMeterWindow* meterWindow, const WCHAR* name) : CSection(name), m_MeterWindow(meterWindow), m_X(), m_Y(), m_W(0), @@ -48,7 +48,6 @@ CMeter::CMeter(CMeterWindow* meterWindow, const WCHAR* name) : m_MeterWindow(met m_WDefined(false), m_HDefined(false), m_RelativeMeter(), - m_DynamicVariables(false), m_Transformation(), m_ToolTipWidth(), m_ToolTipType(false), @@ -58,8 +57,6 @@ CMeter::CMeter(CMeterWindow* meterWindow, const WCHAR* name) : m_MeterWindow(met m_MouseOver(false), m_RelativeX(POSITION_ABSOLUTE), m_RelativeY(POSITION_ABSOLUTE), - m_UpdateDivider(1), - m_UpdateCounter(1), m_SolidBevel(BEVELTYPE_NONE), m_SolidAngle(), m_AntiAlias(false), diff --git a/Library/Meter.h b/Library/Meter.h index 7b18b138..97657ca2 100644 --- a/Library/Meter.h +++ b/Library/Meter.h @@ -26,28 +26,22 @@ #include "Litestep.h" #include "ConfigParser.h" #include "MeterWindow.h" +#include "Section.h" #include "Measure.h" -#include "Group.h" class CMeasure; -class CMeter : public CGroup +class CMeter : public CSection { public: - CMeter(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeter(); - virtual UINT GetTypeID() = 0; - void ReadOptions(CConfigParser& parser) { ReadOptions(parser, GetName()); parser.ClearStyleTemplate(); } virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); virtual bool HasActiveTransition() { return false; } - - bool HasDynamicVariables() { return m_DynamicVariables; } - void SetDynamicVariables(bool b) { m_DynamicVariables = b; } virtual int GetW() { return m_Hidden ? 0 : m_W; } virtual int GetH() { return m_Hidden ? 0 : m_H; } @@ -82,13 +76,6 @@ public: void SetMouseOver(bool over) { m_MouseOver = over; } bool IsMouseOver() { return m_MouseOver; } - const WCHAR* GetName() { return m_Name.c_str(); } - const std::wstring& GetOriginalName() { return m_Name; } - - void ResetUpdateCounter() { m_UpdateCounter = m_UpdateDivider; } - int GetUpdateCounter() { return m_UpdateCounter; } - int GetUpdateDivider() { return m_UpdateDivider; } - CMeterWindow* GetMeterWindow() { return m_MeterWindow; } static CMeter* Create(const WCHAR* meter, CMeterWindow* meterWindow, const WCHAR* name); @@ -117,6 +104,8 @@ protected: POSITION_RELATIVE_BR }; + CMeter(CMeterWindow* meterWindow, const WCHAR* name); + virtual void ReadOptions(CConfigParser& parser, const WCHAR* section); virtual void BindMeasures(CConfigParser& parser, const WCHAR* section); @@ -127,7 +116,6 @@ protected: bool ReplaceMeasures(std::wstring& str, AUTOSCALE autoScale = AUTOSCALE_ON, double scale = 1.0, int decimals = 0, bool percentual = false); - const std::wstring m_Name; std::vector m_Measures; int m_X; int m_Y; @@ -137,7 +125,6 @@ protected: bool m_WDefined; bool m_HDefined; CMeter* m_RelativeMeter; - bool m_DynamicVariables; Gdiplus::Matrix* m_Transformation; @@ -157,9 +144,6 @@ protected: METER_POSITION m_RelativeX; METER_POSITION m_RelativeY; - int m_UpdateDivider; - int m_UpdateCounter; - BEVELTYPE m_SolidBevel; Gdiplus::Color m_SolidColor; Gdiplus::Color m_SolidColor2; diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 5b5a65a5..789859f7 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -935,16 +935,6 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const std::vector& ar } } -/* -** This is a helper template that compares the given name to measure/meter's name. -** -*/ -template -bool CompareName(T* m, const WCHAR* name, bool group) -{ - return (group) ? m->BelongsToGroup(name) : (_wcsicmp(m->GetName(), name) == 0); -} - /* ** Enables blurring of the window background (using Aero) ** @@ -1074,6 +1064,15 @@ void CMeterWindow::ResizeBlur(const std::wstring& arg, int mode) } } +/* +** Helper function that compares the given name to section's name. +** +*/ +bool CompareName(const CSection* section, const WCHAR* name, bool group) +{ + return (group) ? section->BelongsToGroup(name) : (_wcsicmp(section->GetName(), name) == 0); +} + /* ** Shows the given meter ** diff --git a/Library/Section.h b/Library/Section.h new file mode 100644 index 00000000..6033728a --- /dev/null +++ b/Library/Section.h @@ -0,0 +1,53 @@ +/* + Copyright (C) 2012 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. +*/ + +#ifndef __SECTION_H__ +#define __SECTION_H__ + +#include +#include +#include "Group.h" + +class CSection : public CGroup +{ +public: + virtual ~CSection() {}; + + virtual UINT GetTypeID() = 0; + + const WCHAR* GetName() const { return m_Name.c_str(); } + const std::wstring& GetOriginalName() const { return m_Name; } + + bool HasDynamicVariables() const { return m_DynamicVariables; } + void SetDynamicVariables(bool b) { m_DynamicVariables = b; } + + void ResetUpdateCounter() { m_UpdateCounter = m_UpdateDivider; } + int GetUpdateCounter() const { return m_UpdateCounter; } + int GetUpdateDivider() const { return m_UpdateDivider; } + +protected: + CSection(const WCHAR* name) : m_Name(name), m_DynamicVariables(false), m_UpdateDivider(1), m_UpdateCounter(1) {} + + const std::wstring m_Name; // Name of this Section + + bool m_DynamicVariables; // If true, the section contains dynamic variables + int m_UpdateDivider; // Divider for the update + int m_UpdateCounter; // Current update counter +}; + +#endif