diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index ce0ccecf8c..cdcdd63640 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -2670,7 +2670,7 @@ void FrontendRenderer::RenderLayer::Sort(ref_ptr overlayTree) } // static -m2::AnyRectD TapInfo::GetDefaultSearchRect(m2::PointD const & mercator, ScreenBase const & screen) +m2::AnyRectD TapInfo::GetDefaultTapRect(m2::PointD const & mercator, ScreenBase const & screen) { m2::AnyRectD result; double const halfSize = VisualParams::Instance().GetTouchRectRadius(); @@ -2679,7 +2679,7 @@ m2::AnyRectD TapInfo::GetDefaultSearchRect(m2::PointD const & mercator, ScreenBa } // static -m2::AnyRectD TapInfo::GetBookmarkSearchRect(m2::PointD const & mercator, ScreenBase const & screen) +m2::AnyRectD TapInfo::GetBookmarkTapRect(m2::PointD const & mercator, ScreenBase const & screen) { static int constexpr kBmTouchPixelIncrease = 20; @@ -2694,7 +2694,7 @@ m2::AnyRectD TapInfo::GetBookmarkSearchRect(m2::PointD const & mercator, ScreenB } // static -m2::AnyRectD TapInfo::GetRoutingPointSearchRect(m2::PointD const & mercator, ScreenBase const & screen) +m2::AnyRectD TapInfo::GetRoutingPointTapRect(m2::PointD const & mercator, ScreenBase const & screen) { static int constexpr kRoutingPointTouchPixelIncrease = 20; @@ -2706,7 +2706,7 @@ m2::AnyRectD TapInfo::GetRoutingPointSearchRect(m2::PointD const & mercator, Scr } // static -m2::AnyRectD TapInfo::GetGuideSearchRect(m2::PointD const & mercator, ScreenBase const & screen) +m2::AnyRectD TapInfo::GetGuideTapRect(m2::PointD const & mercator, ScreenBase const & screen) { static int constexpr kGuideTouchPixelIncrease = 20; @@ -2718,7 +2718,7 @@ m2::AnyRectD TapInfo::GetGuideSearchRect(m2::PointD const & mercator, ScreenBase } // static -m2::AnyRectD TapInfo::GetPreciseSearchRect(m2::PointD const & mercator, double const eps) +m2::AnyRectD TapInfo::GetPreciseTapRect(m2::PointD const & mercator, double const eps) { return m2::AnyRectD(mercator, ang::AngleD(0.0) /* angle */, m2::RectD(-eps, -eps, eps, eps)); } diff --git a/drape_frontend/frontend_renderer.hpp b/drape_frontend/frontend_renderer.hpp index 97c18400e5..92e008430d 100755 --- a/drape_frontend/frontend_renderer.hpp +++ b/drape_frontend/frontend_renderer.hpp @@ -64,11 +64,11 @@ struct TapInfo bool const m_isMyPositionTapped; FeatureID const m_featureTapped; - static m2::AnyRectD GetDefaultSearchRect(m2::PointD const & mercator, ScreenBase const & screen); - static m2::AnyRectD GetBookmarkSearchRect(m2::PointD const & mercator, ScreenBase const & screen); - static m2::AnyRectD GetRoutingPointSearchRect(m2::PointD const & mercator, ScreenBase const & screen); - static m2::AnyRectD GetGuideSearchRect(m2::PointD const & mercator, ScreenBase const & screen); - static m2::AnyRectD GetPreciseSearchRect(m2::PointD const & mercator, double const eps); + static m2::AnyRectD GetDefaultTapRect(m2::PointD const & mercator, ScreenBase const & screen); + static m2::AnyRectD GetBookmarkTapRect(m2::PointD const & mercator, ScreenBase const & screen); + static m2::AnyRectD GetRoutingPointTapRect(m2::PointD const & mercator, ScreenBase const & screen); + static m2::AnyRectD GetGuideTapRect(m2::PointD const & mercator, ScreenBase const & screen); + static m2::AnyRectD GetPreciseTapRect(m2::PointD const & mercator, double const eps); }; class FrontendRenderer : public BaseRenderer, diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index 435a73d9af..ddcc55b994 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -2752,26 +2752,38 @@ UserMark const * BookmarkManager::FindNearestUserMark(TTouchRectHolder const & h TFindOnlyVisibleChecker const & findOnlyVisible) const { CHECK_THREAD_CHECKER(m_threadChecker, ()); + + // Among the marks inside the rect (if any) finder stores the closest one to its center. BestUserMarkFinder finder(holder, findOnlyVisible, this); - auto hasFound = finder(UserMark::Type::ROUTING) || - finder(UserMark::Type::ROAD_WARNING) || - finder(UserMark::Type::SEARCH) || - finder(UserMark::Type::API); - hasFound = finder(UserMark::Type::GUIDE) || hasFound; - hasFound = finder(UserMark::Type::GUIDE_CLUSTER) || hasFound; + // Look for the closest mark among GUIDE and GUIDE_CLUSTER marks. + finder(UserMark::Type::GUIDE); + finder(UserMark::Type::GUIDE_CLUSTER); - if (!hasFound) + if (finder.GetFoundMark() != nullptr) + return finder.GetFoundMark(); + + // For each type X in the condition, ordered by priority: + // - look for the closest mark among the marks of the same type X. + // - if the mark has been found, stop looking for a closer one in the other types. + if (finder(UserMark::Type::ROUTING) || + finder(UserMark::Type::ROAD_WARNING) || + finder(UserMark::Type::SEARCH) || + finder(UserMark::Type::API)) { - for (auto const & pair : m_categories) - hasFound = finder(pair.first) || hasFound; + return finder.GetFoundMark(); } - if (!hasFound) - { - hasFound = finder(UserMark::Type::TRACK_INFO) || - finder(UserMark::Type::TRACK_SELECTION); - } + // Look for the closest bookmark. + for (auto const & pair : m_categories) + finder(pair.first); + + if (finder.GetFoundMark() != nullptr) + return finder.GetFoundMark(); + + // Look for the closest TRACK_INFO or TRACK_SELECTION mark. + finder(UserMark::Type::TRACK_INFO); + finder(UserMark::Type::TRACK_SELECTION); return finder.GetFoundMark(); } @@ -3824,8 +3836,10 @@ void BookmarkManager::MarksChangesTracker::OnUpdateMark(kml::MarkId markId) m_updatedMarks.insert(markId); } -void BookmarkManager::MarksChangesTracker::InsertBookmark(kml::MarkId markId, kml::MarkGroupId catId, - GroupMarkIdSet & setToInsert, GroupMarkIdSet & setToErase) +void BookmarkManager::MarksChangesTracker::InsertBookmark(kml::MarkId markId, + kml::MarkGroupId catId, + GroupMarkIdSet & setToInsert, + GroupMarkIdSet & setToErase) { auto const itCat = setToErase.find(catId); if (itCat != setToErase.end()) @@ -3842,12 +3856,25 @@ void BookmarkManager::MarksChangesTracker::InsertBookmark(kml::MarkId markId, km setToInsert[catId].insert(markId); } -void BookmarkManager::MarksChangesTracker::OnAttachBookmark(kml::MarkId markId, kml::MarkGroupId catId) +bool BookmarkManager::MarksChangesTracker::HasBookmarkCategories( + kml::GroupIdSet const & groupIds) const +{ + for (auto groupId : groupIds) + { + if (m_bmManager->IsBookmarkCategory(groupId)) + return true; + } + return false; +} + +void BookmarkManager::MarksChangesTracker::OnAttachBookmark(kml::MarkId markId, + kml::MarkGroupId catId) { InsertBookmark(markId, catId, m_attachedBookmarks, m_detachedBookmarks); } -void BookmarkManager::MarksChangesTracker::OnDetachBookmark(kml::MarkId markId, kml::MarkGroupId catId) +void BookmarkManager::MarksChangesTracker::OnDetachBookmark(kml::MarkId markId, + kml::MarkGroupId catId) { InsertBookmark(markId, catId, m_detachedBookmarks, m_attachedBookmarks); } @@ -3959,32 +3986,12 @@ bool BookmarkManager::MarksChangesTracker::HasChanges() const bool BookmarkManager::MarksChangesTracker::HasBookmarksChanges() const { - for (auto groupId : m_updatedGroups) - { - if (m_bmManager->IsBookmarkCategory(groupId)) - return true; - } - for (auto groupId : m_removedGroups) - { - if (m_bmManager->IsBookmarkCategory(groupId)) - return true; - } - return false; + return HasBookmarkCategories(m_updatedGroups) || HasBookmarkCategories(m_removedGroups); } bool BookmarkManager::MarksChangesTracker::HasCategoriesChanges() const { - for (auto groupId : m_createdGroups) - { - if (m_bmManager->IsBookmarkCategory(groupId)) - return true; - } - for (auto groupId : m_removedGroups) - { - if (m_bmManager->IsBookmarkCategory(groupId)) - return true; - } - return false; + return HasBookmarkCategories(m_createdGroups) || HasBookmarkCategories(m_removedGroups); } void BookmarkManager::MarksChangesTracker::ResetChanges() diff --git a/map/bookmark_manager.hpp b/map/bookmark_manager.hpp index 1c23132afa..f48caee5ca 100644 --- a/map/bookmark_manager.hpp +++ b/map/bookmark_manager.hpp @@ -555,6 +555,7 @@ private: void InsertBookmark(kml::MarkId markId, kml::MarkGroupId catId, GroupMarkIdSet & setToInsert, GroupMarkIdSet & setToErase); + bool HasBookmarkCategories(kml::GroupIdSet const & groupIds) const; BookmarkManager * m_bmManager; diff --git a/map/framework.cpp b/map/framework.cpp index 50d6df1210..051f3ee495 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -2816,7 +2816,7 @@ BookmarkManager::TrackSelectionInfo Framework::FindTrackInTapPosition( CHECK_NOT_EQUAL(selection.m_trackId, kml::kInvalidTrackId, ()); return selection; } - auto const touchRect = df::TapInfo::GetDefaultSearchRect(buildInfo.m_mercator, + auto const touchRect = df::TapInfo::GetDefaultTapRect(buildInfo.m_mercator, m_currentModelView).GetGlobalRect(); return bm.FindNearestTrack(touchRect); } @@ -2837,18 +2837,18 @@ UserMark const * Framework::FindUserMarkInTapPosition(place_page::BuildInfo cons { double constexpr kEps = 1e-7; if (buildInfo.m_source != place_page::BuildInfo::Source::User) - return df::TapInfo::GetPreciseSearchRect(buildInfo.m_mercator, kEps); + return df::TapInfo::GetPreciseTapRect(buildInfo.m_mercator, kEps); if (type == UserMark::Type::BOOKMARK || type == UserMark::Type::TRACK_INFO) - return df::TapInfo::GetBookmarkSearchRect(buildInfo.m_mercator, m_currentModelView); + return df::TapInfo::GetBookmarkTapRect(buildInfo.m_mercator, m_currentModelView); if (type == UserMark::Type::ROUTING || type == UserMark::Type::ROAD_WARNING) - return df::TapInfo::GetRoutingPointSearchRect(buildInfo.m_mercator, m_currentModelView); + return df::TapInfo::GetRoutingPointTapRect(buildInfo.m_mercator, m_currentModelView); if (type == UserMark::Type::GUIDE || type == UserMark::Type::GUIDE_CLUSTER) - return df::TapInfo::GetGuideSearchRect(buildInfo.m_mercator, m_currentModelView); + return df::TapInfo::GetGuideTapRect(buildInfo.m_mercator, m_currentModelView); - return df::TapInfo::GetDefaultSearchRect(buildInfo.m_mercator, m_currentModelView); + return df::TapInfo::GetDefaultTapRect(buildInfo.m_mercator, m_currentModelView); }, [](UserMark::Type type) { diff --git a/map/guides_manager.cpp b/map/guides_manager.cpp index d94426af1c..f2144125e6 100644 --- a/map/guides_manager.cpp +++ b/map/guides_manager.cpp @@ -324,6 +324,9 @@ void GuidesManager::SetActiveGuide(std::string const & guideId) void GuidesManager::ResetActiveGuide() { + if (m_state == GuidesState::Disabled) + return; + if (m_activeGuide.empty()) return; @@ -373,12 +376,21 @@ void GuidesManager::UpdateDownloadedStatus() if (m_state == GuidesState::Disabled) return; + bool changed = false; auto es = m_bmManager->GetEditSession(); for (auto markId : m_bmManager->GetUserMarkIds(UserMark::Type::GUIDE)) { auto * mark = es.GetMarkForEdit(markId); - mark->SetIsDownloaded(IsGuideDownloaded(mark->GetGuideId())); + auto const isDownloaded = IsGuideDownloaded(mark->GetGuideId()); + if (isDownloaded != mark->GetIsDownloaded()) + { + changed = true; + mark->SetIsDownloaded(isDownloaded); + } } + + if (changed && m_onGalleryChanged) + m_onGalleryChanged(true /* reload */); } void GuidesManager::UpdateGuidesMarks()