diff --git a/Library/Meter.cpp b/Library/Meter.cpp index c826c64e..a555ffb1 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -40,7 +40,6 @@ extern CRainmeter* Rainmeter; ** */ CMeter::CMeter(CMeterWindow* meterWindow, const WCHAR* name) : m_MeterWindow(meterWindow), m_Name(name), - m_Measure(), m_X(), m_Y(), m_W(), @@ -339,11 +338,6 @@ void CMeter::ReadOptions(CConfigParser& parser, const WCHAR* section) m_Hidden = 0!=parser.ParseInt(hidden.c_str(), 0); } - if (!m_Initialized) - { - m_MeasureName = parser.ReadString(section, L"MeasureName", L""); - } - m_SolidBevel = (BEVELTYPE)parser.ReadInt(section, L"BevelType", BEVELTYPE_NONE); m_SolidColor = parser.ReadColor(section, L"SolidColor", Color::MakeARGB(0, 0, 0, 0)); @@ -404,34 +398,9 @@ void CMeter::ReadOptions(CConfigParser& parser, const WCHAR* section) ** several meters but one meter and only be bound to one measure. ** */ -void CMeter::BindMeasure(const std::list& measures) +void CMeter::BindMeasures(CConfigParser& parser, const WCHAR* section) { - // The meter is not bound to anything - if (m_MeasureName.empty()) - { - std::wstring error = L"The meter [" + m_Name; - error += L"] is unbound"; - throw CError(error); - } - - // Go through the list and check it there is a measure for us - const WCHAR* measure = m_MeasureName.c_str(); - std::list::const_iterator i = measures.begin(); - for ( ; i != measures.end(); ++i) - { - if (_wcsicmp((*i)->GetName(), measure) == 0) - { - m_Measure = (*i); - return; - } - } - - // Error :) - std::wstring error = L"The meter [" + m_Name; - error += L"] cannot be bound with ["; - error += m_MeasureName; - error += L']'; - throw CError(error); + BindPrimaryMeasure(parser, section, false); } /* @@ -498,56 +467,61 @@ bool CMeter::Update() } /* -** Creates a vector containing all the defined measures (for Histogram) +** Reads and binds the primary MeasureName. +** */ -void CMeter::SetAllMeasures(CMeasure* measure) +bool CMeter::BindPrimaryMeasure(CConfigParser& parser, const WCHAR* section, bool optional) { - m_AllMeasures.clear(); - m_AllMeasures.reserve(2); - m_AllMeasures.push_back(m_Measure); - m_AllMeasures.push_back(measure); + const std::wstring& measureName = parser.ReadString(section, L"MeasureName", L""); + + // The meter is not bound to anything + CMeasure* measure = parser.GetMeasure(measureName); + if (measure) + { + m_Measures.push_back(measure); + return true; + } + else if (!optional) + { + LogWithArgs(LOG_ERROR, L"MeasureName=%s is not valid in [%s]", measureName.c_str(), section); + } + + return false; } /* -** Creates a vector containing all the defined measures (for Image/Line/String) +** Reads and binds secondary measures (MeasureName2 - MeasureNameN). +** */ -void CMeter::SetAllMeasures(const std::vector& measures) +void CMeter::BindSecondaryMeasures(CConfigParser& parser, const WCHAR* section) { - m_AllMeasures.clear(); - m_AllMeasures.reserve(1 + measures.size()); - m_AllMeasures.push_back(m_Measure); - - std::vector::const_iterator i = measures.begin(); - for ( ; i != measures.end(); ++i) + if (!m_Measures.empty()) { - m_AllMeasures.push_back(*i); - } -} + WCHAR tmpName[64]; -/* -** Reads measure names (MeasureName2 - MeasureName[N]) -*/ -void CMeter::ReadMeasureNames(CConfigParser& parser, const WCHAR* section, std::vector& measureNames) -{ - WCHAR tmpName[64]; + int i = 2; + do + { + _snwprintf_s(tmpName, _TRUNCATE, L"MeasureName%i", i); + const std::wstring& measureName = parser.ReadString(section, tmpName, L""); + CMeasure* measure = parser.GetMeasure(measureName); + if (measure) + { + m_Measures.push_back(measure); + } + else + { + if (!measureName.empty()) + { + LogWithArgs(LOG_ERROR, L"MeasureName%i=%s is not valid in [%s]", i, measureName.c_str(), section); + } - int i = 2; - bool loop = true; - do - { - _snwprintf_s(tmpName, _TRUNCATE, L"MeasureName%i", i); - const std::wstring& measure = parser.ReadString(section, tmpName, L""); - if (!measure.empty()) - { - measureNames.push_back(measure); + break; + } + ++i; } - else - { - loop = false; - } - ++i; + while (true); } - while(loop); } /* @@ -590,26 +564,15 @@ void CMeter::ReplaceToolTipMeasures(std::wstring& str) { std::vector stringValues; - if (!m_AllMeasures.empty()) + if (!m_Measures.empty()) { // Get the values for the measures - std::vector::const_iterator iter = m_AllMeasures.begin(); - for ( ; iter != m_AllMeasures.end(); ++iter) + std::vector::const_iterator iter = m_Measures.begin(); + for ( ; iter != m_Measures.end(); ++iter) { stringValues.push_back((*iter)->GetStringValue(AUTOSCALE_ON, 1, 0, false)); } - } - else if (m_Measure != NULL) - { - stringValues.push_back(m_Measure->GetStringValue(AUTOSCALE_ON, 1, 0, false)); - } - else - { - return; - } - if (!stringValues.empty()) - { ReplaceMeasures(stringValues, str); } } diff --git a/Library/Meter.h b/Library/Meter.h index c8851fee..a4868ee4 100644 --- a/Library/Meter.h +++ b/Library/Meter.h @@ -39,11 +39,11 @@ public: virtual UINT GetTypeID() = 0; void ReadOptions(CConfigParser& parser) { ReadOptions(parser, GetName()); parser.ClearStyleTemplate(); } + void BindMeasures(CConfigParser& parser) { BindMeasures(parser, GetName()); } virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); - virtual void BindMeasure(const std::list& measures); virtual bool HasActiveTransition() { return false; } bool HasDynamicVariables() { return m_DynamicVariables; } @@ -116,18 +116,16 @@ protected: }; virtual void ReadOptions(CConfigParser& parser, const WCHAR* section); + virtual void BindMeasures(CConfigParser& parser, const WCHAR* section); + + bool BindPrimaryMeasure(CConfigParser& parser, const WCHAR* section, bool optional); + void BindSecondaryMeasures(CConfigParser& parser, const WCHAR* section); - void SetAllMeasures(CMeasure* measure); - void SetAllMeasures(const std::vector& measures); void ReplaceToolTipMeasures(std::wstring& str); - - static void ReadMeasureNames(CConfigParser& parser, const WCHAR* section, std::vector& measureNames); static bool ReplaceMeasures(const std::vector& stringValues, std::wstring& str); const std::wstring m_Name; - std::wstring m_MeasureName; // Name of bound measure - CMeasure* m_Measure; // Pointer to bound measure - std::vector m_AllMeasures; + std::vector m_Measures; int m_X; int m_Y; int m_W; diff --git a/Library/MeterBar.cpp b/Library/MeterBar.cpp index 364c9037..25775686 100644 --- a/Library/MeterBar.cpp +++ b/Library/MeterBar.cpp @@ -148,9 +148,9 @@ void CMeterBar::ReadOptions(CConfigParser& parser, const WCHAR* section) */ bool CMeterBar::Update() { - if (CMeter::Update() && m_Measure) + if (CMeter::Update() && !m_Measures.empty()) { - m_Value = m_Measure->GetRelativeValue(); + m_Value = m_Measures[0]->GetRelativeValue(); return true; } return false; diff --git a/Library/MeterBitmap.cpp b/Library/MeterBitmap.cpp index 82e972fc..e6147a90 100644 --- a/Library/MeterBitmap.cpp +++ b/Library/MeterBitmap.cpp @@ -227,9 +227,10 @@ void CMeterBitmap::ReadOptions(CConfigParser& parser, const WCHAR* section) */ bool CMeterBitmap::Update() { - if (CMeter::Update() && m_Measure) + if (CMeter::Update() && !m_Measures.empty()) { - double value = (m_Extend) ? m_Measure->GetValue() : m_Measure->GetRelativeValue(); + CMeasure* measure = m_Measures[0]; + double value = (m_Extend) ? measure->GetValue() : measure->GetRelativeValue(); if (m_TransitionFrameCount > 0) { diff --git a/Library/MeterButton.cpp b/Library/MeterButton.cpp index cac19ec0..86001baa 100644 --- a/Library/MeterButton.cpp +++ b/Library/MeterButton.cpp @@ -200,13 +200,9 @@ bool CMeterButton::Draw(Graphics& graphics) ** Overridden method. The meters need not to be bound on anything ** */ -void CMeterButton::BindMeasure(const std::list& measures) +void CMeterButton::BindMeasures(CConfigParser& parser, const WCHAR* section) { - // It's ok not to bind meter to anything - if (!m_MeasureName.empty()) - { - CMeter::BindMeasure(measures); - } + BindPrimaryMeasure(parser, section, true); } /* diff --git a/Library/MeterButton.h b/Library/MeterButton.h index 2e477744..280189df 100644 --- a/Library/MeterButton.h +++ b/Library/MeterButton.h @@ -35,7 +35,6 @@ public: virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); - virtual void BindMeasure(const std::list& measures); bool MouseMove(POINT pos); bool MouseUp(POINT pos, bool execute); @@ -45,6 +44,7 @@ public: protected: virtual void ReadOptions(CConfigParser& parser, const WCHAR* section); + virtual void BindMeasures(CConfigParser& parser, const WCHAR* section); private: bool HitTest2(int px, int py, bool checkAlpha); diff --git a/Library/MeterHistogram.cpp b/Library/MeterHistogram.cpp index 306d9823..71682749 100644 --- a/Library/MeterHistogram.cpp +++ b/Library/MeterHistogram.cpp @@ -35,7 +35,6 @@ CTintedImageHelper_DefineOptionArray(CMeterHistogram::c_BothOptionArray, L"Both" ** */ CMeterHistogram::CMeterHistogram(CMeterWindow* meterWindow, const WCHAR* name) : CMeter(meterWindow, name), - m_SecondaryMeasure(), m_PrimaryColor(Color::Green), m_SecondaryColor(Color::Red), m_OverlapColor(Color::Yellow), @@ -95,8 +94,10 @@ void CMeterHistogram::Initialize() { CMeter::Initialize(); + CMeasure* secondaryMeasure = (m_Measures.size() >= 2) ? m_Measures[1] : NULL; + // A sanity check - if (m_SecondaryMeasure && !m_PrimaryImageName.empty() && (m_OverlapImageName.empty() || m_SecondaryImageName.empty())) + if (secondaryMeasure && !m_PrimaryImageName.empty() && (m_OverlapImageName.empty() || m_SecondaryImageName.empty())) { Log(LOG_WARNING, L"Histogram: SecondaryImage and BothImage not defined"); @@ -168,7 +169,7 @@ void CMeterHistogram::Initialize() { int maxSize = m_GraphHorizontalOrientation ? m_H : m_W; m_PrimaryValues = new double[maxSize](); - if (m_SecondaryMeasure) + if (secondaryMeasure) { m_SecondaryValues = new double[maxSize](); } @@ -197,15 +198,6 @@ void CMeterHistogram::ReadOptions(CConfigParser& parser, const WCHAR* section) m_SecondaryColor = parser.ReadColor(section, L"SecondaryColor", Color::Red); m_OverlapColor = parser.ReadColor(section, L"BothColor", Color::Yellow); - if (!m_Initialized && !m_MeasureName.empty()) - { - m_SecondaryMeasureName = parser.ReadString(section, L"MeasureName2", L""); - if (m_SecondaryMeasureName.empty()) - { - m_SecondaryMeasureName = parser.ReadString(section, L"SecondaryMeasureName", L""); - } - } - m_PrimaryImageName = parser.ReadString(section, L"PrimaryImage", L""); if (!m_PrimaryImageName.empty()) { @@ -307,7 +299,7 @@ void CMeterHistogram::ReadOptions(CConfigParser& parser, const WCHAR* section) if (m_W > 0) { m_PrimaryValues = new double[m_W](); - if (m_SecondaryMeasure) + if (m_Measures.size() >= 2) { m_SecondaryValues = new double[m_W](); } @@ -330,7 +322,7 @@ void CMeterHistogram::ReadOptions(CConfigParser& parser, const WCHAR* section) if (m_H > 0) { m_PrimaryValues = new double[m_H](); - if (m_SecondaryMeasure) + if (m_Measures.size() >= 2) { m_SecondaryValues = new double[m_H](); } @@ -353,28 +345,31 @@ void CMeterHistogram::ReadOptions(CConfigParser& parser, const WCHAR* section) */ bool CMeterHistogram::Update() { - if (CMeter::Update() && m_Measure && m_PrimaryValues) + if (CMeter::Update() && !m_Measures.empty() && m_PrimaryValues) { - // Gather values - m_PrimaryValues[m_MeterPos] = m_Measure->GetValue(); + CMeasure* measure = m_Measures[0]; + CMeasure* secondaryMeasure = (m_Measures.size() >= 2) ? m_Measures[1] : NULL; - if (m_SecondaryMeasure && m_SecondaryValues) + // Gather values + m_PrimaryValues[m_MeterPos] = measure->GetValue(); + + if (secondaryMeasure && m_SecondaryValues) { - m_SecondaryValues[m_MeterPos] = m_SecondaryMeasure->GetValue(); + m_SecondaryValues[m_MeterPos] = secondaryMeasure->GetValue(); } ++m_MeterPos; int maxSize = m_GraphHorizontalOrientation ? m_H : m_W; m_MeterPos %= maxSize; - m_MaxPrimaryValue = m_Measure->GetMaxValue(); - m_MinPrimaryValue = m_Measure->GetMinValue(); + m_MaxPrimaryValue = measure->GetMaxValue(); + m_MinPrimaryValue = measure->GetMinValue(); m_MaxSecondaryValue = 0.0; m_MinSecondaryValue = 0.0; - if (m_SecondaryMeasure) + if (secondaryMeasure) { - m_MaxSecondaryValue = m_SecondaryMeasure->GetMaxValue(); - m_MinSecondaryValue = m_SecondaryMeasure->GetMinValue(); + m_MaxSecondaryValue = secondaryMeasure->GetMaxValue(); + m_MinSecondaryValue = secondaryMeasure->GetMinValue(); } if (m_Autoscale) @@ -401,7 +396,7 @@ bool CMeterHistogram::Update() } } - if (m_SecondaryMeasure && m_SecondaryValues) + if (secondaryMeasure && m_SecondaryValues) { for (int i = 0; i < maxSize; ++i) { @@ -435,8 +430,10 @@ bool CMeterHistogram::Update() bool CMeterHistogram::Draw(Graphics& graphics) { if (!CMeter::Draw(graphics) || - (m_Measure && !m_PrimaryValues) || - (m_SecondaryMeasure && !m_SecondaryValues)) return false; + (m_Measures.size() >= 1 && !m_PrimaryValues) || + (m_Measures.size() >= 2 && !m_SecondaryValues)) return false; + + CMeasure* secondaryMeasure = m_Measures[1]; GraphicsPath primaryPath; GraphicsPath secondaryPath; @@ -490,7 +487,7 @@ bool CMeterHistogram::Draw(Graphics& graphics) primaryBarHeight = min(m_W, primaryBarHeight); primaryBarHeight = max(0, primaryBarHeight); - if (m_SecondaryMeasure) + if (secondaryMeasure) { value = (m_MaxSecondaryValue == 0.0) ? 0.0 @@ -552,7 +549,7 @@ bool CMeterHistogram::Draw(Graphics& graphics) primaryBarHeight = min(m_H, primaryBarHeight); primaryBarHeight = max(0, primaryBarHeight); - if (m_SecondaryMeasure) + if (secondaryMeasure) { value = (m_MaxSecondaryValue == 0.0) ? 0.0 @@ -617,7 +614,7 @@ bool CMeterHistogram::Draw(Graphics& graphics) SolidBrush brush(m_PrimaryColor); graphics.FillPath(&brush, &primaryPath); } - if (m_SecondaryMeasure) + if (secondaryMeasure) { if (secondaryBitmap) { @@ -654,29 +651,25 @@ bool CMeterHistogram::Draw(Graphics& graphics) ** Overwritten method to handle the secondary measure binding. ** */ -void CMeterHistogram::BindMeasure(const std::list& measures) +void CMeterHistogram::BindMeasures(CConfigParser& parser, const WCHAR* section) { - CMeter::BindMeasure(measures); - - if (!m_SecondaryMeasureName.empty()) + if (BindPrimaryMeasure(parser, section, true)) { - // Go through the list and check it there is a secondary measure for us - const WCHAR* name = m_SecondaryMeasureName.c_str(); - std::list::const_iterator i = measures.begin(); - for ( ; i != measures.end(); ++i) + const std::wstring* secondaryMeasure = &parser.ReadString(section, L"MeasureName2", L""); + if (secondaryMeasure->empty()) { - if (_wcsicmp((*i)->GetName(), name) == 0) - { - m_SecondaryMeasure = (*i); - CMeter::SetAllMeasures(m_SecondaryMeasure); - return; - } + // For backwards compatibility. + secondaryMeasure = &parser.ReadString(section, L"SecondaryMeasureName", L""); } - std::wstring error = L"The meter [" + m_Name; - error += L"] cannot be bound with ["; - error += m_SecondaryMeasureName; - error += L']'; - throw CError(error); + CMeasure* measure = parser.GetMeasure(*secondaryMeasure); + if (measure) + { + m_Measures.push_back(measure); + } + else + { + LogWithArgs(LOG_ERROR, L"MeasureName%i=%s is not valid in [%s]", 2, secondaryMeasure->c_str(), section); + } } } diff --git a/Library/MeterHistogram.h b/Library/MeterHistogram.h index ba428376..859beee5 100644 --- a/Library/MeterHistogram.h +++ b/Library/MeterHistogram.h @@ -33,16 +33,14 @@ public: virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); - virtual void BindMeasure(const std::list& measures); protected: virtual void ReadOptions(CConfigParser& parser, const WCHAR* section); + virtual void BindMeasures(CConfigParser& parser, const WCHAR* section); private: void DisposeBuffer(); - std::wstring m_SecondaryMeasureName; - CMeasure* m_SecondaryMeasure; Gdiplus::Color m_PrimaryColor; Gdiplus::Color m_SecondaryColor; Gdiplus::Color m_OverlapColor; diff --git a/Library/MeterImage.cpp b/Library/MeterImage.cpp index b1a7fd9c..316f38a1 100644 --- a/Library/MeterImage.cpp +++ b/Library/MeterImage.cpp @@ -55,7 +55,7 @@ void CMeterImage::Initialize() { CMeter::Initialize(); - if (!m_Measure && !m_DynamicVariables && !m_ImageName.empty()) + if (m_Measures.empty() && !m_DynamicVariables && !m_ImageName.empty()) { m_ImageNameResult = m_Path; m_ImageNameResult += m_ImageName; @@ -110,12 +110,6 @@ void CMeterImage::ReadOptions(CConfigParser& parser, const WCHAR* section) { CMeter::ReadOptions(parser, section); - // Check for extra measures - if (!m_Initialized && !m_MeasureName.empty()) - { - ReadMeasureNames(parser, section, m_MeasureNames); - } - m_Path = parser.ReadString(section, L"Path", L""); if (!m_Path.empty()) { @@ -136,8 +130,7 @@ void CMeterImage::ReadOptions(CConfigParser& parser, const WCHAR* section) // Read tinting options m_Image.ReadOptions(parser, section); - if (m_Initialized && - !m_Measure && !m_DynamicVariables) + if (m_Initialized && m_Measures.empty() && !m_DynamicVariables) { Initialize(); m_NeedsRedraw = true; @@ -152,14 +145,14 @@ bool CMeterImage::Update() { if (CMeter::Update()) { - if (m_Measure || m_DynamicVariables) + if (!m_Measures.empty() || m_DynamicVariables) { // Store the current values so we know if the image needs to be updated std::wstring oldResult = m_ImageNameResult; - if (m_Measure) // read from the measures + if (!m_Measures.empty()) // read from the measures { - std::wstring val = m_Measure->GetStringValue(AUTOSCALE_OFF, 1, 0, false); + std::wstring val = m_Measures[0]->GetStringValue(AUTOSCALE_OFF, 1, 0, false); if (m_ImageName.empty()) { @@ -346,35 +339,10 @@ bool CMeterImage::Draw(Graphics& graphics) ** Overridden method. The Image meters need not to be bound on anything ** */ -void CMeterImage::BindMeasure(const std::list& measures) +void CMeterImage::BindMeasures(CConfigParser& parser, const WCHAR* section) { - if (m_MeasureName.empty()) return; // Allow NULL measure binding - - CMeter::BindMeasure(measures); - - std::vector::const_iterator j = m_MeasureNames.begin(); - for (; j != m_MeasureNames.end(); ++j) + if (BindPrimaryMeasure(parser, section, true)) { - // Go through the list and check it there is a secondary measures for us - const WCHAR* name = (*j).c_str(); - std::list::const_iterator i = measures.begin(); - for ( ; i != measures.end(); ++i) - { - if (_wcsicmp((*i)->GetName(), name) == 0) - { - m_Measures.push_back(*i); - break; - } - } - - if (i == measures.end()) - { - std::wstring error = L"The meter [" + m_Name; - error += L"] cannot be bound with ["; - error += (*j); - error += L']'; - throw CError(error); - } + BindSecondaryMeasures(parser, section); } - CMeter::SetAllMeasures(m_Measures); } diff --git a/Library/MeterImage.h b/Library/MeterImage.h index e68355d4..fffd23fc 100644 --- a/Library/MeterImage.h +++ b/Library/MeterImage.h @@ -33,10 +33,10 @@ public: virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); - virtual void BindMeasure(const std::list& measures); protected: virtual void ReadOptions(CConfigParser& parser, const WCHAR* section); + virtual void BindMeasures(CConfigParser& parser, const WCHAR* section); private: void LoadImage(const std::wstring& imageName, bool bLoadAlways); @@ -53,7 +53,6 @@ private: RECT m_ScaleMargins; std::vector m_MeasureNames; - std::vector m_Measures; }; #endif diff --git a/Library/MeterLine.cpp b/Library/MeterLine.cpp index d315211f..9e146f95 100644 --- a/Library/MeterLine.cpp +++ b/Library/MeterLine.cpp @@ -137,15 +137,6 @@ void CMeterLine::ReadOptions(CConfigParser& parser, const WCHAR* section) } m_ScaleValues.push_back(parser.ReadFloat(section, tmpName, 1.0)); - - if (!m_Initialized && !m_MeasureName.empty()) - { - if (i != 0) - { - _snwprintf_s(tmpName, _TRUNCATE, L"MeasureName%i", i + 1); - m_MeasureNames.push_back(parser.ReadString(section, tmpName, L"")); - } - } } m_Flip = 0!=parser.ReadInt(section, L"Flip", 0); @@ -218,21 +209,13 @@ void CMeterLine::ReadOptions(CConfigParser& parser, const WCHAR* section) */ bool CMeterLine::Update() { - if (CMeter::Update() && m_Measure) + if (CMeter::Update() && !m_Measures.empty()) { int maxSize = m_GraphHorizontalOrientation ? m_H : m_W; if (maxSize > 0) { - // Collect the values - if (!m_Measure->IsDisabled()) - { - double value = m_Measure->GetValue(); - - m_AllValues[0][m_CurrentPos] = value; - } - - int counter = 1; + int counter = 0; std::vector::const_iterator i = m_Measures.begin(); for ( ; i != m_Measures.end(); ++i) { @@ -296,9 +279,9 @@ bool CMeterLine::Draw(Graphics& graphics) } else { - if (m_Measure) + if (!m_Measures.empty()) { - maxValue = m_Measure->GetMaxValue(); + double maxValue = m_Measures[0]->GetMaxValue(); std::vector::const_iterator i = m_Measures.begin(); for (; i != m_Measures.end(); ++i) @@ -484,33 +467,10 @@ bool CMeterLine::Draw(Graphics& graphics) ** Overwritten method to handle the other measure bindings. ** */ -void CMeterLine::BindMeasure(const std::list& measures) +void CMeterLine::BindMeasures(CConfigParser& parser, const WCHAR* section) { - CMeter::BindMeasure(measures); - - std::vector::const_iterator j = m_MeasureNames.begin(); - for (; j != m_MeasureNames.end(); ++j) + if (BindPrimaryMeasure(parser, section, true)) { - // Go through the list and check it there is a secondary measure for us - const WCHAR* name = (*j).c_str(); - std::list::const_iterator i = measures.begin(); - for ( ; i != measures.end(); ++i) - { - if (_wcsicmp((*i)->GetName(), name) == 0) - { - m_Measures.push_back(*i); - break; - } - } - - if (i == measures.end()) - { - std::wstring error = L"The meter [" + m_Name; - error += L"] cannot be bound with ["; - error += (*j); - error += L']'; - throw CError(error); - } + BindSecondaryMeasures(parser, section); } - CMeter::SetAllMeasures(m_Measures); } diff --git a/Library/MeterLine.h b/Library/MeterLine.h index 65c407d7..b51e22ee 100644 --- a/Library/MeterLine.h +++ b/Library/MeterLine.h @@ -32,15 +32,12 @@ public: virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); - virtual void BindMeasure(const std::list& measures); protected: virtual void ReadOptions(CConfigParser& parser, const WCHAR* section); + virtual void BindMeasures(CConfigParser& parser, const WCHAR* section); private: - std::vector m_MeasureNames; - std::vector m_Measures; - std::vector m_Colors; std::vector m_ScaleValues; diff --git a/Library/MeterRotator.cpp b/Library/MeterRotator.cpp index 6827c375..868f81ae 100644 --- a/Library/MeterRotator.cpp +++ b/Library/MeterRotator.cpp @@ -122,17 +122,18 @@ void CMeterRotator::ReadOptions(CConfigParser& parser, const WCHAR* section) */ bool CMeterRotator::Update() { - if (CMeter::Update() && m_Measure) + if (CMeter::Update() && !m_Measures.empty()) { + CMeasure* measure = m_Measures[0]; if (m_ValueRemainder > 0) { - LONGLONG time = (LONGLONG)m_Measure->GetValue(); + LONGLONG time = (LONGLONG)measure->GetValue(); m_Value = (double)(time % m_ValueRemainder); m_Value /= (double)m_ValueRemainder; } else { - m_Value = m_Measure->GetRelativeValue(); + m_Value = measure->GetRelativeValue(); } return true; } diff --git a/Library/MeterRoundLine.cpp b/Library/MeterRoundLine.cpp index e800baf2..0d3f086d 100644 --- a/Library/MeterRoundLine.cpp +++ b/Library/MeterRoundLine.cpp @@ -86,17 +86,18 @@ void CMeterRoundLine::ReadOptions(CConfigParser& parser, const WCHAR* section) */ bool CMeterRoundLine::Update() { - if (CMeter::Update() && m_Measure) + if (CMeter::Update() && !m_Measures.empty()) { + CMeasure* measure = m_Measures[0]; if (m_ValueRemainder > 0) { - LONGLONG time = (LONGLONG)m_Measure->GetValue(); + LONGLONG time = (LONGLONG)measure->GetValue(); m_Value = (double)(time % m_ValueRemainder); m_Value /= (double)m_ValueRemainder; } else { - m_Value = m_Measure->GetRelativeValue(); + m_Value = measure->GetRelativeValue(); } return true; } diff --git a/Library/MeterString.cpp b/Library/MeterString.cpp index 047e859a..b2a3244b 100644 --- a/Library/MeterString.cpp +++ b/Library/MeterString.cpp @@ -319,12 +319,6 @@ void CMeterString::ReadOptions(CConfigParser& parser, const WCHAR* section) CMeter::ReadOptions(parser, section); - // Check for extra measures - if (!m_Initialized && !m_MeasureName.empty()) - { - ReadMeasureNames(parser, section, m_MeasureNames); - } - m_Color = parser.ReadColor(section, L"FontColor", Color::Black); m_EffectColor = parser.ReadColor(section, L"FontEffectColor", Color::Black); @@ -494,13 +488,9 @@ bool CMeterString::Update() { if (CMeter::Update()) { - std::vector stringValues; - int decimals = (m_NumOfDecimals != -1) ? m_NumOfDecimals : (m_NoDecimals && (m_Percentual || m_AutoScale == AUTOSCALE_OFF)) ? 0 : 1; - if (m_Measure) stringValues.push_back(m_Measure->GetStringValue(m_AutoScale, m_Scale, decimals, m_Percentual)); - - // Get the values for the other measures + std::vector stringValues; std::vector::const_iterator iter = m_Measures.begin(); for ( ; iter != m_Measures.end(); ++iter) { @@ -716,37 +706,12 @@ bool CMeterString::DrawString(Graphics& graphics, RectF* rect) ** Overridden method. The string meters need not to be bound on anything ** */ -void CMeterString::BindMeasure(const std::list& measures) +void CMeterString::BindMeasures(CConfigParser& parser, const WCHAR* section) { - if (m_MeasureName.empty()) return; // Allow NULL measure binding - - CMeter::BindMeasure(measures); - - std::vector::const_iterator j = m_MeasureNames.begin(); - for (; j != m_MeasureNames.end(); ++j) + if (BindPrimaryMeasure(parser, section, true)) { - // Go through the list and check it there is a secondary measures for us - const WCHAR* name = (*j).c_str(); - std::list::const_iterator i = measures.begin(); - for ( ; i != measures.end(); ++i) - { - if (_wcsicmp((*i)->GetName(), name) == 0) - { - m_Measures.push_back(*i); - break; - } - } - - if (i == measures.end()) - { - std::wstring error = L"The meter [" + m_Name; - error += L"] cannot be bound with ["; - error += (*j); - error += L"]"; - throw CError(error); - } + BindSecondaryMeasures(parser, section); } - CMeter::SetAllMeasures(m_Measures); } /* diff --git a/Library/MeterString.h b/Library/MeterString.h index 26dafb15..4e34eac9 100644 --- a/Library/MeterString.h +++ b/Library/MeterString.h @@ -38,7 +38,6 @@ public: virtual bool Update(); void SetText(const WCHAR* text) { m_Text = text; } virtual bool Draw(Gdiplus::Graphics& graphics); - virtual void BindMeasure(const std::list& measures); Gdiplus::RectF GetRect() { return m_Rect; } static void FreeFontCache(Gdiplus::PrivateFontCollection* collection = NULL); @@ -46,6 +45,7 @@ public: protected: virtual void ReadOptions(CConfigParser& parser, const WCHAR* section); + virtual void BindMeasures(CConfigParser& parser, const WCHAR* section); private: enum TEXTSTYLE @@ -97,9 +97,6 @@ private: std::wstring m_String; - std::vector m_MeasureNames; - std::vector m_Measures; - static std::wstring FontFaceToString(const std::wstring& fontFace, Gdiplus::PrivateFontCollection* collection); static std::wstring FontPropertiesToString(Gdiplus::REAL size, Gdiplus::FontStyle style); diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 6e2539f4..da00a2f9 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -2225,14 +2225,7 @@ bool CMeterWindow::ReadSkin() std::list::const_iterator j = m_Meters.begin(); for ( ; j != m_Meters.end(); ++j) { - try - { - (*j)->BindMeasure(m_Measures); - } - catch (CError& error) - { - LogError(error); - } + (*j)->BindMeasures(m_Parser); } }