Code cleanup

This commit is contained in:
spx 2013-02-06 19:12:16 +09:00
parent 1c8b798928
commit 95aacda3cb
9 changed files with 71 additions and 51 deletions

View File

@ -119,6 +119,8 @@ void CMeasure::ReadOptions(CConfigParser& parser, const WCHAR* section)
{
bool oldOnChangeActionEmpty = m_OnChangeAction.empty();
CSection::ReadOptions(parser, section);
// Clear substitutes to prevent from being added more than once.
if (!m_Substitute.empty())
{
@ -129,12 +131,6 @@ void CMeasure::ReadOptions(CConfigParser& parser, const WCHAR* section)
m_Disabled = 0!=parser.ReadInt(section, L"Disabled", 0);
int updateDivider = parser.ReadInt(section, L"UpdateDivider", 1);
if (updateDivider != m_UpdateDivider)
{
m_UpdateCounter = m_UpdateDivider = updateDivider;
}
m_MinValue = parser.ReadFloat(section, L"MinValue", m_MinValue);
m_MaxValue = parser.ReadFloat(section, L"MaxValue", m_MaxValue);
@ -149,13 +145,10 @@ void CMeasure::ReadOptions(CConfigParser& parser, const WCHAR* section)
m_IfEqualValue = (int64_t)parser.ReadFloat(section, L"IfEqualValue", 0.0);
m_IfEqualAction = parser.ReadString(section, L"IfEqualAction", L"", false);
m_OnUpdateAction = parser.ReadString(section, L"OnUpdateAction", L"", false);
m_OnChangeAction = parser.ReadString(section, L"OnChangeAction", L"", false);
m_AverageSize = parser.ReadUInt(section, L"AverageSize", 0);
m_DynamicVariables = 0!=parser.ReadInt(section, L"DynamicVariables", 0);
m_RegExpSubstitute = 0!=parser.ReadInt(section, L"RegExpSubstitute", 0);
std::wstring subs = parser.ReadString(section, L"Substitute", L"");
if (!subs.empty())
@ -173,9 +166,6 @@ void CMeasure::ReadOptions(CConfigParser& parser, const WCHAR* section)
}
}
const std::wstring& group = parser.ReadString(section, L"Group", L"");
InitializeGroup(group);
if (m_Initialized &&
oldOnChangeActionEmpty && !m_OnChangeAction.empty())
{
@ -450,9 +440,7 @@ bool CMeasure::Update()
if (!m_Disabled)
{
// Only update the counter if the divider
++m_UpdateCounter;
if (m_UpdateCounter < m_UpdateDivider) return false;
m_UpdateCounter = 0;
if (!UpdateCounter()) return false;
// Call derived method to update value
UpdateValue();

View File

@ -169,15 +169,13 @@ RECT CMeter::GetMeterRect()
/*
** Checks if the given point is inside the meter.
** This function doesn't check Hidden state, so check it before calling this function if needed.
**
*/
bool CMeter::HitTest(int x, int y)
{
if (x >= GetX() && x < GetX() + GetW() && y >= GetY() && y < GetY() + GetH())
{
return true;
}
return false;
int p;
return (x >= (p = GetX()) && x < p + m_W && y >= (p = GetY()) && y < p + m_H);
}
/*
@ -231,6 +229,8 @@ void CMeter::ReadOptions(CConfigParser& parser, const WCHAR* section)
parser.SetStyleTemplate(style);
}
CSection::ReadOptions(parser, section);
BindMeasures(parser, section);
int oldX = m_X;
@ -321,26 +321,17 @@ void CMeter::ReadOptions(CConfigParser& parser, const WCHAR* section)
m_SolidColor2 = parser.ReadColor(section, L"SolidColor2", m_SolidColor.GetValue());
m_SolidAngle = (Gdiplus::REAL)parser.ReadFloat(section, L"GradientAngle", 0.0);
m_OnUpdateAction = parser.ReadString(section, L"OnUpdateAction", L"", false);
m_Mouse.ReadOptions(parser, section);
m_HasMouseAction = m_Mouse.HasButtonAction() || m_Mouse.HasScrollAction();
m_ToolTipText = parser.ReadString(section, L"ToolTipText", L"");
m_ToolTipTitle = parser.ReadString(section, L"ToolTipTitle", L"");
m_ToolTipIcon = parser.ReadString(section, L"ToolTipIcon", L"");
m_ToolTipWidth = (int)parser.ReadFloat(section, L"ToolTipWidth", 1000);
m_ToolTipWidth = parser.ReadInt(section, L"ToolTipWidth", 1000);
m_ToolTipType = 0!=parser.ReadInt(section, L"ToolTipType", 0);
m_ToolTipHidden = 0!=parser.ReadInt(section, L"ToolTipHidden", m_MeterWindow->GetMeterToolTipHidden());
int updateDivider = parser.ReadInt(section, L"UpdateDivider", 1);
if (updateDivider != m_UpdateDivider)
{
m_UpdateCounter = m_UpdateDivider = updateDivider;
}
m_AntiAlias = 0!=parser.ReadInt(section, L"AntiAlias", 0);
m_DynamicVariables = 0!=parser.ReadInt(section, L"DynamicVariables", 0);
std::vector<Gdiplus::REAL> matrix = parser.ReadFloats(section, L"TransformationMatrix");
if (matrix.size() == 6)
@ -361,9 +352,6 @@ void CMeter::ReadOptions(CConfigParser& parser, const WCHAR* section)
LogWithArgs(LOG_ERROR, L"Meter: Incorrect number of values in TransformationMatrix=%s", parser.ReadString(section, L"TransformationMatrix", L"").c_str());
}
const std::wstring& group = parser.ReadString(section, L"Group", L"");
InitializeGroup(group);
}
/*
@ -432,11 +420,7 @@ CMeter* CMeter::Create(const WCHAR* meter, CMeterWindow* meterWindow, const WCHA
bool CMeter::Update()
{
// Only update the meter's value when the divider is equal to the counter
++m_UpdateCounter;
if (m_UpdateCounter < m_UpdateDivider) return false;
m_UpdateCounter = 0;
return true;
return UpdateCounter();
}
/*

View File

@ -65,8 +65,8 @@ public:
void CreateToolTip(CMeterWindow* meterWindow);
void UpdateToolTip();
virtual void Hide();
virtual void Show();
void Hide();
void Show();
bool IsHidden() { return m_Hidden; }
const Gdiplus::Matrix* GetTransformationMatrix() { return m_Transformation; }

View File

@ -108,7 +108,7 @@ void CMeterBar::ReadOptions(CConfigParser& parser, const WCHAR* section)
m_Border = parser.ReadInt(section, L"BarBorder", 0);
m_Flip = parser.ReadInt(section, L"Flip", 0) == 1;
m_Flip = 0!=parser.ReadInt(section, L"Flip", 0);
const WCHAR* orientation = parser.ReadString(section, L"BarOrientation", L"VERTICAL").c_str();
if (_wcsicmp(L"VERTICAL", orientation) == 0)

View File

@ -377,7 +377,7 @@ void CMeterString::ReadOptions(CConfigParser& parser, const WCHAR* section)
m_FontFace = L"Arial";
}
m_FontSize = (int)parser.ReadFloat(section, L"FontSize", 10);
m_FontSize = parser.ReadInt(section, L"FontSize", 10);
if (m_FontSize < 0)
{
m_FontSize = 10;

View File

@ -709,8 +709,6 @@ void CMeterWindow::ChangeSingleZPos(ZPOSITION zPos, bool all)
*/
void CMeterWindow::RunBang(BANGCOMMAND bang, const std::vector<std::wstring>& args)
{
if (!m_Window) return;
switch (bang)
{
case BANG_REFRESH:

View File

@ -73,7 +73,22 @@ void CMouse::ReadOptions(CConfigParser& parser, const WCHAR* section)
const WCHAR* defaultMouseCursor = (section == L"Rainmeter") ? L"HAND" : L"";
const WCHAR* mouseCursor = parser.ReadString(section, L"MouseActionCursorName", defaultMouseCursor).c_str();
if (_wcsicmp(mouseCursor, L"HAND") == 0)
auto inheritSkinDefault = [&]()
{
// Inherit from [Rainmeter].
m_CursorType = m_MeterWindow->GetMouse().GetCursorType();
if (m_CursorType == MOUSECURSOR_CUSTOM)
{
mouseCursor = m_MeterWindow->GetParser().ReadString(L"Rainmeter", L"MouseActionCursorName", L"").c_str();
}
};
if (*mouseCursor == L'\0') // meters' default
{
inheritSkinDefault();
}
else if (_wcsicmp(mouseCursor, L"HAND") == 0) // skin's default
{
m_CursorType = MOUSECURSOR_HAND;
}
@ -103,12 +118,7 @@ void CMouse::ReadOptions(CConfigParser& parser, const WCHAR* section)
}
else
{
// Inherit from [Rainmeter].
m_CursorType = m_MeterWindow->GetMouse().GetCursorType();
if (m_CursorType == MOUSECURSOR_CUSTOM)
{
mouseCursor = m_MeterWindow->GetParser().ReadString(L"Rainmeter", L"MouseActionCursorName", L"").c_str();
}
inheritSkinDefault();
}
if (m_CursorType == MOUSECURSOR_CUSTOM)

View File

@ -18,6 +18,7 @@
#include "StdAfx.h"
#include "Section.h"
#include "ConfigParser.h"
#include "Rainmeter.h"
extern CRainmeter* Rainmeter;
@ -41,6 +42,40 @@ CSection::~CSection()
{
}
/*
** Read the common options specified in the ini file. The inherited classes must
** call this base implementation if they overwrite this method.
**
*/
void CSection::ReadOptions(CConfigParser& parser, const WCHAR* section)
{
int updateDivider = parser.ReadInt(section, L"UpdateDivider", 1);
if (updateDivider != m_UpdateDivider)
{
m_UpdateCounter = m_UpdateDivider = updateDivider;
}
m_DynamicVariables = 0!=parser.ReadInt(section, L"DynamicVariables", 0);
m_OnUpdateAction = parser.ReadString(section, L"OnUpdateAction", L"", false);
const std::wstring& group = parser.ReadString(section, L"Group", L"");
InitializeGroup(group);
}
/*
** Updates the counter value
**
*/
bool CSection::UpdateCounter()
{
++m_UpdateCounter;
if (m_UpdateCounter < m_UpdateDivider) return false;
m_UpdateCounter = 0;
return true;
}
/*
** Execute OnUpdateAction if action is set
**

View File

@ -24,6 +24,7 @@
#include "Group.h"
class CMeterWindow;
class CConfigParser;
class CSection : public CGroup
{
@ -48,6 +49,10 @@ public:
protected:
CSection(CMeterWindow* meterWindow, const WCHAR* name);
virtual void ReadOptions(CConfigParser& parser, const WCHAR* section);
bool UpdateCounter();
const std::wstring m_Name; // Name of this Section
bool m_DynamicVariables; // If true, the section contains dynamic variables