diff options
author | ExMix <rahuba.youri@mapswithme.com> | 2014-05-30 18:31:46 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:16:16 +0300 |
commit | 16429903fc9ce0fbb5413f39508ae63d9699a962 (patch) | |
tree | 4e496f563efc728ee77d19eb26ef5bf4956462dc /map/user_mark_container.cpp | |
parent | 9f9d9e1269d63c3b1882b69ad88cd2450d3ae882 (diff) |
[core] move selection drawing into separate container, because when re-search on viewport changed search container cleared, and it's clear selection
Diffstat (limited to 'map/user_mark_container.cpp')
-rw-r--r-- | map/user_mark_container.cpp | 212 |
1 files changed, 120 insertions, 92 deletions
diff --git a/map/user_mark_container.cpp b/map/user_mark_container.cpp index b978fb8c29..59b80e33da 100644 --- a/map/user_mark_container.cpp +++ b/map/user_mark_container.cpp @@ -71,14 +71,66 @@ namespace m2::AnyRectD const & m_rect; m2::PointD m_globalCenter; }; + + void DrawUserMarkByPoint(double scale, + double visualScale, + m2::PointD const & pixelOfsset, + PaintOverlayEvent const & event, + graphics::DisplayList * dl, + m2::PointD const & ptOrg) + { + ScreenBase modelView = event.GetModelView(); + graphics::Screen * screen = event.GetDrawer()->screen(); + m2::PointD pxPoint = modelView.GtoP(ptOrg); + pxPoint += (pixelOfsset * visualScale); + math::Matrix<double, 3, 3> m = math::Shift(math::Scale(math::Identity<double, 3>(), + scale, scale), + pxPoint.x, pxPoint.y); + dl->draw(screen, m); + } + + void DrawUserMarkImpl(double scale, + double visualScale, + m2::PointD const & pixelOfsset, + PaintOverlayEvent const & event, + graphics::DisplayList * dl, + UserMark const * mark) + { + DrawUserMarkByPoint(scale, visualScale, pixelOfsset, event, dl, mark->GetOrg()); + } + + void DrawUserMark(double scale, + double visualScale, + PaintOverlayEvent const & event, + UserMarkDLCache * cache, + UserMarkDLCache::Key const & defaultKey, + UserMark const * mark) + { + if (mark->IsCustomDrawable()) + { + ICustomDrawable const * drawable = static_cast<ICustomDrawable const *>(mark); + DrawUserMarkImpl(drawable->GetAnimScaleFactor(), visualScale, drawable->GetPixelOffset(), event, drawable->GetDisplayList(cache), mark); + } + else + DrawUserMarkImpl(scale, visualScale, m2::PointD(0.0, 0.0), event, cache->FindUserMark(defaultKey), mark); + } + + void DefaultDrawUserMark(double scale, + double visualScale, + PaintOverlayEvent const & event, + UserMarkDLCache * cache, + UserMarkDLCache::Key const & defaultKey, + UserMark const * mark) + { + DrawUserMarkImpl(scale, visualScale, m2::PointD(0.0, 0.0), event, cache->FindUserMark(defaultKey), mark); + } } -UserMarkContainer::UserMarkContainer(double layerDepth, Framework & framework) - : m_controller(this) +UserMarkContainer::UserMarkContainer(double layerDepth, Framework & fm) + : m_framework(fm) + , m_controller(this) , m_isVisible(true) , m_layerDepth(layerDepth) - , m_activeMark(NULL) - , m_framework(framework) { } @@ -101,37 +153,14 @@ void UserMarkContainer::Draw(PaintOverlayEvent const & e, UserMarkDLCache * cach if (m_isVisible == false) return; - if (m_activeMark != NULL) - { - UserMarkDLCache::Key defaultKey(GetActiveTypeName(), graphics::EPosCenter, m_layerDepth); - DefaultDrawUserMark(GetActiveMarkScale(), e, cache, defaultKey, m_activeMark); - } - UserMarkDLCache::Key defaultKey(GetTypeName(), graphics::EPosCenter, m_layerDepth); - for_each(m_userMarks.begin(), m_userMarks.end(), bind(&UserMarkContainer::DrawUserMark, this, - 1.0, e, cache, defaultKey, _1)); -} - -void UserMarkContainer::ActivateMark(UserMark const * mark) -{ - ASSERT(mark->GetContainer() == this, ()); - m_activeMark = mark; - StartActivationAnim(); -} - -void UserMarkContainer::DiactivateMark() -{ - if (m_activeMark != NULL) - { - KillActivationAnim(); - m_activeMark = NULL; - } + for_each(m_userMarks.begin(), m_userMarks.end(), bind(&DrawUserMark, 1.0, m_framework.GetVisualScale(), + e, cache, defaultKey, _1)); } void UserMarkContainer::Clear() { DeleteRange(m_userMarks, DeleteFunctor()); - m_activeMark = NULL; } namespace @@ -196,9 +225,6 @@ template <class T> void DeleteItem(vector<T> & v, size_t i) void UserMarkContainer::DeleteUserMark(size_t index) { ASSERT_LESS(index, m_userMarks.size(), ()); - if (m_activeMark == m_userMarks[index]) - m_activeMark = NULL; - DeleteItem(m_userMarks, index); } @@ -209,104 +235,106 @@ void UserMarkContainer::DeleteUserMark(UserMark const * mark) DeleteUserMark(distance(m_userMarks.begin(), it)); } -void UserMarkContainer::DrawUserMarkImpl(double scale, - m2::PointD const & pixelOfsset, - PaintOverlayEvent const & event, - graphics::DisplayList * dl, - UserMark const * mark) const +SearchUserMarkContainer::SearchUserMarkContainer(double layerDepth, Framework & framework) + : UserMarkContainer(layerDepth, framework) { - ScreenBase modelView = event.GetModelView(); - graphics::Screen * screen = event.GetDrawer()->screen(); - m2::PointD pxPoint = modelView.GtoP(mark->GetOrg()); - pxPoint += (pixelOfsset * m_framework.GetVisualScale()); - math::Matrix<double, 3, 3> m = math::Shift(math::Scale(math::Identity<double, 3>(), - scale, scale), - pxPoint.x, pxPoint.y); - dl->draw(screen, m); } -void UserMarkContainer::DrawUserMark(double scale, - PaintOverlayEvent const & event, - UserMarkDLCache * cache, - UserMarkDLCache::Key const & defaultKey, - UserMark const * mark) const +string SearchUserMarkContainer::GetTypeName() const { - if (mark->IsCustomDrawable()) - { - ICustomDrawable const * drawable = static_cast<ICustomDrawable const *>(mark); - DrawUserMarkImpl(drawable->GetAnimScaleFactor(), drawable->GetPixelOffset(), event, drawable->GetDisplayList(cache), mark); - } - else - DefaultDrawUserMark(scale, event, cache, defaultKey, mark); + return "search-result"; } -void UserMarkContainer::DefaultDrawUserMark(double scale, - PaintOverlayEvent const & event, - UserMarkDLCache * cache, - UserMarkDLCache::Key const & defaultKey, - const UserMark * mark) const +string SearchUserMarkContainer::GetActiveTypeName() const { - DrawUserMarkImpl(scale, m2::PointD(0.0, 0.0), event, cache->FindUserMark(defaultKey), mark); + return "search-result-active"; } -void UserMarkContainer::StartActivationAnim() +UserMark * SearchUserMarkContainer::AllocateUserMark(const m2::PointD & ptOrg) { - m_animTask.reset(new PinAnimation(m_framework)); - m_framework.GetAnimController()->AddTask(m_animTask); + return new SearchMarkPoint(ptOrg, this); } -void UserMarkContainer::KillActivationAnim() +ApiUserMarkContainer::ApiUserMarkContainer(double layerDepth, Framework & framework) + : UserMarkContainer(layerDepth, framework) { - m_animTask.reset(); } -double UserMarkContainer::GetActiveMarkScale() const +string ApiUserMarkContainer::GetTypeName() const { - if (m_animTask != NULL) - { - PinAnimation * a = static_cast<PinAnimation *>(m_animTask.get()); - return a->GetScale(); - } - - return 1.0; + return "api-result"; } -SearchUserMarkContainer::SearchUserMarkContainer(double layerDepth, Framework & framework) - : UserMarkContainer(layerDepth, framework) +string ApiUserMarkContainer::GetActiveTypeName() const { + return "search-result-active"; } -string SearchUserMarkContainer::GetTypeName() const +UserMark * ApiUserMarkContainer::AllocateUserMark(const m2::PointD & ptOrg) { - return "search-result"; + return new ApiMarkPoint(ptOrg, this); } -string SearchUserMarkContainer::GetActiveTypeName() const + +SelectionContainer::SelectionContainer(Framework & fm) + : m_hasActiveMark(false) + , m_depth(graphics::minDepth - 100) + , m_fm(fm) { - return "search-result-active"; } -UserMark * SearchUserMarkContainer::AllocateUserMark(const m2::PointD & ptOrg) +void SelectionContainer::ActivateMark(UserMark const * userMark) { - return new SearchMarkPoint(ptOrg, this); + KillActivationAnim(); + if (userMark != NULL) + { + m_hasActiveMark = true; + m_ptOrg = userMark->GetOrg(); + UserMarkContainer const * container = userMark->GetContainer(); + m_pinImageName = container->GetActiveTypeName(); + m_depth = container->GetDepth(); + StartActivationAnim(); + } + else + { + m_hasActiveMark = false; + m_depth = graphics::minDepth - 100; + } } -ApiUserMarkContainer::ApiUserMarkContainer(double layerDepth, Framework & framework) - : UserMarkContainer(layerDepth, framework) +void SelectionContainer::Draw(const PaintOverlayEvent & e, UserMarkDLCache * cache) const { + if (m_hasActiveMark) + { + UserMarkDLCache::Key defaultKey(m_pinImageName, graphics::EPosCenter, m_depth); + DrawUserMarkByPoint(GetActiveMarkScale(), + m_fm.GetVisualScale(), + m2::PointD(0, 0), + e, cache->FindUserMark(defaultKey), + m_ptOrg); + } } -string ApiUserMarkContainer::GetTypeName() const + +void SelectionContainer::StartActivationAnim() { - return "api-result"; + m_animTask.reset(new PinAnimation(m_fm)); + m_fm.GetAnimController()->AddTask(m_animTask); + m_fm.Invalidate(); } -string ApiUserMarkContainer::GetActiveTypeName() const +void SelectionContainer::KillActivationAnim() { - return "search-result-active"; + m_animTask.reset(); } -UserMark * ApiUserMarkContainer::AllocateUserMark(const m2::PointD & ptOrg) +double SelectionContainer::GetActiveMarkScale() const { - return new ApiMarkPoint(ptOrg, this); + if (m_animTask != NULL) + { + PinAnimation * a = static_cast<PinAnimation *>(m_animTask.get()); + return a->GetScale(); + } + + return 1.0; } |