Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Code cleanup

  • Loading branch information...
commit 95aacda3cbabf84c8b963a11907b3bfef709cade 1 parent 1c8b798
spx spx268 authored
18 Library/Measure.cpp
@@ -119,6 +119,8 @@ void CMeasure::ReadOptions(CConfigParser& parser, const WCHAR* section)
119 119 {
120 120 bool oldOnChangeActionEmpty = m_OnChangeAction.empty();
121 121
  122 + CSection::ReadOptions(parser, section);
  123 +
122 124 // Clear substitutes to prevent from being added more than once.
123 125 if (!m_Substitute.empty())
124 126 {
@@ -129,12 +131,6 @@ void CMeasure::ReadOptions(CConfigParser& parser, const WCHAR* section)
129 131
130 132 m_Disabled = 0!=parser.ReadInt(section, L"Disabled", 0);
131 133
132   - int updateDivider = parser.ReadInt(section, L"UpdateDivider", 1);
133   - if (updateDivider != m_UpdateDivider)
134   - {
135   - m_UpdateCounter = m_UpdateDivider = updateDivider;
136   - }
137   -
138 134 m_MinValue = parser.ReadFloat(section, L"MinValue", m_MinValue);
139 135 m_MaxValue = parser.ReadFloat(section, L"MaxValue", m_MaxValue);
140 136
@@ -149,13 +145,10 @@ void CMeasure::ReadOptions(CConfigParser& parser, const WCHAR* section)
149 145 m_IfEqualValue = (int64_t)parser.ReadFloat(section, L"IfEqualValue", 0.0);
150 146 m_IfEqualAction = parser.ReadString(section, L"IfEqualAction", L"", false);
151 147
152   - m_OnUpdateAction = parser.ReadString(section, L"OnUpdateAction", L"", false);
153 148 m_OnChangeAction = parser.ReadString(section, L"OnChangeAction", L"", false);
154 149
155 150 m_AverageSize = parser.ReadUInt(section, L"AverageSize", 0);
156 151
157   - m_DynamicVariables = 0!=parser.ReadInt(section, L"DynamicVariables", 0);
158   -
159 152 m_RegExpSubstitute = 0!=parser.ReadInt(section, L"RegExpSubstitute", 0);
160 153 std::wstring subs = parser.ReadString(section, L"Substitute", L"");
161 154 if (!subs.empty())
@@ -173,9 +166,6 @@ void CMeasure::ReadOptions(CConfigParser& parser, const WCHAR* section)
173 166 }
174 167 }
175 168
176   - const std::wstring& group = parser.ReadString(section, L"Group", L"");
177   - InitializeGroup(group);
178   -
179 169 if (m_Initialized &&
180 170 oldOnChangeActionEmpty && !m_OnChangeAction.empty())
181 171 {
@@ -450,9 +440,7 @@ bool CMeasure::Update()
450 440 if (!m_Disabled)
451 441 {
452 442 // Only update the counter if the divider
453   - ++m_UpdateCounter;
454   - if (m_UpdateCounter < m_UpdateDivider) return false;
455   - m_UpdateCounter = 0;
  443 + if (!UpdateCounter()) return false;
456 444
457 445 // Call derived method to update value
458 446 UpdateValue();
30 Library/Meter.cpp
@@ -169,15 +169,13 @@ RECT CMeter::GetMeterRect()
169 169
170 170 /*
171 171 ** Checks if the given point is inside the meter.
  172 +** This function doesn't check Hidden state, so check it before calling this function if needed.
172 173 **
173 174 */
174 175 bool CMeter::HitTest(int x, int y)
175 176 {
176   - if (x >= GetX() && x < GetX() + GetW() && y >= GetY() && y < GetY() + GetH())
177   - {
178   - return true;
179   - }
180   - return false;
  177 + int p;
  178 + return (x >= (p = GetX()) && x < p + m_W && y >= (p = GetY()) && y < p + m_H);
181 179 }
182 180
183 181 /*
@@ -231,6 +229,8 @@ void CMeter::ReadOptions(CConfigParser& parser, const WCHAR* section)
231 229 parser.SetStyleTemplate(style);
232 230 }
233 231
  232 + CSection::ReadOptions(parser, section);
  233 +
234 234 BindMeasures(parser, section);
235 235
236 236 int oldX = m_X;
@@ -321,26 +321,17 @@ void CMeter::ReadOptions(CConfigParser& parser, const WCHAR* section)
321 321 m_SolidColor2 = parser.ReadColor(section, L"SolidColor2", m_SolidColor.GetValue());
322 322 m_SolidAngle = (Gdiplus::REAL)parser.ReadFloat(section, L"GradientAngle", 0.0);
323 323
324   - m_OnUpdateAction = parser.ReadString(section, L"OnUpdateAction", L"", false);
325   -
326 324 m_Mouse.ReadOptions(parser, section);
327 325 m_HasMouseAction = m_Mouse.HasButtonAction() || m_Mouse.HasScrollAction();
328 326
329 327 m_ToolTipText = parser.ReadString(section, L"ToolTipText", L"");
330 328 m_ToolTipTitle = parser.ReadString(section, L"ToolTipTitle", L"");
331 329 m_ToolTipIcon = parser.ReadString(section, L"ToolTipIcon", L"");
332   - m_ToolTipWidth = (int)parser.ReadFloat(section, L"ToolTipWidth", 1000);
  330 + m_ToolTipWidth = parser.ReadInt(section, L"ToolTipWidth", 1000);
333 331 m_ToolTipType = 0!=parser.ReadInt(section, L"ToolTipType", 0);
334 332 m_ToolTipHidden = 0!=parser.ReadInt(section, L"ToolTipHidden", m_MeterWindow->GetMeterToolTipHidden());
335 333
336   - int updateDivider = parser.ReadInt(section, L"UpdateDivider", 1);
337   - if (updateDivider != m_UpdateDivider)
338   - {
339   - m_UpdateCounter = m_UpdateDivider = updateDivider;
340   - }
341   -
342 334 m_AntiAlias = 0!=parser.ReadInt(section, L"AntiAlias", 0);
343   - m_DynamicVariables = 0!=parser.ReadInt(section, L"DynamicVariables", 0);
344 335
345 336 std::vector<Gdiplus::REAL> matrix = parser.ReadFloats(section, L"TransformationMatrix");
346 337 if (matrix.size() == 6)
@@ -361,9 +352,6 @@ void CMeter::ReadOptions(CConfigParser& parser, const WCHAR* section)
361 352
362 353 LogWithArgs(LOG_ERROR, L"Meter: Incorrect number of values in TransformationMatrix=%s", parser.ReadString(section, L"TransformationMatrix", L"").c_str());
363 354 }
364   -
365   - const std::wstring& group = parser.ReadString(section, L"Group", L"");
366   - InitializeGroup(group);
367 355 }
368 356
369 357 /*
@@ -432,11 +420,7 @@ CMeter* CMeter::Create(const WCHAR* meter, CMeterWindow* meterWindow, const WCHA
432 420 bool CMeter::Update()
433 421 {
434 422 // Only update the meter's value when the divider is equal to the counter
435   - ++m_UpdateCounter;
436   - if (m_UpdateCounter < m_UpdateDivider) return false;
437   - m_UpdateCounter = 0;
438   -
439   - return true;
  423 + return UpdateCounter();
440 424 }
441 425
442 426 /*
4 Library/Meter.h
@@ -65,8 +65,8 @@ class CMeter : public CSection
65 65 void CreateToolTip(CMeterWindow* meterWindow);
66 66 void UpdateToolTip();
67 67
68   - virtual void Hide();
69   - virtual void Show();
  68 + void Hide();
  69 + void Show();
70 70 bool IsHidden() { return m_Hidden; }
71 71
72 72 const Gdiplus::Matrix* GetTransformationMatrix() { return m_Transformation; }
2  Library/MeterBar.cpp
@@ -108,7 +108,7 @@ void CMeterBar::ReadOptions(CConfigParser& parser, const WCHAR* section)
108 108
109 109 m_Border = parser.ReadInt(section, L"BarBorder", 0);
110 110
111   - m_Flip = parser.ReadInt(section, L"Flip", 0) == 1;
  111 + m_Flip = 0!=parser.ReadInt(section, L"Flip", 0);
112 112
113 113 const WCHAR* orientation = parser.ReadString(section, L"BarOrientation", L"VERTICAL").c_str();
114 114 if (_wcsicmp(L"VERTICAL", orientation) == 0)
2  Library/MeterString.cpp
@@ -377,7 +377,7 @@ void CMeterString::ReadOptions(CConfigParser& parser, const WCHAR* section)
377 377 m_FontFace = L"Arial";
378 378 }
379 379
380   - m_FontSize = (int)parser.ReadFloat(section, L"FontSize", 10);
  380 + m_FontSize = parser.ReadInt(section, L"FontSize", 10);
381 381 if (m_FontSize < 0)
382 382 {
383 383 m_FontSize = 10;
2  Library/MeterWindow.cpp
@@ -709,8 +709,6 @@ void CMeterWindow::ChangeSingleZPos(ZPOSITION zPos, bool all)
709 709 */
710 710 void CMeterWindow::RunBang(BANGCOMMAND bang, const std::vector<std::wstring>& args)
711 711 {
712   - if (!m_Window) return;
713   -
714 712 switch (bang)
715 713 {
716 714 case BANG_REFRESH:
24 Library/Mouse.cpp
@@ -73,7 +73,22 @@ void CMouse::ReadOptions(CConfigParser& parser, const WCHAR* section)
73 73
74 74 const WCHAR* defaultMouseCursor = (section == L"Rainmeter") ? L"HAND" : L"";
75 75 const WCHAR* mouseCursor = parser.ReadString(section, L"MouseActionCursorName", defaultMouseCursor).c_str();
76   - if (_wcsicmp(mouseCursor, L"HAND") == 0)
  76 +
  77 + auto inheritSkinDefault = [&]()
  78 + {
  79 + // Inherit from [Rainmeter].
  80 + m_CursorType = m_MeterWindow->GetMouse().GetCursorType();
  81 + if (m_CursorType == MOUSECURSOR_CUSTOM)
  82 + {
  83 + mouseCursor = m_MeterWindow->GetParser().ReadString(L"Rainmeter", L"MouseActionCursorName", L"").c_str();
  84 + }
  85 + };
  86 +
  87 + if (*mouseCursor == L'\0') // meters' default
  88 + {
  89 + inheritSkinDefault();
  90 + }
  91 + else if (_wcsicmp(mouseCursor, L"HAND") == 0) // skin's default
77 92 {
78 93 m_CursorType = MOUSECURSOR_HAND;
79 94 }
@@ -103,12 +118,7 @@ void CMouse::ReadOptions(CConfigParser& parser, const WCHAR* section)
103 118 }
104 119 else
105 120 {
106   - // Inherit from [Rainmeter].
107   - m_CursorType = m_MeterWindow->GetMouse().GetCursorType();
108   - if (m_CursorType == MOUSECURSOR_CUSTOM)
109   - {
110   - mouseCursor = m_MeterWindow->GetParser().ReadString(L"Rainmeter", L"MouseActionCursorName", L"").c_str();
111   - }
  121 + inheritSkinDefault();
112 122 }
113 123
114 124 if (m_CursorType == MOUSECURSOR_CUSTOM)
35 Library/Section.cpp
@@ -18,6 +18,7 @@
18 18
19 19 #include "StdAfx.h"
20 20 #include "Section.h"
  21 +#include "ConfigParser.h"
21 22 #include "Rainmeter.h"
22 23
23 24 extern CRainmeter* Rainmeter;
@@ -42,6 +43,40 @@ CSection::~CSection()
42 43 }
43 44
44 45 /*
  46 +** Read the common options specified in the ini file. The inherited classes must
  47 +** call this base implementation if they overwrite this method.
  48 +**
  49 +*/
  50 +void CSection::ReadOptions(CConfigParser& parser, const WCHAR* section)
  51 +{
  52 + int updateDivider = parser.ReadInt(section, L"UpdateDivider", 1);
  53 + if (updateDivider != m_UpdateDivider)
  54 + {
  55 + m_UpdateCounter = m_UpdateDivider = updateDivider;
  56 + }
  57 +
  58 + m_DynamicVariables = 0!=parser.ReadInt(section, L"DynamicVariables", 0);
  59 +
  60 + m_OnUpdateAction = parser.ReadString(section, L"OnUpdateAction", L"", false);
  61 +
  62 + const std::wstring& group = parser.ReadString(section, L"Group", L"");
  63 + InitializeGroup(group);
  64 +}
  65 +
  66 +/*
  67 +** Updates the counter value
  68 +**
  69 +*/
  70 +bool CSection::UpdateCounter()
  71 +{
  72 + ++m_UpdateCounter;
  73 + if (m_UpdateCounter < m_UpdateDivider) return false;
  74 + m_UpdateCounter = 0;
  75 +
  76 + return true;
  77 +}
  78 +
  79 +/*
45 80 ** Execute OnUpdateAction if action is set
46 81 **
47 82 */
5 Library/Section.h
@@ -24,6 +24,7 @@
24 24 #include "Group.h"
25 25
26 26 class CMeterWindow;
  27 +class CConfigParser;
27 28
28 29 class CSection : public CGroup
29 30 {
@@ -48,6 +49,10 @@ class CSection : public CGroup
48 49 protected:
49 50 CSection(CMeterWindow* meterWindow, const WCHAR* name);
50 51
  52 + virtual void ReadOptions(CConfigParser& parser, const WCHAR* section);
  53 +
  54 + bool UpdateCounter();
  55 +
51 56 const std::wstring m_Name; // Name of this Section
52 57
53 58 bool m_DynamicVariables; // If true, the section contains dynamic variables

0 comments on commit 95aacda

Please sign in to comment.
Something went wrong with that request. Please try again.