diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index e28d87d6..2ff6daf6 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -599,26 +599,16 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT std::vector::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 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& vec) +{ + if (vec.size() > 0) + { + std::vector::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 ** diff --git a/Library/ConfigParser.h b/Library/ConfigParser.h index a5f15a7f..928ca72b 100644 --- a/Library/ConfigParser.h +++ b/Library/ConfigParser.h @@ -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 Tokenize(const std::wstring& str, const std::wstring& delimiters); + static void Shrink(std::vector& 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); diff --git a/Library/Meter.cpp b/Library/Meter.cpp index 7dc5dbc9..e0d77f97 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -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 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()); } diff --git a/Library/Meter.h b/Library/Meter.h index e22dafc7..19a7bea2 100644 --- a/Library/Meter.h +++ b/Library/Meter.h @@ -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& measureNames); static bool ReplaceMeasures(const std::vector& 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; diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 63c1328a..b8d014ed 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -2759,10 +2759,11 @@ void CMeterWindow::Redraw() std::list::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);