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
|
#include "map/animator.hpp"
#include "map/rotate_screen_task.hpp"
#include "map/change_viewport_task.hpp"
#include "map/move_screen_task.hpp"
#include "map/framework.hpp"
#include "anim/controller.hpp"
#include "geometry/angles.hpp"
Animator::Animator(Framework * framework)
: m_framework(framework)
{}
void Animator::StopAnimation(shared_ptr<anim::Task> const & task)
{
if (task)
{
task->Lock();
if (!task->IsEnded()
&& !task->IsCancelled())
task->Cancel();
task->Unlock();
}
}
void Animator::RotateScreen(double startAngle, double endAngle)
{
if (m_rotateScreenTask)
m_rotateScreenTask->Lock();
bool const inProgress =
m_rotateScreenTask &&
!m_rotateScreenTask->IsCancelled() &&
!m_rotateScreenTask->IsEnded();
if (inProgress)
{
m_rotateScreenTask->SetEndAngle(endAngle);
}
else
{
double const eps = my::DegToRad(1.5);
if (fabs(ang::GetShortestDistance(startAngle, endAngle)) > eps)
{
if (m_rotateScreenTask)
{
m_rotateScreenTask->Unlock();
m_rotateScreenTask.reset();
}
m_rotateScreenTask.reset(new RotateScreenTask(m_framework,
startAngle,
endAngle,
GetRotationSpeed()));
m_framework->GetAnimController()->AddTask(m_rotateScreenTask);
return;
}
}
if (m_rotateScreenTask)
m_rotateScreenTask->Unlock();
}
void Animator::StopRotation()
{
StopAnimation(m_rotateScreenTask);
m_rotateScreenTask.reset();
}
shared_ptr<MoveScreenTask> const & Animator::MoveScreen(m2::PointD const & startPt,
m2::PointD const & endPt,
double speed)
{
StopMoveScreen();
m_moveScreenTask.reset(new MoveScreenTask(m_framework,
startPt,
endPt,
speed));
m_framework->GetAnimController()->AddTask(m_moveScreenTask);
return m_moveScreenTask;
}
void Animator::StopMoveScreen()
{
StopAnimation(m_moveScreenTask);
m_moveScreenTask.reset();
}
shared_ptr<ChangeViewportTask> const & Animator::ChangeViewport(m2::AnyRectD const & start,
m2::AnyRectD const & end,
double rotationSpeed)
{
StopChangeViewport();
m_changeViewportTask.reset(new ChangeViewportTask(start,
end,
rotationSpeed,
m_framework));
m_framework->GetAnimController()->AddTask(m_changeViewportTask);
return m_changeViewportTask;
}
void Animator::StopChangeViewport()
{
StopAnimation(m_changeViewportTask);
m_changeViewportTask.reset();
}
double Animator::GetRotationSpeed() const
{
// making full circle in ~1 seconds.
return 6.0;
}
|