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

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

namespace df
{

// static
bool Animation::GetCachedProperty(TPropertyCache const & properties, Object object, ObjectProperty property, PropertyValue & value)
{
  auto const it = properties.find(make_pair(object, property));
  if (it != properties.end())
  {
    value = it->second;
    return true;
  }
  return false;
}

// static
void Animation::GetCurrentScreen(TPropertyCache const & properties, ScreenBase const & screen, ScreenBase & currentScreen)
{
  currentScreen = screen;

  if (!properties.empty())
  {
    double scale = currentScreen.GetScale();
    double angle = currentScreen.GetAngle();
    m2::PointD pos = currentScreen.GlobalRect().GlobalZero();

    PropertyValue value;
    if (GetCachedProperty(properties, Object::MapPlane, ObjectProperty::Scale, value))
      scale = value.m_valueD;

    if (GetCachedProperty(properties, Object::MapPlane, ObjectProperty::Angle, value))
      angle = value.m_valueD;

    if (GetCachedProperty(properties, Object::MapPlane, ObjectProperty::Position, value))
      pos = value.m_valuePointD;

    currentScreen.SetFromParams(pos, angle, scale);
  }
}

bool Animation::HasSameObjects(Animation const & animation) const
{
  TAnimObjects const & objects = animation.GetObjects();
  for (auto const & object : objects)
  {
    if (HasObject(object))
      return true;
  }
  return false;
}

bool Animation::CouldBeBlendedWith(Animation const & animation) const
{
  return !HasSameObjects(animation) ||
         ((GetType() != animation.GetType()) && m_couldBeBlended && animation.m_couldBeBlended);
}

bool Animation::HasTargetProperty(Object object, ObjectProperty property) const
{
  return HasProperty(object, property);
}

// static
bool Animation::GetMinDuration(Interpolator const & interpolator, double & minDuration)
{
  if (interpolator.IsActive())
  {
    double const duration = interpolator.GetMinDuration();
    if (duration >= 0.0)
      minDuration = minDuration >= 0.0 ? min(duration, minDuration) : duration;
    else
      return false;
  }
  return true;
}

// static
bool Animation::GetMaxDuration(Interpolator const & interpolator, double & maxDuration)
{
  if (interpolator.IsActive())
  {
    double const duration = interpolator.GetMaxDuration();
    if (duration >= 0.0)
      maxDuration = maxDuration >= 0.0 ? max(duration, maxDuration) : duration;
    else
      return false;
  }
  return true;
}

std::string DebugPrint(Animation::Type const & type)
{
  switch (type)
  {
  case Animation::Type::Sequence: return "Sequence";
  case Animation::Type::Parallel: return "Parallel";
  case Animation::Type::MapLinear: return "MapLinear";
  case Animation::Type::MapScale: return "MapScale";
  case Animation::Type::MapFollow: return "MapFollow";
  case Animation::Type::Arrow: return "Arrow";
  case Animation::Type::KineticScroll: return "KineticScroll";
  }
  return "Unknown type";
}

std::string DebugPrint(Animation::Object const & object)
{
  switch (object)
  {
  case Animation::Object::MyPositionArrow: return "MyPositionArrow";
  case Animation::Object::MapPlane: return "MapPlane";
  case Animation::Object::Selection: return "Selection";
  }
  return "Unknown object";
}

std::string DebugPrint(Animation::ObjectProperty const & property)
{
  switch (property)
  {
  case Animation::ObjectProperty::Position: return "Position";
  case Animation::ObjectProperty::Scale: return "Scale";
  case Animation::ObjectProperty::Angle: return "Angle";
  }
  return "Unknown property";
}

} // namespace df