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

overlay_element.cpp « graphics - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d10552e66b52088ac6619b3c2b82bf9f39bdd3a2 (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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#include "../base/SRC_FIRST.hpp"
#include "overlay_element.hpp"

namespace graphics
{
  OverlayElement::~OverlayElement()
  {}

  OverlayElement::Params::Params()
    : m_pivot(0, 0),
      m_position(EPosAboveRight),
      m_depth(0),
      m_userInfo()
  {}

  OverlayElement::OverlayElement(Params const & p)
    : m_pivot(p.m_pivot),
      m_position(p.m_position),
      m_depth(p.m_depth),
      m_isNeedRedraw(true),
      m_isFrozen(false),
      m_isVisible(true),
      m_isValid(true),
      m_isDirtyRect(true),
      m_isDirtyLayout(true),
      m_isDirtyRoughRect(true),
      m_inverseMatrix(math::Identity<double, 3>()),
      m_userInfo(p.m_userInfo)
  {}

  m2::PointD const OverlayElement::computeTopLeft(m2::PointD const & sz,
                                                  m2::PointD const & pv,
                                                  EPosition pos)
  {
    m2::PointD res;

    if (pos & EPosLeft)
      res.x = pv.x - sz.x;
    else if (pos & EPosRight)
      res.x = pv.x;
    else
      res.x = pv.x - sz.x / 2;

    if (pos & EPosAbove)
      res.y = pv.y - sz.y;
    else if (pos & EPosUnder)
      res.y = pv.y;
    else
      res.y = pv.y - sz.y / 2;

    return res;
  }

  void OverlayElement::offset(m2::PointD const & offs)
  {
    setPivot(pivot() + offs);
    setIsDirtyRect(true);
  }

  m2::PointD const & OverlayElement::pivot() const
  {
    return m_pivot;
  }

  void OverlayElement::setPivot(m2::PointD const & pivot)
  {
    m_pivot = pivot;
    setIsDirtyRect(true);
  }

  graphics::EPosition OverlayElement::position() const
  {
    return m_position;
  }

  void OverlayElement::setPosition(graphics::EPosition pos)
  {
    m_position = pos;
    setIsDirtyRect(true);
  }

  double OverlayElement::depth() const
  {
    return m_depth;
  }

  void OverlayElement::setDepth(double depth)
  {
    m_depth = depth;
  }

  bool OverlayElement::isFrozen() const
  {
    return m_isFrozen;
  }

  void OverlayElement::setIsFrozen(bool flag)
  {
    m_isFrozen = flag;
  }

  bool OverlayElement::isNeedRedraw() const
  {
    return m_isNeedRedraw;
  }

  void OverlayElement::setIsNeedRedraw(bool flag)
  {
    m_isNeedRedraw = flag;
  }

  bool OverlayElement::isVisible() const
  {
    return m_isVisible;
  }

  void OverlayElement::setIsVisible(bool flag)
  {
    m_isVisible = flag;
  }

  bool OverlayElement::isDirtyLayout() const
  {
   return m_isDirtyLayout;
  }

  void OverlayElement::setIsDirtyLayout(bool flag) const
  {
    m_isDirtyLayout = flag;
    if (flag)
      setIsDirtyRect(true);
  }

  bool OverlayElement::isDirtyRect() const
  {
    return m_isDirtyRect;
  }

  void OverlayElement::setIsDirtyRect(bool flag) const
  {
    if (flag)
      m_isDirtyRoughRect = true;
    m_isDirtyRect = flag;
  }

  m2::RectD const & OverlayElement::roughBoundRect() const
  {
    if (m_isDirtyRoughRect)
    {
      vector<m2::AnyRectD> const & rects = boundRects();
      size_t const count = rects.size();
      if (count == 0)
      {
        /// @todo Is it correct use-case?
        m_roughBoundRect = m2::RectD(pivot(), pivot());
      }
      else
      {
        m_roughBoundRect = rects[0].GetGlobalRect();
        for (size_t i = 1; i < count; ++i)
          m_roughBoundRect.Add(rects[i].GetGlobalRect());
      }

      m_isDirtyRoughRect = false;
    }

    return m_roughBoundRect;
  }

  bool OverlayElement::hitTest(m2::PointD const & pt) const
  {
    vector<m2::AnyRectD> const & rects = boundRects();

    for (vector<m2::AnyRectD>::const_iterator it = rects.begin(); it != rects.end(); ++it)
      if (it->IsPointInside(pt))
        return true;

    return false;
  }

  bool OverlayElement::isValid() const
  {
    return m_isValid;
  }

  void OverlayElement::setIsValid(bool flag)
  {
    m_isValid = flag;
  }

  bool OverlayElement::roughHitTest(m2::PointD const & pt) const
  {
    return roughBoundRect().IsPointInside(pt);
  }

  OverlayElement::UserInfo const & OverlayElement::userInfo() const
  {
    return m_userInfo;
  }

  m2::PointD const OverlayElement::point(EPosition pos) const
  {
    /// @todo It's better to call roughBoundRect(), or place ASSERT(!m_isDirtyRoughRect, ()) here.
    /// In general there is no need to store m_roughBoundRect at all.
    /// It's calculating time is fast, because elements already cache vector<m2::AnyRectD>.

    m2::PointD res = m_roughBoundRect.Center();

    if (pos & EPosLeft)
      res.x = m_roughBoundRect.minX();
    if (pos & EPosRight)
      res.x = m_roughBoundRect.maxX();

    if (pos & EPosAbove)
      res.y = m_roughBoundRect.minY();
    if (pos & EPosUnder)
      res.y = m_roughBoundRect.maxY();

    return res;
  }


  bool OverlayElement::hasSharpGeometry() const
  {
    return false;
  }

  double OverlayElement::priority() const
  {
    return m_depth;
  }

  math::Matrix<double, 3, 3> const & OverlayElement::getResetMatrix() const
  {
    return m_inverseMatrix;
  }

  void OverlayElement::setTransformation(const math::Matrix<double, 3, 3> & m)
  {
    m_inverseMatrix = math::Inverse(m);
  }

  void OverlayElement::resetTransformation()
  {
    setTransformation(math::Identity<double, 3>());
  }
}