Changed all numerical options or numerical parameters of bangs to accept formulas

This commit is contained in:
Birunthan Mohanathas 2012-04-06 15:16:54 +03:00
parent 9ba4021a2b
commit ba239ffeea
11 changed files with 203 additions and 189 deletions

View File

@ -679,13 +679,6 @@ CMeasure* CConfigParser::GetMeasure(const std::wstring& name)
return NULL; 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> CConfigParser::ReadFloats(LPCTSTR section, LPCTSTR key)
{ {
std::vector<Gdiplus::REAL> result; 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""); 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) unsigned int CConfigParser::ReadUInt(LPCTSTR section, LPCTSTR key, unsigned int defValue)
{ {
const std::wstring& result = ReadString(section, key, L""); 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;
}
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;
} }
// Works as ReadFloat except if the value is surrounded by parenthesis in which case it tries to evaluate the formula double CConfigParser::ReadFloat(LPCTSTR section, LPCTSTR key, double defValue)
double CConfigParser::ReadFormula(LPCTSTR section, LPCTSTR key, double defValue)
{ {
const std::wstring& result = ReadString(section, key, L""); const std::wstring& result = ReadString(section, key, L"");
// Formulas must be surrounded by parenthesis if (!m_LastDefaultUsed)
if (!result.empty() && result[0] == L'(' && result[result.size() - 1] == L')')
{ {
double resultValue = defValue; double value;
const WCHAR* errMsg = MathParser::CheckedParse(result.c_str(), &resultValue); const WCHAR* string = result.c_str();
if (errMsg != NULL) if (*string == L'(')
{ {
std::wstring error = L"ReadFormula: "; const WCHAR* errMsg = MathParser::CheckedParse(string, &value);
error += errMsg; if (!errMsg)
error += L" in key \""; {
error += key; return value;
error += L"\" in ["; }
error += section;
error += L']';
Log(LOG_ERROR, error.c_str());
}
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. // 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 // Formulas must be surrounded by parenthesis
if (!formula.empty() && formula[0] == L'(' && formula[formula.size() - 1] == L')') 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) if (errMsg != NULL)
{ {
std::wstring error = L"ParseFormula: "; LogWithArgs(LOG_ERROR, L"Formula: %s: %s", errMsg, string);
error += errMsg;
error += L": ";
error += formula;
Log(LOG_ERROR, error.c_str());
return false; 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. ** If the given string is invalid format or causes overflow/underflow, returns given default value.
** **
*/ */
double CConfigParser::ParseDouble(LPCTSTR string, double defValue) 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; errno = 0;
double resultValue = wcstod(string, NULL); double value = wcstod(string, NULL);
if (errno != ERANGE) if (errno != ERANGE)
{ {
return resultValue; return value;
} }
} }
return defValue; 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. ** If the given string is invalid format or causes overflow/underflow, returns given default value.
** **
*/ */
int CConfigParser::ParseInt(LPCTSTR string, int defValue) 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; errno = 0;
int resultValue = wcstol(string, NULL, 10); int intValue = wcstol(string, NULL, 10);
if (errno != ERANGE) if (errno != ERANGE)
{ {
return resultValue; return intValue;
} }
} }
return defValue; 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. ** If the given string is invalid format or causes overflow/underflow, returns given default value.
** **
*/ */
unsigned int CConfigParser::ParseUInt(LPCTSTR string, unsigned int defValue) 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; errno = 0;
unsigned int resultValue = wcstoul(string, NULL, 10); unsigned int uintValue = wcstoul(string, NULL, 10);
if (errno != ERANGE) if (errno != ERANGE)
{ {
return resultValue; return uintValue;
} }
} }
return defValue; return defValue;
} }
/* /*
** This is a helper method that parses the color values from the given string. ** Helper template that parses four comma separated 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) 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',')) if (wcschr(string, L','))
{ {
WCHAR* parseSz = _wcsdup(string); WCHAR* parseSz = _wcsdup(string);
@ -926,37 +1009,44 @@ ARGB CConfigParser::ParseColor(LPCTSTR string)
token = wcstok(parseSz, L","); token = wcstok(parseSz, L",");
if (token) if (token)
{ {
R = _wtoi(token); v1 = CConfigParser::ParseInt(token, 0);
R = max(R, 0);
R = min(R, 255);
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
G = _wtoi(token); v2 = CConfigParser::ParseInt(token, 0);
G = max(G, 0);
G = min(G, 255);
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
B = _wtoi(token); v3 = CConfigParser::ParseInt(token, 0);
B = max(B, 0);
B = min(B, 255);
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
A = _wtoi(token); v4 = CConfigParser::ParseInt(token, 0);
A = max(A, 0);
A = min(A, 255);
} }
} }
} }
} }
free(parseSz); 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) 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. ** Helper method that parses the Gdiplus::Rect 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.
** The rect can be supplied as four comma separated values (X/Y/Width/Height). ** 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). ** The rect can be supplied as four comma separated values (left/top/right/bottom).
** **
*/ */

View File

@ -70,10 +70,9 @@ public:
const std::wstring& ReadString(LPCTSTR section, LPCTSTR key, LPCTSTR defValue, bool bReplaceMeasures = true); const std::wstring& ReadString(LPCTSTR section, LPCTSTR key, LPCTSTR defValue, bool bReplaceMeasures = true);
bool IsKeyDefined(LPCTSTR section, LPCTSTR key); bool IsKeyDefined(LPCTSTR section, LPCTSTR key);
bool IsValueDefined(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); int ReadInt(LPCTSTR section, LPCTSTR key, int defValue);
unsigned int ReadUInt(LPCTSTR section, LPCTSTR key, unsigned 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::ARGB ReadColor(LPCTSTR section, LPCTSTR key, Gdiplus::ARGB defValue);
Gdiplus::Rect ReadRect(LPCTSTR section, LPCTSTR key, const Gdiplus::Rect& defValue); Gdiplus::Rect ReadRect(LPCTSTR section, LPCTSTR key, const Gdiplus::Rect& defValue);
RECT ReadRECT(LPCTSTR section, LPCTSTR key, const RECT& defValue); RECT ReadRECT(LPCTSTR section, LPCTSTR key, const RECT& defValue);

View File

@ -45,7 +45,7 @@ double __stdcall RmReadFormula(void* rm, LPCWSTR option, double defValue)
CMeasurePlugin* measure = (CMeasurePlugin*)rm; CMeasurePlugin* measure = (CMeasurePlugin*)rm;
CConfigParser& parser = measure->GetMeterWindow()->GetParser(); 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) LPCWSTR __stdcall RmPathToAbsolute(void* rm, LPCWSTR relativePath)

View File

@ -144,18 +144,18 @@ void CMeasure::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_UpdateCounter = m_UpdateDivider = updateDivider; m_UpdateCounter = m_UpdateDivider = updateDivider;
} }
m_MinValue = parser.ReadFormula(section, L"MinValue", m_MinValue); m_MinValue = parser.ReadFloat(section, L"MinValue", m_MinValue);
m_MaxValue = parser.ReadFormula(section, L"MaxValue", m_MaxValue); 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. // 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_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_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_IfEqualAction = parser.ReadString(section, L"IfEqualAction", L"", false);
m_AverageSize = parser.ReadUInt(section, L"AverageSize", 0); m_AverageSize = parser.ReadUInt(section, L"AverageSize", 0);

View File

@ -286,15 +286,7 @@ void CMeter::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_RelativeX = POSITION_ABSOLUTE; m_RelativeX = POSITION_ABSOLUTE;
} }
double val; m_X = parser.ParseInt(coord.c_str(), 0);
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);
}
} }
else else
{ {
@ -325,15 +317,7 @@ void CMeter::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_RelativeY = POSITION_ABSOLUTE; m_RelativeY = POSITION_ABSOLUTE;
} }
double val; m_Y = parser.ParseInt(coord.c_str(), 0);
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);
}
} }
else 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_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(); m_HDefined = parser.GetLastValueDefined();
const std::wstring& hidden = parser.ReadString(section, L"Hidden", L"0"); 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_ToolTipText = parser.ReadString(section, L"ToolTipText", L"");
m_ToolTipTitle = parser.ReadString(section, L"ToolTipTitle", L""); m_ToolTipTitle = parser.ReadString(section, L"ToolTipTitle", L"");
m_ToolTipIcon = parser.ReadString(section, L"ToolTipIcon", 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_ToolTipType = 0!=parser.ReadInt(section, L"ToolTipType", 0);
m_ToolTipHidden = 0!=parser.ReadInt(section, L"ToolTipHidden", m_MeterWindow->GetMeterToolTipHidden()); m_ToolTipHidden = 0!=parser.ReadInt(section, L"ToolTipHidden", m_MeterWindow->GetMeterToolTipHidden());

View File

@ -99,8 +99,8 @@ void CMeterRotator::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_OffsetX = parser.ReadFloat(section, L"OffsetX", 0.0); m_OffsetX = parser.ReadFloat(section, L"OffsetX", 0.0);
m_OffsetY = parser.ReadFloat(section, L"OffsetY", 0.0); m_OffsetY = parser.ReadFloat(section, L"OffsetY", 0.0);
m_StartAngle = parser.ReadFormula(section, L"StartAngle", 0.0); m_StartAngle = parser.ReadFloat(section, L"StartAngle", 0.0);
m_RotationAngle = parser.ReadFormula(section, L"RotationAngle", 6.2832); m_RotationAngle = parser.ReadFloat(section, L"RotationAngle", 6.2832);
m_ValueRemainder = parser.ReadInt(section, L"ValueReminder", 0); // Typo m_ValueRemainder = parser.ReadInt(section, L"ValueReminder", 0); // Typo
m_ValueRemainder = parser.ReadInt(section, L"ValueRemainder", m_ValueRemainder); m_ValueRemainder = parser.ReadInt(section, L"ValueRemainder", m_ValueRemainder);

View File

@ -65,11 +65,11 @@ void CMeterRoundLine::ReadConfig(CConfigParser& parser, const WCHAR* section)
// Read common configs // Read common configs
CMeter::ReadConfig(parser, section); CMeter::ReadConfig(parser, section);
m_LineWidth = parser.ReadFormula(section, L"LineWidth", 1.0); m_LineWidth = parser.ReadFloat(section, L"LineWidth", 1.0);
m_LineLength = parser.ReadFormula(section, L"LineLength", 20.0); m_LineLength = parser.ReadFloat(section, L"LineLength", 20.0);
m_LineStart = parser.ReadFormula(section, L"LineStart", -1.0); m_LineStart = parser.ReadFloat(section, L"LineStart", -1.0);
m_StartAngle = parser.ReadFormula(section, L"StartAngle", 0.0); m_StartAngle = parser.ReadFloat(section, L"StartAngle", 0.0);
m_RotationAngle = parser.ReadFormula(section, L"RotationAngle", 6.2832); m_RotationAngle = parser.ReadFloat(section, L"RotationAngle", 6.2832);
m_ValueRemainder = parser.ReadInt(section, L"ValueReminder", 0); // Typo m_ValueRemainder = parser.ReadInt(section, L"ValueReminder", 0); // Typo
m_ValueRemainder = parser.ReadInt(section, L"ValueRemainder", m_ValueRemainder); m_ValueRemainder = parser.ReadInt(section, L"ValueRemainder", m_ValueRemainder);
m_LineColor = parser.ReadColor(section, L"LineColor", Color::Black); m_LineColor = parser.ReadColor(section, L"LineColor", Color::Black);

View File

@ -310,7 +310,7 @@ void CMeterString::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_FontFace = L"Arial"; 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) if (m_FontSize < 0)
{ {
m_FontSize = 10; m_FontSize = 10;
@ -318,7 +318,7 @@ void CMeterString::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_NumOfDecimals = parser.ReadInt(section, L"NumOfDecimals", -1); 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"); const std::wstring& autoscale = parser.ReadString(section, L"AutoScale", L"0");
int autoscaleValue = _wtoi(autoscale.c_str()); 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"); const std::wstring& scale = parser.ReadString(section, L"Scale", L"1");
if (scale.find(L'.') == std::wstring::npos) m_NoDecimals = (scale.find(L'.') == std::wstring::npos);
{ m_Scale = parser.ParseDouble(scale.c_str(), 1);
m_NoDecimals = true;
}
else
{
m_NoDecimals = false;
}
m_Scale = wcstod(scale.c_str(), NULL);
const WCHAR* align = parser.ReadString(section, L"StringAlign", L"LEFT").c_str(); const WCHAR* align = parser.ReadString(section, L"StringAlign", L"LEFT").c_str();
if (_wcsicmp(align, L"LEFT") == 0) if (_wcsicmp(align, L"LEFT") == 0)

View File

@ -853,42 +853,40 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const std::vector<std::wstring>& ar
case BANG_MOVE: case BANG_MOVE:
{ {
double value; int x = m_Parser.ParseInt(args[0].c_str(), 0);
int x = m_Parser.ParseFormula(args[0], &value) ? (int)value : _wtoi(args[0].c_str()); int y = m_Parser.ParseInt(args[1].c_str(), 0);
int y = m_Parser.ParseFormula(args[1], &value) ? (int)value : _wtoi(args[1].c_str());
MoveWindow(x, y); MoveWindow(x, y);
} }
break; break;
case BANG_ZPOS: case BANG_ZPOS:
SetWindowZPosition((ZPOSITION)_wtoi(args[0].c_str())); SetWindowZPosition((ZPOSITION)m_Parser.ParseInt(args[0].c_str(), 0));
break; break;
case BANG_CLICKTHROUGH: 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); SetClickThrough((f == -1) ? !m_ClickThrough : f);
} }
break; break;
case BANG_DRAGGABLE: 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); SetWindowDraggable((f == -1) ? !m_WindowDraggable : f);
} }
break; break;
case BANG_SNAPEDGES: 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); SetSnapEdges((f == -1) ? !m_SnapEdges : f);
} }
break; break;
case BANG_KEEPONSCREEN: 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); SetKeepOnScreen((f == -1) ? !m_KeepOnScreen : f);
} }
break; break;
@ -905,10 +903,8 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const std::vector<std::wstring>& ar
case BANG_MOVEMETER: case BANG_MOVEMETER:
{ {
double value; int x = m_Parser.ParseInt(args[0].c_str(), 0);
int x = m_Parser.ParseFormula(args[0], &value) ? (int)value : _wtoi(args[0].c_str()); int y = m_Parser.ParseInt(args[1].c_str(), 0);
int y = m_Parser.ParseFormula(args[1], &value) ? (int)value : _wtoi(args[1].c_str());
MoveMeter(args[2], x, y); MoveMeter(args[2], x, y);
} }
break; break;
@ -1048,38 +1044,37 @@ void CMeterWindow::ResizeBlur(const std::wstring& arg, int mode)
if (CSystem::GetOSPlatform() >= OSPLATFORM_VISTA) if (CSystem::GetOSPlatform() >= OSPLATFORM_VISTA)
{ {
WCHAR* parseSz = _wcsdup(arg.c_str()); WCHAR* parseSz = _wcsdup(arg.c_str());
double val;
int type, x, y, w = 0, h = 0; int type, x, y, w = 0, h = 0;
WCHAR* token = wcstok(parseSz, L","); WCHAR* token = wcstok(parseSz, L",");
if (token) if (token)
{ {
while (token[0] == L' ') ++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","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
while (token[0] == L' ') ++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","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
while (token[0] == L' ') ++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","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
while (token[0] == L' ') ++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","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
while (token[0] == L' ') ++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) if (token)
{ {
while (token[0] == L' ') ++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); tempRegion = CreateRoundRectRgn(x, y, w, h, r, r);
} }
break; break;
@ -1840,22 +1835,14 @@ void CMeterWindow::ReadConfig()
// Check if the window position should be read as a formula // Check if the window position should be read as a formula
double value; double value;
m_WindowX = parser.ReadString(section, L"WindowX", m_WindowX.c_str()); 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); _itow_s((int)value, buffer, 10);
m_WindowX = buffer; m_WindowX = buffer;
} }
m_WindowY = parser.ReadString(section, L"WindowY", m_WindowY.c_str()); 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); _itow_s((int)value, buffer, 10);
m_WindowY = buffer; m_WindowY = buffer;
} }

View File

@ -592,27 +592,27 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
token = wcstok(parseSz, L","); token = wcstok(parseSz, L",");
if (token) if (token)
{ {
m_Crop.X = _wtoi(token); m_Crop.X = parser.ParseInt(token, 0);
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
m_Crop.Y = _wtoi(token); m_Crop.Y = parser.ParseInt(token, 0);
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
m_Crop.Width = _wtoi(token); m_Crop.Width = parser.ParseInt(token, 0);
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
m_Crop.Height = _wtoi(token); m_Crop.Height = parser.ParseInt(token, 0);
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) 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) 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); m_NeedsTransform = (oldFlip != m_Flip || oldRotate != m_Rotate);

View File

@ -54,7 +54,7 @@ static int GetNumberOption(lua_State* L)
CConfigParser& parser = meterWindow->GetParser(); CConfigParser& parser = meterWindow->GetParser();
std::wstring strTmp = LuaManager::ToWide(L, 2); 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); lua_pushnumber(L, value);
return 1; return 1;