mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Tweaks to reduce OnChangeAction overhead
This commit is contained in:
parent
507e0294fe
commit
aa3c7eb8ce
@ -664,7 +664,7 @@ bool CConfigParser::ReplaceMeasures(std::wstring& result)
|
||||
CMeasure* measure = GetMeasure(var);
|
||||
if (measure)
|
||||
{
|
||||
const WCHAR* value = measure->GetStringValue(AUTOSCALE_OFF, 1, -1, false);
|
||||
const WCHAR* value = measure->GetStringOrFormattedValue(AUTOSCALE_OFF, 1, -1, false);
|
||||
size_t valueLen = wcslen(value);
|
||||
|
||||
// Measure found, replace it with the value
|
||||
|
@ -807,7 +807,8 @@ void CDialogAbout::CTabSkins::UpdateMeasureList(CMeterWindow* meterWindow)
|
||||
range += buffer;
|
||||
|
||||
ListView_SetItemText(item, lvi.iItem, 1, (WCHAR*)range.c_str());
|
||||
ListView_SetItemText(item, lvi.iItem, 2, (WCHAR*)(*j)->GetStringValue(AUTOSCALE_OFF, 1, -1, false));
|
||||
ListView_SetItemText(item, lvi.iItem, 2, (WCHAR*)(*j)->GetStringOrFormattedValue(
|
||||
AUTOSCALE_OFF, 1, -1, false));
|
||||
++lvi.iItem;
|
||||
}
|
||||
|
||||
|
@ -617,6 +617,26 @@ double CMeasure::GetValueRange()
|
||||
return m_MaxValue - m_MinValue;
|
||||
}
|
||||
|
||||
/*
|
||||
** Base implementation. Derivied classes can provide an alternative implementation if they have a
|
||||
** string value that is not based on m_Value.
|
||||
**
|
||||
*/
|
||||
const WCHAR* CMeasure::GetStringValue()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
** Returns the unformatted string value if the measure has one or a formatted value otherwise.
|
||||
**
|
||||
*/
|
||||
const WCHAR* CMeasure::GetStringOrFormattedValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
|
||||
{
|
||||
const WCHAR* stringValue = GetStringValue();
|
||||
return stringValue ? stringValue : GetFormattedValue(autoScale, scale, decimals, percentual);
|
||||
}
|
||||
|
||||
/*
|
||||
** This method returns the value as text string. The actual value is
|
||||
** get with GetValue() so we don't have to worry about m_Invert.
|
||||
@ -626,7 +646,7 @@ double CMeasure::GetValueRange()
|
||||
** decimals Number of decimals used in the value. If -1, get rid of ".00000" for dynamic variables.
|
||||
** percentual Return the value as % from the maximum value.
|
||||
*/
|
||||
const WCHAR* CMeasure::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
|
||||
const WCHAR* CMeasure::GetFormattedValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
|
||||
{
|
||||
static WCHAR buffer[128];
|
||||
WCHAR format[32];
|
||||
@ -737,7 +757,7 @@ void CMeasure::DoChangeAction(bool execute)
|
||||
if (!m_OnChangeAction.empty() && m_ValueAssigned)
|
||||
{
|
||||
double newValue = GetValue();
|
||||
const WCHAR* newStringValue = GetStringValue(AUTOSCALE_OFF, 1, -1, false);
|
||||
const WCHAR* newStringValue = GetStringValue();
|
||||
|
||||
if (!m_OldValue)
|
||||
{
|
||||
|
@ -40,9 +40,34 @@ enum AUTOSCALE
|
||||
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; }
|
||||
CMeasureValueSet(double val, const WCHAR* str) : m_Value(val), m_StringValue(str ? str : L"") {}
|
||||
|
||||
void Set(double val, const WCHAR* str)
|
||||
{
|
||||
m_Value = val;
|
||||
if (str)
|
||||
{
|
||||
m_StringValue = str;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_StringValue.clear();
|
||||
}
|
||||
}
|
||||
|
||||
bool IsChanged(double val, const WCHAR* str)
|
||||
{
|
||||
if (m_Value != val ||
|
||||
(!str && !m_StringValue.empty()) ||
|
||||
(str && wcscmp(m_StringValue.c_str(), str) != 0))
|
||||
{
|
||||
Set(val, str);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
double m_Value;
|
||||
std::wstring m_StringValue;
|
||||
@ -74,7 +99,10 @@ public:
|
||||
double GetMinValue() { return m_MinValue; }
|
||||
double GetMaxValue() { return m_MaxValue; }
|
||||
|
||||
virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
|
||||
virtual const WCHAR* GetStringValue();
|
||||
const WCHAR* GetStringOrFormattedValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
|
||||
const WCHAR* GetFormattedValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
|
||||
|
||||
static void GetScaledValue(AUTOSCALE autoScale, int decimals, double theValue, WCHAR* buffer, size_t sizeInWords);
|
||||
static void RemoveTrailingZero(WCHAR* str, int strLen);
|
||||
|
||||
|
@ -164,14 +164,9 @@ void CMeasureDiskSpace::UpdateValue()
|
||||
** Returns the time as string.
|
||||
**
|
||||
*/
|
||||
const WCHAR* CMeasureDiskSpace::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
|
||||
const WCHAR* CMeasureDiskSpace::GetStringValue()
|
||||
{
|
||||
if (m_Type || m_Label)
|
||||
{
|
||||
return CheckSubstitute(m_StringValue.c_str());
|
||||
}
|
||||
|
||||
return CMeasure::GetStringValue(autoScale, scale, decimals, percentual);
|
||||
return (m_Type || m_Label) ? CheckSubstitute(m_StringValue.c_str()) : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
|
||||
virtual UINT GetTypeID() { return TypeID<CMeasureDiskSpace>(); }
|
||||
|
||||
virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
|
||||
virtual const WCHAR* GetStringValue();
|
||||
|
||||
protected:
|
||||
virtual void ReadOptions(CConfigParser& parser, const WCHAR* section);
|
||||
|
@ -213,7 +213,7 @@ void CMeasurePlugin::ReadOptions(CConfigParser& parser, const WCHAR* section)
|
||||
** Gets the string value from the plugin.
|
||||
**
|
||||
*/
|
||||
const WCHAR* CMeasurePlugin::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
|
||||
const WCHAR* CMeasurePlugin::GetStringValue()
|
||||
{
|
||||
if (m_GetStringFunc)
|
||||
{
|
||||
@ -230,7 +230,7 @@ const WCHAR* CMeasurePlugin::GetStringValue(AUTOSCALE autoScale, double scale, i
|
||||
if (ret) return CheckSubstitute(ret);
|
||||
}
|
||||
|
||||
return CMeasure::GetStringValue(autoScale, scale, decimals, percentual);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
|
||||
virtual UINT GetTypeID() { return TypeID<CMeasurePlugin>(); }
|
||||
|
||||
virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
|
||||
virtual const WCHAR* GetStringValue();
|
||||
virtual void Command(const std::wstring& command);
|
||||
|
||||
protected:
|
||||
|
@ -157,13 +157,8 @@ void CMeasureRegistry::ReadOptions(CConfigParser& parser, const WCHAR* section)
|
||||
** value to string as normal.
|
||||
**
|
||||
*/
|
||||
const WCHAR* CMeasureRegistry::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
|
||||
const WCHAR* CMeasureRegistry::GetStringValue()
|
||||
{
|
||||
if (m_StringValue.empty())
|
||||
{
|
||||
return CMeasure::GetStringValue(autoScale, scale, decimals, percentual);
|
||||
}
|
||||
|
||||
return CheckSubstitute(m_StringValue.c_str());
|
||||
return !m_StringValue.empty() ? CheckSubstitute(m_StringValue.c_str()) : NULL;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
|
||||
virtual UINT GetTypeID() { return TypeID<CMeasureRegistry>(); }
|
||||
|
||||
virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
|
||||
virtual const WCHAR* GetStringValue();
|
||||
|
||||
protected:
|
||||
virtual void ReadOptions(CConfigParser& parser, const WCHAR* section);
|
||||
|
@ -76,14 +76,9 @@ void CMeasureScript::UpdateValue()
|
||||
** Returns the value as a string.
|
||||
**
|
||||
*/
|
||||
const WCHAR* CMeasureScript::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
|
||||
const WCHAR* CMeasureScript::GetStringValue()
|
||||
{
|
||||
if (m_ValueType == LUA_TSTRING)
|
||||
{
|
||||
return CheckSubstitute(m_StringValue.c_str());
|
||||
}
|
||||
|
||||
return CMeasure::GetStringValue(autoScale, scale, decimals, percentual);
|
||||
return (m_ValueType == LUA_TSTRING) ? CheckSubstitute(m_StringValue.c_str()) : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
|
||||
virtual UINT GetTypeID() { return TypeID<CMeasureScript>(); }
|
||||
|
||||
virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
|
||||
virtual const WCHAR* GetStringValue();
|
||||
virtual void Command(const std::wstring& command);
|
||||
|
||||
void UninitializeLuaScript();
|
||||
|
@ -163,7 +163,7 @@ void CMeasureTime::UpdateValue()
|
||||
** Returns the time as string.
|
||||
**
|
||||
*/
|
||||
const WCHAR* CMeasureTime::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
|
||||
const WCHAR* CMeasureTime::GetStringValue()
|
||||
{
|
||||
static WCHAR tmpSz[MAX_LINE_LENGTH];
|
||||
struct tm today;
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
|
||||
virtual UINT GetTypeID() { return TypeID<CMeasureTime>(); }
|
||||
|
||||
virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
|
||||
virtual const WCHAR* GetStringValue();
|
||||
|
||||
protected:
|
||||
virtual void ReadOptions(CConfigParser& parser, const WCHAR* section);
|
||||
|
@ -72,7 +72,7 @@ void CMeasureUptime::UpdateValue()
|
||||
** Returns the uptime as string.
|
||||
**
|
||||
*/
|
||||
const WCHAR* CMeasureUptime::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
|
||||
const WCHAR* CMeasureUptime::GetStringValue()
|
||||
{
|
||||
static WCHAR buffer[MAX_LINE_LENGTH];
|
||||
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
|
||||
virtual UINT GetTypeID() { return TypeID<CMeasureUptime>(); }
|
||||
|
||||
virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
|
||||
virtual const WCHAR* GetStringValue();
|
||||
|
||||
protected:
|
||||
virtual void ReadOptions(CConfigParser& parser, const WCHAR* section);
|
||||
|
@ -501,7 +501,8 @@ bool CMeter::ReplaceMeasures(std::wstring& str, AUTOSCALE autoScale, double scal
|
||||
size_t len = _snwprintf_s(buffer, _TRUNCATE, L"%%%i", (int)i);
|
||||
size_t start = 0, pos;
|
||||
|
||||
const WCHAR* measureValue = m_Measures[i - 1]->GetStringValue(autoScale, scale, decimals, percentual);
|
||||
const WCHAR* measureValue = m_Measures[i - 1]->GetStringOrFormattedValue(
|
||||
autoScale, scale, decimals, percentual);
|
||||
int measureValueLen = wcslen(measureValue);
|
||||
|
||||
do
|
||||
|
@ -174,7 +174,8 @@ bool CMeterImage::Update()
|
||||
{
|
||||
if (m_ImageName.empty())
|
||||
{
|
||||
m_ImageNameResult = m_Measures[0]->GetStringValue(AUTOSCALE_OFF, 1, 0, false);
|
||||
m_ImageNameResult = m_Measures[0]->GetStringOrFormattedValue(
|
||||
AUTOSCALE_OFF, 1, 0, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -182,7 +183,8 @@ bool CMeterImage::Update()
|
||||
if (!ReplaceMeasures(m_ImageNameResult, AUTOSCALE_OFF))
|
||||
{
|
||||
// ImageName doesn't contain any measures, so use the result of MeasureName.
|
||||
m_ImageNameResult = m_Measures[0]->GetStringValue(AUTOSCALE_OFF, 1, 0, false);
|
||||
m_ImageNameResult = m_Measures[0]->GetStringOrFormattedValue(
|
||||
AUTOSCALE_OFF, 1, 0, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -360,7 +360,8 @@ bool CMeterString::Update()
|
||||
{
|
||||
if (m_Text.empty())
|
||||
{
|
||||
m_String += m_Measures[0]->GetStringValue(m_AutoScale, m_Scale, decimals, m_Percentual);
|
||||
m_String += m_Measures[0]->GetStringOrFormattedValue(
|
||||
m_AutoScale, m_Scale, decimals, m_Percentual);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -126,7 +126,7 @@ static int GetStringValue(lua_State* L)
|
||||
int decimals = (int)lua_tonumber(L, 4);
|
||||
bool percentual = lua_toboolean(L, 5);
|
||||
|
||||
const WCHAR* val = self->GetStringValue(autoScale, scale, decimals, percentual);
|
||||
const WCHAR* val = self->GetStringOrFormattedValue(autoScale, scale, decimals, percentual);
|
||||
LuaManager::PushWide(L, val);
|
||||
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user