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

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

#include "display_list_cache.hpp"

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

#include "../geometry/point2d.hpp"
#include "../graphics/defines.hpp"

#include "../base/strings_bundle.hpp"

namespace graphics
{
  class GlyphCache;
  class OverlayElement;
  class Screen;
}

namespace gui
{
  class Element;

  /// Controller for GUI elements, which tracks mouse, keyboard and
  /// touch user interactions into interactions with GUI elements.
  class Controller
  {
  public:

    /// Invalidate functor type
    typedef function<void()> TInvalidateFn;

    struct RenderParams
    {
      graphics::EDensity m_Density;
      TInvalidateFn m_InvalidateFn;
      graphics::GlyphCache * m_GlyphCache;
      graphics::Screen * m_CacheScreen;
      RenderParams();
      RenderParams(graphics::EDensity density,
                   TInvalidateFn invalidateFn,
                   graphics::GlyphCache * glyphCache,
                   graphics::Screen * cacheScreen);
    };

  private:

    /// element that has focus.
    shared_ptr<Element> m_focusedElement;

    typedef list<shared_ptr<graphics::OverlayElement> > base_list_t;
    typedef list<shared_ptr<Element> > elem_list_t;

    elem_list_t m_Elements;

    /// select elements under specified point
    void SelectElements(m2::PointD const & pt, elem_list_t & l, bool onlyVisible);

    /// Invalidate GUI function
    TInvalidateFn m_InvalidateFn;

    /// Screen density
    graphics::EDensity m_Density;

    /// VisualScale to multiply all Device-Independent-Pixels dimensions.
    double m_VisualScale;

    /// GlyphCache for text rendering by GUI elements.
    graphics::GlyphCache * m_GlyphCache;

    /// Cache for display lists for fast rendering on GUI thread
    scoped_ptr<DisplayListCache> m_DisplayListCache;

    /// Localized strings for GUI.
    StringsBundle const * m_bundle;

    /// Screen, which is used to cache gui::Elements into display lists.
    graphics::Screen * m_CacheScreen;

    /// Should we call the onTapEnded when the tap finished(we should
    /// not if the tap was cancelled while moving).
    bool m_LastTapCancelled;

  public:

    /// Constructor with GestureDetector to route events from.
    Controller();
    /// Destructor
    virtual ~Controller();

    /// Handlers to be called from the client code to power up the GUI.
    /// @{
    bool OnTapStarted(m2::PointD const & pt);
    bool OnTapMoved(m2::PointD const & pt);
    bool OnTapEnded(m2::PointD const & pt);
    bool OnTapCancelled(m2::PointD const & pt);
    /// @}

    /// Attach GUI Controller to the renderer
    void SetRenderParams(RenderParams const & p);
    /// Set the bundle with localized strings
    void SetStringsBundle(StringsBundle const * bundle);
    /// Detach GUI Controller from the renderer
    void ResetRenderParams();
    /// Invalidate the scene
    void Invalidate();
    /// Remove GUI element by pointer
    void RemoveElement(shared_ptr<Element> const & e);
    /// Add GUI element to the controller
    void AddElement(shared_ptr<Element> const & e);
    /// Get VisualScale parameter
    double GetVisualScale() const;
    /// Get Density parameter
    graphics::EDensity GetDensity() const;
    /// Get localized strings bundle
    StringsBundle const * GetStringsBundle() const;
    /// Get GlyphCache
    graphics::GlyphCache * GetGlyphCache() const;
    /// Get graphics::Screen, which is used to cache gui::Element's
    /// into display lists.
    graphics::Screen * GetCacheScreen() const;
    /// Get display list cache
    DisplayListCache * GetDisplayListCache() const;
    /// Redraw GUI
    void DrawFrame(graphics::Screen * screen);
    /// Calling gui::Element::update for every element.
    void UpdateElements();
    /// Calling gui::Element::purge for every element.
    void PurgeElements();
    /// Calling gui::Element::performLayout for every element
    void LayoutElements();
  };
}