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 "GUIToggleButtonControl.h"
11 #include "GUIDialog.h"
12 #include "GUIInfoManager.h"
13 #include "GUIWindowManager.h"
14 #include "input/actions/Action.h"
15 #include "input/actions/ActionIDs.h"
17 CGUIToggleButtonControl::CGUIToggleButtonControl(int parentID
, int controlID
, float posX
, float posY
, float width
, float height
, const CTextureInfo
& textureFocus
, const CTextureInfo
& textureNoFocus
, const CTextureInfo
& altTextureFocus
, const CTextureInfo
& altTextureNoFocus
, const CLabelInfo
&labelInfo
, bool wrapMultiLine
)
18 : CGUIButtonControl(parentID
, controlID
, posX
, posY
, width
, height
, textureFocus
, textureNoFocus
, labelInfo
, wrapMultiLine
)
19 , m_selectButton(parentID
, controlID
, posX
, posY
, width
, height
, altTextureFocus
, altTextureNoFocus
, labelInfo
, wrapMultiLine
)
21 ControlType
= GUICONTROL_TOGGLEBUTTON
;
24 CGUIToggleButtonControl::~CGUIToggleButtonControl(void) = default;
26 void CGUIToggleButtonControl::Process(unsigned int currentTime
, CDirtyRegionList
&dirtyregions
)
28 // ask our infoManager whether we are selected or not...
30 m_bSelected
= m_toggleSelect
->Get(INFO::DEFAULT_CONTEXT
);
34 // render our Alternate textures...
35 m_selectButton
.SetFocus(HasFocus());
36 m_selectButton
.SetVisible(IsVisible());
37 m_selectButton
.SetEnabled(!IsDisabled());
38 m_selectButton
.SetPulseOnSelect(m_pulseOnSelect
);
39 ProcessToggle(currentTime
);
40 m_selectButton
.DoProcess(currentTime
, dirtyregions
);
41 CGUIControl::Process(currentTime
, dirtyregions
);
44 CGUIButtonControl::Process(currentTime
, dirtyregions
);
47 void CGUIToggleButtonControl::ProcessToggle(unsigned int currentTime
)
51 changed
|= m_label
.SetMaxRect(m_posX
, m_posY
, GetWidth(), m_height
);
52 changed
|= m_label
.SetText(GetDescription());
53 changed
|= m_label
.SetColor(GetTextColor());
54 changed
|= m_label
.SetScrolling(HasFocus());
55 changed
|= m_label
.Process(currentTime
);
61 void CGUIToggleButtonControl::Render()
65 m_selectButton
.Render();
66 CGUIControl::Render();
69 { // render our Normal textures...
70 CGUIButtonControl::Render();
74 bool CGUIToggleButtonControl::OnAction(const CAction
&action
)
76 if (action
.GetID() == ACTION_SELECT_ITEM
)
78 m_bSelected
= !m_bSelected
;
81 return CGUIButtonControl::OnAction(action
);
84 void CGUIToggleButtonControl::AllocResources()
86 CGUIButtonControl::AllocResources();
87 m_selectButton
.AllocResources();
90 void CGUIToggleButtonControl::FreeResources(bool immediately
)
92 CGUIButtonControl::FreeResources(immediately
);
93 m_selectButton
.FreeResources(immediately
);
96 void CGUIToggleButtonControl::DynamicResourceAlloc(bool bOnOff
)
98 CGUIButtonControl::DynamicResourceAlloc(bOnOff
);
99 m_selectButton
.DynamicResourceAlloc(bOnOff
);
102 void CGUIToggleButtonControl::SetInvalid()
104 CGUIButtonControl::SetInvalid();
105 m_selectButton
.SetInvalid();
108 void CGUIToggleButtonControl::SetPosition(float posX
, float posY
)
110 CGUIButtonControl::SetPosition(posX
, posY
);
111 m_selectButton
.SetPosition(posX
, posY
);
114 void CGUIToggleButtonControl::SetWidth(float width
)
116 CGUIButtonControl::SetWidth(width
);
117 m_selectButton
.SetWidth(width
);
120 void CGUIToggleButtonControl::SetHeight(float height
)
122 CGUIButtonControl::SetHeight(height
);
123 m_selectButton
.SetHeight(height
);
126 void CGUIToggleButtonControl::SetMinWidth(float minWidth
)
128 CGUIButtonControl::SetMinWidth(minWidth
);
129 m_selectButton
.SetMinWidth(minWidth
);
132 bool CGUIToggleButtonControl::UpdateColors(const CGUIListItem
* item
)
134 bool changed
= CGUIButtonControl::UpdateColors(nullptr);
135 changed
|= m_selectButton
.SetColorDiffuse(m_diffuseColor
);
136 changed
|= m_selectButton
.UpdateColors(nullptr);
141 void CGUIToggleButtonControl::SetLabel(const std::string
&label
)
143 CGUIButtonControl::SetLabel(label
);
144 m_selectButton
.SetLabel(label
);
147 void CGUIToggleButtonControl::SetAltLabel(const std::string
&label
)
150 m_selectButton
.SetLabel(label
);
153 std::string
CGUIToggleButtonControl::GetDescription() const
156 return m_selectButton
.GetDescription();
157 return CGUIButtonControl::GetDescription();
160 void CGUIToggleButtonControl::SetAltClickActions(const CGUIAction
&clickActions
)
162 m_selectButton
.SetClickActions(clickActions
);
165 void CGUIToggleButtonControl::OnClick()
167 // the ! is here as m_bSelected gets updated before this is called
168 if (!m_bSelected
&& m_selectButton
.HasClickActions())
169 m_selectButton
.OnClick();
171 CGUIButtonControl::OnClick();
174 void CGUIToggleButtonControl::SetToggleSelect(const std::string
&toggleSelect
)
176 m_toggleSelect
= CServiceBroker::GetGUI()->GetInfoManager().Register(toggleSelect
, GetParentID());