Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Code cleanup & cosmetics: Moved Measure/Meter shared part to Section.h

  • Loading branch information...
commit 489f2c5a30b3125b624e574165cb474ad6fa9219 1 parent 5103190
@spx268 spx268 authored
View
4 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;
View
7 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<std::wstring> m_Groups;
std::wstring m_OldGroups;
View
1  Library/Library.vcxproj
@@ -436,6 +436,7 @@
<ClInclude Include="RainmeterQuery.h" />
<ClInclude Include="RawString.h" />
<ClInclude Include="resource.h" />
+ <ClInclude Include="Section.h" />
<ClInclude Include="StdAfx.h" />
<ClInclude Include="System.h" />
<ClInclude Include="TintedImage.h" />
View
3  Library/Library.vcxproj.filters
@@ -551,6 +551,9 @@
<ClInclude Include="Mouse.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="Section.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Library.rc">
View
5 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)
{
}
View
23 Library/Measure.h
@@ -23,7 +23,7 @@
#include <vector>
#include <string>
#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 @@ class CMeasure : public CGroup
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 @@ class CMeasure : public CGroup
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 @@ class CMeasure : public CGroup
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<std::wstring> m_Substitute; // Vec of substitute strings
bool m_RegExpSubstitute;
@@ -122,8 +109,6 @@ class CMeasure : public CGroup
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;
View
5 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),
View
24 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 @@ class CMeter : public CGroup
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 @@ class CMeter : public CGroup
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 @@ class CMeter : public CGroup
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<CMeasure*> m_Measures;
int m_X;
int m_Y;
@@ -137,7 +125,6 @@ class CMeter : public CGroup
bool m_WDefined;
bool m_HDefined;
CMeter* m_RelativeMeter;
- bool m_DynamicVariables;
Gdiplus::Matrix* m_Transformation;
@@ -157,9 +144,6 @@ class CMeter : public CGroup
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;
View
19 Library/MeterWindow.cpp
@@ -936,16 +936,6 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const std::vector<std::wstring>& ar
}
/*
-** This is a helper template that compares the given name to measure/meter's name.
-**
-*/
-template <class T>
-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)
**
*/
@@ -1075,6 +1065,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
**
*/
View
53 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 <windows.h>
+#include <string>
+#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
Please sign in to comment.
Something went wrong with that request. Please try again.