From 515d0a36f9f0e7f25abbaa40a0b63c74c0ceffcb Mon Sep 17 00:00:00 2001 From: ExMix Date: Tue, 13 May 2014 13:36:24 +0300 Subject: [PATCH] [core] we don't use many listeners. We use one listener that get UserMark * --- gui/display_list_cache.cpp | 2 +- map/balloon_manager.cpp | 347 ++++++------------------------------- map/balloon_manager.hpp | 52 +----- 3 files changed, 58 insertions(+), 343 deletions(-) diff --git a/gui/display_list_cache.cpp b/gui/display_list_cache.cpp index 21f9551add..d88d7bbbc2 100644 --- a/gui/display_list_cache.cpp +++ b/gui/display_list_cache.cpp @@ -87,7 +87,7 @@ namespace gui /// @todo do not cache depth in display list. use separate vertex shader and uniform constant /// to specify it while rendering display list. - m_CacheScreen->drawSymbol(m2::PointD(0, 0), name, pos, graphics::poiAndBookmarkDepth); + m_CacheScreen->drawSymbol(m2::PointD(0, 0), name, pos, graphics::poiDepth); m_CacheScreen->setDisplayList(0); m_CacheScreen->endFrame(); diff --git a/map/balloon_manager.cpp b/map/balloon_manager.cpp index dc7ceb47c4..0525c715e4 100644 --- a/map/balloon_manager.cpp +++ b/map/balloon_manager.cpp @@ -15,312 +15,89 @@ #include "../gui/controller.hpp" -namespace -{ - struct AnimPhase - { - AnimPhase(double endScale, double timeInterval) - : m_endScale(endScale) - , m_timeInterval(timeInterval) - { - } - - double m_endScale; - double m_timeInterval; - }; - - class PinAnimation : public anim::Task - { - public: - PinAnimation(Framework & f) - : m_f(f) - , m_scale(0.0) - { - } - - void AddAnimPhase(AnimPhase const & phase) - { - m_animPhases.push_back(phase); - } - - virtual void OnStart(double ts) - { - m_startTime = ts; - m_startScale = m_scale; - m_phaseIndex = 0; - } - - virtual void OnStep(double ts) - { - ASSERT(m_phaseIndex < m_animPhases.size(), ()); - - AnimPhase const * phase = &m_animPhases[m_phaseIndex]; - double elapsedTime = ts - m_startTime; - if (elapsedTime > phase->m_timeInterval) - { - m_startTime = ts; - m_scale = phase->m_endScale; - m_startScale = m_scale; - m_phaseIndex++; - if (m_phaseIndex >= m_animPhases.size()) - { - End(); - return; - } - } - - elapsedTime = ts - m_startTime; - double t = elapsedTime / phase->m_timeInterval; - m_scale = m_startScale + t * (phase->m_endScale - m_startScale); - - m_f.Invalidate(); - } - - double GetScale() const - { - return m_scale; - } - - private: - Framework & m_f; - vector m_animPhases; - size_t m_phaseIndex; - double m_scale; - double m_startTime; - double m_startScale; - }; -} - PinClickManager::PinClickManager(Framework & f) - : m_searchPinDL(NULL) - , m_f(f) - , m_updateForLocation(false) - , m_hasPin(false) + : m_f(f) {} -PinClickManager::~PinClickManager() -{ - ASSERT(m_searchPinDL == NULL, ()); -} +//graphics::DisplayList * PinClickManager::GetSearchPinDL() +//{ +// using namespace graphics; -void PinClickManager::Shutdown() -{ - delete m_searchPinDL; - m_searchPinDL = NULL; -} +// if (!m_searchPinDL) +// { +// Screen * cacheScreen = m_f.GetGuiController()->GetCacheScreen(); +// m_searchPinDL = cacheScreen->createDisplayList(); -void PinClickManager::RenderPolicyCreated(graphics::EDensity density) -{ -} +// cacheScreen->beginFrame(); +// cacheScreen->setDisplayList(m_searchPinDL); -void PinClickManager::LocationChanged(location::GpsInfo const & info) -{} +// Icon::Info infoKey("search-result-active"); +// Resource const * res = cacheScreen->fromID(cacheScreen->findInfo(infoKey)); +// shared_ptr texture = cacheScreen->pipeline(res->m_pipelineID).texture(); -void PinClickManager::StartAnimation() -{ - PinAnimation * anim = new PinAnimation(m_f); - anim->AddAnimPhase(AnimPhase(1.2, 0.15)); - anim->AddAnimPhase(AnimPhase(0.8, 0.08)); - anim->AddAnimPhase(AnimPhase(1, 0.05)); - m_animTask.reset(anim); - m_f.GetAnimController()->AddTask(m_animTask); -} +// m2::RectU texRect = res->m_texRect; +// double halfSizeX = texRect.SizeX() / 2.0; +// double halfSizeY = texRect.SizeY() / 2.0; -void PinClickManager::ResetAnimation() -{ - m_animTask.reset(); -} +// m2::PointD coords[] = +// { +// m2::PointD(-halfSizeX, -halfSizeY), +// m2::PointD(-halfSizeX, halfSizeY), +// m2::PointD(halfSizeX, -halfSizeY), +// m2::PointD(halfSizeX, halfSizeY) +// }; +// m2::PointF normal(0.0, 0.0); -double PinClickManager::GetCurrentPinScale() -{ - if (m_animTask != NULL) - { - PinAnimation * a = static_cast(m_animTask.get()); - return a->GetScale(); - } +// m2::PointF texCoords[] = +// { +// texture->mapPixel(m2::PointF(texRect.minX(), texRect.minY())), +// texture->mapPixel(m2::PointF(texRect.minX(), texRect.maxY())), +// texture->mapPixel(m2::PointF(texRect.maxX(), texRect.minY())), +// texture->mapPixel(m2::PointF(texRect.maxX(), texRect.maxY())) +// }; - return 1.0; -} +// cacheScreen->addTexturedStripStrided(coords, sizeof(m2::PointD), +// &normal, 0, +// texCoords, sizeof(m2::PointF), +// 4, graphics::activePinDepth, res->m_pipelineID); -graphics::DisplayList * PinClickManager::GetSearchPinDL() -{ - using namespace graphics; +// cacheScreen->setDisplayList(NULL); +// cacheScreen->endFrame(); +// } - if (!m_searchPinDL) - { - Screen * cacheScreen = m_f.GetGuiController()->GetCacheScreen(); - m_searchPinDL = cacheScreen->createDisplayList(); - - cacheScreen->beginFrame(); - cacheScreen->setDisplayList(m_searchPinDL); - - Icon::Info infoKey("search-result-active"); - Resource const * res = cacheScreen->fromID(cacheScreen->findInfo(infoKey)); - shared_ptr texture = cacheScreen->pipeline(res->m_pipelineID).texture(); - - m2::RectU texRect = res->m_texRect; - double sizeX = texRect.SizeX(); - double halfSizeX = sizeX / 2.0; - double sizeY = texRect.SizeY(); - - m2::PointD coords[] = - { - m2::PointD(-halfSizeX, -sizeY), - m2::PointD(-halfSizeX, 0.0), - m2::PointD(halfSizeX, -sizeY), - m2::PointD(halfSizeX, 0.0) - }; - m2::PointF normal(0.0, 0.0); - - m2::PointF texCoords[] = - { - texture->mapPixel(m2::PointF(texRect.minX(), texRect.minY())), - texture->mapPixel(m2::PointF(texRect.minX(), texRect.maxY())), - texture->mapPixel(m2::PointF(texRect.maxX(), texRect.minY())), - texture->mapPixel(m2::PointF(texRect.maxX(), texRect.maxY())) - }; - - cacheScreen->addTexturedStripStrided(coords, sizeof(m2::PointD), - &normal, 0, - texCoords, sizeof(m2::PointF), - 4, graphics::activePinDepth, res->m_pipelineID); - - cacheScreen->setDisplayList(NULL); - cacheScreen->endFrame(); - } - - return m_searchPinDL; -} - -void PinClickManager::OnPositionClicked(m2::PointD const & pt) -{ - m_positionListener(pt.x, pt.y); - m_updateForLocation = true; -} +// return m_searchPinDL; +//} void PinClickManager::Hide() { - m_updateForLocation = false; m_f.Invalidate(); } void PinClickManager::OnClick(m2::PointD const & pxPoint, bool isLongTouch) { - // By default we assume that we have pin - bool dispatched = false; - - // API - url_scheme::ResultPoint apiPoint; - if (m_f.GetMapApiPoint(pxPoint, apiPoint)) - { - OnActivateAPI(apiPoint); - m_pinGlobalLocation = apiPoint.GetOrg(); - dispatched = true; - } - else - { - // Everything else - search::AddressInfo addrInfo; - m2::PointD pxPivot; - BookmarkAndCategory bmAndCat; - - switch (m_f.GetBookmarkOrPoi(pxPoint, pxPivot, addrInfo, bmAndCat)) - { - case Framework::BOOKMARK: - { - OnActivateBookmark(bmAndCat); - m_pinGlobalLocation = m_f.GetBmCategory(bmAndCat.first)->GetBookmark(bmAndCat.second)->GetOrg(); - dispatched = true; - break; - } - - case Framework::ADDTIONAL_LAYER: - { - OnAdditonalLayer(bmAndCat.second); - m_pinGlobalLocation = m_f.GetBookmarkManager().AdditionalPoiLayerGetBookmark(bmAndCat.second)->GetOrg(); - dispatched = true; - break; - } - - case Framework::POI: - { - m2::PointD globalPoint = m_f.PtoG(pxPivot); - OnActivatePOI(globalPoint, addrInfo); - m_pinGlobalLocation = globalPoint; - dispatched = true; - break; - } - - default: - { - if (isLongTouch) - { - m2::PointD const glbPoint = m_f.PtoG(pxPoint); - m_f.GetAddressInfoForGlobalPoint(glbPoint, addrInfo); - OnActivatePOI(glbPoint, addrInfo); - m_pinGlobalLocation = glbPoint; - dispatched = true; - } - break; - } - } - } - - SetBalloonVisible(dispatched); + UserMark const * mark = m_f.ActivateUserMark(pxPoint, isLongTouch); + OnActivateUserMark(mark); + SetBalloonVisible(mark != NULL); } void PinClickManager::OnBookmarkClick(BookmarkAndCategory const & bnc) { - OnActivateBookmark(bnc); - m_pinGlobalLocation = m_f.GetBmCategory(bnc.first)->GetBookmark(bnc.second)->GetOrg(); - + Bookmark * mark = m_f.GetBmCategory(bnc.first)->GetBookmark(bnc.second); + m_f.GetBookmarkManager().ActivateMark(mark); SetBalloonVisible(true); } void PinClickManager::SetBalloonVisible(bool isVisible) { - m_hasPin = isVisible; - - if (isVisible) - StartAnimation(); - else - { + if (!isVisible) OnDismiss(); - ResetAnimation(); - } m_f.Invalidate(); } -void PinClickManager::DrawPin(const shared_ptr & e) -{ - if (m_hasPin) - { - Navigator const & navigator = m_f.GetNavigator(); - m2::AnyRectD const & glbRect = navigator.Screen().GlobalRect(); - - // @todo change pin picture - if (glbRect.IsPointInside(m_pinGlobalLocation)) - { - m2::PointD pxPoint = navigator.GtoP(m_pinGlobalLocation); - pxPoint += m2::PointD(0.0, 4 * m_f.GetVisualScale()); - graphics::DisplayList * dl = GetSearchPinDL(); - - double scale = GetCurrentPinScale(); - math::Matrix m = math::Shift( - math::Scale(math::Identity(), - scale, scale), - pxPoint.x, pxPoint.y); - - e->drawer()->screen()->drawDisplayList(dl, m); - } - } -} - void PinClickManager::RemovePin() { - ResetAnimation(); - m_hasPin = false; + m_f.GetBookmarkManager().ActivateMark(NULL); m_f.Invalidate(); } @@ -331,37 +108,13 @@ void PinClickManager::Dismiss() void PinClickManager::ClearListeners() { - m_poiListener.clear(); - m_bookmarkListener.clear(); - m_apiListener.clear(); - m_positionListener.clear(); - m_additionalLayerListener.clear(); + m_userMarkListener.clear(); m_dismissListener.clear(); } -void PinClickManager::OnActivateMyPosition() +void PinClickManager::OnActivateUserMark(UserMark const * mark) { - m_positionListener(0,0); -} - -void PinClickManager::OnActivatePOI(m2::PointD const & globalPoint, search::AddressInfo const & info) -{ - m_poiListener(globalPoint, info); -} - -void PinClickManager::OnActivateAPI(url_scheme::ResultPoint const & apiPoint) -{ - m_apiListener(apiPoint.GetPoint()); -} - -void PinClickManager::OnActivateBookmark(BookmarkAndCategory const & bmAndCat) -{ - m_bookmarkListener(bmAndCat); -} - -void PinClickManager::OnAdditonalLayer(size_t index) -{ - m_additionalLayerListener(index); + m_userMarkListener(mark); } void PinClickManager::OnDismiss() diff --git a/map/balloon_manager.hpp b/map/balloon_manager.hpp index fab644addd..e9571b3d7d 100644 --- a/map/balloon_manager.hpp +++ b/map/balloon_manager.hpp @@ -11,79 +11,41 @@ class Framework; class PaintEvent; -namespace anim { class Task; } -namespace graphics { class DisplayList; } namespace location { class GpsInfo; } namespace gui { class Element; } -namespace search { struct AddressInfo; } -namespace url_scheme -{ - struct ApiPoint; - class ResultPoint; -} +namespace url_scheme { struct ApiPoint; } class PinClickManager { - shared_ptr m_animTask; - void StartAnimation(); - void ResetAnimation(); - double GetCurrentPinScale(); - - graphics::DisplayList * m_searchPinDL; - graphics::DisplayList * GetSearchPinDL(); - Framework & m_f; - bool m_updateForLocation; - void OnPositionClicked(m2::PointD const & pt); - void OnActivateMyPosition(); - void OnActivatePOI(const m2::PointD & globalPoint, search::AddressInfo const & info); - void OnActivateAPI(url_scheme::ResultPoint const & apiPoint); - void OnActivateBookmark(BookmarkAndCategory const & bmAndCat); - void OnAdditonalLayer(size_t index); + void OnActivateUserMark(UserMark const * mark); void OnDismiss(); void SetBalloonVisible(bool isVisible); public: PinClickManager(Framework & f); - ~PinClickManager(); - void Shutdown(); - - void RenderPolicyCreated(graphics::EDensity density); - void LocationChanged(location::GpsInfo const & info); + void RenderPolicyCreated(graphics::EDensity density) {} + void LocationChanged(location::GpsInfo const & info) {} void OnClick(m2::PointD const & pxPoint, bool isLongTouch); void OnBookmarkClick(BookmarkAndCategory const & bnc); void Hide(); - void DrawPin(shared_ptr const & e); void RemovePin(); void Dismiss(); - -private: - bool m_hasPin; - m2::PointD m_pinGlobalLocation; - private: /// @name Platform dependent listeners to show special activities. //@{ - function m_poiListener; - function m_bookmarkListener; - function m_apiListener; - function m_positionListener; - function m_additionalLayerListener; - function m_dismissListener; + function m_userMarkListener; + function m_dismissListener; public: - template void ConnectPoiListener(T const & t) { m_poiListener = t; } - template void ConnectBookmarkListener(T const & t) { m_bookmarkListener = t; } - template void ConnectApiListener(T const & t) { m_apiListener = t; } - template void ConnectPositionListener(T const & t) { m_positionListener = t; } - template void ConnectAdditionalListener(T const & t) { m_additionalLayerListener = t; } + template void ConnectUserMarkListener(T const & t) { m_userMarkListener = t; } template void ConnectDismissListener(T const & t) { m_dismissListener = t; } void ClearListeners();