diff --git a/geometry/tree4d.hpp b/geometry/tree4d.hpp index 2634664715..379cd24369 100644 --- a/geometry/tree4d.hpp +++ b/geometry/tree4d.hpp @@ -43,6 +43,15 @@ namespace m4 (m_pts[3] <= r.minY()) || (m_pts[1] >= r.maxY())); } + bool operator ==(value_t const & r) const + { + return ((m_val == r.m_val) + && (m_pts[0] == r.m_pts[0]) + && (m_pts[1] == r.m_pts[1]) + && (m_pts[2] == r.m_pts[2]) + && (m_pts[3] == r.m_pts[3])); + } + double operator[](size_t i) const { return m_pts[i]; } m2::RectD GetRect() const { return m2::RectD(m_pts[0], m_pts[1], m_pts[2], m_pts[3]); } @@ -154,13 +163,7 @@ namespace m4 void Erase(T const & obj) { - vector v; - for (typename tree_t::const_iterator i = m_tree.begin(); i != m_tree.end(); ++i) - if ((*i).m_val == obj) - v.push_back(*i); - - for (unsigned i = 0; i < v.size(); ++i) - m_tree.erase(v[i]); + m_tree.erase_exact(value_t(obj, Traits::LimitRect(obj))); } template diff --git a/gui/controller.cpp b/gui/controller.cpp index 90c8baf5f9..d06a17d7f6 100644 --- a/gui/controller.cpp +++ b/gui/controller.cpp @@ -82,17 +82,47 @@ namespace gui return false; } + struct FindByPointer + { + yg::OverlayElement const * m_e; + shared_ptr * m_res; + FindByPointer(yg::OverlayElement const * e, + shared_ptr * res) : m_e(e), m_res(res) + {} + + void operator()(shared_ptr const & oe) + { + if (m_e == oe.get()) + *m_res = oe; + } + }; + + shared_ptr const Controller::FindElement(Element const * e) + { + shared_ptr res; + shared_ptr resBase; + FindByPointer fn(e, &resBase); + + m_Overlay.forEach(fn); + + if (fn.m_res) + res = boost::static_pointer_cast(resBase); + + return res; + } + + void Controller::RemoveElement(shared_ptr const & e) + { + m_Overlay.removeOverlayElement(e); + e->m_controller = 0; + } + void Controller::AddElement(shared_ptr const & e) { m_Overlay.processOverlayElement(e); e->m_controller = this; } - void Controller::UpdateElement(Element * e) - { - m_Overlay.updateOverlayElement(e); - } - double Controller::VisualScale() const { return m_VisualScale; diff --git a/gui/controller.hpp b/gui/controller.hpp index bab382efc3..dfa44bd273 100644 --- a/gui/controller.hpp +++ b/gui/controller.hpp @@ -68,10 +68,12 @@ namespace gui void SetVisualScale(double val); /// Invalidate the scene void Invalidate(); + /// Find shared_ptr from the pointer in m_Overlay + shared_ptr const FindElement(Element const * e); + /// Remove GUI element by pointer + void RemoveElement(shared_ptr const & e); /// Add GUI element to the controller void AddElement(shared_ptr const & e); - /// Update element position in the Overlay, as it's coordinates might have changed. - void UpdateElement(Element * e); /// Get VisualScale parameter double VisualScale() const; /// Redraw GUI diff --git a/gui/element.cpp b/gui/element.cpp index e6b19c5363..c792af51c6 100644 --- a/gui/element.cpp +++ b/gui/element.cpp @@ -60,13 +60,19 @@ namespace gui void Element::setPivot(m2::PointD const & pv) { + shared_ptr e = m_controller->FindElement(this); + Controller * controller = m_controller; + controller->RemoveElement(e); OverlayElement::setPivot(pv); - m_controller->UpdateElement(this); + controller->AddElement(e); } void Element::offset(m2::PointD const & offs) { + shared_ptr e = m_controller->FindElement(this); + Controller * controller = m_controller; + controller->RemoveElement(e); OverlayElement::offset(offs); - m_controller->UpdateElement(this); + controller->AddElement(e); } } diff --git a/yg/overlay.cpp b/yg/overlay.cpp index 854739ec74..36dce7d0ab 100644 --- a/yg/overlay.cpp +++ b/yg/overlay.cpp @@ -221,34 +221,6 @@ namespace yg m_tree.Erase(oe); } - struct FindByPointer - { - OverlayElement * m_e; - shared_ptr * m_res; - FindByPointer(OverlayElement * e, shared_ptr * res) : m_e(e), m_res(res) - {} - - void operator()(shared_ptr const & oe) - { - if (m_e == oe.get()) - *m_res = oe; - } - }; - - void Overlay::updateOverlayElement(OverlayElement *oe) - { - shared_ptr res; - FindByPointer fn(oe, &res); - - m_tree.ForEach(fn); - - if (res) - { - m_tree.Erase(res); - m_tree.Add(res); - } - } - void Overlay::processOverlayElement(shared_ptr const & oe, math::Matrix const & m) { if (m != math::Identity()) diff --git a/yg/overlay.hpp b/yg/overlay.hpp index fef884bb75..189632f576 100644 --- a/yg/overlay.hpp +++ b/yg/overlay.hpp @@ -41,8 +41,6 @@ namespace yg void removeOverlayElement(shared_ptr const & oe); - void updateOverlayElement(OverlayElement * oe); - void processOverlayElement(shared_ptr const & oe); void processOverlayElement(shared_ptr const & oe, math::Matrix const & m);