Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
spx268 committed Feb 6, 2013
1 parent 1c8b798 commit 95aacda
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 51 deletions.
18 changes: 3 additions & 15 deletions Library/Measure.cpp
Expand Up @@ -119,6 +119,8 @@ void CMeasure::ReadOptions(CConfigParser& parser, const WCHAR* section)
{ {
bool oldOnChangeActionEmpty = m_OnChangeAction.empty(); bool oldOnChangeActionEmpty = m_OnChangeAction.empty();


CSection::ReadOptions(parser, section);

// Clear substitutes to prevent from being added more than once. // Clear substitutes to prevent from being added more than once.
if (!m_Substitute.empty()) if (!m_Substitute.empty())
{ {
Expand All @@ -129,12 +131,6 @@ void CMeasure::ReadOptions(CConfigParser& parser, const WCHAR* section)


m_Disabled = 0!=parser.ReadInt(section, L"Disabled", 0); 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_MinValue = parser.ReadFloat(section, L"MinValue", m_MinValue);
m_MaxValue = parser.ReadFloat(section, L"MaxValue", m_MaxValue); m_MaxValue = parser.ReadFloat(section, L"MaxValue", m_MaxValue);


Expand All @@ -149,13 +145,10 @@ void CMeasure::ReadOptions(CConfigParser& parser, const WCHAR* section)
m_IfEqualValue = (int64_t)parser.ReadFloat(section, L"IfEqualValue", 0.0); m_IfEqualValue = (int64_t)parser.ReadFloat(section, L"IfEqualValue", 0.0);
m_IfEqualAction = parser.ReadString(section, L"IfEqualAction", L"", false); 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_OnChangeAction = parser.ReadString(section, L"OnChangeAction", L"", false);


m_AverageSize = parser.ReadUInt(section, L"AverageSize", 0); 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); m_RegExpSubstitute = 0!=parser.ReadInt(section, L"RegExpSubstitute", 0);
std::wstring subs = parser.ReadString(section, L"Substitute", L""); std::wstring subs = parser.ReadString(section, L"Substitute", L"");
if (!subs.empty()) if (!subs.empty())
Expand All @@ -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 && if (m_Initialized &&
oldOnChangeActionEmpty && !m_OnChangeAction.empty()) oldOnChangeActionEmpty && !m_OnChangeAction.empty())
{ {
Expand Down Expand Up @@ -450,9 +440,7 @@ bool CMeasure::Update()
if (!m_Disabled) if (!m_Disabled)
{ {
// Only update the counter if the divider // Only update the counter if the divider
++m_UpdateCounter; if (!UpdateCounter()) return false;
if (m_UpdateCounter < m_UpdateDivider) return false;
m_UpdateCounter = 0;


// Call derived method to update value // Call derived method to update value
UpdateValue(); UpdateValue();
Expand Down
30 changes: 7 additions & 23 deletions Library/Meter.cpp
Expand Up @@ -169,15 +169,13 @@ RECT CMeter::GetMeterRect()


/* /*
** Checks if the given point is inside the meter. ** 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) bool CMeter::HitTest(int x, int y)
{ {
if (x >= GetX() && x < GetX() + GetW() && y >= GetY() && y < GetY() + GetH()) int p;
{ return (x >= (p = GetX()) && x < p + m_W && y >= (p = GetY()) && y < p + m_H);
return true;
}
return false;
} }


/* /*
Expand Down Expand Up @@ -231,6 +229,8 @@ void CMeter::ReadOptions(CConfigParser& parser, const WCHAR* section)
parser.SetStyleTemplate(style); parser.SetStyleTemplate(style);
} }


CSection::ReadOptions(parser, section);

BindMeasures(parser, section); BindMeasures(parser, section);


int oldX = m_X; int oldX = m_X;
Expand Down Expand Up @@ -321,26 +321,17 @@ void CMeter::ReadOptions(CConfigParser& parser, const WCHAR* section)
m_SolidColor2 = parser.ReadColor(section, L"SolidColor2", m_SolidColor.GetValue()); m_SolidColor2 = parser.ReadColor(section, L"SolidColor2", m_SolidColor.GetValue());
m_SolidAngle = (Gdiplus::REAL)parser.ReadFloat(section, L"GradientAngle", 0.0); 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_Mouse.ReadOptions(parser, section);
m_HasMouseAction = m_Mouse.HasButtonAction() || m_Mouse.HasScrollAction(); m_HasMouseAction = m_Mouse.HasButtonAction() || m_Mouse.HasScrollAction();


m_ToolTipText = parser.ReadString(section, L"ToolTipText", L""); m_ToolTipText = parser.ReadString(section, L"ToolTipText", L"");
m_ToolTipTitle = parser.ReadString(section, L"ToolTipTitle", L""); m_ToolTipTitle = parser.ReadString(section, L"ToolTipTitle", L"");
m_ToolTipIcon = parser.ReadString(section, L"ToolTipIcon", 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_ToolTipType = 0!=parser.ReadInt(section, L"ToolTipType", 0);
m_ToolTipHidden = 0!=parser.ReadInt(section, L"ToolTipHidden", m_MeterWindow->GetMeterToolTipHidden()); 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_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"); std::vector<Gdiplus::REAL> matrix = parser.ReadFloats(section, L"TransformationMatrix");
if (matrix.size() == 6) if (matrix.size() == 6)
Expand All @@ -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()); 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);
} }


/* /*
Expand Down Expand Up @@ -432,11 +420,7 @@ CMeter* CMeter::Create(const WCHAR* meter, CMeterWindow* meterWindow, const WCHA
bool CMeter::Update() bool CMeter::Update()
{ {
// Only update the meter's value when the divider is equal to the counter // Only update the meter's value when the divider is equal to the counter
++m_UpdateCounter; return UpdateCounter();
if (m_UpdateCounter < m_UpdateDivider) return false;
m_UpdateCounter = 0;

return true;
} }


/* /*
Expand Down
4 changes: 2 additions & 2 deletions Library/Meter.h
Expand Up @@ -65,8 +65,8 @@ class CMeter : public CSection
void CreateToolTip(CMeterWindow* meterWindow); void CreateToolTip(CMeterWindow* meterWindow);
void UpdateToolTip(); void UpdateToolTip();


virtual void Hide(); void Hide();
virtual void Show(); void Show();
bool IsHidden() { return m_Hidden; } bool IsHidden() { return m_Hidden; }


const Gdiplus::Matrix* GetTransformationMatrix() { return m_Transformation; } const Gdiplus::Matrix* GetTransformationMatrix() { return m_Transformation; }
Expand Down
2 changes: 1 addition & 1 deletion Library/MeterBar.cpp
Expand Up @@ -108,7 +108,7 @@ void CMeterBar::ReadOptions(CConfigParser& parser, const WCHAR* section)


m_Border = parser.ReadInt(section, L"BarBorder", 0); 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(); const WCHAR* orientation = parser.ReadString(section, L"BarOrientation", L"VERTICAL").c_str();
if (_wcsicmp(L"VERTICAL", orientation) == 0) if (_wcsicmp(L"VERTICAL", orientation) == 0)
Expand Down
2 changes: 1 addition & 1 deletion Library/MeterString.cpp
Expand Up @@ -377,7 +377,7 @@ void CMeterString::ReadOptions(CConfigParser& parser, const WCHAR* section)
m_FontFace = L"Arial"; 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) if (m_FontSize < 0)
{ {
m_FontSize = 10; m_FontSize = 10;
Expand Down
2 changes: 0 additions & 2 deletions Library/MeterWindow.cpp
Expand Up @@ -709,8 +709,6 @@ void CMeterWindow::ChangeSingleZPos(ZPOSITION zPos, bool all)
*/ */
void CMeterWindow::RunBang(BANGCOMMAND bang, const std::vector<std::wstring>& args) void CMeterWindow::RunBang(BANGCOMMAND bang, const std::vector<std::wstring>& args)
{ {
if (!m_Window) return;

switch (bang) switch (bang)
{ {
case BANG_REFRESH: case BANG_REFRESH:
Expand Down
24 changes: 17 additions & 7 deletions Library/Mouse.cpp
Expand Up @@ -73,7 +73,22 @@ void CMouse::ReadOptions(CConfigParser& parser, const WCHAR* section)


const WCHAR* defaultMouseCursor = (section == L"Rainmeter") ? L"HAND" : L""; const WCHAR* defaultMouseCursor = (section == L"Rainmeter") ? L"HAND" : L"";
const WCHAR* mouseCursor = parser.ReadString(section, L"MouseActionCursorName", defaultMouseCursor).c_str(); 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; m_CursorType = MOUSECURSOR_HAND;
} }
Expand Down Expand Up @@ -103,12 +118,7 @@ void CMouse::ReadOptions(CConfigParser& parser, const WCHAR* section)
} }
else else
{ {
// Inherit from [Rainmeter]. inheritSkinDefault();
m_CursorType = m_MeterWindow->GetMouse().GetCursorType();
if (m_CursorType == MOUSECURSOR_CUSTOM)
{
mouseCursor = m_MeterWindow->GetParser().ReadString(L"Rainmeter", L"MouseActionCursorName", L"").c_str();
}
} }


if (m_CursorType == MOUSECURSOR_CUSTOM) if (m_CursorType == MOUSECURSOR_CUSTOM)
Expand Down
35 changes: 35 additions & 0 deletions Library/Section.cpp
Expand Up @@ -18,6 +18,7 @@


#include "StdAfx.h" #include "StdAfx.h"
#include "Section.h" #include "Section.h"
#include "ConfigParser.h"
#include "Rainmeter.h" #include "Rainmeter.h"


extern CRainmeter* Rainmeter; extern CRainmeter* Rainmeter;
Expand All @@ -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 ** Execute OnUpdateAction if action is set
** **
Expand Down
5 changes: 5 additions & 0 deletions Library/Section.h
Expand Up @@ -24,6 +24,7 @@
#include "Group.h" #include "Group.h"


class CMeterWindow; class CMeterWindow;
class CConfigParser;


class CSection : public CGroup class CSection : public CGroup
{ {
Expand All @@ -48,6 +49,10 @@ class CSection : public CGroup
protected: protected:
CSection(CMeterWindow* meterWindow, const WCHAR* name); 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 const std::wstring m_Name; // Name of this Section


bool m_DynamicVariables; // If true, the section contains dynamic variables bool m_DynamicVariables; // If true, the section contains dynamic variables
Expand Down

0 comments on commit 95aacda

Please sign in to comment.