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

anim_phase_chain.cpp « map - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5915ce82cf765ed5d72b0d54f99783bbf34400b2 (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
#include "map/anim_phase_chain.hpp"

#include "map/framework.hpp"

AnimPhase::AnimPhase(double endScale, double timeInterval)
  : m_endScale(endScale)
  , m_timeInterval(timeInterval)
{
}

AnimPhaseChain::AnimPhaseChain(Framework & f, double & scale)
  : m_f(f)
  , m_scale(scale)
{
}

void AnimPhaseChain::AddAnimPhase(AnimPhase const & phase)
{
  m_animPhases.push_back(phase);
}

void AnimPhaseChain::OnStart(double ts)
{
  m_startTime = ts;
  m_startScale = m_scale;
  m_phaseIndex = 0;
}

void AnimPhaseChain::OnStep(double ts)
{
  ASSERT(m_phaseIndex < m_animPhases.size(), ());

  AnimPhase const * phase = &m_animPhases[m_phaseIndex];
  double elapsedTime = ts - m_startTime;
  if (elapsedTime > phase->m_timeInterval)
  {
    m_startTime = ts;
    m_scale = phase->m_endScale;
    m_startScale = m_scale;
    m_phaseIndex++;
    if (m_phaseIndex >= m_animPhases.size())
    {
      End();
      return;
    }
  }

  elapsedTime = ts - m_startTime;
  double t = elapsedTime / phase->m_timeInterval;
  m_scale = m_startScale + t * (phase->m_endScale - m_startScale);

  m_f.Invalidate();
}

void InitDefaultPinAnim(AnimPhaseChain * chain)
{
  chain->AddAnimPhase(AnimPhase(1.2, 0.15));
  chain->AddAnimPhase(AnimPhase(0.8, 0.08));
  chain->AddAnimPhase(AnimPhase(1, 0.05));
}

shared_ptr<anim::Task> CreateDefaultPinAnim(Framework & f, double & scale)
{
  shared_ptr<AnimPhaseChain> anim = make_shared<AnimPhaseChain>(f, scale);
  InitDefaultPinAnim(anim.get());
  return anim;
}