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

drape_api_builder.cpp « drape_frontend - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8b2ed137074401ccf1fc987e2a905776bb8d6283 (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
#include "drape_frontend/drape_api_builder.hpp"
#include "drape_frontend/circle_shape.hpp"
#include "drape_frontend/gui/gui_text.hpp"
#include "drape_frontend/line_shape.hpp"
#include "drape_frontend/shape_view_params.hpp"

#include "drape/batcher.hpp"

#include "indexer/feature_decl.hpp"

#include "base/string_utils.hpp"

namespace
{

void BuildText(string const & str, dp::FontDecl const & font, m2::PointD const & position,
               m2::PointD const & center, ref_ptr<dp::TextureManager> textures, dp::Batcher & batcher)
{
  gui::StaticLabel::LabelResult result;
  gui::StaticLabel::CacheStaticText(str, "\n", dp::LeftTop, font, textures, result);
  glsl::vec2 const pt = glsl::ToVec2(df::MapShape::ConvertToLocal(position, center, df::kShapeCoordScalar));
  for (gui::StaticLabel::Vertex & v : result.m_buffer)
    v.m_position = glsl::vec3(pt, 0.0f);

  dp::AttributeProvider provider(1 /* streamCount */, result.m_buffer.size());
  provider.InitStream(0 /* streamIndex */, gui::StaticLabel::Vertex::GetBindingInfo(),
                      make_ref(result.m_buffer.data()));

  batcher.InsertListOfStrip(result.m_state, make_ref(&provider), dp::Batcher::VertexPerQuad);
}

} // namespace

namespace df
{

void DrapeApiBuilder::BuildLines(DrapeApi::TLines const & lines, ref_ptr<dp::TextureManager> textures,
                                 vector<drape_ptr<DrapeApiRenderProperty>> & properties)
{
  properties.reserve(lines.size());

  uint32_t constexpr kMaxSize = 5000;
  uint32_t constexpr kFontSize = 14;
  FeatureID fakeFeature;

  for (auto const & line : lines)
  {
    string id = line.first;
    DrapeApiLineData const & data = line.second;
    m2::RectD rect;
    for (m2::PointD p : data.m_points)
      rect.Add(p);

    dp::Batcher batcher(kMaxSize, kMaxSize);
    auto property = make_unique_dp<DrapeApiRenderProperty>();
    property->m_center = rect.Center();
    {
      dp::SessionGuard guard(batcher, [&property, id](dp::GLState const & state, drape_ptr<dp::RenderBucket> && b)
      {
        property->m_id = id;
        property->m_buckets.push_back(make_pair(state, move(b)));
      });

      m2::SharedSpline spline(data.m_points);
      LineViewParams lvp;
      lvp.m_tileCenter = property->m_center;
      lvp.m_depth = 0.0f;
      lvp.m_minVisibleScale = 1;
      lvp.m_cap = dp::RoundCap;
      lvp.m_color = data.m_color;
      lvp.m_width = data.m_width;
      lvp.m_join = dp::RoundJoin;
      LineShape(spline, lvp).Draw(make_ref(&batcher), textures);

      if (data.m_showPoints)
      {
        CircleViewParams cvp(fakeFeature);
        cvp.m_tileCenter = property->m_center;
        cvp.m_depth = 0.0f;
        cvp.m_minVisibleScale = 1;
        cvp.m_color = data.m_color;
        cvp.m_radius = data.m_width * 2.0f;
        for (m2::PointD const & pt : data.m_points)
          CircleShape(m2::PointF(pt), cvp, false /* need overlay */).Draw(make_ref(&batcher), textures);
      }

      if (data.m_markPoints || data.m_showId)
      {
        dp::FontDecl font(data.m_color, kFontSize);
        size_t index = 0;
        for (m2::PointD const & pt : data.m_points)
        {
          if (index > 0 && !data.m_markPoints) break;

          string s;
          if (data.m_markPoints)
            s = strings::to_string(index) + ((data.m_showId && index == 0) ? (" (" + id + ")") : "");
          else
            s = id;

          BuildText(s, font, pt, property->m_center, textures, batcher);
          index++;
        }
      }
    }

    if (!property->m_buckets.empty())
      properties.push_back(move(property));
  }
}

} // namespace df