From 2b2be34748405f9c77851aec64c14987394f13ad Mon Sep 17 00:00:00 2001 From: vng Date: Sat, 14 Sep 2013 18:02:14 +0300 Subject: [PATCH] Avoid copy-paste - use ScalesProcessor::GetBaseTileScale(). --- map/scales_processor.cpp | 2 + map/simple_render_policy.cpp | 15 ++----- map/yopme_render_policy.cpp | 84 ++++++++++++++++++------------------ map/yopme_render_policy.hpp | 3 ++ 4 files changed, 50 insertions(+), 54 deletions(-) diff --git a/map/scales_processor.cpp b/map/scales_processor.cpp index e8ba7d1df8..04587b9f5a 100644 --- a/map/scales_processor.cpp +++ b/map/scales_processor.cpp @@ -6,6 +6,8 @@ #include "../indexer/scales.hpp" +/// Note! Default tile size value should be equal with +/// the default value in RenderPolicy::TileSisze(). ScalesProcessor::ScalesProcessor() : m_tileSize(256), m_visualScale(1.0) { diff --git a/map/simple_render_policy.cpp b/map/simple_render_policy.cpp index b3bd869359..c8740c58e5 100644 --- a/map/simple_render_policy.cpp +++ b/map/simple_render_policy.cpp @@ -2,16 +2,17 @@ #include "events.hpp" #include "drawer.hpp" #include "window_handle.hpp" +#include "scales_processor.hpp" #include "../graphics/overlay.hpp" #include "../graphics/opengl/opengl.hpp" #include "../graphics/render_context.hpp" -#include "../indexer/scales.hpp" #include "../geometry/screenbase.hpp" #include "../platform/platform.hpp" + using namespace graphics; SimpleRenderPolicy::SimpleRenderPolicy(Params const & p) @@ -59,15 +60,6 @@ SimpleRenderPolicy::SimpleRenderPolicy(Params const & p) void SimpleRenderPolicy::DrawFrame(shared_ptr const & e, ScreenBase const & s) { - size_t const scaleEtalonSize = 256; - - m2::RectD glbRect; - m2::PointD const pxCenter = s.PixelRect().Center(); - - s.PtoG(m2::RectD(pxCenter - m2::PointD(scaleEtalonSize / 2, scaleEtalonSize / 2), - pxCenter + m2::PointD(scaleEtalonSize / 2, scaleEtalonSize / 2)), - glbRect); - shared_ptr overlay(new graphics::Overlay()); overlay->setCouldOverlap(false); @@ -78,8 +70,7 @@ void SimpleRenderPolicy::DrawFrame(shared_ptr const & e, pScreen->beginFrame(); pScreen->clear(m_bgColor); - /// @todo Need to review this policy (using in Map server). - m_renderFn(e, s, s.PixelRect(), scales::GetScaleLevel(glbRect)); + m_renderFn(e, s, s.PixelRect(), ScalesProcessor().GetTileScaleBase(s)); overlay->draw(pScreen, math::Identity()); pScreen->resetOverlay(); diff --git a/map/yopme_render_policy.cpp b/map/yopme_render_policy.cpp index abdf1568d8..08800d6627 100644 --- a/map/yopme_render_policy.cpp +++ b/map/yopme_render_policy.cpp @@ -1,8 +1,7 @@ #include "yopme_render_policy.hpp" #include "window_handle.hpp" +#include "scales_processor.hpp" -#include "../base/matrix.hpp" -#include "../indexer/scales.hpp" #include "../geometry/screenbase.hpp" #include "../graphics/opengl/framebuffer.hpp" @@ -10,10 +9,14 @@ #include "../graphics/blitter.hpp" #include "../graphics/pen.hpp" #include "../graphics/display_list.hpp" + #include "../platform/platform.hpp" +#include "../base/matrix.hpp" + #include "../std/vector.hpp" + using namespace graphics; namespace @@ -69,6 +72,40 @@ YopmeRP::YopmeRP(RenderPolicy::Params const & p) InitWindowsHandle(p.m_videoTimer, p.m_primaryRC); } +void YopmeRP::DrawCircle(Screen * pScreen, m2::PointD const & pt) +{ + Circle::Info info(8, Color::Black(), true, 3, Color::White()); + pScreen->drawCircle(pt, info, EPosCenter, MyLocationDepth); +} + +void YopmeRP::DrawCross(Screen * pScreen, m2::PointD const & pt) +{ + Pen::Info outlineInfo(Color::White(), 5); + Pen::Info info(Color::Black(), 3); + + uint32_t outlineID = pScreen->mapInfo(outlineInfo); + uint32_t infoID = pScreen->mapInfo(info); + + m2::PointD firstLineOffset(ApiPinLength, ApiPinLength); + m2::PointD line1[2] = + { + pt - firstLineOffset, + pt + firstLineOffset + }; + + m2::PointD secondLineOffset(ApiPinLength, -ApiPinLength); + m2::PointD line2[2] = + { + pt - secondLineOffset, + pt + secondLineOffset + }; + + pScreen->drawPath(line1, 2, 0.0, outlineID, ApiPinDepth); + pScreen->drawPath(line2, 2, 0.0, outlineID, ApiPinDepth); + pScreen->drawPath(line1, 2, 0.0, infoID, ApiPinDepth); + pScreen->drawPath(line2, 2, 0.0, infoID, ApiPinDepth); +} + void YopmeRP::DrawFrame(shared_ptr const & e, ScreenBase const & s) { shared_ptr renderTarget; @@ -96,16 +133,7 @@ void YopmeRP::DrawFrame(shared_ptr const & e, ScreenBase const & s) shared_ptr paintEvent(new PaintEvent(m_offscreenDrawer.get())); - size_t const scaleEtalonSize = 256; - - m2::RectD glbRect; - m2::PointD const pxCenter = s.PixelRect().Center(); - - s.PtoG(m2::RectD(pxCenter - m2::PointD(scaleEtalonSize / 2, scaleEtalonSize / 2), - pxCenter + m2::PointD(scaleEtalonSize / 2, scaleEtalonSize / 2)), - glbRect); - - m_renderFn(paintEvent, s, m2::RectD(renderRect), scales::GetScaleLevel(glbRect)); + m_renderFn(paintEvent, s, m2::RectD(renderRect), ScalesProcessor().GetTileScaleBase(s)); pScreen->endFrame(); pScreen->resetOverlay(); @@ -136,38 +164,10 @@ void YopmeRP::DrawFrame(shared_ptr const & e, ScreenBase const & s) drawOverlay->draw(pScreen, math::Identity()); if (m_drawMyPosition) - { - Circle::Info info(8, Color::Black(), true, 3, Color::White()); - pScreen->drawCircle(m_myPositionPoint, info, EPosCenter, MyLocationDepth); - } + DrawCircle(pScreen, m_myPositionPoint); if (m_drawApiPin) - { - Pen::Info outlineInfo(Color::White(), 5); - Pen::Info info(Color::Black(), 3); - - uint32_t outlineID = pScreen->mapInfo(outlineInfo); - uint32_t infoID = pScreen->mapInfo(info); - - m2::PointD firstLineOffset(ApiPinLength, ApiPinLength); - m2::PointD line1[2] = - { - m_apiPinPoint - firstLineOffset, - m_apiPinPoint + firstLineOffset - }; - - m2::PointD secondLineOffset(ApiPinLength, -ApiPinLength); - m2::PointD line2[2] = - { - m_apiPinPoint - secondLineOffset, - m_apiPinPoint + secondLineOffset - }; - - pScreen->drawPath(line1, 2, 0.0, outlineID, ApiPinDepth); - pScreen->drawPath(line2, 2, 0.0, outlineID, ApiPinDepth); - pScreen->drawPath(line1, 2, 0.0, infoID, ApiPinDepth); - pScreen->drawPath(line2, 2, 0.0, infoID, ApiPinDepth); - } + DrawCross(pScreen, m_apiPinPoint); pScreen->endFrame(); } diff --git a/map/yopme_render_policy.hpp b/map/yopme_render_policy.hpp index 8572ab514d..46efee34bf 100644 --- a/map/yopme_render_policy.hpp +++ b/map/yopme_render_policy.hpp @@ -16,6 +16,9 @@ public: void DrawMyLocation(bool isNeed, m2::PointD const & point); private: + static void DrawCircle(graphics::Screen * pScreen, m2::PointD const & pt); + static void DrawCross(graphics::Screen * pScreen, m2::PointD const & pt); + shared_ptr m_offscreenDrawer; bool m_drawApiPin; m2::PointD m_apiPinPoint; // in pixels