diff --git a/Library/DialogAbout.cpp b/Library/DialogAbout.cpp index 8a9123e8..a97efb8e 100644 --- a/Library/DialogAbout.cpp +++ b/Library/DialogAbout.cpp @@ -747,8 +747,8 @@ void CDialogAbout::CTabSkins::UpdateMeasureList(CMeterWindow* meterWindow) lvi.lParam = 0; lvi.iGroupId = 0; - const std::list& measures = m_SkinWindow->GetMeasures(); - std::list::const_iterator j = measures.begin(); + const std::vector& measures = m_SkinWindow->GetMeasures(); + std::vector::const_iterator j = measures.begin(); for ( ; j != measures.end(); ++j) { lvi.pszText = (WCHAR*)(*j)->GetName(); diff --git a/Library/MeasureCalc.cpp b/Library/MeasureCalc.cpp index 341e4faf..2b787990 100644 --- a/Library/MeasureCalc.cpp +++ b/Library/MeasureCalc.cpp @@ -147,9 +147,9 @@ void CMeasureCalc::FormulaReplace() bool CMeasureCalc::GetMeasureValue(const WCHAR* str, int len, double* value) { - const std::list& measures = m_MeterWindow->GetMeasures(); + const std::vector& measures = m_MeterWindow->GetMeasures(); - std::list::const_iterator iter = measures.begin(); + std::vector::const_iterator iter = measures.begin(); for ( ; iter != measures.end(); ++iter) { if ((*iter)->GetOriginalName().length() == len && diff --git a/Library/Meter.cpp b/Library/Meter.cpp index f70e1f04..de7e7559 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -92,7 +92,7 @@ void CMeter::Initialize() if (!m_RelativeMeter) { - const std::list& meters = m_MeterWindow->GetMeters(); + const std::vector& meters = m_MeterWindow->GetMeters(); for (auto iter = meters.cbegin(); iter != meters.cend(); ++iter) { if (*iter == this) @@ -251,6 +251,11 @@ void CMeter::ReadOptions(CConfigParser& parser, const WCHAR* section) parser.SetStyleTemplate(style); } + if (!m_Initialized) + { + BindMeasures(parser, section); + } + int oldX = m_X; std::wstring& x = (std::wstring&)parser.ReadString(section, L"X", L"0"); if (!x.empty()) @@ -455,12 +460,6 @@ bool CMeter::Update() */ bool CMeter::BindPrimaryMeasure(CConfigParser& parser, const WCHAR* section, bool optional) { - const std::wstring& style = parser.ReadString(section, L"MeterStyle", L""); - if (!style.empty()) - { - parser.SetStyleTemplate(style); - } - const std::wstring& measureName = parser.ReadString(section, L"MeasureName", L""); // The meter is not bound to anything diff --git a/Library/Meter.h b/Library/Meter.h index 9de02ace..41832091 100644 --- a/Library/Meter.h +++ b/Library/Meter.h @@ -40,7 +40,6 @@ public: virtual UINT GetTypeID() = 0; void ReadOptions(CConfigParser& parser) { ReadOptions(parser, GetName()); parser.ClearStyleTemplate(); } - void BindMeasures(CConfigParser& parser) { BindMeasures(parser, GetName()); parser.ClearStyleTemplate(); } virtual void Initialize(); virtual bool Update(); diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index da00a2f9..2a58f144 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -186,14 +186,14 @@ CMeterWindow::~CMeterWindow() KillTimer(m_Window, TIMER_TRANSITION); // Destroy the meters - std::list::iterator j = m_Meters.begin(); + std::vector::iterator j = m_Meters.begin(); for ( ; j != m_Meters.end(); ++j) { delete (*j); } // Destroy the measures - std::list::iterator i = m_Measures.begin(); + std::vector::iterator i = m_Measures.begin(); for ( ; i != m_Measures.end(); ++i) { delete (*i); @@ -356,14 +356,14 @@ void CMeterWindow::Refresh(bool init, bool all) m_MouseOver = false; SetMouseLeaveEvent(true); - std::list::iterator i = m_Measures.begin(); + std::vector::iterator i = m_Measures.begin(); for ( ; i != m_Measures.end(); ++i) { delete (*i); } m_Measures.clear(); - std::list::iterator j = m_Meters.begin(); + std::vector::iterator j = m_Meters.begin(); for ( ; j != m_Meters.end(); ++j) { delete (*j); @@ -1094,7 +1094,7 @@ void CMeterWindow::ShowMeter(const std::wstring& name, bool group) { const WCHAR* meter = name.c_str(); - std::list::const_iterator j = m_Meters.begin(); + std::vector::const_iterator j = m_Meters.begin(); for ( ; j != m_Meters.end(); ++j) { if (CompareName((*j), meter, group)) @@ -1116,7 +1116,7 @@ void CMeterWindow::HideMeter(const std::wstring& name, bool group) { const WCHAR* meter = name.c_str(); - std::list::const_iterator j = m_Meters.begin(); + std::vector::const_iterator j = m_Meters.begin(); for ( ; j != m_Meters.end(); ++j) { if (CompareName((*j), meter, group)) @@ -1138,7 +1138,7 @@ void CMeterWindow::ToggleMeter(const std::wstring& name, bool group) { const WCHAR* meter = name.c_str(); - std::list::const_iterator j = m_Meters.begin(); + std::vector::const_iterator j = m_Meters.begin(); for ( ; j != m_Meters.end(); ++j) { if (CompareName((*j), meter, group)) @@ -1167,7 +1167,7 @@ void CMeterWindow::MoveMeter(const std::wstring& name, int x, int y) { const WCHAR* meter = name.c_str(); - std::list::const_iterator j = m_Meters.begin(); + std::vector::const_iterator j = m_Meters.begin(); for ( ; j != m_Meters.end(); ++j) { if (CompareName((*j), meter, false)) @@ -1192,7 +1192,7 @@ void CMeterWindow::UpdateMeter(const std::wstring& name, bool group) bool bActiveTransition = false; bool bContinue = true; - std::list::const_iterator j = m_Meters.begin(); + std::vector::const_iterator j = m_Meters.begin(); for ( ; j != m_Meters.end(); ++j) { if (bContinue && CompareName((*j), meter, group)) @@ -1230,7 +1230,7 @@ void CMeterWindow::EnableMeasure(const std::wstring& name, bool group) { const WCHAR* measure = name.c_str(); - std::list::const_iterator i = m_Measures.begin(); + std::vector::const_iterator i = m_Measures.begin(); for ( ; i != m_Measures.end(); ++i) { if (CompareName((*i), measure, group)) @@ -1251,7 +1251,7 @@ void CMeterWindow::DisableMeasure(const std::wstring& name, bool group) { const WCHAR* measure = name.c_str(); - std::list::const_iterator i = m_Measures.begin(); + std::vector::const_iterator i = m_Measures.begin(); for ( ; i != m_Measures.end(); ++i) { if (CompareName((*i), measure, group)) @@ -1272,7 +1272,7 @@ void CMeterWindow::ToggleMeasure(const std::wstring& name, bool group) { const WCHAR* measure = name.c_str(); - std::list::const_iterator i = m_Measures.begin(); + std::vector::const_iterator i = m_Measures.begin(); for ( ; i != m_Measures.end(); ++i) { if (CompareName((*i), measure, group)) @@ -1301,7 +1301,7 @@ void CMeterWindow::UpdateMeasure(const std::wstring& name, bool group) const WCHAR* measure = name.c_str(); bool bNetStats = m_HasNetMeasures; - std::list::const_iterator i = m_Measures.begin(); + std::vector::const_iterator i = m_Measures.begin(); for ( ; i != m_Measures.end(); ++i) { if (CompareName((*i), measure, group)) @@ -1352,7 +1352,7 @@ void CMeterWindow::SetOption(const std::wstring& section, const std::wstring& op { if (group) { - for (std::list::const_iterator j = m_Meters.begin(); j != m_Meters.end(); ++j) + for (std::vector::const_iterator j = m_Meters.begin(); j != m_Meters.end(); ++j) { if ((*j)->BelongsToGroup(section)) { @@ -1370,7 +1370,7 @@ void CMeterWindow::SetOption(const std::wstring& section, const std::wstring& op } } - for (std::list::const_iterator i = m_Measures.begin(); i != m_Measures.end(); ++i) + for (std::vector::const_iterator i = m_Measures.begin(); i != m_Measures.end(); ++i) { if ((*i)->BelongsToGroup(section)) { @@ -2130,12 +2130,9 @@ bool CMeterWindow::ReadSkin() while (*localFont); } - // Create the meters and measures - - m_HasNetMeasures = false; - m_HasButtons = false; - - // Get all the sections (i.e. different meters, measures and the other stuff) + // Create all meters and measures. + std::list meters; + std::list measures; std::list::const_iterator iter = m_Parser.GetSections().begin(); for ( ; iter != m_Parser.GetSections().end(); ++iter) { @@ -2145,34 +2142,13 @@ bool CMeterWindow::ReadSkin() _wcsicmp(L"Variables", section) != 0 && _wcsicmp(L"Metadata", section) != 0) { - // Check if the item is a meter or a measure (or perhaps something else) const std::wstring& measureName = m_Parser.ReadString(section, L"Measure", L"", false); if (!measureName.empty()) { - // It's a measure - CMeasure* measure = NULL; - - try + CMeasure* measure = CMeasure::Create(measureName.c_str(), this, section); + if (measure) { - measure = CMeasure::Create(measureName.c_str(), this, section); - if (measure) - { - measure->ReadOptions(m_Parser); - - m_Measures.push_back(measure); - m_Parser.AddMeasure(measure); - - if (measure->GetTypeID() == TypeID()) - { - m_HasNetMeasures = true; - } - } - } - catch (CError& error) - { - delete measure; - measure = NULL; - LogError(error); + measures.push_back(measure); } continue; @@ -2182,34 +2158,65 @@ bool CMeterWindow::ReadSkin() if (!meterName.empty()) { // It's a meter - CMeter* meter = NULL; - - try + CMeter* meter = CMeter::Create(meterName.c_str(), this, section); + if (meter) { - meter = CMeter::Create(meterName.c_str(), this, section); - if (meter) - { - meter->ReadOptions(m_Parser); - - m_Meters.push_back(meter); - - if (!m_HasButtons && meter->GetTypeID() == TypeID()) - { - m_HasButtons = true; - } - } - } - catch (CError& error) - { - delete meter; - meter = NULL; - LogError(error); + meters.push_back(meter); } continue; } + } + } - // If it's not a meter or measure it will be ignored + m_HasNetMeasures = false; + m_HasButtons = false; + + // Measures must be created first to avoid errors in meters referencing measures. + m_Measures.reserve(measures.size()); + for (auto iter = measures.cbegin(); iter != measures.cend(); ++iter) + { + CMeasure* measure = *iter; + + try + { + measure->ReadOptions(m_Parser); + m_Measures.push_back(measure); + m_Parser.AddMeasure(measure); + + if (measure->GetTypeID() == TypeID()) + { + m_HasNetMeasures = true; + } + } + catch (CError& error) + { + delete measure; + measure = NULL; + LogError(error); + } + } + + m_Meters.reserve(meters.size()); + for (auto iter = meters.cbegin(); iter != meters.cend(); ++iter) + { + CMeter* meter = *iter; + + try + { + meter->ReadOptions(m_Parser); + m_Meters.push_back(meter); + + if (!m_HasButtons && meter->GetTypeID() == TypeID()) + { + m_HasButtons = true; + } + } + catch (CError& error) + { + delete meter; + meter = NULL; + LogError(error); } } @@ -2219,15 +2226,6 @@ bool CMeterWindow::ReadSkin() Rainmeter->ShowMessage(m_Window, text.c_str(), MB_OK | MB_ICONEXCLAMATION); return false; } - else - { - // Bind the meters to the measures - std::list::const_iterator j = m_Meters.begin(); - for ( ; j != m_Meters.end(); ++j) - { - (*j)->BindMeasures(m_Parser); - } - } return true; } @@ -2239,7 +2237,7 @@ bool CMeterWindow::ReadSkin() void CMeterWindow::InitializeMeasures() { // Initalize all measures - std::list::const_iterator i = m_Measures.begin(); + std::vector::const_iterator i = m_Measures.begin(); for ( ; i != m_Measures.end(); ++i) { try @@ -2260,7 +2258,7 @@ void CMeterWindow::InitializeMeasures() void CMeterWindow::InitializeMeters() { // Initalize all meters - std::list::const_iterator j = m_Meters.begin(); + std::vector::const_iterator j = m_Meters.begin(); for ( ; j != m_Meters.end(); ++j) { try @@ -2288,7 +2286,7 @@ bool CMeterWindow::ResizeWindow(bool reset) int h = m_BackgroundMargins.top; // Get the largest meter point - std::list::const_iterator j = m_Meters.begin(); + std::vector::const_iterator j = m_Meters.begin(); for ( ; j != m_Meters.end(); ++j) { int mr = (*j)->GetX() + (*j)->GetW(); @@ -2568,7 +2566,7 @@ void CMeterWindow::Redraw() } // Draw the meters - std::list::const_iterator j = m_Meters.begin(); + std::vector::const_iterator j = m_Meters.begin(); for ( ; j != m_Meters.end(); ++j) { const Matrix* matrix = (*j)->GetTransformationMatrix(); @@ -2724,7 +2722,7 @@ void CMeterWindow::Update(bool refresh) } // Update all measures - std::list::const_iterator i = m_Measures.begin(); + std::vector::const_iterator i = m_Measures.begin(); for ( ; i != m_Measures.end(); ++i) { UpdateMeasure((*i), refresh); @@ -2736,7 +2734,7 @@ void CMeterWindow::Update(bool refresh) // Update all meters bool bActiveTransition = false; bool bUpdate = false; - std::list::const_iterator j = m_Meters.begin(); + std::vector::const_iterator j = m_Meters.begin(); for ( ; j != m_Meters.end(); ++j) { if (UpdateMeter((*j), bActiveTransition, refresh)) @@ -2857,7 +2855,7 @@ LRESULT CMeterWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam) { // Redraw only if there is active transition still going bool bActiveTransition = false; - std::list::const_iterator j = m_Meters.begin(); + std::vector::const_iterator j = m_Meters.begin(); for ( ; j != m_Meters.end(); ++j) { if ((*j)->HasActiveTransition()) @@ -3119,7 +3117,7 @@ void CMeterWindow::HandleButtons(POINT pos, BUTTONPROC proc, bool execute) bool redraw = false; HCURSOR cursor = NULL; - std::list::const_reverse_iterator j = m_Meters.rbegin(); + std::vector::const_reverse_iterator j = m_Meters.rbegin(); for ( ; j != m_Meters.rend(); ++j) { // Hidden meters are ignored @@ -4145,7 +4143,7 @@ bool CMeterWindow::DoAction(int x, int y, MOUSEACTION action, bool test) const WCHAR* command = NULL; // Check if the hitpoint was over some meter - std::list::const_reverse_iterator j = m_Meters.rbegin(); + std::vector::const_reverse_iterator j = m_Meters.rbegin(); for ( ; j != m_Meters.rend(); ++j) { // Hidden meters are ignored @@ -4186,7 +4184,7 @@ bool CMeterWindow::DoMoveAction(int x, int y, MOUSEACTION action) bool buttonFound = false; // Check if the hitpoint was over some meter - std::list::const_reverse_iterator j = m_Meters.rbegin(); + std::vector::const_reverse_iterator j = m_Meters.rbegin(); for ( ; j != m_Meters.rend(); ++j) { if (!(*j)->IsHidden() && (*j)->HitTest(x, y)) @@ -4572,7 +4570,7 @@ std::wstring CMeterWindow::GetResourcesPath() CMeter* CMeterWindow::GetMeter(const std::wstring& meterName) { const WCHAR* name = meterName.c_str(); - std::list::const_iterator j = m_Meters.begin(); + std::vector::const_iterator j = m_Meters.begin(); for ( ; j != m_Meters.end(); ++j) { if (_wcsicmp((*j)->GetName(), name) == 0) diff --git a/Library/MeterWindow.h b/Library/MeterWindow.h index bd4c9c2e..ec673284 100644 --- a/Library/MeterWindow.h +++ b/Library/MeterWindow.h @@ -202,8 +202,8 @@ public: std::wstring GetRootPath(); std::wstring GetResourcesPath(); - std::list& GetMeasures() { return m_Measures; } - std::list& GetMeters() { return m_Meters; } + const std::vector& GetMeasures() { return m_Measures; } + const std::vector& GetMeters() { return m_Meters; } ZPOSITION GetWindowZPosition() { return m_WindowZPosition; } bool GetXPercentage() { return m_WindowXPercentage; } @@ -421,8 +421,8 @@ private: bool m_Hidden; RESIZEMODE m_ResizeWindow; - std::list m_Measures; - std::list m_Meters; + std::vector m_Measures; + std::vector m_Meters; const std::wstring m_FolderPath; const std::wstring m_FileName;