From 409f1a4384a6e7572296dca747fea3635e3a23be Mon Sep 17 00:00:00 2001 From: vng Date: Sat, 11 Jun 2011 00:43:51 +0300 Subject: [PATCH] Don't draw number for roads with visible name. --- map/drawer_yg.cpp | 93 +++++++++++++++++++++++++++-------------------- map/drawer_yg.hpp | 1 + map/framework.cpp | 8 ++-- 3 files changed, 58 insertions(+), 44 deletions(-) diff --git a/map/drawer_yg.cpp b/map/drawer_yg.cpp index 2c1549c3a5..8496edccb7 100644 --- a/map/drawer_yg.cpp +++ b/map/drawer_yg.cpp @@ -277,6 +277,32 @@ bool DrawerYG::drawPathText(di::PathInfo const & info, string const & name, uint yg::maxDepth); } +void DrawerYG::drawPathNumber(di::PathInfo const & path, di::DrawInfo const * pInfo) +{ + int const textHeight = 12; + m2::PointD pt; + double const length = path.GetFullLength(); + if (length >= (pInfo->m_road.size() + 2)*textHeight) + { + size_t const count = size_t(length / 1000.0) + 2; + + for (size_t j = 1; j < count; ++j) + { + if (path.GetSmPoint(double(j) / double(count), pt)) + { + yg::FontDesc fontDesc( + false, + textHeight, + yg::Color(150, 75, 0, 255), // brown + true, + yg::Color(255, 255, 255, 255)); + + m_pScreen->drawText(fontDesc, pt, yg::EPosCenter, 0.0, pInfo->m_road, yg::maxDepth, true); + } + } + } +} + shared_ptr DrawerYG::screen() const { return m_pScreen; @@ -314,37 +340,17 @@ void DrawerYG::Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size if (!pathRules.empty()) { - bool const isNumber = !pInfo->m_road.empty() && m_level >= 12; - for (list::const_iterator i = pInfo->m_pathes.begin(); i != pInfo->m_pathes.end(); ++i) { drawPath(i->m_path, pathRules.data(), pathRules.size()); - - int const textHeight = 12; - m2::PointD pt; - double const length = i->GetFullLength(); - if (isNumber && (length >= (pInfo->m_road.size() + 2)*textHeight)) - { - size_t const count = size_t(length / 1000.0) + 2; - - for (size_t j = 1; j < count; ++j) - { - if (i->GetSmPoint(double(j) / double(count), pt)) - { - yg::FontDesc fontDesc( - false, - textHeight, - yg::Color(150, 75, 0, 255), // brown - true, - yg::Color(255, 255, 255, 255)); - - m_pScreen->drawText(fontDesc, pt, yg::EPosCenter, 0.0, pInfo->m_road, yg::maxDepth, true); - } - } - } } } + bool const isPath = !pInfo->m_pathes.empty(); + bool const isArea = !pInfo->m_areas.empty(); + + bool isNumber = true; + for (unsigned i = 0; i < count; ++i) { rule_ptr_t pRule = rules[i].m_rule; @@ -356,10 +362,6 @@ void DrawerYG::Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size pRule->GetSymbol(symbol); bool const hasSymbol = !symbol.empty(); - bool const isPath = !pInfo->m_pathes.empty(); - bool const isArea = !pInfo->m_areas.empty(); - bool const hasName = !pInfo->m_name.empty(); - bool const isCircle = (pRule->GetRadius() != -1); if (!isCaption) @@ -398,7 +400,7 @@ void DrawerYG::Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size } else { - if (hasName) + if (!pInfo->m_name.empty()) { bool isN = ((pRule->GetType() & drule::way) != 0); @@ -410,17 +412,13 @@ void DrawerYG::Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size } // draw way name - if (isPath && !isArea && isN) + if (isPath && !isArea && isN && !filter_text_size(pRule)) { + uint8_t const fontSize = get_pathtext_font_size(pRule); + list & lst = m_pathsOrg[pInfo->m_name]; + for (list::const_iterator i = pInfo->m_pathes.begin(); i != pInfo->m_pathes.end(); ++i) { - if (filter_text_size(pRule)) - continue; - - uint8_t const fontSize = get_pathtext_font_size(pRule); - - list & lst = m_pathsOrg[pInfo->m_name]; - m2::RectD r = i->GetLimitRect(); r.Inflate(-r.SizeX() / 4.0, -r.SizeY() / 4.0); r.Inflate(fontSize, fontSize); @@ -433,8 +431,16 @@ void DrawerYG::Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size break; } - if (needDraw && drawPathText(*i, pInfo->m_name, fontSize, depth)) - lst.push_back(r); + if (needDraw) + { + if (drawPathText(*i, pInfo->m_name, fontSize, depth)) + { + isNumber = false; // text hides number + lst.push_back(r); + } + } + else + isNumber = false; // neighbor text hides this text and this number } } @@ -445,4 +451,11 @@ void DrawerYG::Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size } } } + + // draw road numbers + if (isNumber && isPath && !pInfo->m_road.empty() && m_level >= 12) + { + for (list::const_iterator i = pInfo->m_pathes.begin(); i != pInfo->m_pathes.end(); ++i) + drawPathNumber(*i, pInfo); + } } diff --git a/map/drawer_yg.hpp b/map/drawer_yg.hpp index 21a15d077d..5ff170ed15 100644 --- a/map/drawer_yg.hpp +++ b/map/drawer_yg.hpp @@ -83,6 +83,7 @@ protected: void drawText(m2::PointD const & pt, di::DrawInfo const * pInfo, rule_ptr_t pRule, yg::EPosition pos, int depth); bool drawPathText(di::PathInfo const & info, string const & name, uint8_t fontSize, int depth); + void drawPathNumber(di::PathInfo const & path, di::DrawInfo const * pInfo); typedef shared_ptr texture_t; typedef shared_ptr frame_buffer_t; diff --git a/map/framework.cpp b/map/framework.cpp index b8c7a34734..664f014f1d 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -173,10 +173,10 @@ namespace fwork m_renderState->m_isEmptyModelCurrent = false; - shared_ptr ptr( - new di::DrawInfo(f.GetPreferredDrawableName(languages::GetCurrentPriorities()), - f.GetRoadNumber(), - m_zoom > 5 ? f.GetPopulationDrawRank() : 0.0)); + shared_ptr ptr(new di::DrawInfo( + f.GetPreferredDrawableName(languages::GetCurrentPriorities()), + f.GetRoadNumber(), + (m_zoom > 5) ? f.GetPopulationDrawRank() : 0.0)); DrawerYG * pDrawer = GetDrawer();