From 1bfcb8df5ca2adb18d356309ecdd176a91b65ea7 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Sun, 24 Apr 2011 01:25:18 +0200 Subject: [PATCH] Finished location refactoring --- map/framework.hpp | 2 +- map/information_display.cpp | 45 -------------------------------- map/information_display.hpp | 4 --- map/location_state.cpp | 51 ++++++++++++++++++++++++++++++++----- map/location_state.hpp | 14 +++++----- 5 files changed, 52 insertions(+), 64 deletions(-) diff --git a/map/framework.hpp b/map/framework.hpp index e9d2641cce..b8c1872b23 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -516,7 +516,7 @@ public: m_informationDisplay.doDraw(pDrawer); - InformationDisplay::DrawMyPosition(*pDrawer, m_navigator.Screen(), m_locationState); + m_locationState.DrawMyPosition(*pDrawer, m_navigator.Screen()); e->drawer()->screen()->endFrame(); diff --git a/map/information_display.cpp b/map/information_display.cpp index fb48ee2a74..6d86a0ceed 100644 --- a/map/information_display.cpp +++ b/map/information_display.cpp @@ -2,7 +2,6 @@ #include "information_display.hpp" #include "drawer_yg.hpp" -#include "location_state.hpp" #include "../indexer/mercator.hpp" #include "../yg/defines.hpp" @@ -16,10 +15,6 @@ #include "../base/logging.hpp" #include "../base/mutex.hpp" -#include - -using namespace location; - InformationDisplay::InformationDisplay() { enableDebugPoints(false); @@ -50,46 +45,6 @@ void InformationDisplay::setDisplayRect(m2::RectI const & rect) m_displayRect = rect; } -void InformationDisplay::DrawMyPosition(DrawerYG & drawer, - ScreenBase const & screen, - location::State const & state) -{ - double pxErrorRadius; - m2::PointD pxPosition; - if ((state & State::EGps) || (state & State::ECompass)) - { - pxPosition = screen.GtoP(state.Position()); - pxErrorRadius = pxPosition.Length(screen.GtoP(state.Position() - + m2::PointD(state.ErrorRadius(), 0))); - } - - if (state & State::EGps) - { - // my position symbol - drawer.drawSymbol(pxPosition, "current-position", yg::EPosCenter, yg::maxDepth); - // my position circle - drawer.screen()->fillSector(pxPosition, 0, math::pi * 2, pxErrorRadius, - yg::Color(0, 0, 255, (state & State::EPreciseMode) ? 32 : 16), - yg::maxDepth - 3); - // display compass only if position is available - if (state & State::ECompass) - { - drawer.screen()->drawSector(pxPosition, - state.Heading() - state.HeadingAccuracy(), - state.Heading() + state.HeadingAccuracy(), - pxErrorRadius, - yg::Color(255, 255, 255, 192), - yg::maxDepth); - drawer.screen()->fillSector(pxPosition, - state.Heading() - state.HeadingAccuracy(), - state.Heading() + state.HeadingAccuracy(), - pxErrorRadius, - yg::Color(255, 255, 255, 96), - yg::maxDepth - 1); - } - } -} - void InformationDisplay::enableDebugPoints(bool doEnable) { m_isDebugPointsEnabled = doEnable; diff --git a/map/information_display.hpp b/map/information_display.hpp index 5cd5ba6cea..04a903f8d6 100644 --- a/map/information_display.hpp +++ b/map/information_display.hpp @@ -73,10 +73,6 @@ public: InformationDisplay(); - static void DrawMyPosition(DrawerYG & drawer, - ScreenBase const & screen, - location::State const & state); - void setScreen(ScreenBase const & screen); void setDisplayRect(m2::RectI const & rect); void setBottomShift(double bottomShift); diff --git a/map/location_state.cpp b/map/location_state.cpp index 5b97a2f731..8dadcc9002 100644 --- a/map/location_state.cpp +++ b/map/location_state.cpp @@ -1,4 +1,5 @@ #include "location_state.hpp" +#include "drawer_yg.hpp" #include "../platform/location.hpp" @@ -7,7 +8,7 @@ namespace location { - State::State() : m_deviceOrientation(-math::pi / 2), m_type(ENone) + State::State() : m_deviceOrientation(-math::pi / 2), m_flags(ENone) { } @@ -16,11 +17,11 @@ namespace location if (info.m_status == EAccurateMode || info.m_status == ERoughMode) { - m_type |= EGps; + m_flags |= EGps; if (info.m_status == EAccurateMode) - m_type |= EPreciseMode; + m_flags |= EPreciseMode; else - m_type &= !EPreciseMode; + m_flags &= !EPreciseMode; m_positionMercator = m2::PointD(MercatorBounds::LonToX(info.m_longitude), MercatorBounds::LatToY(info.m_latitude)); @@ -32,13 +33,13 @@ namespace location } else { - m_type &= !EGps; + m_flags &= !EGps; } } void State::UpdateCompass(CompassInfo const & info) { - m_type |= ECompass; + m_flags |= ECompass; m_headingRad = ((info.m_trueHeading >= 0.0) ? info.m_trueHeading : info.m_magneticHeading) / 180 * math::pi; @@ -63,4 +64,42 @@ namespace location break; } } + + void State::DrawMyPosition(DrawerYG & drawer, ScreenBase const & screen) + { + double pxErrorRadius; + m2::PointD pxPosition; + if ((m_flags & State::EGps) || (m_flags & State::ECompass)) + { + pxPosition = screen.GtoP(Position()); + pxErrorRadius = pxPosition.Length(screen.GtoP(Position() + + m2::PointD(ErrorRadius(), 0))); + } + + if (m_flags & State::EGps) + { + // my position symbol + drawer.drawSymbol(pxPosition, "current-position", yg::EPosCenter, yg::maxDepth); + // my position circle + drawer.screen()->fillSector(pxPosition, 0, math::pi * 2, pxErrorRadius, + yg::Color(0, 0, 255, (m_flags & State::EPreciseMode) ? 32 : 16), + yg::maxDepth - 3); + // display compass only if position is available + if (m_flags & State::ECompass) + { + drawer.screen()->drawSector(pxPosition, + m_deviceOrientation + m_headingRad - m_headingAccuracyRad, + m_deviceOrientation + m_headingRad + m_headingAccuracyRad, + pxErrorRadius, + yg::Color(255, 255, 255, 192), + yg::maxDepth); + drawer.screen()->fillSector(pxPosition, + m_deviceOrientation + m_headingRad - m_headingAccuracyRad, + m_deviceOrientation + m_headingRad + m_headingAccuracyRad, + pxErrorRadius, + yg::Color(255, 255, 255, 96), + yg::maxDepth - 1); + } + } + } } diff --git a/map/location_state.hpp b/map/location_state.hpp index 15d38fbe5d..ff58060602 100644 --- a/map/location_state.hpp +++ b/map/location_state.hpp @@ -3,6 +3,8 @@ #include "../geometry/point2d.hpp" #include "../geometry/screenbase.hpp" +class DrawerYG; + namespace location { class GpsInfo; @@ -32,24 +34,20 @@ namespace location double ErrorRadius() const { return m_errorRadiusMercator; } /// @return GPS center point in mercator m2::PointD Position() const { return m_positionMercator; } - /// takes into account device's orientation - /// @return angle in radians - double Heading() const { return m_deviceOrientation + m_headingRad; } - /// @return angle in radians - double HeadingAccuracy() const { return m_headingAccuracyRad; } - void TurnOff() { m_type = ENone; } + void TurnOff() { m_flags = ENone; } void UpdateGps(GpsInfo const & info); void UpdateCompass(CompassInfo const & info); void SetOrientation(EOrientation orientation); + void DrawMyPosition(DrawerYG & drawer, ScreenBase const & screen); operator int() const { - return m_type; + return m_flags; } private: /// stores flags from SymbolType - int m_type; + int m_flags; }; }