mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Changed all numerical options or numerical parameters of bangs to accept formulas
This commit is contained in:
parent
9ba4021a2b
commit
ba239ffeea
@ -679,13 +679,6 @@ CMeasure* CConfigParser::GetMeasure(const std::wstring& name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
double CConfigParser::ReadFloat(LPCTSTR section, LPCTSTR key, double defValue)
|
||||
{
|
||||
const std::wstring& result = ReadString(section, key, L"");
|
||||
|
||||
return (m_LastDefaultUsed) ? defValue : ParseDouble(result.c_str(), defValue);
|
||||
}
|
||||
|
||||
std::vector<Gdiplus::REAL> CConfigParser::ReadFloats(LPCTSTR section, LPCTSTR key)
|
||||
{
|
||||
std::vector<Gdiplus::REAL> result;
|
||||
@ -707,42 +700,96 @@ int CConfigParser::ReadInt(LPCTSTR section, LPCTSTR key, int defValue)
|
||||
{
|
||||
const std::wstring& result = ReadString(section, key, L"");
|
||||
|
||||
return (m_LastDefaultUsed) ? defValue : ParseInt(result.c_str(), defValue);
|
||||
if (!m_LastDefaultUsed)
|
||||
{
|
||||
const WCHAR* string = result.c_str();
|
||||
if (*string == L'(')
|
||||
{
|
||||
double dblValue;
|
||||
const WCHAR* errMsg = MathParser::CheckedParse(string, &dblValue);
|
||||
if (!errMsg)
|
||||
{
|
||||
return (int)dblValue;
|
||||
}
|
||||
|
||||
LogWithArgs(LOG_ERROR, L"Formula: %s in key \"%s\" in [%s]", errMsg, key, section);
|
||||
}
|
||||
else if (*string)
|
||||
{
|
||||
errno = 0;
|
||||
int intValue = wcstol(string, NULL, 10);
|
||||
if (errno != ERANGE)
|
||||
{
|
||||
return intValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return defValue;
|
||||
}
|
||||
|
||||
unsigned int CConfigParser::ReadUInt(LPCTSTR section, LPCTSTR key, unsigned int defValue)
|
||||
{
|
||||
const std::wstring& result = ReadString(section, key, L"");
|
||||
|
||||
return (m_LastDefaultUsed) ? defValue : ParseUInt(result.c_str(), defValue);
|
||||
if (!m_LastDefaultUsed)
|
||||
{
|
||||
const WCHAR* string = result.c_str();
|
||||
if (*string == L'(')
|
||||
{
|
||||
double dblValue;
|
||||
const WCHAR* errMsg = MathParser::CheckedParse(string, &dblValue);
|
||||
if (!errMsg)
|
||||
{
|
||||
return (unsigned int)dblValue;
|
||||
}
|
||||
|
||||
// Works as ReadFloat except if the value is surrounded by parenthesis in which case it tries to evaluate the formula
|
||||
double CConfigParser::ReadFormula(LPCTSTR section, LPCTSTR key, double defValue)
|
||||
LogWithArgs(LOG_ERROR, L"Formula: %s in key \"%s\" in [%s]", errMsg, key, section);
|
||||
}
|
||||
else if (*string)
|
||||
{
|
||||
errno = 0;
|
||||
unsigned int uintValue = wcstoul(string, NULL, 10);
|
||||
if (errno != ERANGE)
|
||||
{
|
||||
return uintValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return defValue;
|
||||
}
|
||||
|
||||
double CConfigParser::ReadFloat(LPCTSTR section, LPCTSTR key, double defValue)
|
||||
{
|
||||
const std::wstring& result = ReadString(section, key, L"");
|
||||
|
||||
// Formulas must be surrounded by parenthesis
|
||||
if (!result.empty() && result[0] == L'(' && result[result.size() - 1] == L')')
|
||||
if (!m_LastDefaultUsed)
|
||||
{
|
||||
double resultValue = defValue;
|
||||
const WCHAR* errMsg = MathParser::CheckedParse(result.c_str(), &resultValue);
|
||||
if (errMsg != NULL)
|
||||
double value;
|
||||
const WCHAR* string = result.c_str();
|
||||
if (*string == L'(')
|
||||
{
|
||||
std::wstring error = L"ReadFormula: ";
|
||||
error += errMsg;
|
||||
error += L" in key \"";
|
||||
error += key;
|
||||
error += L"\" in [";
|
||||
error += section;
|
||||
error += L']';
|
||||
Log(LOG_ERROR, error.c_str());
|
||||
const WCHAR* errMsg = MathParser::CheckedParse(string, &value);
|
||||
if (!errMsg)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
return resultValue;
|
||||
LogWithArgs(LOG_ERROR, L"Formula: %s in key \"%s\" in [%s]", errMsg, key, section);
|
||||
}
|
||||
else if (*string)
|
||||
{
|
||||
errno = 0;
|
||||
value = wcstod(string, NULL);
|
||||
if (errno != ERANGE)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (m_LastDefaultUsed) ? defValue : ParseDouble(result.c_str(), defValue);
|
||||
return defValue;
|
||||
}
|
||||
|
||||
// Returns true if the formula was read successfully, false for failure.
|
||||
@ -751,14 +798,11 @@ bool CConfigParser::ParseFormula(const std::wstring& formula, double* resultValu
|
||||
// Formulas must be surrounded by parenthesis
|
||||
if (!formula.empty() && formula[0] == L'(' && formula[formula.size() - 1] == L')')
|
||||
{
|
||||
const WCHAR* errMsg = MathParser::CheckedParse(formula.c_str(), resultValue);
|
||||
const WCHAR* string = formula.c_str();
|
||||
const WCHAR* errMsg = MathParser::CheckedParse(string, resultValue);
|
||||
if (errMsg != NULL)
|
||||
{
|
||||
std::wstring error = L"ParseFormula: ";
|
||||
error += errMsg;
|
||||
error += L": ";
|
||||
error += formula;
|
||||
Log(LOG_ERROR, error.c_str());
|
||||
LogWithArgs(LOG_ERROR, L"Formula: %s: %s", errMsg, string);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -852,72 +896,111 @@ void CConfigParser::Shrink(std::vector<std::wstring>& vec)
|
||||
}
|
||||
|
||||
/*
|
||||
** This is a helper method that parses the floating-point value from the given string.
|
||||
** Helper method that parses the floating-point value from the given string.
|
||||
** If the given string is invalid format or causes overflow/underflow, returns given default value.
|
||||
**
|
||||
*/
|
||||
double CConfigParser::ParseDouble(LPCTSTR string, double defValue)
|
||||
{
|
||||
if (string && *string)
|
||||
assert(string);
|
||||
|
||||
double value;
|
||||
if (*string == L'(')
|
||||
{
|
||||
const WCHAR* errMsg = MathParser::CheckedParse(string, &value);
|
||||
if (!errMsg)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
LogWithArgs(LOG_ERROR, L"Formula: %s: %s", errMsg, string);
|
||||
}
|
||||
else if (*string)
|
||||
{
|
||||
errno = 0;
|
||||
double resultValue = wcstod(string, NULL);
|
||||
double value = wcstod(string, NULL);
|
||||
if (errno != ERANGE)
|
||||
{
|
||||
return resultValue;
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
return defValue;
|
||||
}
|
||||
|
||||
/*
|
||||
** This is a helper method that parses the integer value from the given string.
|
||||
** Helper method that parses the integer value from the given string.
|
||||
** If the given string is invalid format or causes overflow/underflow, returns given default value.
|
||||
**
|
||||
*/
|
||||
int CConfigParser::ParseInt(LPCTSTR string, int defValue)
|
||||
{
|
||||
if (string && *string)
|
||||
assert(string);
|
||||
|
||||
if (*string == L'(')
|
||||
{
|
||||
double dblValue;
|
||||
const WCHAR* errMsg = MathParser::CheckedParse(string, &dblValue);
|
||||
if (!errMsg)
|
||||
{
|
||||
return (int)dblValue;
|
||||
}
|
||||
|
||||
LogWithArgs(LOG_ERROR, L"Formula: %s: %s", errMsg, string);
|
||||
}
|
||||
else if (*string)
|
||||
{
|
||||
errno = 0;
|
||||
int resultValue = wcstol(string, NULL, 10);
|
||||
int intValue = wcstol(string, NULL, 10);
|
||||
if (errno != ERANGE)
|
||||
{
|
||||
return resultValue;
|
||||
return intValue;
|
||||
}
|
||||
}
|
||||
|
||||
return defValue;
|
||||
}
|
||||
|
||||
/*
|
||||
** This is a helper method that parses the unsigned integer value from the given string.
|
||||
** Helper method that parses the unsigned integer value from the given string.
|
||||
** If the given string is invalid format or causes overflow/underflow, returns given default value.
|
||||
**
|
||||
*/
|
||||
unsigned int CConfigParser::ParseUInt(LPCTSTR string, unsigned int defValue)
|
||||
{
|
||||
if (string && *string)
|
||||
assert(string);
|
||||
|
||||
if (*string == L'(')
|
||||
{
|
||||
double dblValue;
|
||||
const WCHAR* errMsg = MathParser::CheckedParse(string, &dblValue);
|
||||
if (!errMsg)
|
||||
{
|
||||
return (unsigned int)dblValue;
|
||||
}
|
||||
|
||||
LogWithArgs(LOG_ERROR, L"Formula: %s: %s", errMsg, string);
|
||||
}
|
||||
else if (*string)
|
||||
{
|
||||
errno = 0;
|
||||
unsigned int resultValue = wcstoul(string, NULL, 10);
|
||||
unsigned int uintValue = wcstoul(string, NULL, 10);
|
||||
if (errno != ERANGE)
|
||||
{
|
||||
return resultValue;
|
||||
return uintValue;
|
||||
}
|
||||
}
|
||||
|
||||
return defValue;
|
||||
}
|
||||
|
||||
/*
|
||||
** This is a helper method that parses the color values from the given string.
|
||||
** The color can be supplied as three/four comma separated values or as one
|
||||
** hex-value.
|
||||
** Helper template that parses four comma separated values from the given string.
|
||||
**
|
||||
*/
|
||||
ARGB CConfigParser::ParseColor(LPCTSTR string)
|
||||
template <typename T>
|
||||
bool ParseInt4(LPCTSTR string, T& v1, T& v2, T& v3, T& v4)
|
||||
{
|
||||
int R = 255, G = 255, B = 255, A = 255;
|
||||
|
||||
if (wcschr(string, L','))
|
||||
{
|
||||
WCHAR* parseSz = _wcsdup(string);
|
||||
@ -926,37 +1009,44 @@ ARGB CConfigParser::ParseColor(LPCTSTR string)
|
||||
token = wcstok(parseSz, L",");
|
||||
if (token)
|
||||
{
|
||||
R = _wtoi(token);
|
||||
R = max(R, 0);
|
||||
R = min(R, 255);
|
||||
v1 = CConfigParser::ParseInt(token, 0);
|
||||
|
||||
token = wcstok(NULL, L",");
|
||||
if (token)
|
||||
{
|
||||
G = _wtoi(token);
|
||||
G = max(G, 0);
|
||||
G = min(G, 255);
|
||||
v2 = CConfigParser::ParseInt(token, 0);
|
||||
|
||||
token = wcstok(NULL, L",");
|
||||
if (token)
|
||||
{
|
||||
B = _wtoi(token);
|
||||
B = max(B, 0);
|
||||
B = min(B, 255);
|
||||
v3 = CConfigParser::ParseInt(token, 0);
|
||||
|
||||
token = wcstok(NULL, L",");
|
||||
if (token)
|
||||
{
|
||||
A = _wtoi(token);
|
||||
A = max(A, 0);
|
||||
A = min(A, 255);
|
||||
v4 = CConfigParser::ParseInt(token, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
free(parseSz);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
** Helper method that parses the color values from the given string.
|
||||
** The color can be supplied as three/four comma separated values or as one
|
||||
** hex-value.
|
||||
**
|
||||
*/
|
||||
ARGB CConfigParser::ParseColor(LPCTSTR string)
|
||||
{
|
||||
int R = 255, G = 255, B = 255, A = 255;
|
||||
|
||||
if (!ParseInt4(string, R, G, B, A))
|
||||
{
|
||||
if (wcsncmp(string, L"0x", 2) == 0)
|
||||
{
|
||||
@ -978,46 +1068,7 @@ ARGB CConfigParser::ParseColor(LPCTSTR string)
|
||||
}
|
||||
|
||||
/*
|
||||
** This is a helper template that parses four comma separated values from the given string.
|
||||
**
|
||||
*/
|
||||
template <typename T>
|
||||
void ParseInt4(LPCTSTR string, T& v1, T& v2, T& v3, T& v4)
|
||||
{
|
||||
if (wcschr(string, L','))
|
||||
{
|
||||
WCHAR* parseSz = _wcsdup(string);
|
||||
WCHAR* token;
|
||||
|
||||
token = wcstok(parseSz, L",");
|
||||
if (token)
|
||||
{
|
||||
v1 = _wtoi(token);
|
||||
|
||||
token = wcstok(NULL, L",");
|
||||
if (token)
|
||||
{
|
||||
v2 = _wtoi(token);
|
||||
|
||||
token = wcstok(NULL, L",");
|
||||
if (token)
|
||||
{
|
||||
v3 = _wtoi(token);
|
||||
|
||||
token = wcstok(NULL, L",");
|
||||
if (token)
|
||||
{
|
||||
v4 = _wtoi(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
free(parseSz);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** This is a helper method that parses the Gdiplus::Rect values from the given string.
|
||||
** Helper method that parses the Gdiplus::Rect values from the given string.
|
||||
** The rect can be supplied as four comma separated values (X/Y/Width/Height).
|
||||
**
|
||||
*/
|
||||
@ -1029,7 +1080,7 @@ Rect CConfigParser::ParseRect(LPCTSTR string)
|
||||
}
|
||||
|
||||
/*
|
||||
** This is a helper method that parses the RECT values from the given string.
|
||||
** Helper method that parses the RECT values from the given string.
|
||||
** The rect can be supplied as four comma separated values (left/top/right/bottom).
|
||||
**
|
||||
*/
|
||||
|
@ -70,10 +70,9 @@ public:
|
||||
const std::wstring& ReadString(LPCTSTR section, LPCTSTR key, LPCTSTR defValue, bool bReplaceMeasures = true);
|
||||
bool IsKeyDefined(LPCTSTR section, LPCTSTR key);
|
||||
bool IsValueDefined(LPCTSTR section, LPCTSTR key);
|
||||
double ReadFloat(LPCTSTR section, LPCTSTR key, double defValue);
|
||||
double ReadFormula(LPCTSTR section, LPCTSTR key, double defValue);
|
||||
int ReadInt(LPCTSTR section, LPCTSTR key, int defValue);
|
||||
unsigned int ReadUInt(LPCTSTR section, LPCTSTR key, unsigned int defValue);
|
||||
double ReadFloat(LPCTSTR section, LPCTSTR key, double defValue);
|
||||
Gdiplus::ARGB ReadColor(LPCTSTR section, LPCTSTR key, Gdiplus::ARGB defValue);
|
||||
Gdiplus::Rect ReadRect(LPCTSTR section, LPCTSTR key, const Gdiplus::Rect& defValue);
|
||||
RECT ReadRECT(LPCTSTR section, LPCTSTR key, const RECT& defValue);
|
||||
|
@ -45,7 +45,7 @@ double __stdcall RmReadFormula(void* rm, LPCWSTR option, double defValue)
|
||||
|
||||
CMeasurePlugin* measure = (CMeasurePlugin*)rm;
|
||||
CConfigParser& parser = measure->GetMeterWindow()->GetParser();
|
||||
return parser.ReadFormula(measure->GetName(), option, defValue);
|
||||
return parser.ReadFloat(measure->GetName(), option, defValue);
|
||||
}
|
||||
|
||||
LPCWSTR __stdcall RmPathToAbsolute(void* rm, LPCWSTR relativePath)
|
||||
|
@ -144,18 +144,18 @@ void CMeasure::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
m_UpdateCounter = m_UpdateDivider = updateDivider;
|
||||
}
|
||||
|
||||
m_MinValue = parser.ReadFormula(section, L"MinValue", m_MinValue);
|
||||
m_MaxValue = parser.ReadFormula(section, L"MaxValue", m_MaxValue);
|
||||
m_MinValue = parser.ReadFloat(section, L"MinValue", m_MinValue);
|
||||
m_MaxValue = parser.ReadFloat(section, L"MaxValue", m_MaxValue);
|
||||
|
||||
// The ifabove/ifbelow define actions that are ran when the value goes above/below the given number.
|
||||
|
||||
m_IfAboveValue = parser.ReadFormula(section, L"IfAboveValue", 0.0);
|
||||
m_IfAboveValue = parser.ReadFloat(section, L"IfAboveValue", 0.0);
|
||||
m_IfAboveAction = parser.ReadString(section, L"IfAboveAction", L"", false);
|
||||
|
||||
m_IfBelowValue = parser.ReadFormula(section, L"IfBelowValue", 0.0);
|
||||
m_IfBelowValue = parser.ReadFloat(section, L"IfBelowValue", 0.0);
|
||||
m_IfBelowAction = parser.ReadString(section, L"IfBelowAction", L"", false);
|
||||
|
||||
m_IfEqualValue = parser.ReadFormula(section, L"IfEqualValue", 0.0);
|
||||
m_IfEqualValue = parser.ReadFloat(section, L"IfEqualValue", 0.0);
|
||||
m_IfEqualAction = parser.ReadString(section, L"IfEqualAction", L"", false);
|
||||
|
||||
m_AverageSize = parser.ReadUInt(section, L"AverageSize", 0);
|
||||
|
@ -286,15 +286,7 @@ void CMeter::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
m_RelativeX = POSITION_ABSOLUTE;
|
||||
}
|
||||
|
||||
double val;
|
||||
if (len >= 2 && coord[0] == L'(' && coord[len - 1] == L')' && parser.ParseFormula(coord, &val))
|
||||
{
|
||||
m_X = (int)val;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_X = (int)parser.ParseDouble(coord.c_str(), 0.0);
|
||||
}
|
||||
m_X = parser.ParseInt(coord.c_str(), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -325,15 +317,7 @@ void CMeter::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
m_RelativeY = POSITION_ABSOLUTE;
|
||||
}
|
||||
|
||||
double val;
|
||||
if (len >= 2 && coord[0] == L'(' && coord[len - 1] == L')' && parser.ParseFormula(coord, &val))
|
||||
{
|
||||
m_Y = (int)val;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Y = (int)parser.ParseDouble(coord.c_str(), 0.0);
|
||||
}
|
||||
m_Y = parser.ParseInt(coord.c_str(), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -342,10 +326,10 @@ void CMeter::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
}
|
||||
}
|
||||
|
||||
m_W = (int)parser.ReadFormula(section, L"W", 1.0);
|
||||
m_W = parser.ReadInt(section, L"W", 1);
|
||||
m_WDefined = parser.GetLastValueDefined();
|
||||
|
||||
m_H = (int)parser.ReadFormula(section, L"H", 1.0);
|
||||
m_H = parser.ReadInt(section, L"H", 1);
|
||||
m_HDefined = parser.GetLastValueDefined();
|
||||
|
||||
const std::wstring& hidden = parser.ReadString(section, L"Hidden", L"0");
|
||||
@ -388,7 +372,7 @@ void CMeter::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
m_ToolTipText = parser.ReadString(section, L"ToolTipText", L"");
|
||||
m_ToolTipTitle = parser.ReadString(section, L"ToolTipTitle", L"");
|
||||
m_ToolTipIcon = parser.ReadString(section, L"ToolTipIcon", L"");
|
||||
m_ToolTipWidth = (int)parser.ReadFormula(section, L"ToolTipWidth", 1000);
|
||||
m_ToolTipWidth = (int)parser.ReadFloat(section, L"ToolTipWidth", 1000);
|
||||
m_ToolTipType = 0!=parser.ReadInt(section, L"ToolTipType", 0);
|
||||
m_ToolTipHidden = 0!=parser.ReadInt(section, L"ToolTipHidden", m_MeterWindow->GetMeterToolTipHidden());
|
||||
|
||||
|
@ -99,8 +99,8 @@ void CMeterRotator::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
|
||||
m_OffsetX = parser.ReadFloat(section, L"OffsetX", 0.0);
|
||||
m_OffsetY = parser.ReadFloat(section, L"OffsetY", 0.0);
|
||||
m_StartAngle = parser.ReadFormula(section, L"StartAngle", 0.0);
|
||||
m_RotationAngle = parser.ReadFormula(section, L"RotationAngle", 6.2832);
|
||||
m_StartAngle = parser.ReadFloat(section, L"StartAngle", 0.0);
|
||||
m_RotationAngle = parser.ReadFloat(section, L"RotationAngle", 6.2832);
|
||||
|
||||
m_ValueRemainder = parser.ReadInt(section, L"ValueReminder", 0); // Typo
|
||||
m_ValueRemainder = parser.ReadInt(section, L"ValueRemainder", m_ValueRemainder);
|
||||
|
@ -65,11 +65,11 @@ void CMeterRoundLine::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
// Read common configs
|
||||
CMeter::ReadConfig(parser, section);
|
||||
|
||||
m_LineWidth = parser.ReadFormula(section, L"LineWidth", 1.0);
|
||||
m_LineLength = parser.ReadFormula(section, L"LineLength", 20.0);
|
||||
m_LineStart = parser.ReadFormula(section, L"LineStart", -1.0);
|
||||
m_StartAngle = parser.ReadFormula(section, L"StartAngle", 0.0);
|
||||
m_RotationAngle = parser.ReadFormula(section, L"RotationAngle", 6.2832);
|
||||
m_LineWidth = parser.ReadFloat(section, L"LineWidth", 1.0);
|
||||
m_LineLength = parser.ReadFloat(section, L"LineLength", 20.0);
|
||||
m_LineStart = parser.ReadFloat(section, L"LineStart", -1.0);
|
||||
m_StartAngle = parser.ReadFloat(section, L"StartAngle", 0.0);
|
||||
m_RotationAngle = parser.ReadFloat(section, L"RotationAngle", 6.2832);
|
||||
m_ValueRemainder = parser.ReadInt(section, L"ValueReminder", 0); // Typo
|
||||
m_ValueRemainder = parser.ReadInt(section, L"ValueRemainder", m_ValueRemainder);
|
||||
m_LineColor = parser.ReadColor(section, L"LineColor", Color::Black);
|
||||
|
@ -310,7 +310,7 @@ void CMeterString::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
m_FontFace = L"Arial";
|
||||
}
|
||||
|
||||
m_FontSize = (int)parser.ReadFormula(section, L"FontSize", 10);
|
||||
m_FontSize = (int)parser.ReadFloat(section, L"FontSize", 10);
|
||||
if (m_FontSize < 0)
|
||||
{
|
||||
m_FontSize = 10;
|
||||
@ -318,7 +318,7 @@ void CMeterString::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
|
||||
m_NumOfDecimals = parser.ReadInt(section, L"NumOfDecimals", -1);
|
||||
|
||||
m_Angle = (Gdiplus::REAL)parser.ReadFormula(section, L"Angle", 0.0);
|
||||
m_Angle = (Gdiplus::REAL)parser.ReadFloat(section, L"Angle", 0.0);
|
||||
|
||||
const std::wstring& autoscale = parser.ReadString(section, L"AutoScale", L"0");
|
||||
int autoscaleValue = _wtoi(autoscale.c_str());
|
||||
@ -339,15 +339,8 @@ void CMeterString::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
}
|
||||
|
||||
const std::wstring& scale = parser.ReadString(section, L"Scale", L"1");
|
||||
if (scale.find(L'.') == std::wstring::npos)
|
||||
{
|
||||
m_NoDecimals = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_NoDecimals = false;
|
||||
}
|
||||
m_Scale = wcstod(scale.c_str(), NULL);
|
||||
m_NoDecimals = (scale.find(L'.') == std::wstring::npos);
|
||||
m_Scale = parser.ParseDouble(scale.c_str(), 1);
|
||||
|
||||
const WCHAR* align = parser.ReadString(section, L"StringAlign", L"LEFT").c_str();
|
||||
if (_wcsicmp(align, L"LEFT") == 0)
|
||||
|
@ -853,42 +853,40 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const std::vector<std::wstring>& ar
|
||||
|
||||
case BANG_MOVE:
|
||||
{
|
||||
double value;
|
||||
int x = m_Parser.ParseFormula(args[0], &value) ? (int)value : _wtoi(args[0].c_str());
|
||||
int y = m_Parser.ParseFormula(args[1], &value) ? (int)value : _wtoi(args[1].c_str());
|
||||
|
||||
int x = m_Parser.ParseInt(args[0].c_str(), 0);
|
||||
int y = m_Parser.ParseInt(args[1].c_str(), 0);
|
||||
MoveWindow(x, y);
|
||||
}
|
||||
break;
|
||||
|
||||
case BANG_ZPOS:
|
||||
SetWindowZPosition((ZPOSITION)_wtoi(args[0].c_str()));
|
||||
SetWindowZPosition((ZPOSITION)m_Parser.ParseInt(args[0].c_str(), 0));
|
||||
break;
|
||||
|
||||
case BANG_CLICKTHROUGH:
|
||||
{
|
||||
int f = _wtoi(args[0].c_str());
|
||||
int f = m_Parser.ParseInt(args[0].c_str(), 0);
|
||||
SetClickThrough((f == -1) ? !m_ClickThrough : f);
|
||||
}
|
||||
break;
|
||||
|
||||
case BANG_DRAGGABLE:
|
||||
{
|
||||
int f = _wtoi(args[0].c_str());
|
||||
int f = m_Parser.ParseInt(args[0].c_str(), 0);
|
||||
SetWindowDraggable((f == -1) ? !m_WindowDraggable : f);
|
||||
}
|
||||
break;
|
||||
|
||||
case BANG_SNAPEDGES:
|
||||
{
|
||||
int f = _wtoi(args[0].c_str());
|
||||
int f = m_Parser.ParseInt(args[0].c_str(), 0);
|
||||
SetSnapEdges((f == -1) ? !m_SnapEdges : f);
|
||||
}
|
||||
break;
|
||||
|
||||
case BANG_KEEPONSCREEN:
|
||||
{
|
||||
int f = _wtoi(args[0].c_str());
|
||||
int f = m_Parser.ParseInt(args[0].c_str(), 0);
|
||||
SetKeepOnScreen((f == -1) ? !m_KeepOnScreen : f);
|
||||
}
|
||||
break;
|
||||
@ -905,10 +903,8 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const std::vector<std::wstring>& ar
|
||||
|
||||
case BANG_MOVEMETER:
|
||||
{
|
||||
double value;
|
||||
int x = m_Parser.ParseFormula(args[0], &value) ? (int)value : _wtoi(args[0].c_str());
|
||||
int y = m_Parser.ParseFormula(args[1], &value) ? (int)value : _wtoi(args[1].c_str());
|
||||
|
||||
int x = m_Parser.ParseInt(args[0].c_str(), 0);
|
||||
int y = m_Parser.ParseInt(args[1].c_str(), 0);
|
||||
MoveMeter(args[2], x, y);
|
||||
}
|
||||
break;
|
||||
@ -1048,38 +1044,37 @@ void CMeterWindow::ResizeBlur(const std::wstring& arg, int mode)
|
||||
if (CSystem::GetOSPlatform() >= OSPLATFORM_VISTA)
|
||||
{
|
||||
WCHAR* parseSz = _wcsdup(arg.c_str());
|
||||
double val;
|
||||
int type, x, y, w = 0, h = 0;
|
||||
|
||||
WCHAR* token = wcstok(parseSz, L",");
|
||||
if (token)
|
||||
{
|
||||
while (token[0] == L' ') ++token;
|
||||
type = (m_Parser.ParseFormula(token, &val)) ? (int)val : _wtoi(token);
|
||||
type = m_Parser.ParseInt(token, 0);
|
||||
|
||||
token = wcstok(NULL, L",");
|
||||
if (token)
|
||||
{
|
||||
while (token[0] == L' ') ++token;
|
||||
x = (m_Parser.ParseFormula(token, &val)) ? (int)val : _wtoi(token);
|
||||
x = m_Parser.ParseInt(token, 0);
|
||||
|
||||
token = wcstok(NULL, L",");
|
||||
if (token)
|
||||
{
|
||||
while (token[0] == L' ') ++token;
|
||||
y = (m_Parser.ParseFormula(token, &val)) ? (int)val : _wtoi(token);
|
||||
y = m_Parser.ParseInt(token, 0);
|
||||
|
||||
token = wcstok(NULL, L",");
|
||||
if (token)
|
||||
{
|
||||
while (token[0] == L' ') ++token;
|
||||
w = (m_Parser.ParseFormula(token, &val)) ? (int)val : _wtoi(token);
|
||||
w = m_Parser.ParseInt(token, 0);
|
||||
|
||||
token = wcstok(NULL, L",");
|
||||
if (token)
|
||||
{
|
||||
while (token[0] == L' ') ++token;
|
||||
h = (m_Parser.ParseFormula(token, &val)) ? (int)val : _wtoi(token);
|
||||
h = m_Parser.ParseInt(token, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1101,7 +1096,7 @@ void CMeterWindow::ResizeBlur(const std::wstring& arg, int mode)
|
||||
if (token)
|
||||
{
|
||||
while (token[0] == L' ') ++token;
|
||||
int r = (m_Parser.ParseFormula(token, &val)) ? (int)val : _wtoi(token);
|
||||
int r = m_Parser.ParseInt(token, 0);
|
||||
tempRegion = CreateRoundRectRgn(x, y, w, h, r, r);
|
||||
}
|
||||
break;
|
||||
@ -1840,22 +1835,14 @@ void CMeterWindow::ReadConfig()
|
||||
// Check if the window position should be read as a formula
|
||||
double value;
|
||||
m_WindowX = parser.ReadString(section, L"WindowX", m_WindowX.c_str());
|
||||
if (!m_WindowX.empty() && m_WindowX[0] == L'(' && m_WindowX[m_WindowX.size() - 1] == L')')
|
||||
if (parser.ParseFormula(m_WindowX, &value))
|
||||
{
|
||||
if (!parser.ParseFormula(m_WindowX, &value))
|
||||
{
|
||||
value = 0.0;
|
||||
}
|
||||
_itow_s((int)value, buffer, 10);
|
||||
m_WindowX = buffer;
|
||||
}
|
||||
m_WindowY = parser.ReadString(section, L"WindowY", m_WindowY.c_str());
|
||||
if (!m_WindowY.empty() && m_WindowY[0] == L'(' && m_WindowY[m_WindowY.size() - 1] == L')')
|
||||
if (parser.ParseFormula(m_WindowY, &value))
|
||||
{
|
||||
if (!parser.ParseFormula(m_WindowY, &value))
|
||||
{
|
||||
value = 0.0;
|
||||
}
|
||||
_itow_s((int)value, buffer, 10);
|
||||
m_WindowY = buffer;
|
||||
}
|
||||
|
@ -592,27 +592,27 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
token = wcstok(parseSz, L",");
|
||||
if (token)
|
||||
{
|
||||
m_Crop.X = _wtoi(token);
|
||||
m_Crop.X = parser.ParseInt(token, 0);
|
||||
|
||||
token = wcstok(NULL, L",");
|
||||
if (token)
|
||||
{
|
||||
m_Crop.Y = _wtoi(token);
|
||||
m_Crop.Y = parser.ParseInt(token, 0);
|
||||
|
||||
token = wcstok(NULL, L",");
|
||||
if (token)
|
||||
{
|
||||
m_Crop.Width = _wtoi(token);
|
||||
m_Crop.Width = parser.ParseInt(token, 0);
|
||||
|
||||
token = wcstok(NULL, L",");
|
||||
if (token)
|
||||
{
|
||||
m_Crop.Height = _wtoi(token);
|
||||
m_Crop.Height = parser.ParseInt(token, 0);
|
||||
|
||||
token = wcstok(NULL, L",");
|
||||
if (token)
|
||||
{
|
||||
m_CropMode = (CROPMODE)_wtoi(token);
|
||||
m_CropMode = (CROPMODE)parser.ParseInt(token, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -742,7 +742,7 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
|
||||
if (!m_DisableTransform)
|
||||
{
|
||||
m_Rotate = (REAL)parser.ReadFormula(section, m_ConfigArray[ConfigIndexImageRotate], 0.0);
|
||||
m_Rotate = (REAL)parser.ReadFloat(section, m_ConfigArray[ConfigIndexImageRotate], 0.0);
|
||||
}
|
||||
|
||||
m_NeedsTransform = (oldFlip != m_Flip || oldRotate != m_Rotate);
|
||||
|
@ -54,7 +54,7 @@ static int GetNumberOption(lua_State* L)
|
||||
CConfigParser& parser = meterWindow->GetParser();
|
||||
|
||||
std::wstring strTmp = LuaManager::ToWide(L, 2);
|
||||
double value = parser.ReadFormula(self->GetName(), strTmp.c_str(), lua_tonumber(L, 3));
|
||||
double value = parser.ReadFloat(self->GetName(), strTmp.c_str(), lua_tonumber(L, 3));
|
||||
|
||||
lua_pushnumber(L, value);
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user