From a7c0ec1cfedeec65dd8f0341333bad761cf5f6a7 Mon Sep 17 00:00:00 2001 From: Constantin Shalnev Date: Thu, 5 Nov 2015 13:02:07 +0300 Subject: [PATCH] Draw road number shields by styles specified in mapcss --- drape/color.hpp | 9 +++--- drape_frontend/apply_feature_functors.cpp | 37 ++++++++++++++++++----- drape_frontend/apply_feature_functors.hpp | 3 ++ 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/drape/color.hpp b/drape/color.hpp index d861a5461b..7903b1e9c0 100644 --- a/drape/color.hpp +++ b/drape/color.hpp @@ -25,11 +25,10 @@ struct Color bool operator==(Color const & other) const { return m_rgba == other.m_rgba; } bool operator< (Color const & other) const { return m_rgba < other.m_rgba; } - static Color Black() { return Color(0, 0, 0, 255); } - static Color White() { return Color(255, 255, 255, 255); } - static Color Red() { return Color(255, 0, 0, 255); } - static Color Transparent() { return Color(0, 0, 0, 0); } - static Color RoadNumberOutline() { return Color(150, 75, 0, 255); } + static Color Black() { return Color(0, 0, 0, 255); } + static Color White() { return Color(255, 255, 255, 255); } + static Color Red() { return Color(255, 0, 0, 255); } + static Color Transparent() { return Color(0, 0, 0, 0); } private: uint32_t m_rgba; diff --git a/drape_frontend/apply_feature_functors.cpp b/drape_frontend/apply_feature_functors.cpp index 1307d8c236..cde4cc1aec 100644 --- a/drape_frontend/apply_feature_functors.cpp +++ b/drape_frontend/apply_feature_functors.cpp @@ -150,6 +150,15 @@ void CaptionDefProtoToFontDecl(CaptionDefProto const * capRule, dp::FontDecl &pa params.m_outlineColor = ToDrapeColor(capRule->stroke_color()); } +void ShieldRuleProtoToFontDecl(ShieldRuleProto const * shieldRule, dp::FontDecl ¶ms) +{ + params.m_color = ToDrapeColor(shieldRule->color()); + params.m_size = max(8.0, shieldRule->height() * df::VisualParams::Instance().GetVisualScale()); + + if (shieldRule->has_stroke_color()) + params.m_outlineColor = ToDrapeColor(shieldRule->stroke_color()); +} + dp::Anchor GetAnchor(CaptionDefProto const * capRule) { if (capRule->has_offset_y()) @@ -343,6 +352,8 @@ ApplyLineFeature::ApplyLineFeature(TInsertShapeFn const & insertShape, FeatureID , m_sqrScale(math::sqr(m_currentScaleGtoP)) , m_simplify(simplify) , m_initialPointsCount(pointsCount) + , m_shieldDepth(0.0) + , m_shieldRule(nullptr) #ifdef CALC_FILTERED_POINTS , m_readedCount(0) #endif @@ -394,11 +405,9 @@ void ApplyLineFeature::ProcessRule(Stylist::TRuleWrapper const & rule) bool isWay = (pRule->GetType() & drule::way) != 0; CaptionDefProto const * pCaptionRule = pRule->GetCaption(0); LineDefProto const * pLineRule = pRule->GetLine(); - if (pCaptionRule == NULL && pLineRule == NULL) - return; + ShieldRuleProto const * pShieldRule = pRule->GetShield(); - ASSERT(pCaptionRule == NULL || pLineRule == NULL, ()); - if (pCaptionRule != NULL && pCaptionRule->height() > 2 && + if (pCaptionRule != nullptr && pCaptionRule->height() > 2 && !m_captions.GetPathName().empty() && isWay) { dp::FontDecl fontDecl; @@ -413,7 +422,7 @@ void ApplyLineFeature::ProcessRule(Stylist::TRuleWrapper const & rule) m_insertShape(make_unique_dp(m_spline, params)); } - if (pLineRule != NULL) + if (pLineRule != nullptr) { if (pLineRule->has_pathsym()) { @@ -438,6 +447,12 @@ void ApplyLineFeature::ProcessRule(Stylist::TRuleWrapper const & rule) m_insertShape(make_unique_dp(m_spline, params)); } } + + if (pShieldRule != nullptr) + { + m_shieldDepth = depth; + m_shieldRule = pShieldRule; + } } void ApplyLineFeature::Finish() @@ -446,12 +461,18 @@ void ApplyLineFeature::Finish() LinesStat::Get().InsertLine(m_id, m_currentScaleGtoP, m_readedCount, m_spline->GetSize()); #endif + if (m_shieldRule == nullptr) + return; + string const & roadNumber = m_captions.GetRoadNumber(); if (roadNumber.empty()) return; + dp::FontDecl font; + ShieldRuleProtoToFontDecl(m_shieldRule, font); + double pathPixelLength = m_spline->GetLength() * m_currentScaleGtoP; - int const textHeight = static_cast(11 * df::VisualParams::Instance().GetVisualScale()); + int const textHeight = static_cast(font.m_size); // I don't know why we draw by this, but it's work before and will work now if (pathPixelLength > (roadNumber.size() + 2) * textHeight) @@ -462,11 +483,11 @@ void ApplyLineFeature::Finish() double const splineStep = pathPixelLength / count; TextViewParams viewParams; - viewParams.m_depth = 0; + viewParams.m_depth = m_shieldDepth; viewParams.m_anchor = dp::Center; viewParams.m_featureID = FeatureID(); viewParams.m_primaryText = roadNumber; - viewParams.m_primaryTextFont = dp::FontDecl(dp::Color::RoadNumberOutline(), textHeight, dp::Color::White()); + viewParams.m_primaryTextFont = font; viewParams.m_primaryOffset = m2::PointF(0, 0); m2::Spline::iterator it = m_spline.CreateIterator(); diff --git a/drape_frontend/apply_feature_functors.hpp b/drape_frontend/apply_feature_functors.hpp index 6c0562876f..f0fa838ca4 100644 --- a/drape_frontend/apply_feature_functors.hpp +++ b/drape_frontend/apply_feature_functors.hpp @@ -13,6 +13,7 @@ class CircleRuleProto; class SymbolRuleProto; class CaptionDefProto; +class ShieldRuleProto; //#define CALC_FILTERED_POINTS @@ -99,6 +100,8 @@ private: m2::PointD m_lastAddedPoint; bool m_simplify; size_t m_initialPointsCount; + double m_shieldDepth; + ShieldRuleProto const * m_shieldRule; #ifdef CALC_FILTERED_POINTS int m_readedCount;