2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "GUIListGroup.h"
11 #include "GUIListLabel.h"
12 #include "utils/log.h"
18 // Supported control types. Keep sorted.
19 const std::set
<CGUIControl::GUICONTROLTYPES
> supportedTypes
= {
21 CGUIControl::GUICONTROL_BORDEREDIMAGE
,
22 CGUIControl::GUICONTROL_GAME
,
23 CGUIControl::GUICONTROL_GAMECONTROLLER
,
24 CGUIControl::GUICONTROL_GAMECONTROLLERLIST
,
25 CGUIControl::GUICONTROL_IMAGE
,
26 CGUIControl::GUICONTROL_LISTGROUP
,
27 CGUIControl::GUICONTROL_LISTLABEL
,
28 CGUIControl::GUICONTROL_MULTI_IMAGE
,
29 CGUIControl::GUICONTROL_PROGRESS
,
30 CGUIControl::GUICONTROL_TEXTBOX
,
35 CGUIListGroup::CGUIListGroup(int parentID
, int controlID
, float posX
, float posY
, float width
, float height
)
36 : CGUIControlGroup(parentID
, controlID
, posX
, posY
, width
, height
)
39 ControlType
= GUICONTROL_LISTGROUP
;
42 CGUIListGroup::CGUIListGroup(const CGUIListGroup
&right
)
43 : CGUIControlGroup(right
)
46 ControlType
= GUICONTROL_LISTGROUP
;
49 CGUIListGroup::~CGUIListGroup(void)
54 void CGUIListGroup::AddControl(CGUIControl
*control
, int position
/*= -1*/)
58 if (supportedTypes
.find(control
->GetControlType()) == supportedTypes
.end())
59 CLog::Log(LOGWARNING
, "Trying to add unsupported control type {}", control
->GetControlType());
61 CGUIControlGroup::AddControl(control
, position
);
64 void CGUIListGroup::Process(unsigned int currentTime
, CDirtyRegionList
&dirtyregions
)
66 CServiceBroker::GetWinSystem()->GetGfxContext().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 CServiceBroker::GetWinSystem()->GetGfxContext().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(*static_cast<CGUIListLabel
*>(m_children
[i
]), *static_cast<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_LISTGROUP
)
178 ((CGUIListGroup
*)(*it
))->SetFocusedItem(focus
);
180 (*it
)->SetFocus(focus
> 0);
185 unsigned int CGUIListGroup::GetFocusedItem() const
187 for (ciControls it
= m_children
.begin(); it
!= m_children
.end(); it
++)
189 if ((*it
)->GetControlType() == CGUIControl::GUICONTROL_LISTGROUP
&& ((CGUIListGroup
*)(*it
))->GetFocusedItem())
190 return ((CGUIListGroup
*)(*it
))->GetFocusedItem();
192 return m_bHasFocus
? 1 : 0;
195 bool CGUIListGroup::MoveLeft()
197 for (iControls it
= m_children
.begin(); it
!= m_children
.end(); it
++)
199 if ((*it
)->GetControlType() == CGUIControl::GUICONTROL_LISTGROUP
&& ((CGUIListGroup
*)(*it
))->MoveLeft())
205 bool CGUIListGroup::MoveRight()
207 for (iControls it
= m_children
.begin(); it
!= m_children
.end(); it
++)
209 if ((*it
)->GetControlType() == CGUIControl::GUICONTROL_LISTGROUP
&& ((CGUIListGroup
*)(*it
))->MoveRight())
215 void CGUIListGroup::SetState(bool selected
, bool focused
)
217 for (iControls it
= m_children
.begin(); it
!= m_children
.end(); it
++)
219 if ((*it
)->GetControlType() == CGUIControl::GUICONTROL_LISTLABEL
)
221 CGUIListLabel
*label
= (CGUIListLabel
*)(*it
);
222 label
->SetSelected(selected
);
224 else if ((*it
)->GetControlType() == CGUIControl::GUICONTROL_LISTGROUP
)
225 ((CGUIListGroup
*)(*it
))->SetState(selected
, focused
);
229 void CGUIListGroup::SelectItemFromPoint(const CPoint
&point
)
231 CPoint
controlCoords(point
);
232 m_transform
.InverseTransformPosition(controlCoords
.x
, controlCoords
.y
);
233 for (iControls it
= m_children
.begin(); it
!= m_children
.end(); ++it
)
235 CGUIControl
*child
= *it
;
236 if (child
->GetControlType() == CGUIControl::GUICONTROL_LISTGROUP
)
237 static_cast<CGUIListGroup
*>(child
)->SelectItemFromPoint(point
);