2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
22 #include "GUIListItemLayout.h"
24 #include "GUIControlFactory.h"
25 #include "GUIInfoManager.h"
26 #include "GUIListLabel.h"
28 #include "utils/XBMCTinyXML.h"
32 CGUIListItemLayout::CGUIListItemLayout()
33 : m_group(0, 0, 0, 0, 0, 0)
39 m_group.SetPushUpdates(true);
42 CGUIListItemLayout::CGUIListItemLayout(const CGUIListItemLayout &from)
43 : m_group(from.m_group), m_isPlaying(from.m_isPlaying)
45 m_width = from.m_width;
46 m_height = from.m_height;
47 m_focused = from.m_focused;
48 m_condition = from.m_condition;
52 CGUIListItemLayout::~CGUIListItemLayout()
56 bool CGUIListItemLayout::IsAnimating(ANIMATION_TYPE animType)
58 return m_group.IsAnimating(animType);
61 void CGUIListItemLayout::ResetAnimation(ANIMATION_TYPE animType)
63 return m_group.ResetAnimation(animType);
66 float CGUIListItemLayout::Size(ORIENTATION orientation) const
68 return (orientation == HORIZONTAL) ? m_width : m_height;
71 void CGUIListItemLayout::Process(CGUIListItem *item, int parentID, unsigned int currentTime, CDirtyRegionList &dirtyregions)
74 { // need to update our item
75 m_invalidated = false;
76 // could use a dynamic cast here if RTTI was enabled. As it's not,
77 // let's use a static cast with a virtual base function
78 CFileItem *fileItem = item->IsFileItem() ? (CFileItem *)item : new CFileItem(*item);
79 m_isPlaying.Update(item);
81 m_group.UpdateInfo(fileItem);
82 // delete our temporary fileitem
83 if (!item->IsFileItem())
87 // update visibility, and render
88 m_group.SetState(item->IsSelected() || m_isPlaying, m_focused);
89 m_group.UpdateVisibility(item);
90 m_group.DoProcess(currentTime, dirtyregions);
93 void CGUIListItemLayout::Render(CGUIListItem *item, int parentID)
98 void CGUIListItemLayout::SetFocusedItem(unsigned int focus)
100 m_group.SetFocusedItem(focus);
103 unsigned int CGUIListItemLayout::GetFocusedItem() const
105 return m_group.GetFocusedItem();
108 void CGUIListItemLayout::SetWidth(float width)
110 if (m_width != width)
112 m_group.EnlargeWidth(width - m_width);
118 void CGUIListItemLayout::SetHeight(float height)
120 if (m_height != height)
122 m_group.EnlargeHeight(height - m_height);
128 void CGUIListItemLayout::SelectItemFromPoint(const CPoint &point)
130 m_group.SelectItemFromPoint(point);
133 bool CGUIListItemLayout::MoveLeft()
135 return m_group.MoveLeft();
138 bool CGUIListItemLayout::MoveRight()
140 return m_group.MoveRight();
143 bool CGUIListItemLayout::CheckCondition()
145 return !m_condition || m_condition->Get();
148 void CGUIListItemLayout::LoadControl(TiXmlElement *child, CGUIControlGroup *group)
152 CRect rect(group->GetXPosition(), group->GetYPosition(), group->GetXPosition() + group->GetWidth(), group->GetYPosition() + group->GetHeight());
154 CGUIControlFactory factory;
155 CGUIControl *control = factory.Create(0, rect, child, true); // true indicating we're inside a list for the
156 // different label control + defaults.
159 group->AddControl(control);
160 if (control->IsGroup())
162 TiXmlElement *grandChild = child->FirstChildElement("control");
165 LoadControl(grandChild, (CGUIControlGroup *)control);
166 grandChild = grandChild->NextSiblingElement("control");
172 void CGUIListItemLayout::LoadLayout(TiXmlElement *layout, int context, bool focused)
175 layout->QueryFloatAttribute("width", &m_width);
176 layout->QueryFloatAttribute("height", &m_height);
177 const char *condition = layout->Attribute("condition");
179 m_condition = g_infoManager.Register(condition, context);
180 m_isPlaying.Parse("listitem.isplaying", context);
181 TiXmlElement *child = layout->FirstChildElement("control");
182 m_group.SetWidth(m_width);
183 m_group.SetHeight(m_height);
186 LoadControl(child, &m_group);
187 child = child->NextSiblingElement("control");
189 // ensure width and height are valid
190 m_width = std::max(1.0f, m_width);
191 m_height = std::max(1.0f, m_height);
194 //#ifdef PRE_SKIN_VERSION_9_10_COMPATIBILITY
195 void CGUIListItemLayout::CreateListControlLayouts(float width, float height, bool focused, const CLabelInfo &labelInfo, const CLabelInfo &labelInfo2, const CTextureInfo &texture, const CTextureInfo &textureFocus, float texHeight, float iconWidth, float iconHeight, const CStdString &nofocusCondition, const CStdString &focusCondition)
200 m_isPlaying.Parse("listitem.isplaying", 0);
201 CGUIImage *tex = new CGUIImage(0, 0, 0, 0, width, texHeight, texture);
202 tex->SetVisibleCondition(nofocusCondition);
203 m_group.AddControl(tex);
206 CGUIImage *tex = new CGUIImage(0, 0, 0, 0, width, texHeight, textureFocus);
207 tex->SetVisibleCondition(focusCondition);
208 m_group.AddControl(tex);
210 CGUIImage *image = new CGUIImage(0, 0, 8, 0, iconWidth, texHeight, CTextureInfo(""));
211 image->SetInfo(CGUIInfoLabel("$INFO[ListItem.Icon]", "", m_group.GetParentID()));
212 image->SetAspectRatio(CAspectRatio::AR_KEEP);
213 m_group.AddControl(image);
214 float x = iconWidth + labelInfo.offsetX + 10;
215 CGUIListLabel *label = new CGUIListLabel(0, 0, x, labelInfo.offsetY, width - x - 18, height, labelInfo, CGUIInfoLabel("$INFO[ListItem.Label]", "", m_group.GetParentID()), false);
216 m_group.AddControl(label);
217 x = labelInfo2.offsetX ? labelInfo2.offsetX : m_width - 16;
218 label = new CGUIListLabel(0, 0, x, labelInfo2.offsetY, x - iconWidth - 20, height, labelInfo2, CGUIInfoLabel("$INFO[ListItem.Label2]", "", m_group.GetParentID()), false);
219 m_group.AddControl(label);
223 void CGUIListItemLayout::FreeResources(bool immediately)
225 m_group.FreeResources(immediately);
229 void CGUIListItemLayout::DumpTextureUse()
231 m_group.DumpTextureUse();