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

symbol_element.cpp « graphics - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2fefa5ca84588f9e0fc04a3cdca2d8dd6e149543 (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
#include "../base/logging.hpp"

#include "symbol_element.hpp"
#include "resource.hpp"
#include "icon.hpp"
#include "overlay_renderer.hpp"

namespace graphics
{
  SymbolElement::Params::Params()
    : m_info(),
      m_symbolRect(0, 0, 0, 0),
      m_renderer(0)
  {}

  SymbolElement::SymbolElement(Params const & p)
    : base_t(p),
      m_info(p.m_info),
      m_symbolRect(0, 0, 0, 0)
  {
    uint32_t resID = p.m_renderer->findInfo(m_info);
    Resource const * res = p.m_renderer->fromID(resID);

    if (res == 0)
    {
      LOG(LWARNING, ("POI", m_info.m_name, "wasn't found on current skin."));
      return;
    }

    m_symbolRect = res->m_texRect;
  }

  vector<m2::AnyRectD> const & SymbolElement::boundRects() const
  {
    if (isDirtyRect())
    {
      m_boundRects.clear();
      m_boundRects.push_back(boundRect());
      setIsDirtyRect(false);
    }
    return m_boundRects;
  }

  m2::AnyRectD const SymbolElement::boundRect() const
  {
    m2::RectI texRect(m_symbolRect);
    texRect.Inflate(-1, -1);

    m2::PointD sz(texRect.SizeX(), texRect.SizeY());

    m2::PointD const posPt = computeTopLeft(sz,
                                            pivot(),
                                            position());

    return m2::AnyRectD(m2::RectD(posPt, posPt + sz));
  }

  void SymbolElement::draw(OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const
  {
    if (!isNeedRedraw())
      return;

    uint32_t resID = r->findInfo(m_info);
    Resource const * res = r->fromID(resID);

    if (res == 0)
    {
      LOG(LINFO, ("POI(", m_info.m_name, ") wasn't found on the current skin"));
      return;
    }

    if (res->m_texRect != m_symbolRect)
    {
      LOG(LINFO, ("POI(", m_info.m_name, ") rects doesn't match"));
      return;
    }

    m2::RectI texRect(res->m_texRect);
    texRect.Inflate(-1, -1);

    m2::PointD sz(texRect.SizeX(), texRect.SizeY());

    m2::PointD posPt = computeTopLeft(sz,
                                      pivot() * m,
                                      position());

    posPt -= pivot();

    r->drawStraightTexturedPolygon(pivot(),
                                   texRect.minX(), texRect.minY(), texRect.maxX(), texRect.maxY(),
                                   posPt.x, posPt.y, posPt.x + sz.x, posPt.y + sz.y,
                                   depth(),
                                   res->m_pipelineID);
  }

  void SymbolElement::setTransformation(const math::Matrix<double, 3, 3> & m)
  {
    setPivot(pivot() * getResetMatrix() * m);
    base_t::setTransformation(m);
  }

  bool SymbolElement::hasSharpGeometry() const
  {
    return true;
  }
}