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/>.
21 #include "GUIListItemLayout.h"
23 #include "GUIControlFactory.h"
24 #include "GUIInfoManager.h"
25 #include "GUIListLabel.h"
27 #include "utils/XBMCTinyXML.h"
31 CGUIListItemLayout::CGUIListItemLayout()
32 : 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 m_group.EnlargeWidth(width - m_width);
115 void CGUIListItemLayout::SetHeight(float height)
117 m_group.EnlargeHeight(height - m_height);
122 void CGUIListItemLayout::SelectItemFromPoint(const CPoint &point)
124 m_group.SelectItemFromPoint(point);
127 bool CGUIListItemLayout::MoveLeft()
129 return m_group.MoveLeft();
132 bool CGUIListItemLayout::MoveRight()
134 return m_group.MoveRight();
137 bool CGUIListItemLayout::CheckCondition()
139 return !m_condition || g_infoManager.GetBoolValue(m_condition);
142 void CGUIListItemLayout::LoadControl(TiXmlElement *child, CGUIControlGroup *group)
146 CRect rect(group->GetXPosition(), group->GetYPosition(), group->GetXPosition() + group->GetWidth(), group->GetYPosition() + group->GetHeight());
148 CGUIControlFactory factory;
149 CGUIControl *control = factory.Create(0, rect, child, true); // true indicating we're inside a list for the
150 // different label control + defaults.
153 group->AddControl(control);
154 if (control->IsGroup())
156 TiXmlElement *grandChild = child->FirstChildElement("control");
159 LoadControl(grandChild, (CGUIControlGroup *)control);
160 grandChild = grandChild->NextSiblingElement("control");
166 void CGUIListItemLayout::LoadLayout(TiXmlElement *layout, int context, bool focused)
169 layout->QueryFloatAttribute("width", &m_width);
170 layout->QueryFloatAttribute("height", &m_height);
171 const char *condition = layout->Attribute("condition");
173 m_condition = g_infoManager.Register(condition, context);
174 m_isPlaying.Parse("listitem.isplaying", context);
175 TiXmlElement *child = layout->FirstChildElement("control");
176 m_group.SetWidth(m_width);
177 m_group.SetHeight(m_height);
180 LoadControl(child, &m_group);
181 child = child->NextSiblingElement("control");
183 // ensure width and height are valid
184 m_width = std::max(1.0f, m_width);
185 m_height = std::max(1.0f, m_height);
188 //#ifdef PRE_SKIN_VERSION_9_10_COMPATIBILITY
189 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)
194 m_isPlaying.Parse("listitem.isplaying", 0);
195 CGUIImage *tex = new CGUIImage(0, 0, 0, 0, width, texHeight, texture);
196 tex->SetVisibleCondition(nofocusCondition);
197 m_group.AddControl(tex);
200 CGUIImage *tex = new CGUIImage(0, 0, 0, 0, width, texHeight, textureFocus);
201 tex->SetVisibleCondition(focusCondition);
202 m_group.AddControl(tex);
204 CGUIImage *image = new CGUIImage(0, 0, 8, 0, iconWidth, texHeight, CTextureInfo(""));
205 image->SetInfo(CGUIInfoLabel("$INFO[ListItem.Icon]", "", m_group.GetParentID()));
206 image->SetAspectRatio(CAspectRatio::AR_KEEP);
207 m_group.AddControl(image);
208 float x = iconWidth + labelInfo.offsetX + 10;
209 CGUIListLabel *label = new CGUIListLabel(0, 0, x, labelInfo.offsetY, width - x - 18, height, labelInfo, CGUIInfoLabel("$INFO[ListItem.Label]", "", m_group.GetParentID()), false);
210 m_group.AddControl(label);
211 x = labelInfo2.offsetX ? labelInfo2.offsetX : m_width - 16;
212 label = new CGUIListLabel(0, 0, x, labelInfo2.offsetY, x - iconWidth - 20, height, labelInfo2, CGUIInfoLabel("$INFO[ListItem.Label2]", "", m_group.GetParentID()), false);
213 m_group.AddControl(label);
217 void CGUIListItemLayout::FreeResources(bool immediately)
219 m_group.FreeResources(immediately);
223 void CGUIListItemLayout::DumpTextureUse()
225 m_group.DumpTextureUse();