mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
OnChangeAction: Tweaks
This commit is contained in:
parent
89d477b4e1
commit
8ce97640dd
@ -88,7 +88,7 @@ CMeasure::CMeasure(CMeterWindow* meterWindow, const WCHAR* name) : CSection(mete
|
|||||||
m_Disabled(false),
|
m_Disabled(false),
|
||||||
m_Initialized(false),
|
m_Initialized(false),
|
||||||
m_OldValue(),
|
m_OldValue(),
|
||||||
m_OldValueInitialized(false)
|
m_ValueAssigned(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,6 +98,7 @@ CMeasure::CMeasure(CMeterWindow* meterWindow, const WCHAR* name) : CSection(mete
|
|||||||
*/
|
*/
|
||||||
CMeasure::~CMeasure()
|
CMeasure::~CMeasure()
|
||||||
{
|
{
|
||||||
|
delete m_OldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -116,6 +117,8 @@ void CMeasure::Initialize()
|
|||||||
*/
|
*/
|
||||||
void CMeasure::ReadOptions(CConfigParser& parser, const WCHAR* section)
|
void CMeasure::ReadOptions(CConfigParser& parser, const WCHAR* section)
|
||||||
{
|
{
|
||||||
|
bool oldOnChangeActionEmpty = m_OnChangeAction.empty();
|
||||||
|
|
||||||
// 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())
|
||||||
{
|
{
|
||||||
@ -172,6 +175,12 @@ void CMeasure::ReadOptions(CConfigParser& parser, const WCHAR* section)
|
|||||||
|
|
||||||
const std::wstring& group = parser.ReadString(section, L"Group", L"");
|
const std::wstring& group = parser.ReadString(section, L"Group", L"");
|
||||||
InitializeGroup(group);
|
InitializeGroup(group);
|
||||||
|
|
||||||
|
if (m_Initialized &&
|
||||||
|
oldOnChangeActionEmpty && !m_OnChangeAction.empty())
|
||||||
|
{
|
||||||
|
DoChangeAction(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMeasure::Disable()
|
void CMeasure::Disable()
|
||||||
@ -493,6 +502,8 @@ bool CMeasure::Update()
|
|||||||
m_MinValue = min(m_MinValue, medianValue);
|
m_MinValue = min(m_MinValue, medianValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_ValueAssigned = true;
|
||||||
|
|
||||||
if (m_MeterWindow)
|
if (m_MeterWindow)
|
||||||
{
|
{
|
||||||
if (!m_IfEqualAction.empty())
|
if (!m_IfEqualAction.empty())
|
||||||
@ -729,33 +740,33 @@ void CMeasure::RemoveTrailingZero(WCHAR* str, int strLen)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Execute OnChangeAction if action is set
|
** Executes OnChangeAction if action is set.
|
||||||
|
** If execute parameter is set to false, only updates old value with current value.
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
void CMeasure::DoChangeAction()
|
void CMeasure::DoChangeAction(bool execute)
|
||||||
{
|
{
|
||||||
if (!m_OldValueInitialized)
|
if (!m_OnChangeAction.empty() && m_ValueAssigned)
|
||||||
{
|
{
|
||||||
double newValue = GetValue();
|
double newValue = GetValue();
|
||||||
const WCHAR* newStringValue = GetStringValue(AUTOSCALE_OFF, 1, -1, false);
|
const WCHAR* newStringValue = GetStringValue(AUTOSCALE_OFF, 1, -1, false);
|
||||||
|
|
||||||
m_OldValue = newValue;
|
if (!m_OldValue)
|
||||||
m_OldStringValue = newStringValue;
|
{
|
||||||
m_OldValueInitialized = true;
|
m_OldValue = new CMeasureValueSet(newValue, newStringValue);
|
||||||
}
|
}
|
||||||
else if (!m_OnChangeAction.empty())
|
else if (execute)
|
||||||
{
|
{
|
||||||
double newValue = GetValue();
|
if (m_OldValue->IsChanged(newValue, newStringValue))
|
||||||
const WCHAR* newStringValue = GetStringValue(AUTOSCALE_OFF, 1, -1, false);
|
|
||||||
|
|
||||||
if (m_OldValue != newValue || wcscmp(m_OldStringValue.c_str(), newStringValue) != 0)
|
|
||||||
{
|
{
|
||||||
m_OldValue = newValue;
|
|
||||||
m_OldStringValue = newStringValue;
|
|
||||||
|
|
||||||
Rainmeter->ExecuteCommand(m_OnChangeAction.c_str(), m_MeterWindow);
|
Rainmeter->ExecuteCommand(m_OnChangeAction.c_str(), m_MeterWindow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_OldValue->Set(newValue, newStringValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -37,6 +37,17 @@ enum AUTOSCALE
|
|||||||
AUTOSCALE_ON = AUTOSCALE_1024
|
AUTOSCALE_ON = AUTOSCALE_1024
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CMeasureValueSet
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CMeasureValueSet(double val, const WCHAR* str) : m_Value(val), m_StringValue(str) {}
|
||||||
|
void Set(double val, const WCHAR* str) { m_Value = val; m_StringValue = str; }
|
||||||
|
bool IsChanged(double val, const WCHAR* str) { if (m_Value != val || wcscmp(m_StringValue.c_str(), str) != 0) { Set(val, str); return true; } return false; }
|
||||||
|
private:
|
||||||
|
double m_Value;
|
||||||
|
std::wstring m_StringValue;
|
||||||
|
};
|
||||||
|
|
||||||
class CMeter;
|
class CMeter;
|
||||||
class CMeterWindow;
|
class CMeterWindow;
|
||||||
class CConfigParser;
|
class CConfigParser;
|
||||||
@ -68,7 +79,7 @@ public:
|
|||||||
static void RemoveTrailingZero(WCHAR* str, int strLen);
|
static void RemoveTrailingZero(WCHAR* str, int strLen);
|
||||||
|
|
||||||
const std::wstring& GetOnChangeAction() { return m_OnChangeAction; }
|
const std::wstring& GetOnChangeAction() { return m_OnChangeAction; }
|
||||||
void DoChangeAction();
|
void DoChangeAction(bool execute = true);
|
||||||
|
|
||||||
CMeterWindow* GetMeterWindow() { return m_MeterWindow; }
|
CMeterWindow* GetMeterWindow() { return m_MeterWindow; }
|
||||||
|
|
||||||
@ -114,9 +125,8 @@ protected:
|
|||||||
bool m_Initialized;
|
bool m_Initialized;
|
||||||
|
|
||||||
std::wstring m_OnChangeAction;
|
std::wstring m_OnChangeAction;
|
||||||
double m_OldValue;
|
CMeasureValueSet* m_OldValue;
|
||||||
std::wstring m_OldStringValue;
|
bool m_ValueAssigned;
|
||||||
bool m_OldValueInitialized;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user