diff --git a/drape_frontend/text_layout.cpp b/drape_frontend/text_layout.cpp index a4f1e8ffde..ab624b7d80 100644 --- a/drape_frontend/text_layout.cpp +++ b/drape_frontend/text_layout.cpp @@ -360,10 +360,10 @@ StraightTextLayout::StraightTextLayout(strings::UniString const & text, float fo CalculateOffsets(anchor, m_textSizeRatio, m_metrics, delimIndexes, m_offsets, m_pixelSize, m_rowsCount); } -void StraightTextLayout::AdjustTextOffset(m2::PointF const & symbolSize, dp::Anchor textAnchor, dp::Anchor symbolAnchor, - glsl::vec2 & offset) const +m2::PointF StraightTextLayout::GetSymbolBasedTextOffset(m2::PointF const & symbolSize, dp::Anchor textAnchor, + dp::Anchor symbolAnchor) { - offset = m_baseOffset; + m2::PointF offset(0.0f, 0.0f); float const halfSymbolW = symbolSize.x / 2.0f; float const halfSymbolH = symbolSize.y / 2.0f; @@ -383,6 +383,15 @@ void StraightTextLayout::AdjustTextOffset(m2::PointF const & symbolSize, dp::Anc adjustOffset(textAnchor); adjustOffset(symbolAnchor); + + return offset; +} + +glsl::vec2 StraightTextLayout::GetTextOffset(m2::PointF const & symbolSize, dp::Anchor textAnchor, + dp::Anchor symbolAnchor) const +{ + auto const symbolBasedOffset = GetSymbolBasedTextOffset(symbolSize, textAnchor, symbolAnchor); + return m_baseOffset + glsl::ToVec2(symbolBasedOffset); } void StraightTextLayout::CacheStaticGeometry(dp::TextureManager::ColorRegion const & colorRegion, diff --git a/drape_frontend/text_layout.hpp b/drape_frontend/text_layout.hpp index b135754d53..f66709e0b3 100644 --- a/drape_frontend/text_layout.hpp +++ b/drape_frontend/text_layout.hpp @@ -70,8 +70,12 @@ public: m2::PointF const & GetPixelSize() const { return m_pixelSize; } size_t GetRowsCount() const { return m_rowsCount; } - void AdjustTextOffset(m2::PointF const & symbolSize, dp::Anchor textAnchor, dp::Anchor symbolAnchor, - glsl::vec2 & offset) const; + static m2::PointF GetSymbolBasedTextOffset(m2::PointF const & symbolSize, + dp::Anchor textAnchor, + dp::Anchor symbolAnchor); + + glsl::vec2 GetTextOffset(m2::PointF const & symbolSize, dp::Anchor textAnchor, dp::Anchor symbolAnchor) const; + private: template void Cache(TGenerator & generator) const diff --git a/drape_frontend/text_shape.cpp b/drape_frontend/text_shape.cpp index 26b9edfb6b..6fc2b7464c 100644 --- a/drape_frontend/text_shape.cpp +++ b/drape_frontend/text_shape.cpp @@ -66,8 +66,7 @@ public: float lerpCoef = 0.0f; ExtractZoomFactors(screen, zoom, index, lerpCoef); m2::PointF symbolSize = InterpolateByZoomLevels(index, lerpCoef, m_symbolSizes); - glsl::vec2 offset; - m_layout->AdjustTextOffset(symbolSize, m_anchor, m_symbolAnchor, offset); + auto const offset = m_layout->GetTextOffset(symbolSize, m_anchor, m_symbolAnchor); m_buffer.clear(); m_layout->CacheDynamicGeometry(offset, m_buffer); m_offset = glsl::ToPoint(offset); @@ -311,8 +310,7 @@ void TextShape::DrawSubStringPlain(ref_ptr context, textures->GetColorRegion(font.m_color, color); textures->GetColorRegion(font.m_outlineColor, outline); - glm::vec2 finalOffset = baseOffset; - layout.AdjustTextOffset(m_symbolSizes.front(), m_params.m_titleDecl.m_anchor, m_symbolAnchor, finalOffset); + auto const finalOffset = layout.GetTextOffset(m_symbolSizes.front(), m_params.m_titleDecl.m_anchor, m_symbolAnchor); layout.CacheDynamicGeometry(finalOffset, dynamicBuffer); layout.CacheStaticGeometry(color, staticBuffer); @@ -380,10 +378,9 @@ void TextShape::DrawSubStringOutlined(ref_ptr context, textures->GetColorRegion(font.m_color, color); textures->GetColorRegion(font.m_outlineColor, outline); - glm::vec2 finalOffset = baseOffset; - layout.AdjustTextOffset(m_symbolSizes.front(), m_params.m_titleDecl.m_anchor, m_symbolAnchor, finalOffset); - + auto const finalOffset = layout.GetTextOffset(m_symbolSizes.front(), m_params.m_titleDecl.m_anchor, m_symbolAnchor); layout.CacheDynamicGeometry(finalOffset, dynamicBuffer); + layout.CacheStaticGeometry(color, outline, staticBuffer); auto state = CreateRenderState(gpu::Program::TextOutlined, m_params.m_depthLayer); diff --git a/drape_frontend/user_mark_shapes.cpp b/drape_frontend/user_mark_shapes.cpp index fd7d2e341d..8f2b29e4a1 100644 --- a/drape_frontend/user_mark_shapes.cpp +++ b/drape_frontend/user_mark_shapes.cpp @@ -114,10 +114,12 @@ void GenerateColoredSymbolShapes(ref_ptr context, m2::PointD const & tileCenter, ref_ptr textures, m2::PointF & symbolSize, dp::Batcher & batcher) { - auto const needOverlay = renderInfo.m_coloredSymbols->m_needOverlay; - m2::PointF sizeInc(0.0, 0.0); + m2::PointF sizeInc(0.0f, 0.0f); + m2::PointF offset(0.0f, 0.0f); UserPointMark::SymbolSizes symbolSizesInc; + auto const isTextBg = renderInfo.m_coloredSymbols->m_addTextSize; + if (isTextBg) { auto const & titleDecl = renderInfo.m_titleDecl->at(0); @@ -137,6 +139,8 @@ void GenerateColoredSymbolShapes(ref_ptr context, for (auto const & sz : *renderInfo.m_symbolSizes) symbolSizesInc.push_back(sz + sizeInc); } + + offset = StraightTextLayout::GetSymbolBasedTextOffset(symbolSize, titleDecl.m_anchor, renderInfo.m_anchor); } for (auto itSym = renderInfo.m_coloredSymbols->m_zoomInfo.rbegin(); @@ -146,18 +150,19 @@ void GenerateColoredSymbolShapes(ref_ptr context, { ColoredSymbolViewParams params = itSym->second; + m2::PointF coloredSize(0.0f, 0.0f); if (params.m_shape == ColoredSymbolViewParams::Shape::Circle) { 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); + coloredSize = m2::PointF(params.m_radiusInPixels * 2.0f, params.m_radiusInPixels * 2.0f); } else { params.m_sizeInPixels = params.m_sizeInPixels + sizeInc; - if (!isTextBg) - symbolSize = params.m_sizeInPixels; + coloredSize = params.m_sizeInPixels; } + if (!isTextBg) + symbolSize = m2::PointF(std::max(coloredSize.x, symbolSize.x), std::max(coloredSize.y, symbolSize.y)); params.m_featureID = renderInfo.m_featureId; params.m_tileCenter = tileCenter; @@ -167,6 +172,7 @@ void GenerateColoredSymbolShapes(ref_ptr context, params.m_minVisibleScale = renderInfo.m_minZoom; params.m_specialDisplacement = SpecialDisplacement::UserMark; params.m_specialPriority = renderInfo.m_priority; + params.m_offset += offset; if (renderInfo.m_symbolSizes != nullptr) { ColoredSymbolShape(renderInfo.m_pivot, params, tileKey, @@ -177,7 +183,7 @@ void GenerateColoredSymbolShapes(ref_ptr context, else { ColoredSymbolShape(renderInfo.m_pivot, params, tileKey, - kStartUserMarkOverlayIndex + renderInfo.m_index, needOverlay) + kStartUserMarkOverlayIndex + renderInfo.m_index, renderInfo.m_coloredSymbols->m_needOverlay) .Draw(context, &batcher, textures); } break; @@ -350,7 +356,14 @@ void CacheUserMarks(ref_ptr context, TileKey const & tileKe m2::PointF symbolSize(0.0f, 0.0f); m2::PointF symbolOffset(0.0f, 0.0f); + auto const symbolName = GetSymbolNameForZoomLevel(renderInfo.m_symbolNames, tileKey); + if (!symbolName.empty()) + { + dp::TextureManager::SymbolRegion region; + textures->GetSymbolRegion(symbolName, region); + symbolSize = region.GetPixelSize(); + } dp::Color color = dp::Color::White(); if (!renderInfo.m_color.empty()) @@ -442,14 +455,6 @@ void CacheUserMarks(ref_ptr context, TileKey const & tileKe batcher.InsertListOfStrip(context, state, make_ref(&attribProvider), dp::Batcher::VertexPerQuad); } - if (!symbolName.empty()) - { - dp::TextureManager::SymbolRegion region; - textures->GetSymbolRegion(symbolName, region); - symbolSize.x = std::max(region.GetPixelSize().x, symbolSize.x); - symbolSize.y = std::max(region.GetPixelSize().y, symbolSize.y); - } - if (renderInfo.m_titleDecl != nullptr) { GenerateTextShapes(context, renderInfo, tileKey, tileCenter, symbolSize, symbolOffset, diff --git a/map/routing_mark.cpp b/map/routing_mark.cpp index d85ee24473..cc974a85c4 100644 --- a/map/routing_mark.cpp +++ b/map/routing_mark.cpp @@ -17,18 +17,22 @@ static std::string const kTransitMarkPrimaryTextOutline = "TransitMarkPrimaryTex static std::string const kTransitMarkSecondaryText = "TransitMarkSecondaryText"; static std::string const kTransitMarkSecondaryTextOutline = "TransitMarkSecondaryTextOutline"; -float const kRouteMarkPrimaryTextSize = 11.0f; +float const kRouteMarkPrimaryTextSize = 10.5f; 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; +static std::string const kSpeedCameraMarkText = "SpeedCameraMarkText"; +static std::string const kSpeedCameraMarkBg = "SpeedCameraMarkBg"; +static std::string const kSpeedCameraMarkOutline = "SpeedCameraMarkOutline"; + +float constexpr kSpeedCameraMarkTextSize = 11.0f; +float constexpr kSpeedCameraMarkTextMargin = 1.5f; +float constexpr kSpeedCameraRadius = 3.5f; +float constexpr kSpeedCameraOutlineWidth = 2.0f; + +int constexpr kMinSpeedCameraZoom = 13; +int constexpr kMinSpeedCameraTitleZoom = 13; } // namespace RouteMarkPoint::RouteMarkPoint(m2::PointD const & ptOrg) @@ -410,7 +414,7 @@ TransitMark::TransitMark(m2::PointD const & ptOrg) : UserMark(ptOrg, Type::TRANSIT) {} -void TransitMark::SetFeatureId(FeatureID featureId) +void TransitMark::SetFeatureId(FeatureID const & featureId) { SetDirty(); m_featureId = featureId; @@ -531,18 +535,20 @@ SpeedCameraMark::SpeedCameraMark(m2::PointD const & ptOrg) 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_titleDecl.m_primaryOffset.x = kSpeedCameraOutlineWidth + kSpeedCameraMarkTextMargin; + m_titleDecl.m_anchor = dp::Left; - m_symbolNames.insert(std::make_pair(kSpeedCameraZoomS, "speedcam-s")); - m_symbolNames.insert(std::make_pair(kSpeedCameraZoomM, "speedcam-m")); + m_symbolNames.insert(std::make_pair(kMinSpeedCameraZoom, "speedcam-alert-l")); df::ColoredSymbolViewParams params; - params.m_color = dp::Color::Red(); - params.m_anchor = dp::Right; + params.m_color = df::GetColorConstant(kSpeedCameraMarkBg); + params.m_anchor = dp::Left; params.m_shape = df::ColoredSymbolViewParams::Shape::RoundedRectangle; - params.m_radiusInPixels = kSpeedCameraBorderWidth * vs; - params.m_sizeInPixels = m2::PointF(2.0f * kSpeedCameraBorderWidth, 2.0f * kSpeedCameraBorderWidth) * vs; + params.m_radiusInPixels = kSpeedCameraRadius * vs; + auto const minSize = 2.0f * (kSpeedCameraOutlineWidth + kSpeedCameraMarkTextMargin); + params.m_sizeInPixels = m2::PointF(minSize, minSize) * vs; + params.m_outlineColor = df::GetColorConstant(kSpeedCameraMarkOutline); + params.m_outlineWidth = kSpeedCameraOutlineWidth; m_textBg.m_zoomInfo[kMinSpeedCameraTitleZoom] = params; m_textBg.m_addTextSize = true; } @@ -553,12 +559,6 @@ void SpeedCameraMark::SetTitle(std::string const & title) m_titleDecl.m_primaryText = title; } -void SpeedCameraMark::SetFeatureId(FeatureID featureId) -{ - SetDirty(); - m_featureId = featureId; -} - void SpeedCameraMark::SetIndex(uint32_t index) { SetDirty(); @@ -586,7 +586,7 @@ drape_ptr SpeedCameraMark::GetColoredS int SpeedCameraMark::GetMinZoom() const { - return kSpeedCameraZoomS; + return kMinSpeedCameraZoom; } int SpeedCameraMark::GetMinTitleZoom() const @@ -596,5 +596,5 @@ int SpeedCameraMark::GetMinTitleZoom() const dp::Anchor SpeedCameraMark::GetAnchor() const { - return dp::Left; + return dp::Center; } diff --git a/map/routing_mark.hpp b/map/routing_mark.hpp index ce04be9282..2b0791e775 100644 --- a/map/routing_mark.hpp +++ b/map/routing_mark.hpp @@ -115,7 +115,7 @@ public: void SetAnchor(dp::Anchor anchor); dp::Anchor GetAnchor() const override; - void SetFeatureId(FeatureID featureId); + void SetFeatureId(FeatureID const & featureId); FeatureID GetFeatureID() const override { return m_featureId; } void SetIndex(uint32_t index); @@ -167,9 +167,6 @@ 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; } @@ -188,7 +185,6 @@ public: private: uint32_t m_index = 0; - FeatureID m_featureId; SymbolNameZoomInfo m_symbolNames; ColoredSymbolZoomInfo m_textBg; std::string m_title;