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 "GUIToggleButtonControl.h"
22 #include "GUIWindowManager.h"
23 #include "GUIDialog.h"
24 #include "GUIInfoManager.h"
29 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)
30 : CGUIButtonControl(parentID, controlID, posX, posY, width, height, textureFocus, textureNoFocus, labelInfo)
31 , m_selectButton(parentID, controlID, posX, posY, width, height, altTextureFocus, altTextureNoFocus, labelInfo)
33 ControlType = GUICONTROL_TOGGLEBUTTON;
36 CGUIToggleButtonControl::~CGUIToggleButtonControl(void)
40 void CGUIToggleButtonControl::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
42 // ask our infoManager whether we are selected or not...
43 bool selected = m_bSelected;
45 selected = m_toggleSelect->Get();
46 if (selected != m_bSelected)
49 m_bSelected = selected;
54 // render our Alternate textures...
55 m_selectButton.SetFocus(HasFocus());
56 m_selectButton.SetVisible(IsVisible());
57 m_selectButton.SetEnabled(!IsDisabled());
58 m_selectButton.SetPulseOnSelect(m_pulseOnSelect);
59 m_selectButton.DoProcess(currentTime, dirtyregions);
61 CGUIButtonControl::Process(currentTime, dirtyregions);
64 void CGUIToggleButtonControl::Render()
68 m_selectButton.Render();
69 CGUIControl::Render();
72 { // render our Normal textures...
73 CGUIButtonControl::Render();
77 bool CGUIToggleButtonControl::OnAction(const CAction &action)
79 if (action.GetID() == ACTION_SELECT_ITEM)
81 m_bSelected = !m_bSelected;
84 return CGUIButtonControl::OnAction(action);
87 void CGUIToggleButtonControl::AllocResources()
89 CGUIButtonControl::AllocResources();
90 m_selectButton.AllocResources();
93 void CGUIToggleButtonControl::FreeResources(bool immediately)
95 CGUIButtonControl::FreeResources(immediately);
96 m_selectButton.FreeResources(immediately);
99 void CGUIToggleButtonControl::DynamicResourceAlloc(bool bOnOff)
101 CGUIButtonControl::DynamicResourceAlloc(bOnOff);
102 m_selectButton.DynamicResourceAlloc(bOnOff);
105 void CGUIToggleButtonControl::SetInvalid()
107 CGUIButtonControl::SetInvalid();
108 m_selectButton.SetInvalid();
111 void CGUIToggleButtonControl::SetPosition(float posX, float posY)
113 CGUIButtonControl::SetPosition(posX, posY);
114 m_selectButton.SetPosition(posX, posY);
117 void CGUIToggleButtonControl::SetWidth(float width)
119 CGUIButtonControl::SetWidth(width);
120 m_selectButton.SetWidth(width);
123 void CGUIToggleButtonControl::SetHeight(float height)
125 CGUIButtonControl::SetHeight(height);
126 m_selectButton.SetHeight(height);
129 bool CGUIToggleButtonControl::UpdateColors()
131 bool changed = CGUIButtonControl::UpdateColors();
132 changed |= m_selectButton.SetColorDiffuse(m_diffuseColor);
133 changed |= m_selectButton.UpdateColors();
138 void CGUIToggleButtonControl::SetLabel(const string &strLabel)
140 CGUIButtonControl::SetLabel(strLabel);
141 m_selectButton.SetLabel(strLabel);
144 void CGUIToggleButtonControl::SetAltLabel(const string &label)
147 m_selectButton.SetLabel(label);
150 CStdString CGUIToggleButtonControl::GetDescription() const
153 return m_selectButton.GetDescription();
154 return CGUIButtonControl::GetDescription();
157 void CGUIToggleButtonControl::SetAltClickActions(const CGUIAction &clickActions)
159 m_selectButton.SetClickActions(clickActions);
162 void CGUIToggleButtonControl::OnClick()
164 // the ! is here as m_bSelected gets updated before this is called
165 if (!m_bSelected && m_selectButton.HasClickActions())
166 m_selectButton.OnClick();
168 CGUIButtonControl::OnClick();
171 void CGUIToggleButtonControl::SetToggleSelect(const CStdString &toggleSelect)
173 m_toggleSelect = g_infoManager.Register(toggleSelect, GetParentID());