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

balloon.hpp « gui - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 361e3be119e7da8031a12b77307046ab778e2ddc (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
#pragma once

#include "element.hpp"
#include "text_view.hpp"
#include "image_view.hpp"

#include "../graphics/font_desc.hpp"
#include "../graphics/image.hpp"

#include "../base/string_utils.hpp"
#include "../base/matrix.hpp"

#include "../std/scoped_ptr.hpp"
#include "../std/function.hpp"

namespace graphics
{
  class OverlayRenderer;
  class Screen;
}

namespace gui
{
  class Balloon : public Element
  {
  protected:
    scoped_ptr<TextView> m_mainTextView;
    scoped_ptr<TextView> m_auxTextView;
    scoped_ptr<ImageView> m_imageView;

    double m_balloonScale;
    double m_textImageOffsetH;
    double m_textImageOffsetV;

  private:
    enum ETextMode
    {
      NoText = 0,
      SingleMainText = 0x1,
      SingleAuxText = 0x2,
      DualText = SingleMainText | SingleAuxText
    };

    ETextMode m_textMode;

    uint32_t m_maxWidth;

    void updateTextMode(string const & main, string const & aux);

    scoped_ptr<graphics::DisplayList> m_displayList;

    typedef function<void (Element *)> TOnClickListener;

    mutable vector<m2::AnyRectD> m_boundRects;

    void cacheLeftBorder(graphics::Screen * cs,
                         double offsetX);

    void cacheRightBorder(graphics::Screen * cs,
                          double offsetX);

    void cacheBody(graphics::Screen * cs,
                   double offsetX,
                   double bodyWidth);

    void initBgImages();

    void layoutMainText(double balloonWidth,
                        double leftMargin);
    void layoutAuxText(double balloonWidth,
                       double leftMargin);

    void layoutPointByX(m2::PointD & pv,
                        double balloonWidth,
                        double leftMargin);

    graphics::EPosition layoutPointByY(m2::PointD & pv,
                                       double dualDivisor);

    void calcMaxTextWidth();

    graphics::Image::Info m_borderLImg;
    graphics::Image::Info m_borderRImg;
    graphics::Image::Info m_bodyImg;
    graphics::Image::Info m_arrowImg;

    TOnClickListener m_onClickListener;

    typedef Element base_t;

  protected:
    void cache();
    void purge();
    void layout();

  public:

    struct Params : public base_t::Params
    {
      string m_mainText;
      string m_auxText;
      graphics::Image::Info m_image;
      Params();
    };

    Balloon(Params const & p);

    vector<m2::AnyRectD> const & boundRects() const;
    void draw(graphics::OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const;

    void setController(Controller * controller);
    void setPivot(m2::PointD const & pv);

    void setOnClickListener(TOnClickListener const & fn);

    void setText(string const & main, string const & aux);
    void setImage(graphics::Image::Info const & info);

    bool onTapStarted(m2::PointD const & pt);
    bool onTapMoved(m2::PointD const & pt);
    bool onTapEnded(m2::PointD const & pt);
    bool onTapCancelled(m2::PointD const & pt);

    void onScreenSize(int w, int h);
  };
}