diff options
-rw-r--r-- | graphics/path.hpp | 1 | ||||
-rw-r--r-- | gui/controller.cpp | 30 | ||||
-rw-r--r-- | gui/element.hpp | 15 | ||||
-rw-r--r-- | map/framework.cpp | 6 | ||||
-rw-r--r-- | map/information_display.cpp | 30 | ||||
-rw-r--r-- | map/information_display.hpp | 4 | ||||
-rw-r--r-- | map/ruler.cpp | 268 | ||||
-rw-r--r-- | map/ruler.hpp | 13 |
8 files changed, 162 insertions, 205 deletions
diff --git a/graphics/path.hpp b/graphics/path.hpp index ba8a239e56..14824f8d34 100644 --- a/graphics/path.hpp +++ b/graphics/path.hpp @@ -21,6 +21,7 @@ namespace graphics void lineRel(m2::Point<T> const & pt) { + ASSERT(!m_pts.empty(), ()); m2::Point<T> const & p = m_pts.back(); m_pts.push_back(p + pt); } diff --git a/gui/controller.cpp b/gui/controller.cpp index e1627aba6f..35f2a2aff2 100644 --- a/gui/controller.cpp +++ b/gui/controller.cpp @@ -166,10 +166,7 @@ namespace gui math::Matrix<double, 3, 3> m = math::Identity<double, 3>(); - for (elem_list_t::const_iterator it = m_Elements.begin(); - it != m_Elements.end(); - ++it) - (*it)->draw(screen, m); + for_each(m_Elements.begin(), m_Elements.end(), bind(&Element::draw, _1, screen, m)); screen->endFrame(); } @@ -188,11 +185,7 @@ namespace gui void Controller::SetStringsBundle(StringsBundle const * bundle) { m_bundle = bundle; - - for (elem_list_t::const_iterator it = m_Elements.begin(); - it != m_Elements.end(); - ++it) - (*it)->setIsDirtyLayout(true); + for_each(m_Elements.begin(), m_Elements.end(), bind(&Element::setIsDirtyLayout, _1, true)); } StringsBundle const * Controller::GetStringsBundle() const @@ -207,28 +200,17 @@ namespace gui void Controller::UpdateElements() { - for (elem_list_t::const_iterator it = m_Elements.begin(); - it != m_Elements.end(); - ++it) - (*it)->update(); + for_each(m_Elements.begin(), m_Elements.end(), bind(&Element::update, _1)); } void Controller::PurgeElements() { - for (elem_list_t::const_iterator it = m_Elements.begin(); - it != m_Elements.end(); - ++it) - { - (*it)->purge(); - (*it)->setIsDirtyLayout(true); - } + for_each(m_Elements.begin(), m_Elements.end(), bind(&Element::purge, _1)); + for_each(m_Elements.begin(), m_Elements.end(), bind(&Element::setIsDirtyLayout, _1, true)); } void Controller::LayoutElements() { - for (elem_list_t::const_iterator it = m_Elements.begin(); - it != m_Elements.end(); - ++it) - (*it)->checkDirtyLayout(); + for_each(m_Elements.begin(), m_Elements.end(), bind(&Element::checkDirtyLayout, _1)); } } diff --git a/gui/element.hpp b/gui/element.hpp index fdfee77d93..4d8adfd1ed 100644 --- a/gui/element.hpp +++ b/gui/element.hpp @@ -64,13 +64,11 @@ namespace gui virtual bool onTapEnded(m2::PointD const & pt); virtual bool onTapCancelled(m2::PointD const & pt); + /// invalidate the rendering system to redraw the gui elements. void invalidate(); + /// obtain @see VisualScale double visualScale() const; - graphics::OverlayElement * clone(math::Matrix<double, 3, 3> const & m) const; - void draw(graphics::OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const; - double priority() const; - /// this method is called to cache visual appearance of gui::Element for fast rendering. /// it should be called when isDirtyDrawing is set to true(visual parameters of object is changed). virtual void cache(); @@ -83,9 +81,14 @@ namespace gui /// this method is called after gui::Controller::SetRenderParams to /// perform layout calculations which might depends on RenderParams. virtual void layout(); - + /// set the parent controller for this element. virtual void setController(Controller * controller); - + /// check if the layout of element is dirty and re-layout element if needed. void checkDirtyLayout() const; + + graphics::OverlayElement * clone(math::Matrix<double, 3, 3> const & m) const; + void draw(graphics::OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const; + double priority() const; + }; } diff --git a/map/framework.cpp b/map/framework.cpp index 02c405bb3a..9afd72d7c9 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1382,11 +1382,11 @@ void Framework::SetRenderPolicy(RenderPolicy * renderPolicy) m_navigator.SetMinScreenParams(static_cast<unsigned>(m_minRulerWidth * m_renderPolicy->VisualScale()), m_metresMinWidth); + m_informationDisplay.setVisualScale(m_renderPolicy->VisualScale()); + if (m_width != 0 && m_height != 0) OnSize(m_width, m_height); - m_informationDisplay.setVisualScale(m_renderPolicy->VisualScale()); - // Do full invalidate instead of any "pending" stuff. Invalidate(); @@ -1402,7 +1402,7 @@ RenderPolicy * Framework::GetRenderPolicy() const void Framework::SetupMeasurementSystem() { - m_informationDisplay.setupRuler(); + m_informationDisplay.ruler()->setIsDirtyLayout(true); Invalidate(); } diff --git a/map/information_display.cpp b/map/information_display.cpp index 89d9553ce7..6ca449d820 100644 --- a/map/information_display.cpp +++ b/map/information_display.cpp @@ -171,13 +171,7 @@ void InformationDisplay::setVisualScale(double visualScale) m_fontDesc.m_size = static_cast<uint32_t>(FONT_SIZE * m_visualScale); - m_ruler->setFontDesc(m_fontDesc); - m_ruler->setVisualScale(m_visualScale); - - m2::PointD pt(m2::PointD(m_displayRect.maxX() - 5 * m_visualScale, - m_displayRect.maxY() - 4 * m_visualScale)); - - m_ruler->setPivot(pt); + m_ruler->setFont(gui::Element::EActive, m_fontDesc); } void InformationDisplay::enableCenter(bool doEnable) @@ -194,16 +188,14 @@ void InformationDisplay::drawCenter(Drawer * drawer) { ostringstream out; - out - << fixed << setprecision(4) + out << fixed << setprecision(4) << m_centerPtLonLat.y << ", " - << m_centerPtLonLat.x - ; + << m_centerPtLonLat.x; graphics::StraightTextElement::Params params; - params.m_depth = graphics::maxDepth; + params.m_depth = graphics::maxDepth - 10; params.m_fontDesc = m_fontDesc; params.m_log2vis = false; @@ -256,7 +248,7 @@ void InformationDisplay::drawDebugInfo(Drawer * drawer) pos, graphics::EPosAboveRight, out.str(), - graphics::maxDepth, + graphics::maxDepth - 10, false); } @@ -283,7 +275,7 @@ void InformationDisplay::drawMemoryWarning(Drawer * drawer) pos, graphics::EPosAboveRight, out.str(), - graphics::maxDepth, + graphics::maxDepth - 10, false); if (m_lastMemoryWarning.ElapsedSeconds() > 5) @@ -465,11 +457,6 @@ void InformationDisplay::drawBenchmarkInfo(Drawer * pDrawer) } -void InformationDisplay::setupRuler() -{ - m_ruler->setup(); -} - void InformationDisplay::doDraw(Drawer *drawer) { m_yOffset = 0; @@ -496,3 +483,8 @@ shared_ptr<location::State> const & InformationDisplay::locationState() const { return m_locationState; } + +shared_ptr<Ruler> const & InformationDisplay::ruler() const +{ + return m_ruler; +} diff --git a/map/information_display.hpp b/map/information_display.hpp index fef2a5bcad..aeea08e453 100644 --- a/map/information_display.hpp +++ b/map/information_display.hpp @@ -49,7 +49,6 @@ private: bool m_isDebugPointsEnabled; m2::PointD m_DebugPts[10]; - bool m_isRulerEnabled; shared_ptr<Ruler> m_ruler; bool m_isCenterEnabled; @@ -107,7 +106,6 @@ public: void enableRuler(bool doEnable); void setRulerParams(unsigned pxMinWidth, double metresMinWidth, double metresMaxWidth); - void setupRuler(); void enableCenter(bool doEnable); void setCenter(m2::PointD const & latLongPt); @@ -143,6 +141,8 @@ public: void setEmptyCountryIndex(storage::TIndex const & idx); shared_ptr<CountryStatusDisplay> const & countryStatusDisplay() const; + shared_ptr<Ruler> const & ruler() const; + static void logMessage(my::LogLevel, my::SrcPoint const &, string const &); }; diff --git a/map/ruler.cpp b/map/ruler.cpp index 1deb41f7d2..b30b6c31a8 100644 --- a/map/ruler.cpp +++ b/map/ruler.cpp @@ -16,64 +16,63 @@ namespace { - -struct UnitValue -{ - char const * m_s; - int m_i; -}; - -UnitValue g_arrFeets[] = { - { "100 ft", 100 }, - { "200 ft", 200 }, - { "0.1 mi", 528 }, - { "0.2 mi", 528 * 2 }, - { "0.5 mi", 528 * 5 }, - { "1 mi", 5280 }, - { "2 mi", 2 * 5280 }, - { "5 mi", 5 * 5280 }, - { "10 mi", 10 * 5280 }, - { "20 mi", 20 * 5280 }, - { "50 mi", 50 * 5280 }, - { "100 mi", 100 * 5280 }, - { "200 mi", 200 * 5280 }, - { "500 mi", 500 * 5280 } -}; - -UnitValue g_arrYards[] = { - { "50 yd", 50 }, - { "100 yd", 100 }, - { "200 yd", 200 }, - { "500 yd", 500 }, - { "0.5 mi", 0.5 * 1760 }, - { "1 mi", 1760 }, - { "2 mi", 2 * 1760 }, - { "5 mi", 5 * 1760 }, - { "10 mi", 10 * 1760 }, - { "20 mi", 20 * 1760 }, - { "50 mi", 50 * 1760 }, - { "100 mi", 100 * 1760 }, - { "200 mi", 200 * 1760 }, - { "500 mi", 500 * 1760 } -}; - -UnitValue g_arrMetres[] = { - { "20 m", 20 }, - { "50 m", 50 }, - { "100 m", 100 }, - { "200 m", 200 }, - { "500 m", 500 }, - { "1 km", 1000 }, - { "2 km", 2000 }, - { "5 km", 5000 }, - { "10 km", 10000 }, - { "20 km", 20000 }, - { "50 km", 50000 }, - { "100 km", 100000 }, - { "200 km", 200000 }, - { "500 km", 500000 }, - { "1000 km", 1000000 } -}; + struct UnitValue + { + char const * m_s; + int m_i; + }; + + UnitValue g_arrFeets[] = { + { "100 ft", 100 }, + { "200 ft", 200 }, + { "0.1 mi", 528 }, + { "0.2 mi", 528 * 2 }, + { "0.5 mi", 528 * 5 }, + { "1 mi", 5280 }, + { "2 mi", 2 * 5280 }, + { "5 mi", 5 * 5280 }, + { "10 mi", 10 * 5280 }, + { "20 mi", 20 * 5280 }, + { "50 mi", 50 * 5280 }, + { "100 mi", 100 * 5280 }, + { "200 mi", 200 * 5280 }, + { "500 mi", 500 * 5280 } + }; + + UnitValue g_arrYards[] = { + { "50 yd", 50 }, + { "100 yd", 100 }, + { "200 yd", 200 }, + { "500 yd", 500 }, + { "0.5 mi", 0.5 * 1760 }, + { "1 mi", 1760 }, + { "2 mi", 2 * 1760 }, + { "5 mi", 5 * 1760 }, + { "10 mi", 10 * 1760 }, + { "20 mi", 20 * 1760 }, + { "50 mi", 50 * 1760 }, + { "100 mi", 100 * 1760 }, + { "200 mi", 200 * 1760 }, + { "500 mi", 500 * 1760 } + }; + + UnitValue g_arrMetres[] = { + { "20 m", 20 }, + { "50 m", 50 }, + { "100 m", 100 }, + { "200 m", 200 }, + { "500 m", 500 }, + { "1 km", 1000 }, + { "2 km", 2000 }, + { "5 km", 5000 }, + { "10 km", 10000 }, + { "20 km", 20000 }, + { "50 km", 50000 }, + { "100 km", 100000 }, + { "200 km", 200000 }, + { "500 km", 500000 }, + { "1000 km", 1000000 } + }; double identity(double val) { @@ -81,7 +80,7 @@ UnitValue g_arrMetres[] = { } } -void Ruler::setup() +void Ruler::layout() { Settings::Units units = Settings::Metric; Settings::Get("Units", units); @@ -104,10 +103,6 @@ void Ruler::setup() m_conversionFn = &MeasurementUtils::MetersToYards; break; } - - m_isInitialized = true; - if (m_hasPendingUpdate) - update(); } void Ruler::CalcMetresDiff(double v) @@ -158,13 +153,15 @@ void Ruler::CalcMetresDiff(double v) Ruler::Ruler(Params const & p) - : base_t(p), m_boundRects(1), m_currSystem(0), m_isInitialized(false), m_hasPendingUpdate(false) -{ -} + : base_t(p), + m_boundRects(1), + m_currSystem(0) +{} void Ruler::setScreen(ScreenBase const & screen) { m_screen = screen; + setIsDirtyRect(true); } ScreenBase const & Ruler::screen() const @@ -175,141 +172,132 @@ ScreenBase const & Ruler::screen() const void Ruler::setMinPxWidth(unsigned minPxWidth) { m_minPxWidth = minPxWidth; + setIsDirtyRect(true); } void Ruler::setMinMetersWidth(double v) { m_minMetersWidth = v; + setIsDirtyRect(true); } void Ruler::setMaxMetersWidth(double v) { m_maxMetersWidth = v; + setIsDirtyRect(true); } -void Ruler::setVisualScale(double visualScale) +void Ruler::update() { - m_visualScale = visualScale; -} + checkDirtyLayout(); -void Ruler::setFontDesc(graphics::FontDesc const & fontDesc) -{ - m_fontDesc = fontDesc; -} + double k = visualScale(); -void Ruler::update() -{ - if (m_isInitialized) - { - int const rulerHeight = my::rounds(5 * m_visualScale); - int const minPxWidth = my::rounds(m_minPxWidth * m_visualScale); + int const rulerHeight = my::rounds(5 * k); + int const minPxWidth = my::rounds(m_minPxWidth * k); - // pivot() here is the down right point of the ruler. - // Get global points of ruler and distance according to minPxWidth. + // pivot() here is the down right point of the ruler. + // Get global points of ruler and distance according to minPxWidth. - m2::PointD pt1 = m_screen.PtoG(pivot()); - m2::PointD pt0 = m_screen.PtoG(pivot() - m2::PointD(minPxWidth, 0)); + m2::PointD pt1 = m_screen.PtoG(pivot()); + m2::PointD pt0 = m_screen.PtoG(pivot() - m2::PointD(minPxWidth, 0)); - double const distanceInMetres = ms::DistanceOnEarth( - MercatorBounds::YToLat(pt0.y), MercatorBounds::XToLon(pt0.x), - MercatorBounds::YToLat(pt1.y), MercatorBounds::XToLon(pt1.x)); + double const distanceInMetres = ms::DistanceOnEarth( + MercatorBounds::YToLat(pt0.y), MercatorBounds::XToLon(pt0.x), + MercatorBounds::YToLat(pt1.y), MercatorBounds::XToLon(pt1.x)); - // convert metres to units for calculating m_metresDiff - CalcMetresDiff(m_conversionFn(distanceInMetres)); + // convert metres to units for calculating m_metresDiff + CalcMetresDiff(m_conversionFn(distanceInMetres)); - bool const higherThanMax = m_metresDiff > m_maxMetersWidth; - bool const lessThanMin = m_metresDiff < m_minMetersWidth; + bool const higherThanMax = m_metresDiff > m_maxMetersWidth; + bool const lessThanMin = m_metresDiff < m_minMetersWidth; - // Calculate width of the ruler in pixels. - double scalerWidthInPx = minPxWidth; + // Calculate width of the ruler in pixels. + double scalerWidthInPx = minPxWidth; - if (higherThanMax) - { - scalerWidthInPx = minPxWidth * 3 / 2; - } - else if (!lessThanMin) - { - // Here we need to convert metres to pixels according to angle - // (in global coordinates) of the ruler. + if (higherThanMax) + scalerWidthInPx = minPxWidth * 3 / 2; + else if (!lessThanMin) + { + // Here we need to convert metres to pixels according to angle + // (in global coordinates) of the ruler. - double const a = ang::AngleTo(pt1, pt0); - pt0 = MercatorBounds::GetSmPoint(pt1, cos(a) * m_metresDiff, sin(a) * m_metresDiff); + double const a = ang::AngleTo(pt1, pt0); + pt0 = MercatorBounds::GetSmPoint(pt1, cos(a) * m_metresDiff, sin(a) * m_metresDiff); - scalerWidthInPx = my::rounds(pivot().Length(m_screen.GtoP(pt0))); - } + scalerWidthInPx = my::rounds(pivot().Length(m_screen.GtoP(pt0))); + } - m2::PointD scalerOrg = pivot() + m2::PointD(-scalerWidthInPx / 2, rulerHeight / 2); + m2::PointD scalerOrg = pivot() + m2::PointD(-scalerWidthInPx / 2, rulerHeight / 2); - if (position() & graphics::EPosLeft) - scalerOrg.x -= scalerWidthInPx / 2; + if (position() & graphics::EPosLeft) + scalerOrg.x -= scalerWidthInPx / 2; - if (position() & graphics::EPosRight) - scalerOrg.x += scalerWidthInPx / 2; + if (position() & graphics::EPosRight) + scalerOrg.x += scalerWidthInPx / 2; - if (position() & graphics::EPosAbove) - scalerOrg.y -= rulerHeight / 2; + if (position() & graphics::EPosAbove) + scalerOrg.y -= rulerHeight / 2; - if (position() & graphics::EPosUnder) - scalerOrg.y += rulerHeight / 2; + if (position() & graphics::EPosUnder) + scalerOrg.y += rulerHeight / 2; - m_path.clear(); - m_path.push_back(scalerOrg); - m_path.push_back(scalerOrg + m2::PointD(scalerWidthInPx, 0)); + m_path.clear(); + m_path.push_back(scalerOrg); + m_path.push_back(scalerOrg + m2::PointD(scalerWidthInPx, 0)); - m_boundRect = m2::RectD(m_path[0], m_path[1]); - } - else - m_hasPendingUpdate = true; + m_boundRect = m2::RectD(m_path[0], m_path[1]); + setIsDirtyRect(true); } vector<m2::AnyRectD> const & Ruler::boundRects() const { - m_boundRects[0] = m2::AnyRectD(m_boundRect); + if (isDirtyRect()) + { + m_boundRects[0] = m2::AnyRectD(m_boundRect); + setIsDirtyRect(false); + } + return m_boundRects; } void Ruler::draw(graphics::OverlayRenderer * s, math::Matrix<double, 3, 3> const & m) const { - if (m_isInitialized) + if (isVisible()) { + checkDirtyLayout(); + + double k = visualScale(); + s->drawPath( &m_path[0], m_path.size(), 0, - s->mapInfo(graphics::Pen::Info(graphics::Color(0, 0, 0, 0x99), 4 * m_visualScale, 0, 0, 0)), + s->mapInfo(graphics::Pen::Info(graphics::Color(0, 0, 0, 0x99), 4 * k, 0, 0, 0)), depth()); + graphics::FontDesc f = font(state()); + if (position() & graphics::EPosLeft) - s->drawText(m_fontDesc, - m_path[1] + m2::PointD(1 * m_visualScale, -2 * m_visualScale), + s->drawText(f, + m_path[1] + m2::PointD(1 * k, -2 * k), graphics::EPosAboveLeft, m_scalerText, depth(), false); else if (position() & graphics::EPosRight) - s->drawText(m_fontDesc, - m_path[0] + m2::PointD(7 * m_visualScale, -4 * m_visualScale), + s->drawText(f, + m_path[0] + m2::PointD(7 * k, -4 * k), graphics::EPosAboveRight, m_scalerText, depth(), false); else - s->drawText(m_fontDesc, + s->drawText(f, (m_path[0] + m_path[1]) * 0.5 - + m2::PointD(7 * m_visualScale, -4 * m_visualScale), + + m2::PointD(7 * k, -4 * k), graphics::EPosAbove, m_scalerText, depth(), false); } } - -double Ruler::priority() const -{ - return 0; -} - -graphics::OverlayElement * Ruler::clone(math::Matrix<double, 3, 3> const & m) const -{ - return new Ruler(*this); -} - diff --git a/map/ruler.hpp b/map/ruler.hpp index 13fca1b769..fea0ce265c 100644 --- a/map/ruler.hpp +++ b/map/ruler.hpp @@ -28,9 +28,6 @@ private: double m_maxMetersWidth; //@} - double m_visualScale; - - graphics::FontDesc m_fontDesc; ScreenBase m_screen; /// Current diff in units between two endpoints of the ruler. @@ -54,16 +51,11 @@ private: int m_currSystem; void CalcMetresDiff(double v); - bool m_isInitialized; - bool m_hasPendingUpdate; - public: - void update(); //< update internal params after some other params changed. typedef base_t::Params Params; Ruler(Params const & p); - void setup(); void setScreen(ScreenBase const & screen); ScreenBase const & screen() const; @@ -71,13 +63,12 @@ public: void setMinPxWidth(unsigned minPxWidth); void setMinMetersWidth(double v); void setMaxMetersWidth(double v); - void setVisualScale(double visualScale); void setFontDesc(graphics::FontDesc const & fontDesc); vector<m2::AnyRectD> const & boundRects() const; void draw(graphics::OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const; - double priority() const; - graphics::OverlayElement * clone(math::Matrix<double, 3, 3> const & m) const; + void layout(); + void update(); }; |