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

information_display.cpp « map - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 33290a17b820b1f2a8b8e76577d2f9c9aaf49379 (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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#include "map/information_display.hpp"
#include "map/country_status_display.hpp"
#include "map/compass_arrow.hpp"
#include "map/framework.hpp"
#include "map/ruler.hpp"
#include "map/alfa_animation_task.hpp"

#include "render/drawer.hpp"

#include "anim/task.hpp"
#include "anim/controller.hpp"

#include "gui/controller.hpp"
#include "gui/button.hpp"
#include "gui/cached_text_view.hpp"

#include "graphics/defines.hpp"
#include "graphics/depth_constants.hpp"
#include "graphics/display_list.hpp"

#include "platform/platform.hpp"

#include "geometry/transformations.hpp"


using namespace graphics;

namespace
{
  static int const RULLER_X_OFFSET = 6;
  static int const RULLER_Y_OFFSET = 42;
  static int const FONT_SIZE = 14;
  static int const COMPASS_X_OFFSET = 8;
  static int const COMPASS_Y_OFFSET = 65;
#ifdef OMIM_OS_ANDROID
  static double const RULLER_X_OFFSET_L = 70.4;
  static double const RULLER_Y_OFFSET_L = 10.5;
  static int const COMPASS_X_OFFSET_L = 18;
  static double const COMPASS_Y_OFFSET_L = 11.4;
#endif
}

InformationDisplay::InformationDisplay(Framework * fw)
  : m_framework(fw)
{
  m_fontDesc.m_color = Color(0x4D, 0x4D, 0x4D, 0xCC);

  InitRuler(fw);
  InitCountryStatusDisplay(fw);
  InitCompassArrow(fw);
  InitLocationState(fw);
  InitDebugLabel();
  InitCopyright(fw);

#ifndef DEBUG
  enableDebugInfo(false);
#endif

  setVisualScale(1);
}

void InformationDisplay::InitRuler(Framework * fw)
{
  Ruler::Params p;

  p.m_depth = rulerDepth;
  p.m_position = EPosAboveLeft;
  p.m_framework = fw;

  m_ruler.reset(new Ruler(p));
  m_ruler->setIsVisible(false);
}

void InformationDisplay::InitCountryStatusDisplay(Framework * fw)
{
  CountryStatusDisplay::Params p(fw->GetCountryTree().GetActiveMapLayout());

  p.m_pivot = m2::PointD(0, 0);
  p.m_position = EPosCenter;
  p.m_depth = countryStatusDepth;

  m_countryStatusDisplay.reset(new CountryStatusDisplay(p));
}

void InformationDisplay::InitCopyright(Framework * fw)
{
  gui::CachedTextView::Params p;

  p.m_depth = rulerDepth;
  p.m_position = EPosAboveLeft;
  p.m_pivot = m2::PointD(0, 0);
  p.m_text = "Map data © OpenStreetMap";

  m_copyrightLabel.reset(new gui::CachedTextView(p));
}

void InformationDisplay::InitCompassArrow(Framework * fw)
{
  CompassArrow::Params p;

  p.m_position = EPosCenter;
  p.m_depth = compassDepth;
  p.m_pivot = m2::PointD(0, 0);
  p.m_framework = fw;

  m_compassArrow.reset(new CompassArrow(p));
  m_compassArrow->setIsVisible(false);
}

void InformationDisplay::InitLocationState(Framework * fw)
{
  location::State::Params p;

  p.m_position = EPosCenter;
  p.m_depth = locationDepth;
  p.m_pivot = m2::PointD(0, 0);
  p.m_locationAreaColor = Color(30, 150, 240, 20);
  p.m_framework = fw;

  m_locationState.reset(new location::State(p));
}

void InformationDisplay::InitDebugLabel()
{
  gui::CachedTextView::Params p;

  p.m_depth = debugDepth;
  p.m_position = EPosAboveRight;
  p.m_pivot = m2::PointD(0, 0);

  m_debugLabel.reset(new gui::CachedTextView(p));
}

void InformationDisplay::setController(gui::Controller * controller)
{
  m_controller = controller;
  m_controller->AddElement(m_countryStatusDisplay);
  m_controller->AddElement(m_compassArrow);
  m_controller->AddElement(m_locationState);
  m_controller->AddElement(m_ruler);
  m_controller->AddElement(m_debugLabel);

  m_controller->AddElement(m_copyrightLabel);
  shared_ptr<anim::Task> task(new AlfaAnimationTask(1.0, 0.0, 0.15, 3.0, m_framework));
  task->AddCallback(anim::Task::EEnded, [this] ()
                                        {
                                          m_controller->RemoveElement(m_copyrightLabel);
                                          m_copyrightLabel.reset();
                                        });

  m_copyrightLabel->setAnimated([task] ()
                                {
                                  AlfaAnimationTask * t = static_cast<AlfaAnimationTask *>(task.get());
                                  return t->GetCurrentAlfa();
                                });

  m_framework->GetAnimController()->AddTask(task);
}

void InformationDisplay::SetWidgetPivotsByDefault(int screenWidth, int screenHeight)
{
  double rulerOffsX = RULLER_X_OFFSET;
  double rulerOffsY = RULLER_Y_OFFSET;
  double compassOffsX = COMPASS_X_OFFSET;
  double compassOffsY = COMPASS_Y_OFFSET;
  m2::RectI const rect = m2::RectI(0, 0, screenWidth, screenHeight);

#ifdef OMIM_OS_ANDROID
  if (GetPlatform().IsTablet())
  {
    rulerOffsX = RULLER_X_OFFSET_L;
    rulerOffsY = RULLER_Y_OFFSET_L;
    compassOffsX = COMPASS_X_OFFSET_L;
    compassOffsY = COMPASS_Y_OFFSET_L;
  }
#endif

  double const vs = m_framework->GetVisualScale();
  m_countryStatusDisplay->setPivot(m2::PointD(rect.Center()));

  m2::PointD const size = m_compassArrow->GetPixelSize();
  m_compassArrow->setPivot(m2::PointD(compassOffsX * vs + size.x / 2.0,
                                      rect.maxY() - compassOffsY * vs - size.y / 2.0));

  m_ruler->setPivot(m2::PointD(rect.maxX() - rulerOffsX * vs,
                               rect.maxY() - rulerOffsY * vs));

  if (m_copyrightLabel)
  {
    m_copyrightLabel->setPivot(m2::PointD(rect.maxX() - rulerOffsX * vs,
                                          rect.maxY() - rulerOffsY * vs));
  }

  m_debugLabel->setPivot(m2::PointD(rect.minX() + 10,
                                    rect.minY() + 50 + 5 * vs));
}

bool InformationDisplay::isCopyrightActive() const
{
  return m_copyrightLabel != nullptr;
}

void InformationDisplay::enableCopyright(bool doEnable)
{
  if (m_copyrightLabel != nullptr)
    m_copyrightLabel->setIsVisible(doEnable);
}

void InformationDisplay::enableRuler(bool doEnable)
{
  if (doEnable)
    m_ruler->AnimateShow();
  else
    m_ruler->AnimateHide();
}

bool InformationDisplay::isRulerEnabled() const
{
  return m_ruler->isVisible();
}

void InformationDisplay::setVisualScale(double visualScale)
{
  m_fontDesc.m_size = static_cast<uint32_t>(FONT_SIZE * visualScale);

  m_ruler->setFont(gui::Element::EActive, m_fontDesc);
  m_debugLabel->setFont(gui::Element::EActive, m_fontDesc);
  if (m_copyrightLabel)
    m_copyrightLabel->setFont(gui::Element::EActive, m_fontDesc);
}

void InformationDisplay::enableDebugInfo(bool doEnable)
{
  m_debugLabel->setIsVisible(doEnable);
}

void InformationDisplay::setDebugInfo(double frameDuration, int currentScale)
{
  ostringstream out;
  out << "Scale : " << currentScale;

  m_debugLabel->setText(out.str());
}

void InformationDisplay::enableCompassArrow(bool doEnable)
{
  if (doEnable)
    m_compassArrow->AnimateShow();
  else
    m_compassArrow->AnimateHide();
}

bool InformationDisplay::isCompassArrowEnabled() const
{
  return m_compassArrow->isVisible();
}

void InformationDisplay::setCompassArrowAngle(double angle)
{
  m_compassArrow->SetAngle(angle);
}

void InformationDisplay::setEmptyCountryIndex(storage::TIndex const & idx)
{
  m_countryStatusDisplay->SetCountryIndex(idx);
}

shared_ptr<CountryStatusDisplay> const & InformationDisplay::countryStatusDisplay() const
{
  return m_countryStatusDisplay;
}

shared_ptr<location::State> const & InformationDisplay::locationState() const
{
  return m_locationState;
}

void InformationDisplay::measurementSystemChanged()
{
  m_ruler->setIsDirtyLayout(true);
}

void InformationDisplay::ResetRouteMatchingInfo()
{
  m_locationState->ResetRouteMatchingInfo();
}

void InformationDisplay::SetWidgetPivot(WidgetType widget, m2::PointD const & pivot)
{
  auto const setPivotFn = [](shared_ptr<gui::Element> e, m2::PointD const & point)
  {
    if (e)
      e->setPivot(point);
  };

  switch(widget)
  {
  case WidgetType::Ruler:
    setPivotFn(m_ruler, pivot);
    return;
  case WidgetType::CopyrightLabel:
    setPivotFn(m_copyrightLabel, pivot);
    return;
  case WidgetType::CountryStatusDisplay:
    setPivotFn(m_countryStatusDisplay, pivot);
    return;
  case WidgetType::CompassArrow:
    setPivotFn(m_compassArrow, pivot);
    return;
  case WidgetType::DebugLabel:
    setPivotFn(m_debugLabel, pivot);
    return;
  default:
    ASSERT(false, ());
  }
}

m2::PointD InformationDisplay::GetWidgetSize(WidgetType widget) const
{
  m2::RectD boundRect;
  switch(widget)
  {
  case WidgetType::Ruler:
    if (m_ruler)
      boundRect = m_ruler->GetBoundRect();
    break;
  case WidgetType::CompassArrow:
    if (m_compassArrow)
      return m_compassArrow->GetPixelSize();
  case WidgetType::DebugLabel:
  case WidgetType::CountryStatusDisplay:
  case WidgetType::CopyrightLabel:
  default:
    ASSERT(false, ());
  }
  return m2::PointD(boundRect.SizeX(), boundRect.SizeY());
}