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

overlay_renderer.cpp « graphics - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5ed69f23f7cf12e4d9b398f906a51e6041fe716a (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
#include "graphics/overlay_renderer.hpp"
#include "graphics/straight_text_element.hpp"
#include "graphics/path_text_element.hpp"
#include "graphics/symbol_element.hpp"
#include "graphics/circle_element.hpp"
#include "graphics/circled_symbol.hpp"
#include "graphics/overlay.hpp"
#include "graphics/resource_manager.hpp"


namespace graphics
{
  OverlayRenderer::Params::Params()
    : m_drawTexts(true),
      m_drawSymbols(true)
  {
  }

  OverlayRenderer::OverlayRenderer(Params const & p)
    : TextRenderer(p),
      m_drawTexts(p.m_drawTexts),
      m_drawSymbols(p.m_drawSymbols)
  {
  }

  void OverlayRenderer::drawSymbol(SymbolElement::Params & params)
  {
    if (!m_drawSymbols)
      return;

    shared_ptr<OverlayElement> oe(new SymbolElement(params));

    math::Matrix<double, 3, 3> id = math::Identity<double, 3>();

    if (!m_overlayStorage.get())
      oe->draw(this, id);
    else
      m_overlayStorage->AddElement(oe);
  }

  void OverlayRenderer::drawSymbol(m2::PointD const & pt, string const & name, EPosition pos, int depth)
  {
    graphics::SymbolElement::Params params;

    params.m_depth = depth;
    params.m_position = pos;
    params.m_pivot = pt;
    params.m_info.m_name = name;
    params.m_renderer = this;

    drawSymbol(params);
  }

  void OverlayRenderer::drawCircle(CircleElement::Params & params)
  {
    shared_ptr<OverlayElement> oe(new CircleElement(params));

    math::Matrix<double, 3, 3> id = math::Identity<double, 3>();

    if (!m_overlayStorage.get())
      oe->draw(this, id);
    else
      m_overlayStorage->AddElement(oe);
  }

  void OverlayRenderer::drawCircle(m2::PointD const & pt,
                                   graphics::Circle::Info const & ci,
                                   EPosition pos,
                                   double depth)
  {
    CircleElement::Params params;

    params.m_depth = depth;
    params.m_position = pos;
    params.m_pivot = pt;
    params.m_ci = ci;

    drawCircle(params);
  }

  void OverlayRenderer::drawCircledSymbol(SymbolElement::Params const & symParams,
                         CircleElement::Params const & circleParams)
  {
    shared_ptr<OverlayElement> oe(new CircledSymbol(symParams, circleParams));

    math::Matrix<double, 3, 3> id = math::Identity<double, 3>();

    if (!m_overlayStorage.get())
      oe->draw(this, id);
    else
      m_overlayStorage->AddElement(oe);
  }

  void OverlayRenderer::drawText(FontDesc const & fontDesc,
                                 m2::PointD const & pt,
                                 graphics::EPosition pos,
                                 string const & utf8Text,
                                 double depth,
                                 bool log2vis,
                                 bool doSplit)
  {
    if (!m_drawTexts)
      return;

    StraightTextElement::Params params;
    params.m_depth = depth;
    params.m_fontDesc = fontDesc;
    params.m_log2vis = log2vis;
    params.m_pivot = pt;
    params.m_position = pos;
    params.m_logText = strings::MakeUniString(utf8Text);
    params.m_doSplit = doSplit;
    params.m_useAllParts = false;
    params.m_offset = m2::PointD(0,0);
    params.m_glyphCache = glyphCache();

    shared_ptr<OverlayElement> oe(new StraightTextElement(params));

    math::Matrix<double, 3, 3> id = math::Identity<double, 3>();

    if (!m_overlayStorage.get())
      oe->draw(this, id);
    else
      m_overlayStorage->AddElement(oe);
  }

  void OverlayRenderer::drawTextEx(StraightTextElement::Params & params)
  {
    if (!m_drawTexts)
      return;

    params.m_glyphCache = glyphCache();

    shared_ptr<OverlayElement> oe(new StraightTextElement(params));

    math::Matrix<double, 3, 3> id = math::Identity<double, 3>();

    if (!m_overlayStorage.get())
      oe->draw(this, id);
    else
      m_overlayStorage->AddElement(oe);
  }

  void OverlayRenderer::drawTextEx(FontDesc const & primaryFont,
                                   FontDesc const & secondaryFont,
                                   m2::PointD const & pt,
                                   graphics::EPosition pos,
                                   string const & text,
                                   string const & secondaryText,
                                   double depth,
                                   bool log2vis,
                                   bool doSplit)
  {
    if (!m_drawTexts)
      return;

    StraightTextElement::Params params;
    params.m_depth = depth;
    params.m_fontDesc = primaryFont;
    params.m_auxFontDesc = secondaryFont;
    params.m_log2vis = log2vis;
    params.m_pivot = pt;
    params.m_position = pos;
    params.m_logText = strings::MakeUniString(text);
    params.m_auxLogText = strings::MakeUniString(secondaryText);
    params.m_doSplit = doSplit;
    params.m_useAllParts = false;

    drawTextEx(params);
  }

  void OverlayRenderer::drawPathText(FontDesc const & fontDesc,
                                     m2::PointD const * path,
                                     size_t pathSize,
                                     string const & utf8Text,
                                     double fullLength,
                                     double pathOffset,
                                     double textOffset,
                                     double depth)
  {
    if (!m_drawTexts)
      return;

    PathTextElement::Params params;

    params.m_pts = path;
    params.m_ptsCount = pathSize;
    params.m_fullLength = fullLength;
    params.m_pathOffset = pathOffset;
    params.m_fontDesc = fontDesc;
    params.m_logText = strings::MakeUniString(utf8Text);
    params.m_depth = depth;
    params.m_log2vis = true;
    params.m_textOffset = textOffset;
    params.m_glyphCache = glyphCache();
    params.m_pivot = path[0];

    shared_ptr<PathTextElement> pte(new PathTextElement(params));

    math::Matrix<double, 3, 3> id = math::Identity<double, 3>();

    if (!m_overlayStorage.get())
      pte->draw(this, id);
    else
      m_overlayStorage->AddElement(pte);
  }

  void OverlayRenderer::drawPathText(FontDesc const & fontDesc,
                                     m2::PointD const * path,
                                     size_t pathSize,
                                     string const & utf8Text,
                                     double fullLength,
                                     double pathOffset,
                                     double const * textOffsets,
                                     size_t offsSize,
                                     double depth)
  {
    if (!m_drawTexts)
      return;

    for (unsigned i = 0; i < offsSize; ++i)
      drawPathText(fontDesc,
                   path,
                   pathSize,
                   utf8Text,
                   fullLength,
                   pathOffset,
                   textOffsets[i],
                   depth);
  }

  void OverlayRenderer::setOverlay(const shared_ptr<OverlayStorage> & overlayStorage)
  {
    m_overlayStorage = overlayStorage;
  }

  void OverlayRenderer::resetOverlay()
  {
    m_overlayStorage.reset();
  }
}