Merge pull request #4580 from jmarshallnz/anim_length_fix
[vuplus_xbmc] / xbmc / guilib / VisibleEffect.cpp
index e4cc526..035c998 100644 (file)
@@ -61,7 +61,7 @@ CAnimEffect::CAnimEffect(const CAnimEffect &src)
   *this = src;
 }
 
-const CAnimEffect &CAnimEffect::operator=(const CAnimEffect &src)
+CAnimEffect& CAnimEffect::operator=(const CAnimEffect &src)
 {
   if (&src == this) return *this;
 
@@ -248,12 +248,11 @@ void CRotateEffect::ApplyEffect(float offset, const CPoint &center)
     m_matrix.SetZRotation(((m_endAngle - m_startAngle)*offset + m_startAngle) * degree_to_radian, m_center.x, m_center.y, g_graphicsContext.GetScalingPixelRatio());
 }
 
-CZoomEffect::CZoomEffect(const TiXmlElement *node, const CRect &rect) : CAnimEffect(node, EFFECT_TYPE_ZOOM)
+CZoomEffect::CZoomEffect(const TiXmlElement *node, const CRect &rect) : CAnimEffect(node, EFFECT_TYPE_ZOOM), m_center(CPoint(0,0))
 {
   // effect defaults
   m_startX = m_startY = 100;
   m_endX = m_endY = 100;
-  m_center = CPoint(0,0);
   m_autoCenter = false;
 
   float startPosX = rect.x1;
@@ -361,7 +360,6 @@ CAnimation::CAnimation()
 {
   m_type = ANIM_TYPE_NONE;
   m_reversible = true;
-  m_condition = 0;
   m_repeatAnim = ANIM_REPEAT_NONE;
   m_currentState = ANIM_STATE_NONE;
   m_currentProcess = ANIM_PROCESS_NONE;
@@ -385,12 +383,12 @@ CAnimation::~CAnimation()
   m_effects.clear();
 }
 
-const CAnimation &CAnimation::operator =(const CAnimation &src)
+CAnimation &CAnimation::operator =(const CAnimation &src)
 {
   if (this == &src) return *this; // same
   m_type = src.m_type;
   m_reversible = src.m_reversible;
-  m_condition = src.m_condition; // TODO: register/unregister
+  m_condition = src.m_condition;
   m_repeatAnim = src.m_repeatAnim;
   m_lastCondition = src.m_lastCondition;
   m_queuedProcess = src.m_queuedProcess;
@@ -576,18 +574,22 @@ CAnimation CAnimation::CreateFader(float start, float end, unsigned int delay, u
 {
   CAnimation anim;
   anim.m_type = type;
-  anim.AddEffect(new CFadeEffect(start, end, delay, length));
+  anim.m_delay = delay;
+  anim.m_length = length;
+  anim.m_effects.push_back(new CFadeEffect(start, end, delay, length));
   return anim;
 }
 
 bool CAnimation::CheckCondition()
 {
-  return !m_condition || g_infoManager.GetBoolValue(m_condition);
+  return !m_condition || m_condition->Get();
 }
 
 void CAnimation::UpdateCondition(const CGUIListItem *item)
 {
-  bool condition = g_infoManager.GetBoolValue(m_condition, item);
+  if (!m_condition)
+    return;
+  bool condition = m_condition->Get(item);
   if (condition && !m_lastCondition)
     QueueAnimation(ANIM_PROCESS_NORMAL);
   else if (!condition && m_lastCondition)
@@ -602,7 +604,7 @@ void CAnimation::UpdateCondition(const CGUIListItem *item)
 
 void CAnimation::SetInitialCondition()
 {
-  m_lastCondition = g_infoManager.GetBoolValue(m_condition);
+  m_lastCondition = m_condition ? m_condition->Get() : false;
   if (m_lastCondition)
     ApplyAnimation();
   else
@@ -629,7 +631,7 @@ void CAnimation::Create(const TiXmlElement *node, const CRect &rect, int context
   if (effect) // new layout
     type = node->Attribute("type");
 
-  if (type.Left(7).Equals("visible")) m_type = ANIM_TYPE_VISIBLE;
+  if (StringUtils::StartsWithNoCase(type, "visible")) m_type = ANIM_TYPE_VISIBLE;
   else if (type.Equals("hidden")) m_type = ANIM_TYPE_HIDDEN;
   else if (type.Equals("focus"))  m_type = ANIM_TYPE_FOCUS;
   else if (type.Equals("unfocus"))  m_type = ANIM_TYPE_UNFOCUS;
@@ -653,7 +655,6 @@ void CAnimation::Create(const TiXmlElement *node, const CRect &rect, int context
       m_repeatAnim = ANIM_REPEAT_LOOP;
   }
 
-  m_delay = 0xffffffff;
   if (!effect)
   { // old layout:
     // <animation effect="fade" start="0" end="100" delay="10" time="2000" condition="blahdiblah" reversible="false">focus</animation>
@@ -670,6 +671,15 @@ void CAnimation::Create(const TiXmlElement *node, const CRect &rect, int context
     AddEffect(type, effect, rect);
     effect = effect->NextSiblingElement("effect");
   }
+  // compute the minimum delay and maximum length
+  m_delay = 0xffffffff;
+  unsigned int total = 0;
+  for (vector<CAnimEffect*>::const_iterator i = m_effects.begin(); i != m_effects.end(); ++i)
+  {
+    m_delay = min(m_delay, (*i)->GetDelay());
+    total   = max(total, (*i)->GetLength());
+  }
+  m_length = total - m_delay;
 }
 
 void CAnimation::AddEffect(const CStdString &type, const TiXmlElement *node, const CRect &rect)
@@ -689,18 +699,7 @@ void CAnimation::AddEffect(const CStdString &type, const TiXmlElement *node, con
     effect = new CZoomEffect(node, rect);
 
   if (effect)
-    AddEffect(effect);
-}
-
-void CAnimation::AddEffect(CAnimEffect *effect)
-{
-  m_effects.push_back(effect);
-  // our delay is the minimum of all the effect delays
-  if (effect->GetDelay() < m_delay)
-    m_delay = effect->GetDelay();
-  // our length is the maximum of all the effect lengths
-  if (effect->GetLength() > m_delay + m_length)
-    m_length = effect->GetLength() - m_delay;
+    m_effects.push_back(effect);
 }
 
 CScroller::CScroller(unsigned int duration /* = 200 */, boost::shared_ptr<Tweener> tweener /* = NULL */)
@@ -721,7 +720,7 @@ CScroller::CScroller(const CScroller& right)
   *this = right;
 }
 
-const CScroller &CScroller::operator=(const CScroller &right)
+CScroller& CScroller::operator=(const CScroller &right)
 {
   if (&right == this) return *this;