From 9322e2e74fce2a3702f9605204192c7edc377fc2 Mon Sep 17 00:00:00 2001 From: rachytski Date: Sun, 8 Jan 2012 15:25:27 +0400 Subject: [PATCH] added clipping elements in InfoLayer to the specified rectangle bounds. --- map/tile_renderer.cpp | 4 ++++ yg/info_layer.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++ yg/info_layer.hpp | 2 ++ 3 files changed, 50 insertions(+) diff --git a/map/tile_renderer.cpp b/map/tile_renderer.cpp index f8eb19791b..258e00cf93 100644 --- a/map/tile_renderer.cpp +++ b/map/tile_renderer.cpp @@ -177,6 +177,10 @@ void TileRenderer::DrawTile(core::CommandsQueue::Environment const & env, if (!env.isCancelled()) drawer->screen()->resetInfoLayer(); + /// filter out the overlay elements that are out of the bound rect for the tile + if (!env.isCancelled()) + tileInfoLayer->clip(renderRect); + yg::gl::PacketsQueue * glQueue = threadData.m_drawerParams.m_renderQueue; if (!env.isCancelled()) diff --git a/yg/info_layer.cpp b/yg/info_layer.cpp index dbef6fb941..fb02064245 100644 --- a/yg/info_layer.cpp +++ b/yg/info_layer.cpp @@ -255,5 +255,49 @@ namespace yg v[pos]->setIsNeedRedraw(false); } } + + void InfoLayer::clip(m2::RectI const & r) + { + vector > v; + m_tree.ForEach(MakeBackInsertFunctor(v)); + m_tree.Clear(); + + int clippedCnt = 0; + int elemCnt = v.size(); + + m2::RectD rd(r); + m2::AnyRectD ard(rd); + + for (unsigned i = 0; i < v.size(); ++i) + { + shared_ptr const & e = v[i]; + + if (!e->isVisible()) + { + clippedCnt++; + continue; + } + + if (!e->roughBoundRect().IsIntersect(rd)) + clippedCnt++; + else + { + bool hasIntersection = false; + for (unsigned j = 0; j < e->boundRects().size(); ++j) + { + if (ard.IsIntersect(e->boundRects()[j])) + { + hasIntersection = true; + break; + } + } + + if (hasIntersection) + processOverlayElement(e); + } + } + + LOG(LINFO, ("clipped out", clippedCnt, "elements,", elemCnt, "elements total")); + } } diff --git a/yg/info_layer.hpp b/yg/info_layer.hpp index e317f81244..ad93643d3f 100644 --- a/yg/info_layer.hpp +++ b/yg/info_layer.hpp @@ -51,5 +51,7 @@ namespace yg void setCouldOverlap(bool flag); void merge(InfoLayer const & infoLayer, math::Matrix const & m); + + void clip(m2::RectI const & r); }; }