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

This commit is contained in:
spx 2012-08-09 06:50:58 -07:00
parent 5103190129
commit 489f2c5a30
10 changed files with 82 additions and 62 deletions

View File

@ -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 File

@ -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 File

@ -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 File

@ -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 File

@ -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 File

@ -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 @@ 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<std::wstring> 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;

View File

@ -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 File

@ -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<CMeasure*> 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;

View File

@ -935,16 +935,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)
**
@ -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
**

53
Library/Section.h Normal file
View File

@ -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