diff --git a/Library/Meter.cpp b/Library/Meter.cpp index b870e408..31f52964 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -446,7 +446,7 @@ void CMeter::ReadConfig(const WCHAR* section) ** several meters but one meter and only be bound to one measure. ** */ -void CMeter::BindMeasure(std::list& measures) +void CMeter::BindMeasure(const std::list& measures) { // The meter is not bound to anything if (m_MeasureName.empty()) @@ -554,7 +554,7 @@ void CMeter::SetAllMeasures(CMeasure* measure) ** ** Creates a vector containing all the defined measures (for Line/String) */ -void CMeter::SetAllMeasures(std::vector measures) +void CMeter::SetAllMeasures(const std::vector& measures) { m_AllMeasures.clear(); m_AllMeasures.push_back(m_Measure); @@ -571,11 +571,40 @@ void CMeter::SetAllMeasures(std::vector measures) ** ** Replaces %1, %2 etc with the corresponding measure value */ -std::wstring CMeter::ReplaceMeasures(std::wstring source) +void CMeter::ReplaceMeasures(const std::vector& stringValues, std::wstring& str) +{ + 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) + { + wsprintf(buffer, L"%%%i", i); + + size_t start = 0; + size_t pos = std::wstring::npos; + + do + { + pos = str.find(buffer, start); + if (pos != std::wstring::npos) + { + str.replace(str.begin() + pos, str.begin() + pos + wcslen(buffer), stringValues[i - 1]); + start = pos + stringValues[i - 1].length(); + } + } while(pos != std::wstring::npos); + } +} + +/* +** ReplaceToolTipMeasures +** +** Replaces %1, %2 etc with the corresponding measure value +*/ +void CMeter::ReplaceToolTipMeasures(std::wstring& str) { std::vector stringValues; - if (!m_AllMeasures.empty()) + if (!m_AllMeasures.empty()) { // Get the values for the measures for (size_t i = 0; i < m_AllMeasures.size(); ++i) @@ -589,30 +618,13 @@ std::wstring CMeter::ReplaceMeasures(std::wstring source) } else { - return source; + return; } - 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) + if (!stringValues.empty()) { - wsprintf(buffer, L"%%%i", i); - - size_t start = 0; - size_t pos = std::wstring::npos; - - do - { - pos = source.find(buffer, start); - if (pos != std::wstring::npos) - { - source.replace(source.begin() + pos, source.begin() + pos + wcslen(buffer), stringValues[i - 1]); - start = pos + stringValues[i - 1].length(); - } - } while(pos != std::wstring::npos); + ReplaceMeasures(stringValues, str); } - return source; } /* @@ -674,7 +686,8 @@ void CMeter::UpdateToolTip() SendMessage(hwndTT, TTM_GETTOOLINFO, NULL, (LPARAM) (LPTOOLINFO) &ti); - std::wstring text = ReplaceMeasures(m_ToolTipText); + std::wstring text = m_ToolTipText; + ReplaceToolTipMeasures(text); ti.lpszText = (PTSTR) text.c_str(); ti.rect = GetMeterRect(); @@ -715,7 +728,8 @@ void CMeter::UpdateToolTip() } } - text = ReplaceMeasures(m_ToolTipTitle); + text = m_ToolTipTitle; + ReplaceToolTipMeasures(text); SendMessage(hwndTT, TTM_SETTITLE, (WPARAM) hIcon, (LPARAM) text.c_str()); if (destroy) diff --git a/Library/Meter.h b/Library/Meter.h index b59b36d9..e2d2ac6d 100644 --- a/Library/Meter.h +++ b/Library/Meter.h @@ -38,7 +38,7 @@ public: virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); - virtual void BindMeasure(std::list& measures); + virtual void BindMeasure(const std::list& measures); virtual bool HasActiveTransition() { return false; } bool HasDynamicVariables() { return m_DynamicVariables; } @@ -52,22 +52,17 @@ public: void SetX(int x) { m_X = x; m_RelativeX = POSITION_ABSOLUTE; } void SetY(int y) { m_Y = y; m_RelativeY = POSITION_ABSOLUTE; } - std::wstring& GetRightMouseDownAction() { return m_RightMouseDownAction; } - std::wstring& GetRightMouseUpAction() { return m_RightMouseUpAction; } - std::wstring& GetRightMouseDoubleClickAction() { return m_RightMouseDoubleClickAction; } - std::wstring& GetLeftMouseDownAction() { return m_LeftMouseDownAction; } - std::wstring& GetLeftMouseUpAction() { return m_LeftMouseUpAction; } - std::wstring& GetLeftMouseDoubleClickAction() { return m_LeftMouseDoubleClickAction; } - std::wstring& GetMiddleMouseDownAction() { return m_MiddleMouseDownAction; } - std::wstring& GetMiddleMouseUpAction() { return m_MiddleMouseUpAction; } - std::wstring& GetMiddleMouseDoubleClickAction() { return m_MiddleMouseDoubleClickAction; } - std::wstring& GetMouseOverAction() { return m_MouseOverAction; } - std::wstring& GetMouseLeaveAction() { return m_MouseLeaveAction; } - - void SetAllMeasures(CMeasure* measure); - void SetAllMeasures(std::vector measures); - - std::wstring CMeter::ReplaceMeasures(std::wstring source); + const std::wstring& GetRightMouseDownAction() { return m_RightMouseDownAction; } + const std::wstring& GetRightMouseUpAction() { return m_RightMouseUpAction; } + const std::wstring& GetRightMouseDoubleClickAction() { return m_RightMouseDoubleClickAction; } + const std::wstring& GetLeftMouseDownAction() { return m_LeftMouseDownAction; } + const std::wstring& GetLeftMouseUpAction() { return m_LeftMouseUpAction; } + const std::wstring& GetLeftMouseDoubleClickAction() { return m_LeftMouseDoubleClickAction; } + const std::wstring& GetMiddleMouseDownAction() { return m_MiddleMouseDownAction; } + const std::wstring& GetMiddleMouseUpAction() { return m_MiddleMouseUpAction; } + const std::wstring& GetMiddleMouseDoubleClickAction() { return m_MiddleMouseDoubleClickAction; } + const std::wstring& GetMouseOverAction() { return m_MouseOverAction; } + const std::wstring& GetMouseLeaveAction() { return m_MouseLeaveAction; } const std::wstring& GetToolTipText() { return m_ToolTipText; } bool HasToolTip() { return m_ToolTipHandle != NULL; } @@ -114,6 +109,12 @@ protected: POSITION_RELATIVE_BR }; + void SetAllMeasures(CMeasure* measure); + void SetAllMeasures(const std::vector& measures); + void ReplaceToolTipMeasures(std::wstring& str); + + static void ReplaceMeasures(const std::vector& stringValues, std::wstring& str); + Gdiplus::Matrix m_Transformation; // The transformation matrix std::wstring m_Name; // Name of the meter std::wstring m_MeasureName; // Name of the measure this is bound to diff --git a/Library/MeterButton.cpp b/Library/MeterButton.cpp index 9140907e..36a5357d 100644 --- a/Library/MeterButton.cpp +++ b/Library/MeterButton.cpp @@ -227,7 +227,7 @@ bool CMeterButton::Draw(Graphics& graphics) ** Overridden method. The meters need not to be bound on anything ** */ -void CMeterButton::BindMeasure(std::list& measures) +void CMeterButton::BindMeasure(const std::list& measures) { // It's ok not to bind meter to anything if (!m_MeasureName.empty()) diff --git a/Library/MeterButton.h b/Library/MeterButton.h index 6dd9beaf..8c85eeba 100644 --- a/Library/MeterButton.h +++ b/Library/MeterButton.h @@ -34,7 +34,7 @@ public: virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); - virtual void BindMeasure(std::list& measures); + virtual void BindMeasure(const std::list& measures); bool MouseMove(POINT pos); bool MouseUp(POINT pos, CMeterWindow* window); diff --git a/Library/MeterHistogram.cpp b/Library/MeterHistogram.cpp index 3fd47bd4..fbd87c95 100644 --- a/Library/MeterHistogram.cpp +++ b/Library/MeterHistogram.cpp @@ -562,7 +562,7 @@ bool CMeterHistogram::Draw(Graphics& graphics) ** Overwritten method to handle the secondary measure binding. ** */ -void CMeterHistogram::BindMeasure(std::list& measures) +void CMeterHistogram::BindMeasure(const std::list& measures) { CMeter::BindMeasure(measures); diff --git a/Library/MeterHistogram.h b/Library/MeterHistogram.h index a861fd14..afa60830 100644 --- a/Library/MeterHistogram.h +++ b/Library/MeterHistogram.h @@ -32,7 +32,7 @@ public: virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); - virtual void BindMeasure(std::list& measures); + virtual void BindMeasure(const std::list& measures); private: std::wstring m_SecondaryMeasureName; // Name of the secondary measure diff --git a/Library/MeterImage.cpp b/Library/MeterImage.cpp index c893723e..0fe89bc6 100644 --- a/Library/MeterImage.cpp +++ b/Library/MeterImage.cpp @@ -668,7 +668,7 @@ bool CMeterImage::Draw(Graphics& graphics) ** Overridden method. The Image meters need not to be bound on anything ** */ -void CMeterImage::BindMeasure(std::list& measures) +void CMeterImage::BindMeasure(const std::list& measures) { // It's ok not to bind image meter to anything if (!m_MeasureName.empty()) diff --git a/Library/MeterImage.h b/Library/MeterImage.h index 7bb45d6d..90fe128b 100644 --- a/Library/MeterImage.h +++ b/Library/MeterImage.h @@ -37,7 +37,7 @@ public: virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); - virtual void BindMeasure(std::list& measures); + virtual void BindMeasure(const std::list& measures); protected: void LoadImage(bool bLoadAlways); diff --git a/Library/MeterLine.cpp b/Library/MeterLine.cpp index abfb9125..497cfad5 100644 --- a/Library/MeterLine.cpp +++ b/Library/MeterLine.cpp @@ -69,6 +69,11 @@ void CMeterLine::Initialize() { m_AllValues.push_back(std::vector()); + if (m_W > 0) + { + m_AllValues.back().reserve(m_W); + } + if (num > 0) { m_AllValues.back().assign(num, 0); @@ -299,23 +304,37 @@ bool CMeterLine::Draw(Graphics& graphics) } // Draw all the lines + const REAL H = m_H - 1.0f; + const bool closeRequired = (m_LineWidth != 1.0); counter = 0; std::vector< std::vector >::const_iterator i = m_AllValues.begin(); for (; i != m_AllValues.end(); ++i) { // Draw a line - REAL Y = 0.0f; - REAL oldY = 0.0f; - REAL H = m_H - 1.0f; + REAL Y, oldY; - double scale = m_ScaleValues[counter] * H / maxValue; + const double scale = m_ScaleValues[counter] * H / maxValue; + const int size = (int)(*i).size(); int pos = m_CurrentPos; - int size = (int)(*i).size(); - - Pen pen(m_Colors[counter], (REAL)m_LineWidth); + if (pos >= m_W) pos = 0; - for (int j = x, R = x + m_W; j < R; ++j) + if (pos < size) + { + oldY = (REAL)((*i)[pos] * scale); + oldY = min(oldY, H); + oldY = max(oldY, 0.0f); + } + else + { + oldY = 0.0f; + } + oldY = (m_Flip) ? y + oldY : y + H - oldY; + ++pos; + + // Cache all lines + GraphicsPath path; + for (int j = x + 1, R = x + m_W; j < R; ++j) { if (pos >= m_W) pos = 0; @@ -327,20 +346,25 @@ bool CMeterLine::Draw(Graphics& graphics) } else { - Y = 0.0f; + Y = 0.0f; } - Y = (m_Flip) ? y + Y : y + H - Y; - if (j != x) - { - graphics.DrawLine(&pen, (REAL)(j - 1), oldY, (REAL)j, Y); // GDI+ - } - oldY = Y; + path.AddLine((REAL)(j - 1), oldY, (REAL)j, Y); + if (closeRequired) + { + path.CloseFigure(); + } + + oldY = Y; ++pos; } + // Draw cached lines + Pen pen(m_Colors[counter], (REAL)m_LineWidth); + graphics.DrawPath(&pen, &path); + ++counter; } @@ -353,7 +377,7 @@ bool CMeterLine::Draw(Graphics& graphics) ** Overwritten method to handle the other measure bindings. ** */ -void CMeterLine::BindMeasure(std::list& measures) +void CMeterLine::BindMeasure(const std::list& measures) { CMeter::BindMeasure(measures); diff --git a/Library/MeterLine.h b/Library/MeterLine.h index d592debe..a3c6dbb1 100644 --- a/Library/MeterLine.h +++ b/Library/MeterLine.h @@ -32,7 +32,7 @@ public: virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); - virtual void BindMeasure(std::list& measures); + virtual void BindMeasure(const std::list& measures); private: std::vector m_MeasureNames; // Name of the other measures diff --git a/Library/MeterString.cpp b/Library/MeterString.cpp index d11a6e56..ed5398a3 100644 --- a/Library/MeterString.cpp +++ b/Library/MeterString.cpp @@ -444,31 +444,15 @@ bool CMeterString::Update() m_String += stringValues[0]; } } + else if (!stringValues.empty()) + { + std::wstring tmpText = m_Text; + ReplaceMeasures(stringValues, tmpText); + m_String += tmpText; + } else { - WCHAR buffer[64]; - // Create the actual text (i.e. replace %1, %2, .. with the measure texts) - std::wstring tmpText = m_Text; - - for (size_t i = stringValues.size(); i > 0; --i) - { - wsprintf(buffer, L"%%%i", i); - - size_t start = 0; - size_t pos = std::wstring::npos; - - do - { - pos = tmpText.find(buffer, start); - if (pos != std::wstring::npos) - { - tmpText.replace(tmpText.begin() + pos, tmpText.begin() + pos + wcslen(buffer), stringValues[i - 1]); - start = pos + stringValues[i - 1].length(); - } - } while(pos != std::wstring::npos); - } - - m_String += tmpText; + m_String += m_Text; } if (!m_Postfix.empty()) m_String += m_Postfix; @@ -628,7 +612,7 @@ bool CMeterString::DrawString(Graphics& graphics, RectF* rect) ** Overridden method. The string meters need not to be bound on anything ** */ -void CMeterString::BindMeasure(std::list& measures) +void CMeterString::BindMeasure(const std::list& measures) { if (m_MeasureName.empty()) return; // Allow NULL measure binding diff --git a/Library/MeterString.h b/Library/MeterString.h index 4db07dfe..5c61a5e7 100644 --- a/Library/MeterString.h +++ b/Library/MeterString.h @@ -39,7 +39,7 @@ public: virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); - virtual void BindMeasure(std::list& measures); + virtual void BindMeasure(const std::list& measures); static void FreeFontCache(); static void EnumerateInstalledFontFamilies();