[WASAPI] fix stream types and frequencies enumeration
[xbmc.git] / xbmc / guilib / GUIRadioButtonControl.cpp
blob4cad844e699b0ca23d3cdcb3ac95efca1edb0f30
1 /*
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.
7 */
9 #include "GUIRadioButtonControl.h"
11 #include "GUIInfoManager.h"
12 #include "LocalizeStrings.h"
13 #include "input/actions/Action.h"
14 #include "input/actions/ActionIDs.h"
16 CGUIRadioButtonControl::CGUIRadioButtonControl(int parentID,
17 int controlID,
18 float posX,
19 float posY,
20 float width,
21 float height,
22 const CTextureInfo& textureFocus,
23 const CTextureInfo& textureNoFocus,
24 const CLabelInfo& labelInfo,
25 const CTextureInfo& radioOnFocus,
26 const CTextureInfo& radioOnNoFocus,
27 const CTextureInfo& radioOffFocus,
28 const CTextureInfo& radioOffNoFocus,
29 const CTextureInfo& radioOnDisabled,
30 const CTextureInfo& radioOffDisabled)
31 : CGUIButtonControl(
32 parentID, controlID, posX, posY, width, height, textureFocus, textureNoFocus, labelInfo),
33 m_imgRadioOnFocus(CGUITexture::CreateTexture(posX, posY, 16, 16, radioOnFocus)),
34 m_imgRadioOnNoFocus(CGUITexture::CreateTexture(posX, posY, 16, 16, radioOnNoFocus)),
35 m_imgRadioOffFocus(CGUITexture::CreateTexture(posX, posY, 16, 16, radioOffFocus)),
36 m_imgRadioOffNoFocus(CGUITexture::CreateTexture(posX, posY, 16, 16, radioOffNoFocus)),
37 m_imgRadioOnDisabled(CGUITexture::CreateTexture(posX, posY, 16, 16, radioOnDisabled)),
38 m_imgRadioOffDisabled(CGUITexture::CreateTexture(posX, posY, 16, 16, radioOffDisabled))
40 m_radioPosX = 0;
41 m_radioPosY = 0;
42 m_imgRadioOnFocus->SetAspectRatio(CAspectRatio::AR_KEEP);
43 m_imgRadioOnNoFocus->SetAspectRatio(CAspectRatio::AR_KEEP);
44 m_imgRadioOffFocus->SetAspectRatio(CAspectRatio::AR_KEEP);
45 m_imgRadioOffNoFocus->SetAspectRatio(CAspectRatio::AR_KEEP);
46 m_imgRadioOnDisabled->SetAspectRatio(CAspectRatio::AR_KEEP);
47 m_imgRadioOffDisabled->SetAspectRatio(CAspectRatio::AR_KEEP);
48 ControlType = GUICONTROL_RADIO;
49 m_useLabel2 = false;
52 CGUIRadioButtonControl::CGUIRadioButtonControl(const CGUIRadioButtonControl& control)
53 : CGUIButtonControl(control),
54 m_imgRadioOnFocus(control.m_imgRadioOnFocus->Clone()),
55 m_imgRadioOnNoFocus(control.m_imgRadioOnNoFocus->Clone()),
56 m_imgRadioOffFocus(control.m_imgRadioOffFocus->Clone()),
57 m_imgRadioOffNoFocus(control.m_imgRadioOffNoFocus->Clone()),
58 m_imgRadioOnDisabled(control.m_imgRadioOnDisabled->Clone()),
59 m_imgRadioOffDisabled(control.m_imgRadioOffDisabled->Clone()),
60 m_radioPosX(control.m_radioPosX),
61 m_radioPosY(control.m_radioPosY),
62 m_toggleSelect(control.m_toggleSelect),
63 m_useLabel2(control.m_useLabel2)
67 void CGUIRadioButtonControl::Render()
69 CGUIButtonControl::Render();
71 if ( IsSelected() && !IsDisabled() )
73 if (HasFocus())
74 m_imgRadioOnFocus->Render();
75 else
76 m_imgRadioOnNoFocus->Render();
78 else if ( !IsSelected() && !IsDisabled() )
80 if (HasFocus())
81 m_imgRadioOffFocus->Render();
82 else
83 m_imgRadioOffNoFocus->Render();
85 else if ( IsSelected() && IsDisabled() )
86 m_imgRadioOnDisabled->Render();
87 else
88 m_imgRadioOffDisabled->Render();
91 void CGUIRadioButtonControl::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
93 if (m_toggleSelect)
95 // ask our infoManager whether we are selected or not...
96 bool selected = m_toggleSelect->Get(INFO::DEFAULT_CONTEXT);
98 if (selected != m_bSelected)
100 MarkDirtyRegion();
101 m_bSelected = selected;
105 m_imgRadioOnFocus->Process(currentTime);
106 m_imgRadioOnNoFocus->Process(currentTime);
107 m_imgRadioOffFocus->Process(currentTime);
108 m_imgRadioOffNoFocus->Process(currentTime);
109 m_imgRadioOnDisabled->Process(currentTime);
110 m_imgRadioOffDisabled->Process(currentTime);
112 if (m_useLabel2)
113 SetLabel2(g_localizeStrings.Get(m_bSelected ? 16041 : 351));
115 CGUIButtonControl::Process(currentTime, dirtyregions);
118 bool CGUIRadioButtonControl::OnAction(const CAction &action)
120 if (action.GetID() == ACTION_SELECT_ITEM)
122 m_bSelected = !m_bSelected;
123 MarkDirtyRegion();
125 return CGUIButtonControl::OnAction(action);
128 bool CGUIRadioButtonControl::OnMessage(CGUIMessage& message)
130 return CGUIButtonControl::OnMessage(message);
133 void CGUIRadioButtonControl::AllocResources()
135 CGUIButtonControl::AllocResources();
136 m_imgRadioOnFocus->AllocResources();
137 m_imgRadioOnNoFocus->AllocResources();
138 m_imgRadioOffFocus->AllocResources();
139 m_imgRadioOffNoFocus->AllocResources();
140 m_imgRadioOnDisabled->AllocResources();
141 m_imgRadioOffDisabled->AllocResources();
142 SetPosition(m_posX, m_posY);
145 void CGUIRadioButtonControl::FreeResources(bool immediately)
147 CGUIButtonControl::FreeResources(immediately);
148 m_imgRadioOnFocus->FreeResources(immediately);
149 m_imgRadioOnNoFocus->FreeResources(immediately);
150 m_imgRadioOffFocus->FreeResources(immediately);
151 m_imgRadioOffNoFocus->FreeResources(immediately);
152 m_imgRadioOnDisabled->FreeResources(immediately);
153 m_imgRadioOffDisabled->FreeResources(immediately);
156 void CGUIRadioButtonControl::DynamicResourceAlloc(bool bOnOff)
158 CGUIControl::DynamicResourceAlloc(bOnOff);
159 m_imgRadioOnFocus->DynamicResourceAlloc(bOnOff);
160 m_imgRadioOnNoFocus->DynamicResourceAlloc(bOnOff);
161 m_imgRadioOffFocus->DynamicResourceAlloc(bOnOff);
162 m_imgRadioOffNoFocus->DynamicResourceAlloc(bOnOff);
163 m_imgRadioOnDisabled->DynamicResourceAlloc(bOnOff);
164 m_imgRadioOffDisabled->DynamicResourceAlloc(bOnOff);
167 void CGUIRadioButtonControl::SetInvalid()
169 CGUIButtonControl::SetInvalid();
170 m_imgRadioOnFocus->SetInvalid();
171 m_imgRadioOnNoFocus->SetInvalid();
172 m_imgRadioOffFocus->SetInvalid();
173 m_imgRadioOffNoFocus->SetInvalid();
174 m_imgRadioOnDisabled->SetInvalid();
175 m_imgRadioOffDisabled->SetInvalid();
178 void CGUIRadioButtonControl::SetPosition(float posX, float posY)
180 CGUIButtonControl::SetPosition(posX, posY);
181 float radioPosX =
182 m_radioPosX ? m_posX + m_radioPosX : (m_posX + m_width - 8) - m_imgRadioOnFocus->GetWidth();
183 float radioPosY =
184 m_radioPosY ? m_posY + m_radioPosY : m_posY + (m_height - m_imgRadioOnFocus->GetHeight()) / 2;
185 m_imgRadioOnFocus->SetPosition(radioPosX, radioPosY);
186 m_imgRadioOnNoFocus->SetPosition(radioPosX, radioPosY);
187 m_imgRadioOffFocus->SetPosition(radioPosX, radioPosY);
188 m_imgRadioOffNoFocus->SetPosition(radioPosX, radioPosY);
189 m_imgRadioOnDisabled->SetPosition(radioPosX, radioPosY);
190 m_imgRadioOffDisabled->SetPosition(radioPosX, radioPosY);
193 void CGUIRadioButtonControl::SetRadioDimensions(float posX, float posY, float width, float height)
195 m_radioPosX = posX;
196 m_radioPosY = posY;
197 if (width)
199 m_imgRadioOnFocus->SetWidth(width);
200 m_imgRadioOnNoFocus->SetWidth(width);
201 m_imgRadioOffFocus->SetWidth(width);
202 m_imgRadioOffNoFocus->SetWidth(width);
203 m_imgRadioOnDisabled->SetWidth(width);
204 m_imgRadioOffDisabled->SetWidth(width);
206 if (height)
208 m_imgRadioOnFocus->SetHeight(height);
209 m_imgRadioOnNoFocus->SetHeight(height);
210 m_imgRadioOffFocus->SetHeight(height);
211 m_imgRadioOffNoFocus->SetHeight(height);
212 m_imgRadioOnDisabled->SetHeight(height);
213 m_imgRadioOffDisabled->SetHeight(height);
216 // use label2 to display the button value in case no
217 // dimensions were specified and there's no label2 yet.
218 if (GetLabel2().empty() && !width && !height)
219 m_useLabel2 = true;
221 SetPosition(GetXPosition(), GetYPosition());
224 void CGUIRadioButtonControl::SetWidth(float width)
226 CGUIButtonControl::SetWidth(width);
227 SetPosition(GetXPosition(), GetYPosition());
230 void CGUIRadioButtonControl::SetHeight(float height)
232 CGUIButtonControl::SetHeight(height);
233 SetPosition(GetXPosition(), GetYPosition());
236 std::string CGUIRadioButtonControl::GetDescription() const
238 std::string strLabel = CGUIButtonControl::GetDescription();
239 if (m_bSelected)
240 strLabel += " (*)";
241 else
242 strLabel += " ( )";
243 return strLabel;
246 bool CGUIRadioButtonControl::UpdateColors(const CGUIListItem* item)
248 bool changed = CGUIButtonControl::UpdateColors(nullptr);
249 changed |= m_imgRadioOnFocus->SetDiffuseColor(m_diffuseColor);
250 changed |= m_imgRadioOnNoFocus->SetDiffuseColor(m_diffuseColor);
251 changed |= m_imgRadioOffFocus->SetDiffuseColor(m_diffuseColor);
252 changed |= m_imgRadioOffNoFocus->SetDiffuseColor(m_diffuseColor);
253 changed |= m_imgRadioOnDisabled->SetDiffuseColor(m_diffuseColor);
254 changed |= m_imgRadioOffDisabled->SetDiffuseColor(m_diffuseColor);
255 return changed;
258 void CGUIRadioButtonControl::SetToggleSelect(const std::string &toggleSelect)
260 m_toggleSelect = CServiceBroker::GetGUI()->GetInfoManager().Register(toggleSelect, GetParentID());