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 "GUIListGroup.h"
22 #include "GUIListLabel.h"
23 #include "GUIMultiSelectText.h"
24 #include "GUIBorderedImage.h"
25 #include "GUIControlProfiler.h"
26 #include "utils/log.h"
28 CGUIListGroup::CGUIListGroup(int parentID, int controlID, float posX, float posY, float width, float height)
29 : CGUIControlGroup(parentID, controlID, posX, posY, width, height)
32 ControlType = GUICONTROL_LISTGROUP;
35 CGUIListGroup::CGUIListGroup(const CGUIListGroup &right)
36 : CGUIControlGroup(right)
39 ControlType = GUICONTROL_LISTGROUP;
42 CGUIListGroup::~CGUIListGroup(void)
47 void CGUIListGroup::AddControl(CGUIControl *control, int position /*= -1*/)
51 if (!(control->GetControlType() == CGUIControl::GUICONTROL_LISTLABEL ||
52 control->GetControlType() == CGUIControl::GUICONTROL_LISTGROUP ||
53 control->GetControlType() == CGUIControl::GUICONTROL_IMAGE ||
54 control->GetControlType() == CGUIControl::GUICONTROL_BORDEREDIMAGE ||
55 control->GetControlType() == CGUIControl::GUICONTROL_MULTI_IMAGE ||
56 control->GetControlType() == CGUIControl::GUICONTROL_MULTISELECT ||
57 control->GetControlType() == CGUIControl::GUICONTROL_TEXTBOX ||
58 control->GetControlType() == CGUIControl::GUICONTROL_PROGRESS))
59 CLog::Log(LOGWARNING, "Trying to add unsupported control type %d", control->GetControlType());
61 CGUIControlGroup::AddControl(control, position);
64 void CGUIListGroup::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
66 g_graphicsContext.SetOrigin(m_posX, m_posY);
69 for (iControls it = m_children.begin(); it != m_children.end(); ++it)
71 CGUIControl *control = *it;
72 control->UpdateVisibility(m_item);
73 unsigned int oldDirty = dirtyregions.size();
74 control->DoProcess(currentTime, dirtyregions);
75 if (control->IsVisible() || (oldDirty != dirtyregions.size())) // visible or dirty (was visible?)
76 rect.Union(control->GetRenderRegion());
79 g_graphicsContext.RestoreOrigin();
80 CGUIControl::Process(currentTime, dirtyregions);
81 m_renderRegion = rect;
85 void CGUIListGroup::ResetAnimation(ANIMATION_TYPE type)
87 CGUIControl::ResetAnimation(type);
88 for (iControls it = m_children.begin(); it != m_children.end(); ++it)
89 (*it)->ResetAnimation(type);
92 void CGUIListGroup::UpdateVisibility(const CGUIListItem *item)
94 CGUIControlGroup::UpdateVisibility(item);
98 void CGUIListGroup::UpdateInfo(const CGUIListItem *item)
100 for (iControls it = m_children.begin(); it != m_children.end(); it++)
102 (*it)->UpdateInfo(item);
103 (*it)->UpdateVisibility(item);
105 // now we have to check our overlapping label pairs
106 for (unsigned int i = 0; i < m_children.size(); i++)
108 if (m_children[i]->GetControlType() == CGUIControl::GUICONTROL_LISTLABEL && m_children[i]->IsVisible())
110 for (unsigned int j = i + 1; j < m_children.size(); j++)
112 if (m_children[j]->GetControlType() == CGUIControl::GUICONTROL_LISTLABEL && m_children[j]->IsVisible())
113 CGUIListLabel::CheckAndCorrectOverlap(*(CGUIListLabel *)m_children[i], *(CGUIListLabel *)m_children[j]);
119 void CGUIListGroup::EnlargeWidth(float difference)
121 // Alters the width of the controls that have an ID of 1 to 14
122 for (iControls it = m_children.begin(); it != m_children.end(); it++)
124 CGUIControl *child = *it;
125 if (child->GetID() >= 1 && child->GetID() <= 14)
127 if (child->GetID() == 1)
129 child->SetWidth(child->GetWidth() + difference);
130 child->SetVisible(child->GetWidth() > 10);
134 child->SetWidth(child->GetWidth() + difference);
141 void CGUIListGroup::EnlargeHeight(float difference)
143 // Alters the height of the controls that have an ID of 1 to 14
144 for (iControls it = m_children.begin(); it != m_children.end(); it++)
146 CGUIControl *child = *it;
147 if (child->GetID() >= 1 && child->GetID() <= 14)
149 if (child->GetID() == 1)
151 child->SetHeight(child->GetHeight() + difference);
152 child->SetVisible(child->GetHeight() > 10);
156 child->SetHeight(child->GetHeight() + difference);
163 void CGUIListGroup::SetInvalid()
166 { // this can be triggered by an item change, so all children need invalidating rather than just the group
167 for (iControls it = m_children.begin(); it != m_children.end(); ++it)
169 CGUIControlGroup::SetInvalid();
173 void CGUIListGroup::SetFocusedItem(unsigned int focus)
175 for (iControls it = m_children.begin(); it != m_children.end(); it++)
177 if ((*it)->GetControlType() == CGUIControl::GUICONTROL_MULTISELECT)
178 ((CGUIMultiSelectTextControl *)(*it))->SetFocusedItem(focus);
179 else if ((*it)->GetControlType() == CGUIControl::GUICONTROL_LISTGROUP)
180 ((CGUIListGroup *)(*it))->SetFocusedItem(focus);
182 (*it)->SetFocus(focus > 0);
187 unsigned int CGUIListGroup::GetFocusedItem() const
189 for (ciControls it = m_children.begin(); it != m_children.end(); it++)
191 if ((*it)->GetControlType() == CGUIControl::GUICONTROL_MULTISELECT && ((CGUIMultiSelectTextControl *)(*it))->GetFocusedItem())
192 return ((CGUIMultiSelectTextControl *)(*it))->GetFocusedItem();
193 else if ((*it)->GetControlType() == CGUIControl::GUICONTROL_LISTGROUP && ((CGUIListGroup *)(*it))->GetFocusedItem())
194 return ((CGUIListGroup *)(*it))->GetFocusedItem();
199 bool CGUIListGroup::MoveLeft()
201 for (iControls it = m_children.begin(); it != m_children.end(); it++)
203 if ((*it)->GetControlType() == CGUIControl::GUICONTROL_MULTISELECT && ((CGUIMultiSelectTextControl *)(*it))->MoveLeft())
205 else if ((*it)->GetControlType() == CGUIControl::GUICONTROL_LISTGROUP && ((CGUIListGroup *)(*it))->MoveLeft())
211 bool CGUIListGroup::MoveRight()
213 for (iControls it = m_children.begin(); it != m_children.end(); it++)
215 if ((*it)->GetControlType() == CGUIControl::GUICONTROL_MULTISELECT && ((CGUIMultiSelectTextControl *)(*it))->MoveLeft())
217 else if ((*it)->GetControlType() == CGUIControl::GUICONTROL_LISTGROUP && ((CGUIListGroup *)(*it))->MoveLeft())
223 void CGUIListGroup::SetState(bool selected, bool focused)
225 for (iControls it = m_children.begin(); it != m_children.end(); it++)
227 if ((*it)->GetControlType() == CGUIControl::GUICONTROL_LISTLABEL)
229 CGUIListLabel *label = (CGUIListLabel *)(*it);
230 label->SetSelected(selected);
231 label->SetScrolling(focused);
233 else if ((*it)->GetControlType() == CGUIControl::GUICONTROL_LISTGROUP)
234 ((CGUIListGroup *)(*it))->SetState(selected, focused);
238 void CGUIListGroup::SelectItemFromPoint(const CPoint &point)
240 CPoint controlCoords(point);
241 m_transform.InverseTransformPosition(controlCoords.x, controlCoords.y);
242 for (iControls it = m_children.begin(); it != m_children.end(); ++it)
244 CGUIControl *child = *it;
245 if (child->GetControlType() == CGUIControl::GUICONTROL_MULTISELECT)
246 ((CGUIMultiSelectTextControl *)child)->SelectItemFromPoint(point);
247 else if (child->GetControlType() == CGUIControl::GUICONTROL_LISTGROUP)
248 ((CGUIListGroup *)child)->SelectItemFromPoint(point);