Some code review.

This commit is contained in:
vng 2012-04-18 20:21:13 +03:00 committed by Alex Zolotarev
parent ac67dd8782
commit 8efe95e2f4
3 changed files with 21 additions and 21 deletions

View file

@ -614,7 +614,7 @@ void Framework::DrawAdditionalInfo(shared_ptr<PaintEvent> const & e)
m_informationDisplay.doDraw(pDrawer);
m_locationState.DrawMyPosition(*pDrawer, m_navigator.Screen());
m_locationState.DrawMyPosition(*pDrawer, m_navigator);
if (m_drawPlacemark)
m_informationDisplay.drawPlacemark(pDrawer, "placemark", m_navigator.GtoP(m_placemark));

View file

@ -1,11 +1,13 @@
#include "location_state.hpp"
#include "drawer_yg.hpp"
#include "navigator.hpp"
#include "../platform/location.hpp"
#include "../platform/platform.hpp"
#include "../indexer/mercator.hpp"
namespace location
{
@ -27,39 +29,35 @@ namespace location
{
m_flags |= ECompass;
m_headingRad = ((info.m_trueHeading >= 0.0) ? info.m_trueHeading : info.m_magneticHeading)
/ 180 * math::pi
- math::pi / 2; // 0 angle is for North ("up"), but in our coordinates it's to the right.
m_headingRad = ((info.m_trueHeading >= 0.0) ? info.m_trueHeading : info.m_magneticHeading);
// 0 angle is for North ("up"), but in our coordinates it's to the right.
m_headingRad = my::DegToRad(m_headingRad) - math::pi / 2.0;
// Avoid situations when offset between magnetic north and true north is too small
static double const MIN_SECTOR_DEG = 10.;
m_headingHalfSectorRad = (info.m_accuracy < MIN_SECTOR_DEG ? MIN_SECTOR_DEG : info.m_accuracy)
/ 180 * math::pi;
static double const MIN_SECTOR_DEG = 10.0;
m_headingHalfSectorRad = (info.m_accuracy < MIN_SECTOR_DEG ? MIN_SECTOR_DEG : info.m_accuracy);
m_headingHalfSectorRad = my::DegToRad(m_headingHalfSectorRad);
}
void State::DrawMyPosition(DrawerYG & drawer, ScreenBase const & screen)
void State::DrawMyPosition(DrawerYG & drawer, Navigator const & nav)
{
double pxErrorRadius;
m2::PointD pxPosition;
m2::PointD pxShift(screen.PixelRect().minX(), screen.PixelRect().minY());
if ((m_flags & State::EGps) || (m_flags & State::ECompass))
{
pxPosition = screen.GtoP(Position());
pxErrorRadius = pxPosition.Length(screen.GtoP(Position() + m2::PointD(m_errorRadiusMercator, 0.0)));
pxPosition -= pxShift;
m2::PointD const pxPosition = nav.GtoP(Position());
double const pxErrorRadius = pxPosition.Length(nav.GtoP(Position() + m2::PointD(m_errorRadiusMercator, 0.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,
drawer.screen()->fillSector(pxPosition, 0, 2.0 * math::pi, pxErrorRadius,
yg::Color(0, 0, 255, 32),
yg::maxDepth - 3);
// display compass only if position is available
double orientationRadius = max(pxErrorRadius, 30 * GetPlatform().VisualScale());
// display compass only if position is available
double orientationRadius = max(pxErrorRadius, 30.0 * GetPlatform().VisualScale());
if (m_flags & State::ECompass)
{
@ -69,6 +67,7 @@ namespace location
orientationRadius,
yg::Color(255, 255, 255, 192),
yg::maxDepth);
drawer.screen()->fillSector(pxPosition,
m_headingRad - m_headingHalfSectorRad,
m_headingRad + m_headingHalfSectorRad,

View file

@ -1,9 +1,10 @@
#pragma once
#include "../geometry/point2d.hpp"
#include "../geometry/screenbase.hpp"
#include "../geometry/rect2d.hpp"
class DrawerYG;
class Navigator;
namespace location
{
@ -41,7 +42,7 @@ namespace location
void UpdateGps(m2::RectD const & rect);
void UpdateCompass(CompassInfo const & info);
void DrawMyPosition(DrawerYG & drawer, ScreenBase const & screen);
void DrawMyPosition(DrawerYG & drawer, Navigator const & nav);
operator int() const
{