From 204fa3798691632ec4cae2c57e0f68f4e3559168 Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 12 Jan 2011 14:20:48 +0200 Subject: [PATCH] Filter equal path texts. --- map/draw_info.hpp | 9 +++++++++ map/drawer_yg.cpp | 31 ++++++++++++++++++++++++++----- map/drawer_yg.hpp | 12 +++++++----- yg/geometry_batcher.cpp | 22 +++++++++++----------- yg/geometry_batcher.hpp | 4 ++-- 5 files changed, 55 insertions(+), 23 deletions(-) diff --git a/map/draw_info.hpp b/map/draw_info.hpp index fba792b873..21c099659b 100644 --- a/map/draw_info.hpp +++ b/map/draw_info.hpp @@ -1,6 +1,7 @@ #pragma once #include "../geometry/point2d.hpp" +#include "../geometry/rect2d.hpp" #include "../std/vector.hpp" #include "../std/algorithm.hpp" @@ -54,6 +55,14 @@ namespace di ASSERT ( m_offset >= 0.0, (m_offset) ); return m_offset; } + + m2::RectD GetLimitRect() const + { + m2::RectD rect; + for (size_t i = 0; i < m_path.size(); ++i) + rect.Add(m_path[i]); + return rect; + } }; class AreaInfo diff --git a/map/drawer_yg.cpp b/map/drawer_yg.cpp index 73aaecafcc..bb9f17c74c 100644 --- a/map/drawer_yg.cpp +++ b/map/drawer_yg.cpp @@ -58,6 +58,7 @@ void DrawerYG::beginFrame() void DrawerYG::endFrame() { m_pScreen->endFrame(); + m_pathsOrg.clear(); } void DrawerYG::clear(yg::Color const & c, bool clearRT, float depth, bool clearDepth) @@ -152,14 +153,15 @@ void DrawerYG::drawText(m2::PointD const & pt, string const & name, rule_ptr_t p m_pScreen->drawText(pt, 0.0, fontSize, name, depth); } -void DrawerYG::drawPathText(di::PathInfo const & info, string const & name, rule_ptr_t pRule, int /*depth*/) +bool DrawerYG::drawPathText(di::PathInfo const & info, string const & name, uint8_t fontSize, int /*depth*/) { - uint8_t fontSize = get_font_size(pRule) - 2; if (fontSize >= yg::minTextSize * m_visualScale) { - m_pScreen->drawPathText(&info.m_path[0], info.m_path.size(), fontSize, name, info.GetLength(), info.GetOffset(), - yg::gl::Screen::middle_line, true, yg::maxDepth); + return m_pScreen->drawPathText( &info.m_path[0], info.m_path.size(), fontSize, name, + info.GetLength(), info.GetOffset(), + yg::gl::Screen::middle_line, true, yg::maxDepth); } + return false; } shared_ptr DrawerYG::screen() const @@ -234,7 +236,26 @@ void DrawerYG::Draw(di::DrawInfo const * pInfo, rule_ptr_t pRule, int depth) if (isPath && !isArea && isN) { for (list::const_iterator i = pInfo->m_pathes.begin(); i != pInfo->m_pathes.end(); ++i) - drawPathText(*i, pInfo->m_name, pRule, depth); + { + uint8_t const fontSize = get_font_size(pRule) - 2; // subtract to fit name in path + + 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); + + bool needDraw = true; + for (list::const_iterator j = lst.begin(); j != lst.end(); ++j) + if (r.IsIntersect(*j)) + { + needDraw = false; + break; + } + + if (needDraw && drawPathText(*i, pInfo->m_name, fontSize, depth)) + lst.push_back(r); + } } // draw point text diff --git a/map/drawer_yg.hpp b/map/drawer_yg.hpp index ce4ad78d63..6d220e6c82 100644 --- a/map/drawer_yg.hpp +++ b/map/drawer_yg.hpp @@ -8,10 +8,13 @@ #include "../std/list.hpp" #include "../std/string.hpp" #include "../std/shared_ptr.hpp" +#include "../std/map.hpp" + class ScreenBase; namespace drule { class BaseRule; } + namespace yg { namespace gl @@ -55,13 +58,16 @@ private: uint8_t get_font_size(rule_ptr_t pRule); + typedef map > org_map_t; + org_map_t m_pathsOrg; + protected: void drawSymbol(m2::PointD const & pt, rule_ptr_t pRule, int depth); void drawPath(vector const & pts, rule_ptr_t pRule, int depth); void drawArea(vector const & pts, rule_ptr_t pRule, int depth); void drawText(m2::PointD const & pt, string const & name, rule_ptr_t pRule, int depth); - void drawPathText(di::PathInfo const & info, string const & name, rule_ptr_t pRule, int depth); + bool drawPathText(di::PathInfo const & info, string const & name, uint8_t fontSize, int depth); typedef shared_ptr texture_t; typedef shared_ptr frame_buffer_t; @@ -74,10 +80,6 @@ public: void drawSymbol(m2::PointD const & pt, string const & symbolName, int depth); - //render_target_t renderTarget() const; -// void setFrameBuffer(frame_buffer_t frameBuffer); - //frame_buffer_t frameBuffer() const; - void beginFrame(); void endFrame(); diff --git a/yg/geometry_batcher.cpp b/yg/geometry_batcher.cpp index f521944caa..5267a43de8 100644 --- a/yg/geometry_batcher.cpp +++ b/yg/geometry_batcher.cpp @@ -707,16 +707,19 @@ namespace yg return true; } - void GeometryBatcher::drawPathText( + bool GeometryBatcher::drawPathText( m2::PointD const * path, size_t s, uint8_t fontSize, string const & utf8Text, double fullLength, double pathOffset, TextPos pos, bool isMasked, double depth, bool isFixedFont) { if (isMasked) - drawPathTextImpl(path, s, fontSize, utf8Text, fullLength, pathOffset, pos, true, depth, isFixedFont); - drawPathTextImpl(path, s, fontSize, utf8Text, fullLength, pathOffset, pos, false, depth, isFixedFont); + { + if (!drawPathTextImpl(path, s, fontSize, utf8Text, fullLength, pathOffset, pos, true, depth, isFixedFont)) + return false; + } + return drawPathTextImpl(path, s, fontSize, utf8Text, fullLength, pathOffset, pos, false, depth, isFixedFont); } - void GeometryBatcher::drawPathTextImpl( + bool GeometryBatcher::drawPathTextImpl( m2::PointD const * path, size_t s, uint8_t fontSize, string const & utf8Text, double fullLength, double pathOffset, TextPos pos, bool fromMask, double depth, bool isFixedFont) { @@ -724,11 +727,6 @@ namespace yg wstring const text = GetDrawString(utf8Text); -// FontInfo const & fontInfo = fontSize > 0 ? m_skin->getBigFont() : m_skin->getSmallFont(); -// FontInfo const & fontInfo = m_skin->getFont(translateFontSize(fontSize)); - -// fontSize = translateFontSize(fontSize); - // calculate base line offset float blOffset = 2; switch (pos) @@ -752,9 +750,9 @@ namespace yg // offset of the text from path's start double offset = (fullLength - strLength) / 2.0; - if (offset < 0.0) return; + if (offset < 0.0) return false; offset -= pathOffset; - if (-offset >= strLength) return; + if (-offset >= strLength) return false; // find first visible glyph size_t i = 0; @@ -778,6 +776,8 @@ namespace yg offset = glyphs[i]->m_xAdvance; } + + return true; } void GeometryBatcher::enableClipRect(bool flag) diff --git a/yg/geometry_batcher.hpp b/yg/geometry_batcher.hpp index 006e48130a..e0e9902468 100644 --- a/yg/geometry_batcher.hpp +++ b/yg/geometry_batcher.hpp @@ -81,7 +81,7 @@ namespace yg int m_aaShift; - void drawPathTextImpl(m2::PointD const * path, + bool drawPathTextImpl(m2::PointD const * path, size_t s, uint8_t fontSize, string const & utf8Text, @@ -139,7 +139,7 @@ namespace yg uint8_t fontSize); /// Drawing text in the middle of the path. - void drawPathText(m2::PointD const * path, + bool drawPathText(m2::PointD const * path, size_t s, uint8_t fontSize, string const & utf8Text,