Section Variables:

- Added [Measure:MaxValue] and [Measure:MinValue] functionality. You can use it with scaling modifiers. (For instance, [Measure:MaxValue:/1024, 2])
- Now trailing zeros are trimmed if decimal places modifier is not used.
This commit is contained in:
spx 2012-08-07 14:11:01 -07:00
parent 66c3231b90
commit 5103190129

View File

@ -201,7 +201,9 @@ bool CConfigParser::GetSectionVariable(std::wstring& strVariable, std::wstring&
const WCHAR* selectorSz = selector.c_str(); const WCHAR* selectorSz = selector.c_str();
strVariable.resize(colonPos); strVariable.resize(colonPos);
if (!selector.empty() && iswalpha(selectorSz[0])) bool isKeySelector = (!selector.empty() && iswalpha(selectorSz[0]));
if (isKeySelector)
{ {
// [Meter:X], [Meter:Y], [Meter:W], [Meter:H] // [Meter:X], [Meter:Y], [Meter:W], [Meter:H]
CMeter* meter = m_MeterWindow->GetMeter(strVariable); CMeter* meter = m_MeterWindow->GetMeter(strVariable);
@ -233,16 +235,69 @@ bool CConfigParser::GetSectionVariable(std::wstring& strVariable, std::wstring&
return true; return true;
} }
} }
else
{
// Number: [Measure:], [Measure:dec] // Number: [Measure:], [Measure:dec]
// Percentual: [Measure:%], [Measure:%, dec] // Percentual: [Measure:%], [Measure:%, dec]
// Scale: [Measure:/scale], [Measure:/scale, dec] // Scale: [Measure:/scale], [Measure:/scale, dec]
// Max/Min: [Measure:MaxValue], [Measure:MaxValue:/scale, dec] ('%' cannot be used)
enum VALUETYPE
{
RAW = 0,
PERCENTUAL = 1,
MAX = 2,
MIN = 3
} valueType = RAW;
if (isKeySelector)
{
if (_wcsicmp(selectorSz, L"MaxValue") == 0)
{
valueType = MAX;
}
else if (_wcsicmp(selectorSz, L"MinValue") == 0)
{
valueType = MIN;
}
else
{
return false;
}
selectorSz = L"";
}
else
{
colonPos = strVariable.find_last_of(L':');
if (colonPos != std::wstring::npos)
{
do
{
const WCHAR* keySelectorSz = strVariable.c_str() + colonPos + 1;
if (_wcsicmp(keySelectorSz, L"MaxValue") == 0)
{
valueType = MAX;
}
else if (_wcsicmp(keySelectorSz, L"MinValue") == 0)
{
valueType = MIN;
}
else
{
// Section name contains ':' ?
break;
}
strVariable.resize(colonPos);
}
while (0);
}
}
CMeasure* measure = m_MeterWindow->GetMeasure(strVariable); CMeasure* measure = m_MeterWindow->GetMeasure(strVariable);
if (measure) if (measure)
{ {
double scale = 1.0; double scale = 1.0;
bool percentual = false;
const WCHAR* decimalsSz = wcschr(selectorSz, L','); const WCHAR* decimalsSz = wcschr(selectorSz, L',');
if (decimalsSz) if (decimalsSz)
@ -252,7 +307,12 @@ bool CConfigParser::GetSectionVariable(std::wstring& strVariable, std::wstring&
if (*selectorSz == L'%') // Percentual if (*selectorSz == L'%') // Percentual
{ {
percentual = true; if (valueType == MAX || valueType == MIN) // '%' cannot be used with MAX/MIN value
{
return false;
}
valueType = PERCENTUAL;
} }
else if (*selectorSz == L'/') // Scale else if (*selectorSz == L'/') // Scale
{ {
@ -269,14 +329,31 @@ bool CConfigParser::GetSectionVariable(std::wstring& strVariable, std::wstring&
{ {
return false; return false;
} }
else
{
decimalsSz = selectorSz; decimalsSz = selectorSz;
} }
}
int decimals = decimalsSz && *decimalsSz ? _wtoi(decimalsSz) : 10; double value = (valueType == PERCENTUAL) ? measure->GetRelativeValue() * 100.0
double value = percentual ? measure->GetRelativeValue() * 100.0 : measure->GetValue() / scale; : (valueType == MAX) ? measure->GetMaxValue() / scale
: (valueType == MIN) ? measure->GetMinValue() / scale
: measure->GetValue() / scale;
int decimals = 10;
if (decimalsSz)
{
while (iswspace(*decimalsSz)) ++decimalsSz;
if (*decimalsSz)
{
decimals = _wtoi(decimalsSz);
decimals = max(0, decimals);
decimals = min(32, decimals);
}
else
{
decimalsSz = NULL;
}
}
WCHAR format[32]; WCHAR format[32];
WCHAR buffer[128]; WCHAR buffer[128];
@ -293,7 +370,6 @@ bool CConfigParser::GetSectionVariable(std::wstring& strVariable, std::wstring&
strValue.assign(buffer, bufferLen); strValue.assign(buffer, bufferLen);
return true; return true;
} }
}
return false; return false;
} }