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
|
#include "compass_arrow.hpp"
#include "framework.hpp"
#include "../anim/controller.hpp"
#include "../gui/controller.hpp"
#include "../geometry/any_rect2d.hpp"
#include "../geometry/transformations.hpp"
#include "../graphics/display_list.hpp"
#include "../graphics/screen.hpp"
#include "../graphics/skin.hpp"
CompassArrow::CompassArrow(Params const & p)
: base_t(p),
m_arrowWidth(p.m_arrowWidth),
m_arrowHeight(p.m_arrowHeight),
m_northLeftColor(0xcc, 0x33, 0x00, 0xcc),
m_northRightColor(0xff, 0x33, 0x00, 0xcc),
m_southLeftColor(0xcc, 0xcc, 0xcc, 0xcc),
m_southRightColor(0xff, 0xff, 0xff, 0xcc),
m_angle(0),
m_boundRects(1),
m_framework(p.m_framework)
{
}
void CompassArrow::SetAngle(double angle)
{
m_angle = angle;
setIsDirtyRect(true);
}
vector<m2::AnyRectD> const & CompassArrow::boundRects() const
{
if (isDirtyRect())
{
double k = visualScale();
double halfW = m_arrowWidth / 2.0 * k;
double halfH = m_arrowHeight / 2.0 * k;
m_boundRects[0] = m2::AnyRectD(pivot(),
-math::pi / 2 + m_angle,
m2::RectD(-halfW, -halfH, halfW, halfH));
setIsDirtyRect(false);
}
return m_boundRects;
}
void CompassArrow::draw(graphics::gl::OverlayRenderer * r,
math::Matrix<double, 3, 3> const & m) const
{
if (isVisible())
{
checkDirtyDrawing();
math::Matrix<double, 3, 3> drawM = math::Shift(
math::Rotate(
math::Identity<double, 3>(),
m_angle),
pivot());
r->drawDisplayList(m_displayList.get(), drawM * m);
}
}
void CompassArrow::cache()
{
graphics::gl::Screen * cacheScreen = m_controller->GetCacheScreen();
m_displayList.reset();
m_displayList.reset(cacheScreen->createDisplayList());
cacheScreen->beginFrame();
cacheScreen->setDisplayList(m_displayList.get());
double const k = visualScale();
double const halfW = m_arrowWidth / 2.0 * k;
double const halfH = m_arrowHeight / 2.0 * k;
m2::PointF const northLeftPts[3] = {
m2::PointF(-halfW, 0),
m2::PointF(0, -halfH),
m2::PointF(0, 0)
};
cacheScreen->drawConvexPolygon(northLeftPts, 3, m_northLeftColor, depth());
m2::PointF const northRightPts[3] = {
m2::PointF(0, 0),
m2::PointF(0, -halfH),
m2::PointF(halfW, 0)
};
cacheScreen->drawConvexPolygon(northRightPts, 3, m_northRightColor, depth());
m2::PointF const southLeftPts[3] = {
m2::PointF(-halfW, 0),
m2::PointF(0, 0),
m2::PointF(0, halfH),
};
cacheScreen->drawConvexPolygon(southLeftPts, 3, m_southLeftColor, depth());
m2::PointF const southRightPts[3] = {
m2::PointF(0, 0),
m2::PointF(halfW, 0),
m2::PointF(0, halfH),
};
cacheScreen->drawConvexPolygon(southRightPts, 3, m_southRightColor, depth());
m2::PointD outlinePts[6] = {
m2::PointD(-halfW, 0),
m2::PointD(0, -halfH),
m2::PointD(halfW, 0),
m2::PointD(0, halfH),
m2::PointD(-halfW, 0),
m2::PointD(halfW, 0)
};
graphics::PenInfo const outlinePenInfo(graphics::Color(0x66, 0x66, 0x66, 0xcc), 1, 0, 0, 0);
cacheScreen->drawPath(outlinePts, sizeof(outlinePts) / sizeof(m2::PointD), 0, cacheScreen->skin()->mapPenInfo(outlinePenInfo), depth());
cacheScreen->setDisplayList(0);
cacheScreen->endFrame();
// we should not call cacheScreen->completeCommands
// as the gui::Element::cache is called on the GUI thread.
}
void CompassArrow::purge()
{
m_displayList.reset();
}
bool CompassArrow::onTapEnded(m2::PointD const & pt)
{
anim::Controller * animController = m_framework->GetAnimController();
animController->Lock();
/// switching off compass follow mode
m_framework->GetInformationDisplay().locationState()->StopCompassFollowing();
double startAngle = m_framework->GetNavigator().Screen().GetAngle();
double endAngle = 0;
m_framework->GetAnimator().RotateScreen(startAngle, endAngle);
animController->Unlock();
m_framework->Invalidate();
return true;
}
unsigned CompassArrow::GetArrowHeight() const
{
return m_arrowHeight;
}
bool CompassArrow::hitTest(m2::PointD const & pt) const
{
double rad = max(m_arrowWidth / 2, m_arrowHeight / 2);
return pt.Length(pivot()) < rad * visualScale();
}
|