Welcome to mirror list, hosted at ThFree Co, Russian Federation.

location_state.hpp « map - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 538b25218d51a6f649c491f1d451ceb89348349c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#pragma once

#include "compass_filter.hpp"

#include "../platform/location.hpp"

#include "../geometry/point2d.hpp"
#include "../geometry/screenbase.hpp"

#include "../std/shared_ptr.hpp"
#include "../std/scoped_ptr.hpp"
#include "../std/map.hpp"

#include "../gui/element.hpp"

class Framework;

namespace anim
{
  class AngleInterpolation;
}

namespace graphics
{
  namespace gl
  {
    class DisplayList;
  }
}

namespace location
{
  class GpsInfo;
  class CompassInfo;

  enum ELocationProcessMode
  {
    ELocationDoNothing = 0,
    ELocationCenterAndScale,
    ELocationCenterOnly
  };

  enum ECompassProcessMode
  {
    ECompassDoNothing = 0,
    ECompassFollow
  };

  // Class, that handles position and compass updates,
  // centers, scales and rotates map according to this updates
  // and draws location and compass marks.
  class State : public gui::Element
  {
  public:

    typedef function<void(int)> TCompassStatusListener;

  private:

    static const double s_cacheRadius;

    double m_errorRadius;   //< error radius in mercator
    m2::PointD m_position;  //< position in mercator

    CompassFilter m_compassFilter;
    double m_drawHeading;

    bool m_hasPosition;
    bool m_hasCompass;
    bool m_isCentered;
    bool m_isFirstPosition;

    ELocationProcessMode m_locationProcessMode;
    ECompassProcessMode m_compassProcessMode;

    void FollowCompass();

    typedef gui::Element base_t;

    graphics::Color m_locationAreaColor;

    graphics::Color m_compassAreaColor;
    graphics::Color m_compassBorderColor;

    Framework * m_framework;

    /// Compass Rendering Parameters
    /// @{

    double m_arrowHeight;
    double m_arrowWidth;
    double m_arrowBackHeight;
    double m_arrowScale;

    map<EState, shared_ptr<graphics::gl::DisplayList> > m_arrowBodyLists;
    map<EState, shared_ptr<graphics::gl::DisplayList> > m_arrowBorderLists;
    scoped_ptr<graphics::gl::DisplayList> m_locationMarkDL;
    scoped_ptr<graphics::gl::DisplayList> m_positionMarkDL;

    /// @}

    void cacheArrowBorder(EState state);
    void cacheArrowBody(EState state);
    void cacheLocationMark();

    void cache();
    void purge();
    void update();

    mutable vector<m2::AnyRectD> m_boundRects;
    m2::RectD m_boundRect;

    shared_ptr<anim::AngleInterpolation> m_headingInterpolation;

    typedef map<int, TCompassStatusListener> TCompassStatusListeners;
    TCompassStatusListeners m_compassStatusListeners;
    int m_currentSlotID;

    void CallCompassStatusListeners(ECompassProcessMode mode);

    double ComputeMoveSpeed(m2::PointD const & globalPt0,
                            m2::PointD const & globalPt1,
                            ScreenBase const & s);

  public:

    struct Params : base_t::Params
    {
      graphics::Color m_locationAreaColor;
      graphics::Color m_compassAreaColor;
      graphics::Color m_compassBorderColor;
      Framework * m_framework;
      Params();
    };

    State(Params const & p);

    /// @return GPS center point in mercator
    m2::PointD const & Position() const;

    bool HasPosition() const;
    bool HasCompass() const;
    bool IsFirstPosition() const;

    ELocationProcessMode GetLocationProcessMode() const;
    void SetLocationProcessMode(ELocationProcessMode mode);

    ECompassProcessMode GetCompassProcessMode() const;
    void SetCompassProcessMode(ECompassProcessMode mode);

    void TurnOff();

    void StartCompassFollowing();
    void StopCompassFollowing();

    void OnStartLocation();
    void OnStopLocation();

    int AddCompassStatusListener(TCompassStatusListener const & l);
    void RemoveCompassStatusListener(int slotID);

    void SetIsCentered(bool flag);
    bool IsCentered() const;

    void AnimateToPosition();
    void AnimateToPositionAndEnqueueFollowing();

    void CheckCompassRotation();
    void CheckCompassFollowing();

    /// @name GPS location updates routine.
    //@{
    void OnLocationUpdate(location::GpsInfo const & info);
    void OnCompassUpdate(location::CompassInfo const & info);
    //@}

    /// graphics::OverlayElement and gui::Element related methods
    // @{
    vector<m2::AnyRectD> const & boundRects() const;
    void draw(graphics::gl::OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const;
    bool roughHitTest(m2::PointD const & pt) const;
    bool hitTest(m2::PointD const & pt) const;
    bool onTapEnded(m2::PointD const & p);
    /// @}
  };
}