mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
IfActions: Tweaks
This commit is contained in:
parent
b62fca59d0
commit
40e0b70baf
@ -22,7 +22,7 @@
|
|||||||
#include "Rainmeter.h"
|
#include "Rainmeter.h"
|
||||||
#include "../Common/MathParser.h"
|
#include "../Common/MathParser.h"
|
||||||
|
|
||||||
IfActions::IfActions(MeterWindow* meterWindow, Measure* measure) :
|
IfActions::IfActions() :
|
||||||
m_AboveValue(0.0f),
|
m_AboveValue(0.0f),
|
||||||
m_BelowValue(0.0f),
|
m_BelowValue(0.0f),
|
||||||
m_EqualValue(0),
|
m_EqualValue(0),
|
||||||
@ -32,10 +32,7 @@ IfActions::IfActions(MeterWindow* meterWindow, Measure* measure) :
|
|||||||
m_AboveCommitted(false),
|
m_AboveCommitted(false),
|
||||||
m_BelowCommitted(false),
|
m_BelowCommitted(false),
|
||||||
m_EqualCommitted(false),
|
m_EqualCommitted(false),
|
||||||
m_Conditions(),
|
m_Conditions()
|
||||||
m_HasConditions(false),
|
|
||||||
m_MeterWindow(meterWindow),
|
|
||||||
m_Measure(measure)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,15 +54,12 @@ void IfActions::ReadOptions(ConfigParser& parser, const WCHAR* section)
|
|||||||
|
|
||||||
void IfActions::ReadConditionOptions(ConfigParser& parser, const WCHAR* section)
|
void IfActions::ReadConditionOptions(ConfigParser& parser, const WCHAR* section)
|
||||||
{
|
{
|
||||||
m_HasConditions = false;
|
|
||||||
std::wstring condition = parser.ReadString(section, L"IfCondition", L"");
|
std::wstring condition = parser.ReadString(section, L"IfCondition", L"");
|
||||||
std::wstring tAction = parser.ReadString(section, L"IfTrueAction", L"", false);
|
std::wstring tAction = parser.ReadString(section, L"IfTrueAction", L"", false);
|
||||||
std::wstring fAction = parser.ReadString(section, L"IfFalseAction", L"", false);
|
std::wstring fAction = parser.ReadString(section, L"IfFalseAction", L"", false);
|
||||||
if (!condition.empty() && (!tAction.empty() || !fAction.empty()))
|
if (!condition.empty() && (!tAction.empty() || !fAction.empty()))
|
||||||
{
|
{
|
||||||
m_HasConditions = true;
|
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (m_Conditions.size() > (i - 1))
|
if (m_Conditions.size() > (i - 1))
|
||||||
@ -89,9 +83,13 @@ void IfActions::ReadConditionOptions(ConfigParser& parser, const WCHAR* section)
|
|||||||
}
|
}
|
||||||
while (!condition.empty() && (!tAction.empty() || !fAction.empty()));
|
while (!condition.empty() && (!tAction.empty() || !fAction.empty()));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_Conditions.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IfActions::DoIfActions(double& value)
|
void IfActions::DoIfActions(Measure& measure, double value)
|
||||||
{
|
{
|
||||||
if (!m_EqualAction.empty())
|
if (!m_EqualAction.empty())
|
||||||
{
|
{
|
||||||
@ -100,7 +98,7 @@ void IfActions::DoIfActions(double& value)
|
|||||||
if (!m_EqualCommitted)
|
if (!m_EqualCommitted)
|
||||||
{
|
{
|
||||||
m_EqualCommitted = true; // To avoid infinite loop from !Update
|
m_EqualCommitted = true; // To avoid infinite loop from !Update
|
||||||
GetRainmeter().ExecuteCommand(m_EqualAction.c_str(), m_MeterWindow);
|
GetRainmeter().ExecuteCommand(m_EqualAction.c_str(), measure.GetMeterWindow());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -116,7 +114,7 @@ void IfActions::DoIfActions(double& value)
|
|||||||
if (!m_AboveCommitted)
|
if (!m_AboveCommitted)
|
||||||
{
|
{
|
||||||
m_AboveCommitted = true; // To avoid infinite loop from !Update
|
m_AboveCommitted = true; // To avoid infinite loop from !Update
|
||||||
GetRainmeter().ExecuteCommand(m_AboveAction.c_str(), m_MeterWindow);
|
GetRainmeter().ExecuteCommand(m_AboveAction.c_str(), measure.GetMeterWindow());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -132,7 +130,7 @@ void IfActions::DoIfActions(double& value)
|
|||||||
if (!m_BelowCommitted)
|
if (!m_BelowCommitted)
|
||||||
{
|
{
|
||||||
m_BelowCommitted = true; // To avoid infinite loop from !Update
|
m_BelowCommitted = true; // To avoid infinite loop from !Update
|
||||||
GetRainmeter().ExecuteCommand(m_BelowAction.c_str(), m_MeterWindow);
|
GetRainmeter().ExecuteCommand(m_BelowAction.c_str(), measure.GetMeterWindow());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -141,8 +139,6 @@ void IfActions::DoIfActions(double& value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_HasConditions)
|
|
||||||
{
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (auto& item : m_Conditions)
|
for (auto& item : m_Conditions)
|
||||||
{
|
{
|
||||||
@ -150,18 +146,19 @@ void IfActions::DoIfActions(double& value)
|
|||||||
if (!item.condition.empty() && (!item.tAction.empty() || !item.fAction.empty()))
|
if (!item.condition.empty() && (!item.tAction.empty() || !item.fAction.empty()))
|
||||||
{
|
{
|
||||||
double result = 0.0f;
|
double result = 0.0f;
|
||||||
const WCHAR* errMsg = MathParser::Parse(item.condition.c_str(), &result, m_Measure->GetCurrentMeasureValue, m_Measure);
|
const WCHAR* errMsg = MathParser::Parse(
|
||||||
|
item.condition.c_str(), &result, measure.GetCurrentMeasureValue, &measure);
|
||||||
if (errMsg != nullptr)
|
if (errMsg != nullptr)
|
||||||
{
|
{
|
||||||
if (!item.parseError)
|
if (!item.parseError)
|
||||||
{
|
{
|
||||||
if (i == 1)
|
if (i == 1)
|
||||||
{
|
{
|
||||||
LogErrorF(m_Measure, L"%s: IfCondition=%s", errMsg, item.condition.c_str());
|
LogErrorF(&measure, L"%s: IfCondition=%s", errMsg, item.condition.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogErrorF(m_Measure, L"%s: IfCondition%i=%s", errMsg, i, item.condition.c_str());
|
LogErrorF(&measure, L"%s: IfCondition%i=%s", errMsg, i, item.condition.c_str());
|
||||||
}
|
}
|
||||||
item.parseError = true;
|
item.parseError = true;
|
||||||
}
|
}
|
||||||
@ -172,12 +169,11 @@ void IfActions::DoIfActions(double& value)
|
|||||||
|
|
||||||
if (result == 1.0f) // "True"
|
if (result == 1.0f) // "True"
|
||||||
{
|
{
|
||||||
GetRainmeter().ExecuteCommand(item.tAction.c_str(), m_MeterWindow);
|
GetRainmeter().ExecuteCommand(item.tAction.c_str(), measure.GetMeterWindow());
|
||||||
}
|
}
|
||||||
else if (result == 0.0f) // "False"
|
else if (result == 0.0f) // "False"
|
||||||
{
|
{
|
||||||
GetRainmeter().ExecuteCommand(item.fAction.c_str(), m_MeterWindow);
|
GetRainmeter().ExecuteCommand(item.fAction.c_str(), measure.GetMeterWindow());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,12 +55,12 @@ public:
|
|||||||
class IfActions
|
class IfActions
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IfActions(MeterWindow* meterWindow, Measure* measure);
|
IfActions();
|
||||||
~IfActions();
|
~IfActions();
|
||||||
|
|
||||||
void ReadOptions(ConfigParser& parser, const WCHAR* section);
|
void ReadOptions(ConfigParser& parser, const WCHAR* section);
|
||||||
void ReadConditionOptions(ConfigParser& parser, const WCHAR* section);
|
void ReadConditionOptions(ConfigParser& parser, const WCHAR* section);
|
||||||
void DoIfActions(double& value);
|
void DoIfActions(Measure& measure, double value);
|
||||||
void SetState(double value = 0.0f);
|
void SetState(double value = 0.0f);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -77,9 +77,5 @@ private:
|
|||||||
bool m_EqualCommitted;
|
bool m_EqualCommitted;
|
||||||
|
|
||||||
std::vector<IfCondition> m_Conditions;
|
std::vector<IfCondition> m_Conditions;
|
||||||
bool m_HasConditions;
|
|
||||||
|
|
||||||
MeterWindow* m_MeterWindow;
|
|
||||||
Measure* m_Measure;
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user