Minor tweaks.

This commit is contained in:
spx 2011-11-04 12:48:03 +00:00
parent 153b466abd
commit f945bacfb7
5 changed files with 66 additions and 25 deletions

View File

@ -599,26 +599,16 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT
std::vector<std::wstring>::const_reverse_iterator iter = m_StyleTemplate.rbegin();
for ( ; iter != m_StyleTemplate.rend(); ++iter)
{
if ((*iter).size() > 0)
const std::wstring& strStyle = GetValue((*iter), strKey, strDefault);
//LogWithArgs(LOG_DEBUG, L"[%s] %s (from [%s]) : strDefault=%s (0x%p), strStyle=%s (0x%p)",
// section, key, (*iter).c_str(), strDefault.c_str(), &strDefault, strStyle.c_str(), &strStyle);
if (&strStyle != &strDefault)
{
std::wstring::size_type pos = (*iter).find_first_not_of(L" \t\r\n");
if (pos != std::wstring::npos)
{
// Trim white-space
std::wstring strStyleSection((*iter), pos, (*iter).find_last_not_of(L" \t\r\n") - pos + 1);
const std::wstring& strStyle = GetValue(strStyleSection, strKey, strDefault);
//LogWithArgs(LOG_DEBUG, L"[%s] %s (from [%s]) : strDefault=%s (0x%p), strStyle=%s (0x%p)",
// section, key, strStyleSection.c_str(), strDefault.c_str(), &strDefault, strStyle.c_str(), &strStyle);
if (&strStyle != &strDefault)
{
strDefault = strStyle;
m_LastUsedStyle = strStyleSection;
break;
}
}
strDefault = strStyle;
m_LastUsedStyle = (*iter);
break;
}
}
}
@ -836,6 +826,39 @@ std::vector<std::wstring> CConfigParser::Tokenize(const std::wstring& str, const
return tokens;
}
/*
** Shrink
**
** Trims empty element in vector and white-space in each string.
**
*/
void CConfigParser::Shrink(std::vector<std::wstring>& vec)
{
if (vec.size() > 0)
{
std::vector<std::wstring>::iterator iter = vec.begin();
while (iter != vec.end())
{
std::wstring::size_type pos = (*iter).find_first_not_of(L" \t\r\n");
if (pos != std::wstring::npos)
{
std::wstring::size_type lastPos = (*iter).find_last_not_of(L" \t\r\n");
if (pos != 0 || lastPos != ((*iter).size() - 1))
{
// Trim white-space
(*iter).assign((*iter), pos, lastPos - pos + 1);
}
++iter;
}
else
{
// Remove empty element
iter = vec.erase(iter);
}
}
}
}
/*
** ParseDouble
**

View File

@ -51,7 +51,7 @@ public:
void SetValue(const std::wstring& strSection, const std::wstring& strKey, const std::wstring& strValue);
void DeleteValue(const std::wstring& strSection, const std::wstring& strKey);
void SetStyleTemplate(const std::wstring& strStyle) { m_StyleTemplate = Tokenize(strStyle, L"|"); }
void SetStyleTemplate(const std::wstring& strStyle) { m_StyleTemplate = Tokenize(strStyle, L"|"); Shrink(m_StyleTemplate); }
void ClearStyleTemplate() { m_StyleTemplate.clear(); }
const std::wstring& GetLastUsedStyle() { return m_LastUsedStyle; }
@ -84,6 +84,7 @@ public:
bool ReplaceMeasures(std::wstring& result);
static std::vector<std::wstring> Tokenize(const std::wstring& str, const std::wstring& delimiters);
static void Shrink(std::vector<std::wstring>& vec);
static double ParseDouble(const std::wstring& string, double defValue, bool rejectExp = false);
static Gdiplus::Color ParseColor(LPCTSTR string);
static Gdiplus::Rect ParseRect(LPCTSTR string);

View File

@ -50,6 +50,7 @@ CMeter::CMeter(CMeterWindow* meterWindow, const WCHAR* name) : m_MeterWindow(met
m_HDefined(false),
m_RelativeMeter(),
m_DynamicVariables(false),
m_Transformation(),
m_ToolTipWidth(),
m_ToolTipDelay(),
m_ToolTipType(false),
@ -77,6 +78,8 @@ CMeter::CMeter(CMeterWindow* meterWindow, const WCHAR* name) : m_MeterWindow(met
*/
CMeter::~CMeter()
{
delete m_Transformation;
if (m_ToolTipHandle != NULL)
{
DestroyWindow(m_ToolTipHandle);
@ -425,10 +428,22 @@ void CMeter::ReadConfig(CConfigParser& parser, const WCHAR* section)
std::vector<Gdiplus::REAL> matrix = parser.ReadFloats(section, L"TransformationMatrix");
if (matrix.size() == 6)
{
m_Transformation.SetElements(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
if (m_Transformation)
{
m_Transformation->SetElements(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
}
else
{
m_Transformation = new Matrix(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
}
}
else if (!matrix.empty())
{
if (m_Transformation)
{
delete m_Transformation;
m_Transformation = NULL;
}
LogWithArgs(LOG_ERROR, L"Meter: Incorrect number of values in TransformationMatrix=%s", parser.ReadString(section, L"TransformationMatrix", L"").c_str());
}

View File

@ -84,7 +84,7 @@ public:
virtual void Show();
bool IsHidden() { return m_Hidden; }
const Gdiplus::Matrix& GetTransformationMatrix() { return m_Transformation; }
const Gdiplus::Matrix* GetTransformationMatrix() { return m_Transformation; }
virtual bool HitTest(int x, int y);
@ -126,7 +126,6 @@ protected:
static void ReadMeasureNames(CConfigParser& parser, const WCHAR* section, std::vector<std::wstring>& measureNames);
static bool ReplaceMeasures(const std::vector<std::wstring>& stringValues, std::wstring& str);
Gdiplus::Matrix m_Transformation; // The transformation matrix
const std::wstring m_Name; // Name of the meter
std::wstring m_MeasureName; // Name of the measure this is bound to
CMeasure* m_Measure; // Pointer to the measure this meter is bound to
@ -141,6 +140,8 @@ protected:
CMeter* m_RelativeMeter;
bool m_DynamicVariables; // If true, the measure contains dynamic variables
Gdiplus::Matrix* m_Transformation; // The transformation matrix
std::wstring m_StyleX;
std::wstring m_StyleY;
std::wstring m_StyleHidden;

View File

@ -2759,10 +2759,11 @@ void CMeterWindow::Redraw()
std::list<CMeter*>::const_iterator j = m_Meters.begin();
for ( ; j != m_Meters.end(); ++j)
{
if (!(*j)->GetTransformationMatrix().IsIdentity())
const Matrix* matrix = (*j)->GetTransformationMatrix();
if (matrix && matrix->IsIdentity())
{
// Change the world matrix
graphics.SetTransform(&((*j)->GetTransformationMatrix()));
graphics.SetTransform(matrix);
(*j)->Draw(graphics);