This commit is contained in:
Birunthan Mohanathas 2012-07-17 10:57:28 +03:00
parent 4bbc372116
commit 8309eb2bda
4 changed files with 26 additions and 62 deletions

View File

@ -525,9 +525,10 @@ void CMeter::BindSecondaryMeasures(CConfigParser& parser, const WCHAR* section)
}
/*
** Replaces %1, %2 etc with the corresponding measure value
** Replaces %1, %2, ... with the corresponding measure value.
**
*/
bool CMeter::ReplaceMeasures(const std::vector<std::wstring>& stringValues, std::wstring& str)
bool CMeter::ReplaceMeasures(std::wstring& str, AUTOSCALE autoScale, double scale, int decimals, bool percentual)
{
bool replaced = false;
@ -535,18 +536,21 @@ bool CMeter::ReplaceMeasures(const std::vector<std::wstring>& stringValues, std:
{
WCHAR buffer[64];
// Create the actual text (i.e. replace %1, %2, .. with the measure texts)
for (size_t i = stringValues.size(); i > 0; --i)
for (size_t i = m_Measures.size(); i > 0; --i)
{
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);
int measureValueLen = wcslen(measureValue);
do
{
pos = str.find(buffer, start, len);
if (pos != std::wstring::npos)
{
str.replace(pos, len, stringValues[i - 1]);
start = pos + stringValues[i - 1].length();
str.replace(pos, len, measureValue, measureValueLen);
start = pos + measureValueLen;
replaced = true;
}
}
@ -557,26 +561,6 @@ bool CMeter::ReplaceMeasures(const std::vector<std::wstring>& stringValues, std:
return replaced;
}
/*
** Replaces %1, %2 etc with the corresponding measure value
*/
void CMeter::ReplaceToolTipMeasures(std::wstring& str)
{
std::vector<std::wstring> stringValues;
if (!m_Measures.empty())
{
// Get the values for the measures
std::vector<CMeasure*>::const_iterator iter = m_Measures.begin();
for ( ; iter != m_Measures.end(); ++iter)
{
stringValues.push_back((*iter)->GetStringValue(AUTOSCALE_ON, 1, 0, false));
}
ReplaceMeasures(stringValues, str);
}
}
/*
** Does the initial construction of the ToolTip for the meter
*/
@ -630,7 +614,7 @@ void CMeter::UpdateToolTip()
SendMessage(hwndTT, TTM_GETTOOLINFO, NULL, (LPARAM)&ti);
std::wstring text = m_ToolTipText;
ReplaceToolTipMeasures(text);
ReplaceMeasures(text);
ti.lpszText = (LPTSTR)text.c_str();
ti.rect = GetMeterRect();
@ -673,7 +657,7 @@ void CMeter::UpdateToolTip()
}
text = m_ToolTipTitle;
ReplaceToolTipMeasures(text);
ReplaceMeasures(text);
SendMessage(hwndTT, TTM_SETTITLE, (WPARAM) hIcon, (LPARAM)text.c_str());
if (destroy)

View File

@ -26,6 +26,7 @@
#include "Litestep.h"
#include "ConfigParser.h"
#include "MeterWindow.h"
#include "Measure.h"
#include "Group.h"
class CMeasure;
@ -121,8 +122,7 @@ protected:
bool BindPrimaryMeasure(CConfigParser& parser, const WCHAR* section, bool optional);
void BindSecondaryMeasures(CConfigParser& parser, const WCHAR* section);
void ReplaceToolTipMeasures(std::wstring& str);
static bool ReplaceMeasures(const std::vector<std::wstring>& stringValues, std::wstring& str);
bool ReplaceMeasures(std::wstring& str, AUTOSCALE autoScale = AUTOSCALE_ON, double scale = 1.0, int decimals = 0, bool percentual = false);
const std::wstring m_Name;
std::vector<CMeasure*> m_Measures;

View File

@ -152,30 +152,17 @@ bool CMeterImage::Update()
if (!m_Measures.empty()) // read from the measures
{
std::wstring val = m_Measures[0]->GetStringValue(AUTOSCALE_OFF, 1, 0, false);
if (m_ImageName.empty())
{
m_ImageNameResult = val;
m_ImageNameResult = m_Measures[0]->GetStringValue(AUTOSCALE_OFF, 1, 0, false);
}
else
{
std::vector<std::wstring> stringValues;
stringValues.push_back(val);
// Get the values for the other measures
std::vector<CMeasure*>::const_iterator iter = m_Measures.begin();
for ( ; iter != m_Measures.end(); ++iter)
{
stringValues.push_back((*iter)->GetStringValue(AUTOSCALE_OFF, 1, 0, false));
}
m_ImageNameResult = m_ImageName;
if (!ReplaceMeasures(stringValues, m_ImageNameResult))
if (!ReplaceMeasures(m_ImageNameResult))
{
// ImageName doesn't contain any measures, so use the result of MeasureName.
m_ImageNameResult = val;
m_ImageNameResult = m_Measures[0]->GetStringValue(AUTOSCALE_OFF, 1, 0, false);
}
}
}

View File

@ -490,27 +490,20 @@ bool CMeterString::Update()
{
int decimals = (m_NumOfDecimals != -1) ? m_NumOfDecimals : (m_NoDecimals && (m_Percentual || m_AutoScale == AUTOSCALE_OFF)) ? 0 : 1;
std::vector<std::wstring> stringValues;
std::vector<CMeasure*>::const_iterator iter = m_Measures.begin();
for ( ; iter != m_Measures.end(); ++iter)
{
stringValues.push_back((*iter)->GetStringValue(m_AutoScale, m_Scale, decimals, m_Percentual));
}
// Create the text
m_String = m_Prefix;
if (m_Text.empty())
if (!m_Measures.empty())
{
if (!stringValues.empty())
if (m_Text.empty())
{
m_String += stringValues[0];
m_String += m_Measures[0]->GetStringValue(m_AutoScale, m_Scale, decimals, m_Percentual);
}
else
{
std::wstring tmpText = m_Text;
ReplaceMeasures(tmpText, m_AutoScale, m_Scale, decimals, m_Percentual);
m_String += tmpText;
}
}
else if (!stringValues.empty())
{
std::wstring tmpText = m_Text;
ReplaceMeasures(stringValues, tmpText);
m_String += tmpText;
}
else
{