forked from rainmeter/rainmeter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeasureLoop.cpp
128 lines (113 loc) · 3.02 KB
/
MeasureLoop.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* Copyright (C) 2015 Rainmeter Project Developers
*
* This Source Code Form is subject to the terms of the GNU General Public
* License; either version 2 of the License, or (at your option) any later
* version. If a copy of the GPL was not distributed with this file, You can
* obtain one at <https://www.gnu.org/licenses/gpl-2.0.html>. */
#include "StdAfx.h"
#include "MeasureLoop.h"
#include "Rainmeter.h"
MeasureLoop::MeasureLoop(Skin* skin, const WCHAR* name) : Measure(skin, name),
m_StartValue(1),
m_EndValue(100),
m_Increment(1),
m_LoopCount(0),
m_LoopCounter(0),
m_SkipFirst(true),
m_HasOverRun(false)
{
}
MeasureLoop::~MeasureLoop()
{
}
void MeasureLoop::ReadOptions(ConfigParser& parser, const WCHAR* section)
{
int oldStart = m_StartValue, oldEnd = m_EndValue, oldInc = m_Increment, oldCount = m_LoopCount;
bool oldInvert = m_Invert;
Measure::ReadOptions(parser, section);
m_StartValue = parser.ReadInt(section, L"StartValue", 1);
m_EndValue = parser.ReadInt(section, L"EndValue", 100);
m_Increment = parser.ReadInt(section, L"Increment", 1);
m_LoopCount = parser.ReadInt(section, L"LoopCount", 0);
if (!m_Initialized || oldStart != m_StartValue || oldEnd != m_EndValue ||
oldInc != m_Increment || oldCount != m_LoopCount || oldInvert != m_Invert)
{
Reset();
}
}
void MeasureLoop::UpdateValue()
{
// Skip the first update of the loop, otherwise the |m_StartValue| gets skipped
if (m_SkipFirst)
{
m_SkipFirst = false;
return;
}
if (m_LoopCount <= 0 || m_LoopCounter < m_LoopCount)
{
m_Value += m_Increment;
if ((m_Increment > 0 && m_Value >= m_EndValue) ||
(m_Increment <= 0 && m_Value <= m_EndValue))
{
if (!m_Invert)
{
// |m_Value| has overrun. Display the |m_EndValue| for exactly
// one update cycle before starting over (if necessary)
if (m_HasOverRun && (m_LoopCount <= 0 || m_LoopCounter <= m_LoopCount))
{
m_Value = m_StartValue;
m_HasOverRun = false;
}
else
{
m_Value = m_EndValue;
++m_LoopCounter;
m_HasOverRun = true;
}
}
else
{
// For inverted measures, the opposite needs to happen.
// Display |m_StartValue| for exactly one update cycle
// before starting over (if necessary)
if (!m_HasOverRun && (m_LoopCount <= 0 || m_LoopCounter <= m_LoopCount))
{
m_Value = m_EndValue;
++m_LoopCounter;
m_HasOverRun = true;
}
else
{
m_Value = m_StartValue;
m_HasOverRun = false;
}
}
}
}
}
void MeasureLoop::Reset()
{
m_Value = m_StartValue;
m_LoopCounter = 0;
m_SkipFirst = true;
m_HasOverRun = false;
if (m_StartValue < m_EndValue)
{
m_MinValue = m_StartValue;
m_MaxValue = m_EndValue;
}
else
{
m_MinValue = m_EndValue;
m_MaxValue = m_StartValue;
}
}
void MeasureLoop::Command(const std::wstring& command)
{
if (_wcsicmp(command.c_str(), L"Reset") == 0)
{
Reset();
return;
}
LogWarningF(this, L"!CommandMeasure: Not supported");
}