Permalink
Browse files

Merge pull request #791 from pieh/wraplist_focus_animation

  • Loading branch information...
2 parents 0ba76a0 + 6428682 commit 25aff62ec9afdaec47c8d9bbe6bf6360215b952b @pieh pieh committed Jul 27, 2012
Showing with 36 additions and 25 deletions.
  1. +31 −21 xbmc/guilib/GUIBaseContainer.cpp
  2. +3 −2 xbmc/guilib/GUIBaseContainer.h
  3. +2 −2 xbmc/guilib/GUIPanelContainer.cpp
@@ -51,7 +51,6 @@ CGUIBaseContainer::CGUIBaseContainer(int parentID, int controlID, float posX, fl
m_pageControl = 0;
m_orientation = orientation;
m_analogScrollCount = 0;
- m_lastItem = NULL;
m_staticContent = false;
m_staticUpdateTime = 0;
m_staticDefaultItem = -1;
@@ -119,9 +118,9 @@ void CGUIBaseContainer::Process(unsigned int currentTime, CDirtyRegionList &dirt
CGUIListItemPtr item = m_items[itemNo];
// render our item
if (m_orientation == VERTICAL)
- ProcessItem(origin.x, pos, item.get(), focused, currentTime, dirtyregions);
+ ProcessItem(origin.x, pos, item, focused, currentTime, dirtyregions);
else
- ProcessItem(pos, origin.y, item.get(), focused, currentTime, dirtyregions);
+ ProcessItem(pos, origin.y, item, focused, currentTime, dirtyregions);
}
// increment our position
pos += focused ? m_focusedLayout->Size(m_orientation) : m_layout->Size(m_orientation);
@@ -133,7 +132,7 @@ void CGUIBaseContainer::Process(unsigned int currentTime, CDirtyRegionList &dirt
CGUIControl::Process(currentTime, dirtyregions);
}
-void CGUIBaseContainer::ProcessItem(float posX, float posY, CGUIListItem *item, bool focused, unsigned int currentTime, CDirtyRegionList &dirtyregions)
+void CGUIBaseContainer::ProcessItem(float posX, float posY, CGUIListItemPtr& item, bool focused, unsigned int currentTime, CDirtyRegionList &dirtyregions)
{
if (!m_focusedLayout || !m_layout) return;
@@ -163,7 +162,7 @@ void CGUIBaseContainer::ProcessItem(float posX, float posY, CGUIListItem *item,
subItem = m_lastItem->GetFocusedLayout()->GetFocusedItem();
item->GetFocusedLayout()->SetFocusedItem(subItem ? subItem : 1);
}
- item->GetFocusedLayout()->Process(item, m_parentID, currentTime, dirtyregions);
+ item->GetFocusedLayout()->Process(item.get(), m_parentID, currentTime, dirtyregions);
}
m_lastItem = item;
}
@@ -177,9 +176,9 @@ void CGUIBaseContainer::ProcessItem(float posX, float posY, CGUIListItem *item,
item->SetLayout(layout);
}
if (item->GetFocusedLayout())
- item->GetFocusedLayout()->Process(item, m_parentID, currentTime, dirtyregions);
+ item->GetFocusedLayout()->Process(item.get(), m_parentID, currentTime, dirtyregions);
if (item->GetLayout())
- item->GetLayout()->Process(item, m_parentID, currentTime, dirtyregions);
+ item->GetLayout()->Process(item.get(), m_parentID, currentTime, dirtyregions);
}
g_graphicsContext.RestoreOrigin();
@@ -735,7 +734,7 @@ void CGUIBaseContainer::SetFocus(bool bOnOff)
if (bOnOff != HasFocus())
{
SetInvalid();
- m_lastItem = NULL;
+ m_lastItem.reset();
}
CGUIControl::SetFocus(bOnOff);
}
@@ -827,39 +826,51 @@ void CGUIBaseContainer::UpdateVisibility(const CGUIListItem *item)
SelectItem(itemIndex);
}
+ UpdateStaticItems();
+}
+
+void CGUIBaseContainer::UpdateStaticItems(bool refreshItems)
+{
if (m_staticContent)
{ // update our item list with our new content, but only add those items that should
// be visible. Save the previous item and keep it if we are adding that one.
- CGUIListItem *lastItem = m_lastItem;
+ std::vector<CGUIListItemPtr> items;
+ int reselect = -1;
int selected = GetSelectedItem();
CGUIListItem* selectedItem = (selected >= 0 && (unsigned int)selected < m_items.size()) ? m_items[selected].get() : NULL;
- Reset();
- bool updateItems = false;
+ bool updateItemsProperties = false;
if (!m_staticUpdateTime)
m_staticUpdateTime = CTimeUtils::GetFrameTime();
if (CTimeUtils::GetFrameTime() - m_staticUpdateTime > 1000)
{
m_staticUpdateTime = CTimeUtils::GetFrameTime();
- updateItems = true;
+ updateItemsProperties = true;
}
for (unsigned int i = 0; i < m_staticItems.size(); ++i)
{
CGUIStaticItemPtr staticItem = boost::static_pointer_cast<CGUIStaticItem>(m_staticItems[i]);
if (staticItem->UpdateVisibility(GetParentID()))
- MarkDirtyRegion();
+ refreshItems = true;
if (staticItem->IsVisible())
{
- m_items.push_back(staticItem);
- if (staticItem.get() == lastItem)
- m_lastItem = lastItem;
+ items.push_back(staticItem);
// if item is selected and it changed position, re-select it
- if (staticItem.get() == selectedItem && selected != (int)m_items.size() - 1)
- SelectItem(m_items.size() - 1);
+ if (staticItem.get() == selectedItem && selected != (int)items.size() - 1)
+ reselect = items.size() - 1;
}
// update any properties
- if (updateItems)
+ if (updateItemsProperties)
staticItem->UpdateProperties(GetParentID());
}
+ if (refreshItems)
+ {
+ Reset();
+ m_items = items;
+ SetPageControlRange();
+ if (reselect >= 0 && reselect < (int)m_items.size())
+ SelectItem(reselect);
+ MarkDirtyRegion();
+ }
UpdateScrollByLetter();
}
}
@@ -975,7 +986,6 @@ void CGUIBaseContainer::Reset()
{
m_wasReset = true;
m_items.clear();
- m_lastItem = NULL;
}
void CGUIBaseContainer::LoadLayout(TiXmlElement *layout)
@@ -1024,7 +1034,7 @@ void CGUIBaseContainer::SetStaticContent(const vector<CGUIListItemPtr> &items)
m_staticUpdateTime = 0;
m_staticItems.clear();
m_staticItems.assign(items.begin(), items.end());
- UpdateVisibility();
+ UpdateStaticItems(true);
}
void CGUIBaseContainer::SetRenderOffset(const CPoint &offset)
@@ -101,7 +101,7 @@ class CGUIBaseContainer : public CGUIControl
virtual EVENT_RESULT OnMouseEvent(const CPoint &point, const CMouseEvent &event);
bool OnClick(int actionID);
- virtual void ProcessItem(float posX, float posY, CGUIListItem *item, bool focused, unsigned int currentTime, CDirtyRegionList &dirtyregions);
+ virtual void ProcessItem(float posX, float posY, CGUIListItemPtr& item, bool focused, unsigned int currentTime, CDirtyRegionList &dirtyregions);
virtual void Render();
virtual void RenderItem(float posX, float posY, CGUIListItem *item, bool focused);
@@ -124,6 +124,7 @@ class CGUIBaseContainer : public CGUIControl
virtual int GetCurrentPage() const;
bool InsideLayout(const CGUIListItemLayout *layout, const CPoint &point) const;
virtual void OnFocus();
+ void UpdateStaticItems(bool refreshItems = false);
int ScrollCorrectionRange() const;
inline float Size() const;
@@ -142,7 +143,7 @@ class CGUIBaseContainer : public CGUIControl
std::vector< CGUIListItemPtr > m_items;
typedef std::vector<CGUIListItemPtr> ::iterator iItems;
- CGUIListItem *m_lastItem;
+ CGUIListItemPtr m_lastItem;
int m_pageControl;
@@ -75,9 +75,9 @@ void CGUIPanelContainer::Process(unsigned int currentTime, CDirtyRegionList &dir
bool focused = (current == GetOffset() * m_itemsPerRow + GetCursor()) && m_bHasFocus;
if (m_orientation == VERTICAL)
- ProcessItem(origin.x + col * m_layout->Size(HORIZONTAL), pos, item.get(), focused, currentTime, dirtyregions);
+ ProcessItem(origin.x + col * m_layout->Size(HORIZONTAL), pos, item, focused, currentTime, dirtyregions);
else
- ProcessItem(pos, origin.y + col * m_layout->Size(VERTICAL), item.get(), focused, currentTime, dirtyregions);
+ ProcessItem(pos, origin.y + col * m_layout->Size(VERTICAL), item, focused, currentTime, dirtyregions);
}
// increment our position
if (col < m_itemsPerRow - 1)

0 comments on commit 25aff62

Please sign in to comment.