From 833bd37e7e71ccd02c77045a32b853725046d655 Mon Sep 17 00:00:00 2001 From: Daria Volvenkova Date: Fri, 5 Oct 2018 20:02:29 +0300 Subject: [PATCH] SpeedCameraMark and ColoredDebugMark added. --- drape_frontend/drape_engine.cpp | 2 +- drape_frontend/user_mark_shapes.cpp | 61 ++++++++++++++---- drape_frontend/user_mark_shapes.hpp | 2 +- drape_frontend/user_marks_provider.hpp | 9 ++- map/local_ads_mark.hpp | 2 +- map/routing_mark.cpp | 88 +++++++++++++++++++++++++- map/routing_mark.hpp | 38 ++++++++++- map/transit/transit_display.cpp | 18 ++++-- map/user_mark.cpp | 30 +++++++++ map/user_mark.hpp | 20 +++++- 10 files changed, 241 insertions(+), 29 deletions(-) diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index a2974dac95..faea275bb6 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -855,7 +855,7 @@ drape_ptr DrapeEngine::GenerateMarkRenderInfo(UserPointMar renderInfo->m_symbolSizes = mark->GetSymbolSizes(); renderInfo->m_symbolOffsets = mark->GetSymbolOffsets(); renderInfo->m_color = mark->GetColorConstant(); - renderInfo->m_hasSymbolPriority = mark->HasSymbolPriority(); + renderInfo->m_hasSymbolShapes = mark->HasSymbolShapes(); renderInfo->m_hasTitlePriority = mark->HasTitlePriority(); renderInfo->m_priority = mark->GetPriority(); renderInfo->m_index = mark->GetIndex(); diff --git a/drape_frontend/user_mark_shapes.cpp b/drape_frontend/user_mark_shapes.cpp index 25f2a90f81..e02ee9e672 100644 --- a/drape_frontend/user_mark_shapes.cpp +++ b/drape_frontend/user_mark_shapes.cpp @@ -5,6 +5,7 @@ #include "drape_frontend/map_shape.hpp" #include "drape_frontend/poi_symbol_shape.hpp" #include "drape_frontend/shape_view_params.hpp" +#include "drape_frontend/text_layout.hpp" #include "drape_frontend/text_shape.hpp" #include "drape_frontend/tile_utils.hpp" #include "drape_frontend/visual_params.hpp" @@ -113,16 +114,50 @@ void GenerateColoredSymbolShapes(ref_ptr context, m2::PointD const & tileCenter, ref_ptr textures, m2::PointF & symbolSize, dp::Batcher & batcher) { - for (auto itSym = renderInfo.m_coloredSymbols->rbegin(); - itSym != renderInfo.m_coloredSymbols->rend(); ++itSym) + auto const needOverlay = renderInfo.m_coloredSymbols->m_needOverlay; + m2::PointF sizeInc(0.0, 0.0); + UserPointMark::SymbolSizes symbolSizesInc; + auto const isTextBg = renderInfo.m_coloredSymbols->m_addTextSize; + if (isTextBg) + { + auto const & titleDecl = renderInfo.m_titleDecl->at(0); + dp::FontDecl const & fontDecl = titleDecl.m_primaryTextFont; + auto isSdf = df::VisualParams::Instance().IsSdfPrefered(); + isSdf = fontDecl.m_outlineColor != dp::Color::Transparent() ? true : isSdf; + auto const vs = static_cast(df::VisualParams::Instance().GetVisualScale()); + + TextLayout textLayout; + textLayout.Init(strings::MakeUniString(titleDecl.m_primaryText), fontDecl.m_size * vs, isSdf, textures); + sizeInc.x = textLayout.GetPixelLength(); + sizeInc.y = textLayout.GetPixelHeight(); + + if (renderInfo.m_symbolSizes != nullptr) + { + symbolSizesInc.reserve(renderInfo.m_symbolSizes->size()); + for (auto const & sz : *renderInfo.m_symbolSizes) + symbolSizesInc.push_back(sz + sizeInc); + } + } + + for (auto itSym = renderInfo.m_coloredSymbols->m_zoomInfo.rbegin(); + itSym != renderInfo.m_coloredSymbols->m_zoomInfo.rend(); ++itSym) { if (itSym->first <= tileKey.m_zoomLevel) { ColoredSymbolViewParams params = itSym->second; + if (params.m_shape == ColoredSymbolViewParams::Shape::Circle) - symbolSize = m2::PointF(params.m_radiusInPixels * 2.0f, params.m_radiusInPixels * 2.0f); + { + params.m_radiusInPixels = params.m_radiusInPixels + std::max(sizeInc.x, sizeInc.y) / 2.0f; + if (!isTextBg) + symbolSize = m2::PointF(params.m_radiusInPixels * 2.0f, params.m_radiusInPixels * 2.0f); + } else - symbolSize = params.m_sizeInPixels; + { + params.m_sizeInPixels = params.m_sizeInPixels + sizeInc; + if (!isTextBg) + symbolSize = params.m_sizeInPixels; + } params.m_featureID = renderInfo.m_featureId; params.m_tileCenter = tileCenter; @@ -136,13 +171,13 @@ void GenerateColoredSymbolShapes(ref_ptr context, { ColoredSymbolShape(renderInfo.m_pivot, params, tileKey, kStartUserMarkOverlayIndex + renderInfo.m_index, - *renderInfo.m_symbolSizes.get()) + isTextBg ? symbolSizesInc : *renderInfo.m_symbolSizes.get()) .Draw(context, &batcher, textures); } else { ColoredSymbolShape(renderInfo.m_pivot, params, tileKey, - kStartUserMarkOverlayIndex + renderInfo.m_index) + kStartUserMarkOverlayIndex + renderInfo.m_index, needOverlay) .Draw(context, &batcher, textures); } break; @@ -166,8 +201,10 @@ void GeneratePoiSymbolShape(ref_ptr context, params.m_specialPriority = renderInfo.m_priority; params.m_symbolName = symbolName; params.m_anchor = renderInfo.m_anchor; - params.m_startOverlayRank = - renderInfo.m_coloredSymbols != nullptr ? dp::OverlayRank1 : dp::OverlayRank0; + + bool const hasColoredOverlay = renderInfo.m_coloredSymbols != nullptr && renderInfo.m_coloredSymbols->m_needOverlay; + params.m_startOverlayRank = hasColoredOverlay ? dp::OverlayRank1 : dp::OverlayRank0; + if (renderInfo.m_symbolOffsets != nullptr) { ASSERT_GREATER(tileKey.m_zoomLevel, 0, ()); @@ -227,11 +264,11 @@ void GenerateTextShapes(ref_ptr context, params.m_specialDisplacement = SpecialDisplacement::UserMark; params.m_specialPriority = renderInfo.m_priority; params.m_startOverlayRank = dp::OverlayRank0; - if (renderInfo.m_hasSymbolPriority) + if (renderInfo.m_hasSymbolShapes) { if (renderInfo.m_symbolNames != nullptr) params.m_startOverlayRank++; - if (renderInfo.m_coloredSymbols != nullptr) + if (renderInfo.m_coloredSymbols != nullptr && renderInfo.m_coloredSymbols->m_needOverlay) params.m_startOverlayRank++; ASSERT_LESS(params.m_startOverlayRank, dp::OverlayRanksCount, ()); } @@ -327,7 +364,7 @@ void CacheUserMarks(ref_ptr context, TileKey const & tileKe if (!renderInfo.m_color.empty()) color = df::GetColorConstant(renderInfo.m_color); - if (renderInfo.m_hasSymbolPriority) + if (renderInfo.m_hasSymbolShapes) { if (renderInfo.m_coloredSymbols != nullptr) { @@ -400,7 +437,7 @@ void CacheUserMarks(ref_ptr context, TileKey const & tileKe if (renderInfo.m_badgeNames != nullptr) { - ASSERT(!renderInfo.m_hasSymbolPriority || renderInfo.m_symbolNames == nullptr, + ASSERT(!renderInfo.m_hasSymbolShapes || renderInfo.m_symbolNames == nullptr, ("Multiple POI shapes in an usermark are not supported yet")); auto const badgeName = GetSymbolNameForZoomLevel(renderInfo.m_badgeNames, tileKey); if (!badgeName.empty()) diff --git a/drape_frontend/user_mark_shapes.hpp b/drape_frontend/user_mark_shapes.hpp index 90b48c82ff..f13ec6737a 100644 --- a/drape_frontend/user_mark_shapes.hpp +++ b/drape_frontend/user_mark_shapes.hpp @@ -27,7 +27,7 @@ struct UserMarkRenderParams drape_ptr m_symbolOffsets; drape_ptr m_badgeNames; df::ColorConstant m_color; - bool m_hasSymbolPriority = false; + bool m_hasSymbolShapes = false; bool m_hasTitlePriority = false; uint16_t m_priority = 0; uint32_t m_index = 0; diff --git a/drape_frontend/user_marks_provider.hpp b/drape_frontend/user_marks_provider.hpp index 857dc7a725..31a6bf3a3b 100644 --- a/drape_frontend/user_marks_provider.hpp +++ b/drape_frontend/user_marks_provider.hpp @@ -37,7 +37,12 @@ struct IDCollections class UserPointMark { public: - using ColoredSymbolZoomInfo = std::map; + struct ColoredSymbolZoomInfo + { + std::map m_zoomInfo; + bool m_needOverlay = true; + bool m_addTextSize = false; + }; using SymbolNameZoomInfo = std::map; using TitlesInfo = std::vector; using SymbolSizes = std::vector; @@ -67,7 +72,7 @@ public: virtual drape_ptr GetSymbolOffsets() const = 0; virtual uint16_t GetPriority() const = 0; virtual uint32_t GetIndex() const = 0; - virtual bool HasSymbolPriority() const = 0; + virtual bool HasSymbolShapes() const = 0; virtual bool HasTitlePriority() const = 0; virtual int GetMinZoom() const = 0; virtual int GetMinTitleZoom() const = 0; diff --git a/map/local_ads_mark.hpp b/map/local_ads_mark.hpp index 9739edefcf..85ec206534 100644 --- a/map/local_ads_mark.hpp +++ b/map/local_ads_mark.hpp @@ -27,7 +27,7 @@ public: drape_ptr GetTitleDecl() const override; uint16_t GetPriority() const override { return m_data.m_priority; } - bool HasSymbolPriority() const override { return true; } + bool HasSymbolShapes() const override { return true; } bool HasTitlePriority() const override { return true; } int GetMinZoom() const override { return static_cast(m_data.m_minZoomLevel); } FeatureID GetFeatureID() const override { return m_featureId; } diff --git a/map/routing_mark.cpp b/map/routing_mark.cpp index bbd38ba020..d85ee24473 100644 --- a/map/routing_mark.cpp +++ b/map/routing_mark.cpp @@ -1,6 +1,7 @@ #include "map/routing_mark.hpp" #include "drape_frontend/color_constants.hpp" +#include "drape_frontend/visual_params.hpp" #include @@ -20,6 +21,14 @@ float const kRouteMarkPrimaryTextSize = 11.0f; float const kRouteMarkSecondaryTextSize = 10.0f; float const kRouteMarkSecondaryOffsetY = 2.0f; float const kTransitMarkTextSize = 12.0f; + +// TODO(darina): Add to style colors for speed camera marks. +static std::string const kSpeedCameraMarkText = "TransitMarkPrimaryTextOutline"; +float constexpr kSpeedCameraMarkTextSize = 10.0f; +float constexpr kSpeedCameraBorderWidth = 2.0f; +int constexpr kSpeedCameraZoomS = 11; +int constexpr kSpeedCameraZoomM = 16; +int constexpr kMinSpeedCameraTitleZoom = 15; } // namespace RouteMarkPoint::RouteMarkPoint(m2::PointD const & ptOrg) @@ -449,7 +458,7 @@ void TransitMark::SetSymbolNames(std::map const & symbolNames) m_symbolNames = symbolNames; } -void TransitMark::SetColoredSymbols(std::map const & symbolParams) +void TransitMark::SetColoredSymbols(ColoredSymbolZoomInfo const & symbolParams) { SetDirty(); m_coloredSymbols = symbolParams; @@ -457,7 +466,7 @@ void TransitMark::SetColoredSymbols(std::map c drape_ptr TransitMark::GetColoredSymbols() const { - if (m_coloredSymbols.empty()) + if (m_coloredSymbols.m_zoomInfo.empty()) return nullptr; return make_unique_dp(m_coloredSymbols); } @@ -514,3 +523,78 @@ void TransitMark::GetDefaultTransitTitle(dp::TitleDecl & titleDecl) titleDecl.m_secondaryTextFont.m_outlineColor = df::GetColorConstant(kTransitMarkSecondaryTextOutline); titleDecl.m_secondaryTextFont.m_size = kTransitMarkTextSize; } + +SpeedCameraMark::SpeedCameraMark(m2::PointD const & ptOrg) + : UserMark(ptOrg, Type::SPEED_CAM) +{ + auto const vs = static_cast(df::VisualParams::Instance().GetVisualScale()); + + m_titleDecl.m_primaryTextFont.m_color = df::GetColorConstant(kSpeedCameraMarkText); + m_titleDecl.m_primaryTextFont.m_size = kSpeedCameraMarkTextSize; + m_titleDecl.m_anchor = dp::Right; + m_titleDecl.m_primaryOffset.x = -kSpeedCameraBorderWidth; + + m_symbolNames.insert(std::make_pair(kSpeedCameraZoomS, "speedcam-s")); + m_symbolNames.insert(std::make_pair(kSpeedCameraZoomM, "speedcam-m")); + + df::ColoredSymbolViewParams params; + params.m_color = dp::Color::Red(); + params.m_anchor = dp::Right; + params.m_shape = df::ColoredSymbolViewParams::Shape::RoundedRectangle; + params.m_radiusInPixels = kSpeedCameraBorderWidth * vs; + params.m_sizeInPixels = m2::PointF(2.0f * kSpeedCameraBorderWidth, 2.0f * kSpeedCameraBorderWidth) * vs; + m_textBg.m_zoomInfo[kMinSpeedCameraTitleZoom] = params; + m_textBg.m_addTextSize = true; +} + +void SpeedCameraMark::SetTitle(std::string const & title) +{ + SetDirty(); + m_titleDecl.m_primaryText = title; +} + +void SpeedCameraMark::SetFeatureId(FeatureID featureId) +{ + SetDirty(); + m_featureId = featureId; +} + +void SpeedCameraMark::SetIndex(uint32_t index) +{ + SetDirty(); + m_index = index; +} + +drape_ptr SpeedCameraMark::GetSymbolNames() const +{ + return make_unique_dp(m_symbolNames); +} + +drape_ptr SpeedCameraMark::GetTitleDecl() const +{ + if (m_titleDecl.m_primaryText.empty()) + return nullptr; + auto titleInfo = make_unique_dp(); + titleInfo->push_back(m_titleDecl); + return titleInfo; +} + +drape_ptr SpeedCameraMark::GetColoredSymbols() const +{ + return make_unique_dp(m_textBg); +} + +int SpeedCameraMark::GetMinZoom() const +{ + return kSpeedCameraZoomS; +} + +int SpeedCameraMark::GetMinTitleZoom() const +{ + return kMinSpeedCameraTitleZoom; +} + +dp::Anchor SpeedCameraMark::GetAnchor() const +{ + return dp::Left; +} diff --git a/map/routing_mark.hpp b/map/routing_mark.hpp index d23dd2f9d2..ce04be9282 100644 --- a/map/routing_mark.hpp +++ b/map/routing_mark.hpp @@ -62,7 +62,7 @@ public: drape_ptr GetTitleDecl() const override; - bool HasSymbolPriority() const override { return false; } + bool HasSymbolShapes() const override { return false; } bool HasTitlePriority() const override { return true; } void SetFollowingMode(bool enabled); @@ -109,7 +109,7 @@ public: df::DepthLayer GetDepthLayer() const override { return df::DepthLayer::TransitMarkLayer; } - bool HasSymbolPriority() const override { return !m_symbolNames.empty() || !m_coloredSymbols.empty(); } + bool HasSymbolShapes() const override { return !m_symbolNames.empty() || !m_coloredSymbols.m_zoomInfo.empty(); } bool HasTitlePriority() const override { return true; } void SetAnchor(dp::Anchor anchor); @@ -160,3 +160,37 @@ private: SymbolOffsets m_symbolOffsets; dp::Anchor m_anchor = dp::Center; }; + +class SpeedCameraMark : public UserMark +{ +public: + explicit SpeedCameraMark(m2::PointD const & ptOrg); + void SetTitle(std::string const & title); + + void SetFeatureId(FeatureID featureId); + FeatureID GetFeatureID() const override { return m_featureId; } + + void SetIndex(uint32_t index); + uint32_t GetIndex() const override { return m_index; } + + df::DepthLayer GetDepthLayer() const override { return df::DepthLayer::RoutingMarkLayer; } + bool HasSymbolShapes() const override { return true; } + bool HasTitlePriority() const override { return true; } + uint16_t GetPriority() const override { return static_cast(Priority::SpeedCamera); } + + drape_ptr GetSymbolNames() const override; + drape_ptr GetTitleDecl() const override; + drape_ptr GetColoredSymbols() const override; + + int GetMinZoom() const override; + int GetMinTitleZoom() const override; + dp::Anchor GetAnchor() const override; + +private: + uint32_t m_index = 0; + FeatureID m_featureId; + SymbolNameZoomInfo m_symbolNames; + ColoredSymbolZoomInfo m_textBg; + std::string m_title; + dp::TitleDecl m_titleDecl; +}; diff --git a/map/transit/transit_display.cpp b/map/transit/transit_display.cpp index 4ae7135397..a3b4935384 100644 --- a/map/transit/transit_display.cpp +++ b/map/transit/transit_display.cpp @@ -543,8 +543,11 @@ void TransitRouteDisplay::CreateTransitMarks() df::ColoredSymbolViewParams params; params.m_radiusInPixels = max(sz.x, sz.y) * 0.5f; params.m_color = dp::Color::Transparent(); - if (coloredSymbol.empty() || coloredSymbol.rbegin()->second.m_radiusInPixels != params.m_radiusInPixels) - coloredSymbol.insert(make_pair(zoomLevel, params)); + if (coloredSymbol.m_zoomInfo.empty() || + coloredSymbol.m_zoomInfo.rbegin()->second.m_radiusInPixels != params.m_radiusInPixels) + { + coloredSymbol.m_zoomInfo.insert(make_pair(zoomLevel, params)); + } } transitMark->SetColoredSymbols(coloredSymbol); transitMark->SetPriority(UserMark::Priority::TransitTransfer); @@ -574,11 +577,11 @@ void TransitRouteDisplay::CreateTransitMarks() auto sz = m_symbolSizes.at(symbolNames[kSmallIconZoom]); params.m_radiusInPixels = max(sz.x, sz.y) * kGateBgScale * 0.5f; - coloredSymbol[kSmallIconZoom] = params; + coloredSymbol.m_zoomInfo[kSmallIconZoom] = params; sz = m_symbolSizes.at(symbolNames[kMediumIconZoom]); params.m_radiusInPixels = max(sz.x, sz.y) * kGateBgScale * 0.5f; - coloredSymbol[kMediumIconZoom] = params; + coloredSymbol.m_zoomInfo[kMediumIconZoom] = params; transitMark->SetColoredSymbols(coloredSymbol); transitMark->SetPriority(UserMark::Priority::TransitKeyStop); @@ -593,8 +596,11 @@ void TransitRouteDisplay::CreateTransitMarks() df::ColoredSymbolViewParams params; params.m_radiusInPixels = max(sz.x, sz.y) * 0.5f; params.m_color = dp::Color::Transparent(); - if (coloredSymbol.empty() || coloredSymbol.rbegin()->second.m_radiusInPixels != params.m_radiusInPixels) - coloredSymbol.insert(make_pair(zoomLevel, params)); + if (coloredSymbol.m_zoomInfo.empty() || + coloredSymbol.m_zoomInfo.rbegin()->second.m_radiusInPixels != params.m_radiusInPixels) + { + coloredSymbol.m_zoomInfo.insert(make_pair(zoomLevel, params)); + } } transitMark->SetSymbolSizes(stopMarkerSizes); transitMark->SetColoredSymbols(coloredSymbol); diff --git a/map/user_mark.cpp b/map/user_mark.cpp index b47d5ccc3d..0e8784dd9d 100644 --- a/map/user_mark.cpp +++ b/map/user_mark.cpp @@ -1,6 +1,10 @@ #include "map/user_mark.hpp" #include "map/user_mark_id_storage.hpp" +#include "drape_frontend/visual_params.hpp" + +#include "indexer/scales.hpp" + #include "geometry/mercator.hpp" UserMark::UserMark(kml::MarkId id, m2::PointD const & ptOrg, UserMark::Type type) @@ -71,6 +75,31 @@ drape_ptr DebugMarkPoint::GetSymbolNames( return symbol; } +ColoredDebugMarkPoint::ColoredDebugMarkPoint(m2::PointD const & ptOrg) + : UserMark(ptOrg, UserMark::Type::DEBUG_MARK) +{ + auto const vs = static_cast(df::VisualParams::Instance().GetVisualScale()); + + df::ColoredSymbolViewParams params; + params.m_outlineColor = dp::Color::White(); + params.m_outlineWidth = 1.5f * vs; + params.m_radiusInPixels = 7.0f * vs; + params.m_color = dp::Color::Green(); + m_coloredSymbols.m_needOverlay = false; + m_coloredSymbols.m_zoomInfo.insert(make_pair(1, params)); +} + +void ColoredDebugMarkPoint::SetColor(dp::Color const & color) +{ + SetDirty(); + m_coloredSymbols.m_zoomInfo.begin()->second.m_color = color; +} + +drape_ptr ColoredDebugMarkPoint::GetColoredSymbols() const +{ + return make_unique_dp(m_coloredSymbols); +} + string DebugPrint(UserMark::Type type) { switch (type) @@ -81,6 +110,7 @@ string DebugPrint(UserMark::Type type) case UserMark::Type::BOOKMARK: return "BOOKMARK"; case UserMark::Type::DEBUG_MARK: return "DEBUG_MARK"; case UserMark::Type::ROUTING: return "ROUTING"; + case UserMark::Type::SPEED_CAM: return "SPEED_CAM"; case UserMark::Type::LOCAL_ADS: return "LOCAL_ADS"; case UserMark::Type::TRANSIT: return "TRANSIT"; case UserMark::Type::USER_MARK_TYPES_COUNT: return "USER_MARK_TYPES_COUNT"; diff --git a/map/user_mark.hpp b/map/user_mark.hpp index bbd954a8cc..d4d9a2c448 100644 --- a/map/user_mark.hpp +++ b/map/user_mark.hpp @@ -27,7 +27,8 @@ public: TransitStop, TransitGate, TransitTransfer, - TransitKeyStop + TransitKeyStop, + SpeedCamera, }; enum Type: uint32_t @@ -37,6 +38,7 @@ public: SEARCH, STATIC, ROUTING, + SPEED_CAM, TRANSIT, LOCAL_ADS, DEBUG_MARK, @@ -69,7 +71,7 @@ public: drape_ptr GetSymbolOffsets() const override { return nullptr; } uint16_t GetPriority() const override { return static_cast(Priority::Default); } uint32_t GetIndex() const override { return 0; } - bool HasSymbolPriority() const override { return false; } + bool HasSymbolShapes() const override { return false; } bool HasTitlePriority() const override { return false; } int GetMinZoom() const override { return 1; } int GetMinTitleZoom() const override { return GetMinZoom(); } @@ -126,4 +128,18 @@ public: drape_ptr GetSymbolNames() const override; }; +class ColoredDebugMarkPoint : public UserMark +{ +public: + ColoredDebugMarkPoint(m2::PointD const & ptOrg); + + void SetColor(dp::Color const & color); + bool HasSymbolShapes() const override { return true; } + drape_ptr GetSymbolNames() const override { return nullptr; } + drape_ptr GetColoredSymbols() const override; + +private: + ColoredSymbolZoomInfo m_coloredSymbols; +}; + string DebugPrint(UserMark::Type type);