Merged PR #353
authorLars Op den Kamp <lars@opdenkamp.eu>
Tue, 16 Aug 2011 10:50:35 +0000 (12:50 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Tue, 16 Aug 2011 10:50:35 +0000 (12:50 +0200)
Squashed commit of the following:

commit d66ffe776e7a427fa585c964408e3186c9a16e84
Merge: 8c750cf 36fad55
Author: Lars Op den Kamp <lars@opdenkamp.eu>
Date:   Tue Aug 16 12:50:06 2011 +0200

    Merge branch 'getint-listitem' of git://github.com/opdenkamp/xbmc into pr353

commit 36fad5500f396741426e9841dbfd2133eda14d5c
Author: Lars Op den Kamp <lars@opdenkamp.eu>
Date:   Sun Aug 14 23:36:45 2011 +0200

    CGUIProgressControl: removed unneeded m_bChanged; changed width will already mark the control as dirty. moved IsDisabled() check from UpdateLayout() to Process(). removed unneeded include

commit 27d70a7bc8aa1920cfea5d9d75122e50f9151a7b
Author: Lars Op den Kamp <lars@opdenkamp.eu>
Date:   Sun Aug 14 18:18:44 2011 +0200

    removed leftover includes in CGUIProgressControl

commit 15fd50a6256bb3d704efc51f419b48edcb2071e9
Author: Lars Op den Kamp <lars@opdenkamp.eu>
Date:   Sun Aug 14 17:44:15 2011 +0200

    support guiprogresscontrol as listitem

commit b4f9d163452a76c4b4c9dbb893f5be0bd5d725fa
Author: Lars Op den Kamp <lars@opdenkamp.eu>
Date:   Sun Aug 14 17:32:26 2011 +0200

    add support for listitems and multiinfo to CGUIInfoManager::GetInt()

xbmc/GUIInfoManager.cpp
xbmc/GUIInfoManager.h
xbmc/guilib/GUIListGroup.cpp
xbmc/guilib/GUIProgressControl.cpp
xbmc/guilib/GUIProgressControl.h

index 125ca2e..74354e4 100644 (file)
@@ -1611,8 +1611,14 @@ CStdString CGUIInfoManager::GetLabel(int info, int contextWindow)
 }
 
 // tries to get a integer value for use in progressbars/sliders and such
-int CGUIInfoManager::GetInt(int info, int contextWindow) const
+int CGUIInfoManager::GetInt(int info, int contextWindow, const CGUIListItem *item /* = NULL */) const
 {
+  if (info >= MULTI_INFO_START && info <= MULTI_INFO_END)
+    return GetMultiInfoInt(m_multiInfo[info - MULTI_INFO_START], contextWindow);
+
+  if (info >= LISTITEM_START && info <= LISTITEM_END)
+    return GetItemInt(item, info);
+
   switch( info )
   {
     case PLAYER_VOLUME:
@@ -2493,6 +2499,38 @@ bool CGUIInfoManager::GetMultiInfoBool(const GUIInfo &info, int contextWindow, c
   return (info.m_info < 0) ? !bReturn : bReturn;
 }
 
+int CGUIInfoManager::GetMultiInfoInt(const GUIInfo &info, int contextWindow) const
+{
+  if (info.m_info >= LISTITEM_START && info.m_info <= LISTITEM_END)
+  {
+    CFileItemPtr item;
+    CGUIWindow *window = NULL;
+
+    int data1 = info.GetData1();
+    if (!data1) // No container specified, so we lookup the current view container
+    {
+      window = GetWindowWithCondition(contextWindow, WINDOW_CONDITION_HAS_LIST_ITEMS);
+      if (window && window->IsMediaWindow())
+        data1 = ((CGUIMediaWindow*)(window))->GetViewContainerID();
+    }
+
+    if (!window) // If we don't have a window already (from lookup above), get one
+      window = GetWindowWithCondition(contextWindow, 0);
+
+    if (window)
+    {
+      const CGUIControl *control = window->GetControl(data1);
+      if (control && control->IsContainer())
+        item = boost::static_pointer_cast<CFileItem>(((CGUIBaseContainer *)control)->GetListItem(info.GetData2(), info.GetInfoFlag()));
+    }
+
+    if (item) // If we got a valid item, do the lookup
+      return GetItemInt(item.get(), info.m_info);
+  }
+
+  return 0;
+}
+
 /// \brief Examines the multi information sent and returns the string as appropriate
 CStdString CGUIInfoManager::GetMultiInfoLabel(const GUIInfo &info, int contextWindow) const
 {
@@ -3609,6 +3647,26 @@ int CGUIInfoManager::ConditionalStringParameter(const CStdString &parameter)
   return (int)m_stringParameters.size() - 1;
 }
 
+int CGUIInfoManager::GetItemInt(const CGUIListItem *item, int info) const
+{
+  if (!item) return 0;
+
+  if (info >= LISTITEM_PROPERTY_START && info - LISTITEM_PROPERTY_START < (int)m_listitemProperties.size())
+  { // grab the property
+    CStdString property = m_listitemProperties[info - LISTITEM_PROPERTY_START];
+    CStdString val = item->GetProperty(property);
+    return atoi(val);
+  }
+
+  switch (info)
+  {
+    /* add integer LISTITEM_ here */
+    break;
+  }
+
+  return 0;
+}
+
 CStdString CGUIInfoManager::GetItemLabel(const CFileItem *item, int info) const
 {
   if (!item) return "";
index 99fddf5..df7529f 100644 (file)
@@ -569,7 +569,7 @@ public:
   bool EvaluateBool(const CStdString &expression, int context = 0);
 
   int TranslateString(const CStdString &strCondition);
-  int GetInt(int info, int contextWindow = 0) const;
+  int GetInt(int info, int contextWindow = 0, const CGUIListItem *item = NULL) const;
   CStdString GetLabel(int info, int contextWindow = 0);
 
   CStdString GetImage(int info, int contextWindow);
@@ -632,6 +632,7 @@ public:
 
   void ResetCache();
 
+  int GetItemInt(const CGUIListItem *item, int info) const;
   CStdString GetItemLabel(const CFileItem *item, int info) const;
   CStdString GetItemImage(const CFileItem *item, int info) const;
 
@@ -680,6 +681,7 @@ protected:
   };
 
   bool GetMultiInfoBool(const GUIInfo &info, int contextWindow = 0, const CGUIListItem *item = NULL);
+  int GetMultiInfoInt(const GUIInfo &info, int contextWindow = 0) const;
   CStdString GetMultiInfoLabel(const GUIInfo &info, int contextWindow = 0) const;
   int TranslateListItem(const Property &info);
   int TranslateMusicPlayerString(const CStdString &info) const;
index 73d3710..cc23bbe 100644 (file)
@@ -55,7 +55,8 @@ void CGUIListGroup::AddControl(CGUIControl *control, int position /*= -1*/)
           control->GetControlType() == CGUIControl::GUICONTROL_BORDEREDIMAGE ||
           control->GetControlType() == CGUIControl::GUICONTROL_MULTI_IMAGE ||
           control->GetControlType() == CGUIControl::GUICONTROL_MULTISELECT ||
-          control->GetControlType() == CGUIControl::GUICONTROL_TEXTBOX))
+          control->GetControlType() == CGUIControl::GUICONTROL_TEXTBOX ||
+          control->GetControlType() == CGUIControl::GUICONTROL_PROGRESS))
       CLog::Log(LOGWARNING, "Trying to add unsupported control type %d", control->GetControlType());
   }
   CGUIControlGroup::AddControl(control, position);
index 4908feb..bb27bad 100644 (file)
@@ -59,103 +59,7 @@ void CGUIProgressControl::Process(unsigned int currentTime, CDirtyRegionList &di
   bool changed = false;
 
   if (!IsDisabled())
-  {
-    float percent = m_fPercent;
-    if (m_iInfoCode)
-      m_fPercent = (float)g_infoManager.GetInt(m_iInfoCode);
-    if (m_fPercent < 0.0f) m_fPercent = 0.0f;
-    if (m_fPercent > 100.0f) m_fPercent = 100.0f;
-    changed |= (percent != m_fPercent);
-
-    if (m_width == 0)
-      m_width = m_guiBackground.GetTextureWidth();
-    if (m_height == 0)
-      m_height = m_guiBackground.GetTextureHeight();
-
-    changed |= m_guiBackground.SetHeight(m_height);
-    changed |= m_guiBackground.SetWidth(m_width);
-
-    float fScaleX, fScaleY;
-    fScaleY = m_guiBackground.GetTextureHeight() ? m_height / m_guiBackground.GetTextureHeight() : 1.0f;
-    fScaleX = m_guiBackground.GetTextureWidth() ? m_width / m_guiBackground.GetTextureWidth() : 1.0f;
-
-    float posX = m_guiBackground.GetXPosition();
-    float posY = m_guiBackground.GetYPosition();
-
-    if (m_guiLeft.GetFileName().IsEmpty() && m_guiRight.GetFileName().IsEmpty())
-    { // rendering without left and right image - fill the mid image completely
-      float width = m_fPercent * m_width * 0.01f;
-      float offset = fabs(fScaleY * 0.5f * (m_guiMid.GetTextureHeight() - m_guiBackground.GetTextureHeight()));
-      if (offset > 0)  //  Center texture to the background if necessary
-        changed |= m_guiMid.SetPosition(posX, posY + offset);
-      else
-        changed |= m_guiMid.SetPosition(posX, posY);
-      changed |= m_guiMid.SetHeight(fScaleY * m_guiMid.GetTextureHeight());
-      if (m_bReveal)
-      {
-        changed |= m_guiMid.SetWidth(m_width);
-        float x = posX, y = posY + offset, w = width, h = fScaleY * m_guiMid.GetTextureHeight();
-        m_guiMidClipRect = CRect(x, y, x + w, y + h);
-      }
-      else
-      {
-        changed |= m_guiMid.SetWidth(width);
-        m_guiMidClipRect = CRect();
-      }
-    }
-    else
-    {
-      float fWidth = m_fPercent;
-      float fFullWidth = m_guiBackground.GetTextureWidth() - m_guiLeft.GetTextureWidth() - m_guiRight.GetTextureWidth();
-      fWidth /= 100.0f;
-      fWidth *= fFullWidth;
-
-      float offset = fabs(fScaleY * 0.5f * (m_guiLeft.GetTextureHeight() - m_guiBackground.GetTextureHeight()));
-      if (offset > 0)  //  Center texture to the background if necessary
-        changed |= m_guiLeft.SetPosition(posX, posY + offset);
-      else
-        changed |= m_guiLeft.SetPosition(posX, posY);
-      changed |= m_guiLeft.SetHeight(fScaleY * m_guiLeft.GetTextureHeight());
-      changed |= m_guiLeft.SetWidth(fScaleX * m_guiLeft.GetTextureWidth());
-
-      posX += fScaleX * m_guiLeft.GetTextureWidth();
-      offset = fabs(fScaleY * 0.5f * (m_guiMid.GetTextureHeight() - m_guiBackground.GetTextureHeight()));
-      if (offset > 0)  //  Center texture to the background if necessary
-        changed |= m_guiMid.SetPosition(posX, posY + offset);
-      else
-        changed |= m_guiMid.SetPosition(posX, posY);
-      changed |= m_guiMid.SetHeight(fScaleY * m_guiMid.GetTextureHeight());
-      if (m_bReveal)
-      {
-        changed |= m_guiMid.SetWidth(fScaleX * fFullWidth);
-        float x = posX, y = posY + offset, w =  fScaleX * fWidth, h = fScaleY * m_guiMid.GetTextureHeight();
-        m_guiMidClipRect = CRect(x, y, x + w, y + h);
-      }
-      else
-      {
-        changed |= m_guiMid.SetWidth(fScaleX * fWidth);
-        m_guiMidClipRect = CRect();
-      }
-
-      posX += fWidth * fScaleX;
-
-      offset = fabs(fScaleY * 0.5f * (m_guiRight.GetTextureHeight() - m_guiBackground.GetTextureHeight()));
-      if (offset > 0)  //  Center texture to the background if necessary
-        changed |= m_guiRight.SetPosition(posX, posY + offset);
-      else
-        changed |= m_guiRight.SetPosition(posX, posY);
-      changed |= m_guiRight.SetHeight(fScaleY * m_guiRight.GetTextureHeight());
-      changed |= m_guiRight.SetWidth(fScaleX * m_guiRight.GetTextureWidth());
-    }
-    float offset = fabs(fScaleY * 0.5f * (m_guiOverlay.GetTextureHeight() - m_guiBackground.GetTextureHeight()));
-    if (offset > 0)  //  Center texture to the background if necessary
-      changed |= m_guiOverlay.SetPosition(m_guiBackground.GetXPosition(), m_guiBackground.GetYPosition() + offset);
-    else
-      changed |= m_guiOverlay.SetPosition(m_guiBackground.GetXPosition(), m_guiBackground.GetYPosition());
-    changed |= m_guiOverlay.SetHeight(fScaleY * m_guiOverlay.GetTextureHeight());
-    changed |= m_guiOverlay.SetWidth(fScaleX * m_guiOverlay.GetTextureWidth());
-  }
-
+    changed |= UpdateLayout();
   changed |= m_guiBackground.Process(currentTime);
   changed |= m_guiMid.Process(currentTime);
   changed |= m_guiLeft.Process(currentTime);
@@ -301,3 +205,111 @@ CStdString CGUIProgressControl::GetDescription() const
   percent.Format("%2.f", m_fPercent);
   return percent;
 }
+
+bool CGUIProgressControl::UpdateLayout(void)
+{
+  bool bChanged(false);
+
+  if (m_width == 0)
+    m_width = m_guiBackground.GetTextureWidth();
+  if (m_height == 0)
+    m_height = m_guiBackground.GetTextureHeight();
+
+  bChanged |= m_guiBackground.SetHeight(m_height);
+  bChanged |= m_guiBackground.SetWidth(m_width);
+
+  float fScaleX, fScaleY;
+  fScaleY = m_guiBackground.GetTextureHeight() ? m_height / m_guiBackground.GetTextureHeight() : 1.0f;
+  fScaleX = m_guiBackground.GetTextureWidth() ? m_width / m_guiBackground.GetTextureWidth() : 1.0f;
+
+  float posX = m_guiBackground.GetXPosition();
+  float posY = m_guiBackground.GetYPosition();
+
+  if (m_guiLeft.GetFileName().IsEmpty() && m_guiRight.GetFileName().IsEmpty())
+  { // rendering without left and right image - fill the mid image completely
+    float width = m_fPercent * m_width * 0.01f;
+    float offset = fabs(fScaleY * 0.5f * (m_guiMid.GetTextureHeight() - m_guiBackground.GetTextureHeight()));
+    if (offset > 0)  //  Center texture to the background if necessary
+      bChanged |= m_guiMid.SetPosition(posX, posY + offset);
+    else
+      bChanged |= m_guiMid.SetPosition(posX, posY);
+    bChanged |= m_guiMid.SetHeight(fScaleY * m_guiMid.GetTextureHeight());
+    if (m_bReveal)
+    {
+      bChanged |= m_guiMid.SetWidth(m_width);
+      float x = posX, y = posY + offset, w = width, h = fScaleY * m_guiMid.GetTextureHeight();
+      m_guiMidClipRect = CRect(x, y, x + w, y + h);
+    }
+    else
+    {
+      bChanged |= m_guiMid.SetWidth(width);
+      m_guiMidClipRect = CRect();
+    }
+  }
+  else
+  {
+    float fWidth = m_fPercent;
+    float fFullWidth = m_guiBackground.GetTextureWidth() - m_guiLeft.GetTextureWidth() - m_guiRight.GetTextureWidth();
+    fWidth /= 100.0f;
+    fWidth *= fFullWidth;
+
+    float offset = fabs(fScaleY * 0.5f * (m_guiLeft.GetTextureHeight() - m_guiBackground.GetTextureHeight()));
+    if (offset > 0)  //  Center texture to the background if necessary
+      bChanged |= m_guiLeft.SetPosition(posX, posY + offset);
+    else
+      bChanged |= m_guiLeft.SetPosition(posX, posY);
+    bChanged |= m_guiLeft.SetHeight(fScaleY * m_guiLeft.GetTextureHeight());
+    bChanged |= m_guiLeft.SetWidth(fScaleX * m_guiLeft.GetTextureWidth());
+
+    posX += fScaleX * m_guiLeft.GetTextureWidth();
+    offset = fabs(fScaleY * 0.5f * (m_guiMid.GetTextureHeight() - m_guiBackground.GetTextureHeight()));
+    if (offset > 0)  //  Center texture to the background if necessary
+      bChanged |= m_guiMid.SetPosition(posX, posY + offset);
+    else
+      bChanged |= m_guiMid.SetPosition(posX, posY);
+    bChanged |= m_guiMid.SetHeight(fScaleY * m_guiMid.GetTextureHeight());
+    if (m_bReveal)
+    {
+      bChanged |= m_guiMid.SetWidth(fScaleX * fFullWidth);
+      float x = posX, y = posY + offset, w =  fScaleX * fWidth, h = fScaleY * m_guiMid.GetTextureHeight();
+      m_guiMidClipRect = CRect(x, y, x + w, y + h);
+    }
+    else
+    {
+      bChanged |= m_guiMid.SetWidth(fScaleX * fWidth);
+      m_guiMidClipRect = CRect();
+    }
+
+    posX += fWidth * fScaleX;
+
+    offset = fabs(fScaleY * 0.5f * (m_guiRight.GetTextureHeight() - m_guiBackground.GetTextureHeight()));
+    if (offset > 0)  //  Center texture to the background if necessary
+      bChanged |= m_guiRight.SetPosition(posX, posY + offset);
+    else
+      bChanged |= m_guiRight.SetPosition(posX, posY);
+    bChanged |= m_guiRight.SetHeight(fScaleY * m_guiRight.GetTextureHeight());
+    bChanged |= m_guiRight.SetWidth(fScaleX * m_guiRight.GetTextureWidth());
+  }
+  float offset = fabs(fScaleY * 0.5f * (m_guiOverlay.GetTextureHeight() - m_guiBackground.GetTextureHeight()));
+  if (offset > 0)  //  Center texture to the background if necessary
+    bChanged |= m_guiOverlay.SetPosition(m_guiBackground.GetXPosition(), m_guiBackground.GetYPosition() + offset);
+  else
+    bChanged |= m_guiOverlay.SetPosition(m_guiBackground.GetXPosition(), m_guiBackground.GetYPosition());
+  bChanged |= m_guiOverlay.SetHeight(fScaleY * m_guiOverlay.GetTextureHeight());
+  bChanged |= m_guiOverlay.SetWidth(fScaleX * m_guiOverlay.GetTextureWidth());
+
+  return bChanged;
+}
+
+void CGUIProgressControl::UpdateInfo(const CGUIListItem *item)
+{
+  if (!IsDisabled())
+  {
+    float percent = m_fPercent;
+    if (m_iInfoCode)
+      m_fPercent = (float)g_infoManager.GetInt(m_iInfoCode, m_parentID, item);
+
+    if (m_fPercent < 0.0f) m_fPercent = 0.0f;
+    if (m_fPercent > 100.0f) m_fPercent = 100.0f;
+  }
+}
index 4df8356..310879a 100644 (file)
@@ -63,6 +63,8 @@ public:
 
   float GetPercentage() const;
   CStdString GetDescription() const;
+  virtual void UpdateInfo(const CGUIListItem *item = NULL);
+  bool UpdateLayout(void);
 protected:
   virtual bool UpdateColors();
   CGUITexture m_guiBackground;