diff --git a/drape/drape_global.hpp b/drape/drape_global.hpp index 628714e2e2..d66e6e83b7 100644 --- a/drape/drape_global.hpp +++ b/drape/drape_global.hpp @@ -2,6 +2,8 @@ #include "color.hpp" +#include "geometry/point2d.hpp" + #include "base/assert.hpp" #include @@ -79,6 +81,19 @@ struct FontDecl bool m_isSdf = true; }; +struct TitleDecl +{ + dp::FontDecl m_primaryTextFont; + std::string m_primaryText; + dp::FontDecl m_secondaryTextFont; + std::string m_secondaryText; + dp::Anchor m_anchor = Center; + m2::PointF m_primaryOffset = m2::PointF(0.0f, 0.0f); + m2::PointF m_secondaryOffset = m2::PointF(0.0f, 0.0f); + bool m_primaryOptional = false; + bool m_secondaryOptional = false; +}; + inline std::string DebugPrint(dp::ApiVersion apiVersion) { if (apiVersion == dp::OpenGLES2) diff --git a/drape_frontend/apply_feature_functors.cpp b/drape_frontend/apply_feature_functors.cpp index 63f089eea7..ff6a0703a0 100644 --- a/drape_frontend/apply_feature_functors.cpp +++ b/drape_frontend/apply_feature_functors.cpp @@ -433,23 +433,26 @@ void BaseApplyFeature::ExtractCaptionParams(CaptionDefProto const * primaryProto dp::FontDecl decl; CaptionDefProtoToFontDecl(primaryProto, decl); - params.m_anchor = GetAnchor(primaryProto); params.m_depth = depth; params.m_featureID = m_id; - params.m_primaryText = m_captions.GetMainText(); - params.m_primaryTextFont = decl; - params.m_primaryOffset = GetOffset(primaryProto); - params.m_primaryOptional = primaryProto->is_optional(); - params.m_secondaryOptional = true; + + auto & titleDecl = params.m_titleDecl; + titleDecl.m_anchor = GetAnchor(primaryProto); + titleDecl.m_primaryText = m_captions.GetMainText(); + titleDecl.m_primaryTextFont = decl; + titleDecl.m_primaryOffset = GetOffset(primaryProto); + titleDecl.m_primaryOptional = primaryProto->is_optional(); + titleDecl.m_secondaryOptional = true; + if (secondaryProto) { dp::FontDecl auxDecl; CaptionDefProtoToFontDecl(secondaryProto, auxDecl); - params.m_secondaryText = m_captions.GetAuxText(); - params.m_secondaryTextFont = auxDecl; - params.m_secondaryOptional = secondaryProto->is_optional(); + titleDecl.m_secondaryText = m_captions.GetAuxText(); + titleDecl.m_secondaryTextFont = auxDecl; + titleDecl.m_secondaryOptional = secondaryProto->is_optional(); } } @@ -532,18 +535,19 @@ void ApplyPointFeature::ProcessPointRule(Stylist::TRuleWrapper const & rule) params.m_hasArea = m_hasArea; params.m_createdByEditor = m_createdByEditor; + auto & titleDecl = params.m_titleDecl; if (m_displacementMode == dp::displacement::kHotelMode && - m_hotelData.m_isHotel && !params.m_primaryText.empty()) + m_hotelData.m_isHotel && !titleDecl.m_primaryText.empty()) { - params.m_primaryOptional = false; - params.m_primaryTextFont.m_size *= 1.2; - params.m_primaryTextFont.m_outlineColor = df::GetColorConstant(df::kPoiHotelTextOutlineColor); - params.m_secondaryTextFont = params.m_primaryTextFont; - params.m_secondaryText = ExtractHotelInfo(); - params.m_secondaryOptional = false; + titleDecl.m_primaryOptional = false; + titleDecl.m_primaryTextFont.m_size *= 1.2; + titleDecl.m_primaryTextFont.m_outlineColor = df::GetColorConstant(df::kPoiHotelTextOutlineColor); + titleDecl.m_secondaryTextFont = titleDecl.m_primaryTextFont; + titleDecl.m_secondaryText = ExtractHotelInfo(); + titleDecl.m_secondaryOptional = false; } - if (!params.m_primaryText.empty() || !params.m_secondaryText.empty()) + if (!titleDecl.m_primaryText.empty() || !titleDecl.m_secondaryText.empty()) m_textParams.push_back(params); } } @@ -986,13 +990,13 @@ void ApplyLineFeatureAdditional::GetRoadShieldsViewParams(ref_ptrGetSymbolRegion(poiParams.m_symbolName, region); float const symBorderWidth = (region.GetPixelSize().x - textLayout.GetPixelLength()) * 0.5f; float const symBorderHeight = (region.GetPixelSize().y - textLayout.GetPixelHeight()) * 0.5f; - textParams.m_primaryOffset = poiParams.m_offset + GetShieldOffset(anchor, symBorderWidth, symBorderHeight); + textParams.m_titleDecl.m_primaryOffset = poiParams.m_offset + GetShieldOffset(anchor, symBorderWidth, symBorderHeight); shieldPixelSize = region.GetPixelSize(); needAdditionalText = !symbolName.empty() && !shield.m_additionalText.empty() && @@ -1064,12 +1068,13 @@ void ApplyLineFeatureAdditional::GetRoadShieldsViewParams(ref_ptr(); auto idCollection = make_unique_dp(); - IDCollection removedIdCollection; + auto removedIdCollection = make_unique_dp(); marksRenderCollection->reserve(provider->GetUserPointCount()); for (size_t pointIndex = 0, sz = provider->GetUserPointCount(); pointIndex < sz; ++pointIndex) { @@ -227,6 +227,8 @@ void DrapeEngine::UpdateUserMarksLayer(size_t layerId, UserMarksProvider * provi renderInfo->m_pixelOffset = mark->GetPixelOffset(); renderInfo->m_runCreationAnim = mark->HasCreationAnimation(); renderInfo->m_symbolName = mark->GetSymbolName(); + renderInfo->m_titleDecl = mark->GetTitleDecl(); + renderInfo->m_priority = mark->GetProirity(); marksRenderCollection->emplace(mark->GetId(), std::move(renderInfo)); mark->AcceptChanges(); } @@ -253,7 +255,7 @@ void DrapeEngine::UpdateUserMarksLayer(size_t layerId, UserMarksProvider * provi mark->AcceptChanges(); } } - provider->AcceptChanges(removedIdCollection.m_marksID); + provider->AcceptChanges(removedIdCollection->m_marksID); m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread, make_unique_dp(layerId, std::move(idCollection), diff --git a/drape_frontend/message_subclasses.hpp b/drape_frontend/message_subclasses.hpp index 8c3722baec..ef8a2dc069 100644 --- a/drape_frontend/message_subclasses.hpp +++ b/drape_frontend/message_subclasses.hpp @@ -239,7 +239,7 @@ class UpdateUserMarkLayerMessage : public BaseUserMarkLayerMessage public: UpdateUserMarkLayerMessage(size_t layerId, drape_ptr && ids, - IDCollection && removedIds, + drape_ptr && removedIds, drape_ptr && marksRenderParams, drape_ptr && linesRenderParams) : BaseUserMarkLayerMessage(layerId) @@ -254,13 +254,13 @@ public: drape_ptr && AcceptMarkRenderParams() { return std::move(m_marksRenderParams); } drape_ptr && AcceptLineRenderParams() { return std::move(m_linesRenderParams); } drape_ptr && AcceptIds() { return std::move(m_ids); } - IDCollection && AcceptRemovedIds() { return std::move(m_removedIds); } + drape_ptr && AcceptRemovedIds() { return std::move(m_removedIds); } private: drape_ptr m_marksRenderParams; drape_ptr m_linesRenderParams; drape_ptr m_ids; - IDCollection m_removedIds; + drape_ptr m_removedIds; }; class FlushUserMarksMessage : public Message diff --git a/drape_frontend/rule_drawer.cpp b/drape_frontend/rule_drawer.cpp index 5f2850ce5a..12d914fe00 100644 --- a/drape_frontend/rule_drawer.cpp +++ b/drape_frontend/rule_drawer.cpp @@ -541,15 +541,15 @@ void RuleDrawer::DrawTileNet(TInsertShapeFn const & insertShape) df::TextViewParams tp; tp.m_tileCenter = m_globalRect.Center(); - tp.m_anchor = dp::Center; + tp.m_titleDecl.m_anchor = dp::Center; tp.m_depth = 20000; tp.m_depthLayer = dp::GLState::OverlayLayer; - tp.m_primaryText = strings::to_string(key.m_x) + " " + - strings::to_string(key.m_y) + " " + - strings::to_string(key.m_zoomLevel); + tp.m_titleDecl.m_primaryText = strings::to_string(key.m_x) + " " + + strings::to_string(key.m_y) + " " + + strings::to_string(key.m_zoomLevel); - tp.m_primaryTextFont = dp::FontDecl(dp::Color::Red(), 30); - tp.m_primaryOffset = {0.f, 0.f}; + tp.m_titleDecl.m_primaryTextFont = dp::FontDecl(dp::Color::Red(), 30); + tp.m_titleDecl.m_primaryOffset = {0.f, 0.f}; drape_ptr textShape = make_unique_dp(r.Center(), tp, key, false, 0, false); textShape->DisableDisplacing(); insertShape(std::move(textShape)); diff --git a/drape_frontend/shape_view_params.hpp b/drape_frontend/shape_view_params.hpp index 93d8e662d1..4b9b85f364 100644 --- a/drape_frontend/shape_view_params.hpp +++ b/drape_frontend/shape_view_params.hpp @@ -74,15 +74,7 @@ struct TextViewParams : CommonOverlayViewParams TextViewParams() {} FeatureID m_featureID; - dp::FontDecl m_primaryTextFont; - std::string m_primaryText; - dp::FontDecl m_secondaryTextFont; - std::string m_secondaryText; - dp::Anchor m_anchor; - m2::PointF m_primaryOffset = m2::PointF(0.0f, 0.0f); - m2::PointF m_secondaryOffset = m2::PointF(0.0f, 0.0f); - bool m_primaryOptional = false; - bool m_secondaryOptional = false; + dp::TitleDecl m_titleDecl; bool m_hasArea = false; bool m_createdByEditor = false; uint32_t m_extendingSize = 0; diff --git a/drape_frontend/text_shape.cpp b/drape_frontend/text_shape.cpp index 56b041a642..030ccfb56f 100644 --- a/drape_frontend/text_shape.cpp +++ b/drape_frontend/text_shape.cpp @@ -122,26 +122,29 @@ TextShape::TextShape(m2::PointD const & basePoint, TextViewParams const & params void TextShape::Draw(ref_ptr batcher, ref_ptr textures) const { - ASSERT(!m_params.m_primaryText.empty(), ()); - StraightTextLayout primaryLayout(strings::MakeUniString(m_params.m_primaryText), - m_params.m_primaryTextFont.m_size, m_params.m_primaryTextFont.m_isSdf, - textures, m_params.m_anchor); + auto const & titleDecl = m_params.m_titleDecl; + ASSERT(!titleDecl.m_primaryText.empty(), ()); + StraightTextLayout primaryLayout(strings::MakeUniString(titleDecl.m_primaryText), + titleDecl.m_primaryTextFont.m_size, + titleDecl.m_primaryTextFont.m_isSdf, + textures, + titleDecl.m_anchor); if (m_params.m_limitedText && primaryLayout.GetPixelSize().y >= m_params.m_limits.y) { - float const newFontSize = m_params.m_primaryTextFont.m_size * m_params.m_limits.y / primaryLayout.GetPixelSize().y; - primaryLayout = StraightTextLayout(strings::MakeUniString(m_params.m_primaryText), newFontSize, - m_params.m_primaryTextFont.m_isSdf, textures, m_params.m_anchor); + float const newFontSize = titleDecl.m_primaryTextFont.m_size * m_params.m_limits.y / primaryLayout.GetPixelSize().y; + primaryLayout = StraightTextLayout(strings::MakeUniString(titleDecl.m_primaryText), newFontSize, + titleDecl.m_primaryTextFont.m_isSdf, textures, titleDecl.m_anchor); } drape_ptr secondaryLayout; - if (!m_params.m_secondaryText.empty()) + if (!titleDecl.m_secondaryText.empty()) { - secondaryLayout = make_unique_dp(strings::MakeUniString(m_params.m_secondaryText), - m_params.m_secondaryTextFont.m_size, - m_params.m_secondaryTextFont.m_isSdf, + secondaryLayout = make_unique_dp(strings::MakeUniString(titleDecl.m_secondaryText), + titleDecl.m_secondaryTextFont.m_size, + titleDecl.m_secondaryTextFont.m_isSdf, textures, - m_params.m_anchor); + titleDecl.m_anchor); } glsl::vec2 primaryOffset(0.0f, 0.0f); @@ -150,62 +153,62 @@ void TextShape::Draw(ref_ptr batcher, ref_ptr t float const halfSymbolW = m_symbolSize.x / 2.0f; float const halfSymbolH = m_symbolSize.y / 2.0f; - if (m_params.m_anchor & dp::Top) + if (titleDecl.m_anchor & dp::Top) { // In the case when the anchor is dp::Top the value of primary offset y > 0, // the text shape is below the POI. - primaryOffset.y = m_params.m_primaryOffset.y + halfSymbolH; + primaryOffset.y = titleDecl.m_primaryOffset.y + halfSymbolH; if (secondaryLayout != nullptr) { - secondaryOffset.y = m_params.m_primaryOffset.y + primaryLayout.GetPixelSize().y + - m_params.m_secondaryOffset.y + halfSymbolH; + secondaryOffset.y = titleDecl.m_primaryOffset.y + primaryLayout.GetPixelSize().y + + titleDecl.m_secondaryOffset.y + halfSymbolH; } } - else if (m_params.m_anchor & dp::Bottom) + else if (titleDecl.m_anchor & dp::Bottom) { // In the case when the anchor is dp::Bottom the value of primary offset y < 0, // the text shape is above the POI. - primaryOffset.y = m_params.m_primaryOffset.y - halfSymbolH; + primaryOffset.y = titleDecl.m_primaryOffset.y - halfSymbolH; if (secondaryLayout != nullptr) { - primaryOffset.y -= secondaryLayout->GetPixelSize().y + m_params.m_secondaryOffset.y; - secondaryOffset.y = m_params.m_primaryOffset.y - halfSymbolH; + primaryOffset.y -= secondaryLayout->GetPixelSize().y + titleDecl.m_secondaryOffset.y; + secondaryOffset.y = titleDecl.m_primaryOffset.y - halfSymbolH; } } else if (secondaryLayout != nullptr) { // In the case when the anchor is dp::Center there isn't primary offset y. - primaryOffset.y = -(primaryLayout.GetPixelSize().y + m_params.m_secondaryOffset.y) / 2.0f; - secondaryOffset.y = (secondaryLayout->GetPixelSize().y + m_params.m_secondaryOffset.y) / 2.0f; + primaryOffset.y = -(primaryLayout.GetPixelSize().y + titleDecl.m_secondaryOffset.y) / 2.0f; + secondaryOffset.y = (secondaryLayout->GetPixelSize().y + titleDecl.m_secondaryOffset.y) / 2.0f; } - if (m_params.m_anchor & dp::Left) + if (titleDecl.m_anchor & dp::Left) { // In the case when the anchor is dp::Left the value of primary offset x > 0, // the text shape is on the right from the POI. - primaryOffset.x = m_params.m_primaryOffset.x + halfSymbolW; + primaryOffset.x = titleDecl.m_primaryOffset.x + halfSymbolW; if (secondaryLayout != nullptr) secondaryOffset.x = primaryOffset.x; } - else if (m_params.m_anchor & dp::Right) + else if (titleDecl.m_anchor & dp::Right) { // In the case when the anchor is dp::Right the value of primary offset x < 0, // the text shape is on the left from the POI. - primaryOffset.x = m_params.m_primaryOffset.x - halfSymbolW; + primaryOffset.x = titleDecl.m_primaryOffset.x - halfSymbolW; if (secondaryLayout != nullptr) secondaryOffset.x = primaryOffset.x; } if (primaryLayout.GetGlyphCount() > 0) { - DrawSubString(primaryLayout, m_params.m_primaryTextFont, primaryOffset, batcher, - textures, true /* isPrimary */, m_params.m_primaryOptional); + DrawSubString(primaryLayout, titleDecl.m_primaryTextFont, primaryOffset, batcher, + textures, true /* isPrimary */, titleDecl.m_primaryOptional); } if (secondaryLayout != nullptr && secondaryLayout->GetGlyphCount() > 0) { - DrawSubString(*secondaryLayout.get(), m_params.m_secondaryTextFont, secondaryOffset, batcher, - textures, false /* isPrimary */, m_params.m_secondaryOptional); + DrawSubString(*secondaryLayout.get(), titleDecl.m_secondaryTextFont, secondaryOffset, batcher, + textures, false /* isPrimary */, titleDecl.m_secondaryOptional); } } @@ -214,8 +217,8 @@ void TextShape::DrawSubString(StraightTextLayout const & layout, dp::FontDecl co ref_ptr textures, bool isPrimary, bool isOptional) const { - dp::Color outlineColor = isPrimary ? m_params.m_primaryTextFont.m_outlineColor - : m_params.m_secondaryTextFont.m_outlineColor; + dp::Color outlineColor = isPrimary ? m_params.m_titleDecl.m_primaryTextFont.m_outlineColor + : m_params.m_titleDecl.m_secondaryTextFont.m_outlineColor; if (outlineColor == dp::Color::Transparent()) DrawSubStringPlain(layout, font, baseOffset, batcher, textures, isPrimary, isOptional); @@ -256,7 +259,7 @@ void TextShape::DrawSubStringPlain(StraightTextLayout const & layout, dp::FontDe auto overlayId = dp::OverlayID(m_params.m_featureID, m_tileCoords, m_textIndex); drape_ptr handle = make_unique_dp(overlayId, layout.GetText(), - m_params.m_anchor, + m_params.m_titleDecl.m_anchor, glsl::ToVec2(m_basePoint), glsl::vec2(pixelSize.x, pixelSize.y), baseOffset, @@ -305,7 +308,7 @@ void TextShape::DrawSubStringOutlined(StraightTextLayout const & layout, dp::Fon auto overlayId = dp::OverlayID(m_params.m_featureID, m_tileCoords, m_textIndex); drape_ptr handle = make_unique_dp(overlayId, layout.GetText(), - m_params.m_anchor, + m_params.m_titleDecl.m_anchor, glsl::ToVec2(m_basePoint), glsl::vec2(pixelSize.x, pixelSize.y), baseOffset, @@ -347,7 +350,7 @@ uint64_t TextShape::GetOverlayPriority() const static uint64_t constexpr kMask = ~static_cast(0xFFFF); uint64_t priority = dp::CalculateOverlayPriority(m_params.m_minVisibleScale, m_params.m_rank, m_params.m_depth); priority &= kMask; - priority |= (static_cast(m_params.m_primaryText.size()) << 8); + priority |= (static_cast(m_params.m_titleDecl.m_primaryText.size()) << 8); priority |= static_cast(m_textIndex); return priority; diff --git a/drape_frontend/user_mark_generator.cpp b/drape_frontend/user_mark_generator.cpp index b1d8a3d233..2632139575 100644 --- a/drape_frontend/user_mark_generator.cpp +++ b/drape_frontend/user_mark_generator.cpp @@ -30,12 +30,14 @@ void UserMarkGenerator::SetGroup(GroupID groupId, drape_ptr && ids UpdateIndex(groupId); } -void UserMarkGenerator::RemoveUserMarks(IDCollection && ids) +void UserMarkGenerator::RemoveUserMarks(drape_ptr && ids) { - for (auto const & id : ids.m_marksID) - m_marks.erase(id); - for (auto const & id : ids.m_linesID) - m_lines.erase(id); + if (ids == nullptr) + return; + for (auto const & id : ids->m_marksID) + m_marks.erase(id); + for (auto const & id : ids->m_linesID) + m_lines.erase(id); } void UserMarkGenerator::SetUserMarks(drape_ptr && marks) diff --git a/drape_frontend/user_mark_generator.hpp b/drape_frontend/user_mark_generator.hpp index eb1c10674d..5002c6a230 100644 --- a/drape_frontend/user_mark_generator.hpp +++ b/drape_frontend/user_mark_generator.hpp @@ -29,7 +29,7 @@ public: void SetGroup(GroupID groupId, drape_ptr && ids); void RemoveGroup(GroupID groupId); - void RemoveUserMarks(IDCollection && ids); + void RemoveUserMarks(drape_ptr && ids); void SetGroupVisibility(GroupID groupId, bool isVisible); diff --git a/drape_frontend/user_mark_shapes.hpp b/drape_frontend/user_mark_shapes.hpp index 763e806de1..92ad10fafc 100644 --- a/drape_frontend/user_mark_shapes.hpp +++ b/drape_frontend/user_mark_shapes.hpp @@ -19,6 +19,8 @@ struct UserMarkRenderParams m2::PointD m_pixelOffset = m2::PointD(0.0, 0.0); std::string m_symbolName; dp::Anchor m_anchor = dp::Center; + drape_ptr m_titleDecl; + uint16_t m_priority; float m_depth = 0.0; bool m_runCreationAnim = false; bool m_isVisible = true; diff --git a/drape_frontend/user_marks_provider.hpp b/drape_frontend/user_marks_provider.hpp index b5dbd72987..dd3e5716b5 100644 --- a/drape_frontend/user_marks_provider.hpp +++ b/drape_frontend/user_marks_provider.hpp @@ -1,6 +1,7 @@ #pragma once #include "drape/drape_global.hpp" +#include "drape/pointers.hpp" #include "geometry/polyline2d.hpp" @@ -31,6 +32,9 @@ public: virtual bool HasCreationAnimation() const = 0; virtual bool IsVisible() const { return true; } + virtual drape_ptr GetTitleDecl() const { return nullptr; } + virtual uint16_t GetProirity() const { return 0; } + private: uint32_t m_id; }; @@ -50,7 +54,7 @@ public: virtual dp::Color const & GetColor(size_t layerIndex) const = 0; virtual float GetWidth(size_t layerIndex) const = 0; virtual float GetLayerDepth(size_t layerIndex) const = 0; - virtual std::vector const & GetPoints() const = 0; + virtual std::vector const & GetPoints() const = 0; private: uint32_t m_id;