mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Small code optimization.
This commit is contained in:
parent
fc046ac4eb
commit
f689bbe6f1
@ -714,12 +714,9 @@ CMeasure* CConfigParser::GetMeasure(const std::wstring& name)
|
||||
|
||||
double CConfigParser::ReadFloat(LPCTSTR section, LPCTSTR key, double defValue)
|
||||
{
|
||||
TCHAR buffer[256];
|
||||
swprintf(buffer, L"%f", defValue);
|
||||
const std::wstring& result = ReadString(section, key, L"");
|
||||
|
||||
const std::wstring& result = ReadString(section, key, buffer);
|
||||
|
||||
return ParseDouble(result, defValue);
|
||||
return (m_LastDefaultUsed) ? defValue : ParseDouble(result, defValue);
|
||||
}
|
||||
|
||||
std::vector<Gdiplus::REAL> CConfigParser::ReadFloats(LPCTSTR section, LPCTSTR key)
|
||||
@ -742,21 +739,15 @@ std::vector<Gdiplus::REAL> CConfigParser::ReadFloats(LPCTSTR section, LPCTSTR ke
|
||||
|
||||
int CConfigParser::ReadInt(LPCTSTR section, LPCTSTR key, int defValue)
|
||||
{
|
||||
TCHAR buffer[32];
|
||||
swprintf(buffer, L"%i", defValue);
|
||||
const std::wstring& result = ReadString(section, key, L"");
|
||||
|
||||
const std::wstring& result = ReadString(section, key, buffer);
|
||||
|
||||
return (int)ParseDouble(result, defValue, true);
|
||||
return (m_LastDefaultUsed) ? defValue : (int)ParseDouble(result, defValue, true);
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
TCHAR buffer[256];
|
||||
swprintf(buffer, L"%f", defValue);
|
||||
|
||||
const std::wstring& result = ReadString(section, key, buffer);
|
||||
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')')
|
||||
@ -771,7 +762,7 @@ double CConfigParser::ReadFormula(LPCTSTR section, LPCTSTR key, double defValue)
|
||||
return resultValue;
|
||||
}
|
||||
|
||||
return ParseDouble(result, defValue);
|
||||
return (m_LastDefaultUsed) ? defValue : ParseDouble(result, defValue);
|
||||
}
|
||||
|
||||
// Returns an int if the formula was read successfully, -1 for failure.
|
||||
@ -797,12 +788,9 @@ int CConfigParser::ReadFormula(const std::wstring& result, double* resultValue)
|
||||
|
||||
Color CConfigParser::ReadColor(LPCTSTR section, LPCTSTR key, const Color& defValue)
|
||||
{
|
||||
TCHAR buffer[128];
|
||||
swprintf(buffer, L"%i, %i, %i, %i", defValue.GetR(), defValue.GetG(), defValue.GetB(), defValue.GetA());
|
||||
const std::wstring& result = ReadString(section, key, L"");
|
||||
|
||||
const std::wstring& result = ReadString(section, key, buffer);
|
||||
|
||||
return ParseColor(result.c_str());
|
||||
return (m_LastDefaultUsed) ? defValue : ParseColor(result.c_str());
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -259,7 +259,7 @@ void CMeterHistogram::ReadConfig(const WCHAR* section)
|
||||
m_BothColor = parser.ReadColor(section, L"BothColor", Color::Yellow);
|
||||
|
||||
m_SecondaryMeasureName = parser.ReadString(section, L"MeasureName2", L"");
|
||||
if (m_SecondaryMeasureName == L"")
|
||||
if (m_SecondaryMeasureName.empty())
|
||||
{
|
||||
m_SecondaryMeasureName = parser.ReadString(section, L"SecondaryMeasureName", L"");
|
||||
}
|
||||
|
@ -447,7 +447,7 @@ void CMeterImage::ReadConfig(const WCHAR* section)
|
||||
|
||||
if (alpha != tint.GetAlpha())
|
||||
{
|
||||
tint = Color(alpha, tint.GetRed(), tint.GetGreen(), tint.GetBlue());
|
||||
tint.SetValue(Color::MakeARGB(alpha, tint.GetRed(), tint.GetGreen(), tint.GetBlue()));
|
||||
}
|
||||
|
||||
m_ColorMatrix = c_IdentifyMatrix;
|
||||
|
@ -259,22 +259,25 @@ void CMeterString::ReadConfig(const WCHAR* section)
|
||||
m_MeasureNames.clear();
|
||||
|
||||
// Check for extra measures
|
||||
int i = 2;
|
||||
bool loop = true;
|
||||
do
|
||||
if (!m_MeasureName.empty())
|
||||
{
|
||||
swprintf(tmpName, L"MeasureName%i", i);
|
||||
std::wstring measure = parser.ReadString(section, tmpName, L"");
|
||||
if (!measure.empty())
|
||||
int i = 2;
|
||||
bool loop = true;
|
||||
do
|
||||
{
|
||||
m_MeasureNames.push_back(measure);
|
||||
}
|
||||
else
|
||||
{
|
||||
loop = false;
|
||||
}
|
||||
++i;
|
||||
} while(loop);
|
||||
swprintf(tmpName, L"MeasureName%i", i);
|
||||
std::wstring measure = parser.ReadString(section, tmpName, L"");
|
||||
if (!measure.empty())
|
||||
{
|
||||
m_MeasureNames.push_back(measure);
|
||||
}
|
||||
else
|
||||
{
|
||||
loop = false;
|
||||
}
|
||||
++i;
|
||||
} while(loop);
|
||||
}
|
||||
|
||||
m_Color = parser.ReadColor(section, L"FontColor", Color::Black);
|
||||
m_EffectColor = parser.ReadColor(section, L"FontEffectColor", Color::Black);
|
||||
|
Loading…
Reference in New Issue
Block a user