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 "utils/CharsetConverter.h"
25 #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)
34 ControlType = GUICONTROL_TOGGLEBUTTON;
37 CGUIToggleButtonControl::~CGUIToggleButtonControl(void)
41 void CGUIToggleButtonControl::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
43 // ask our infoManager whether we are selected or not...
44 bool selected = m_bSelected;
46 selected = g_infoManager.GetBoolValue(m_toggleSelect);
47 if (selected != m_bSelected)
50 m_bSelected = selected;
55 // render our Alternate textures...
56 m_selectButton.SetFocus(HasFocus());
57 m_selectButton.SetVisible(IsVisible());
58 m_selectButton.SetEnabled(!IsDisabled());
59 m_selectButton.SetPulseOnSelect(m_pulseOnSelect);
60 m_selectButton.DoProcess(currentTime, dirtyregions);
62 CGUIButtonControl::Process(currentTime, dirtyregions);
65 void CGUIToggleButtonControl::Render()
69 m_selectButton.Render();
70 CGUIControl::Render();
73 { // render our Normal textures...
74 CGUIButtonControl::Render();
78 bool CGUIToggleButtonControl::OnAction(const CAction &action)
80 if (action.GetID() == ACTION_SELECT_ITEM)
82 m_bSelected = !m_bSelected;
85 return CGUIButtonControl::OnAction(action);
88 void CGUIToggleButtonControl::AllocResources()
90 CGUIButtonControl::AllocResources();
91 m_selectButton.AllocResources();
94 void CGUIToggleButtonControl::FreeResources(bool immediately)
96 CGUIButtonControl::FreeResources(immediately);
97 m_selectButton.FreeResources(immediately);
100 void CGUIToggleButtonControl::DynamicResourceAlloc(bool bOnOff)
102 CGUIButtonControl::DynamicResourceAlloc(bOnOff);
103 m_selectButton.DynamicResourceAlloc(bOnOff);
106 void CGUIToggleButtonControl::SetInvalid()
108 CGUIButtonControl::SetInvalid();
109 m_selectButton.SetInvalid();
112 void CGUIToggleButtonControl::SetPosition(float posX, float posY)
114 CGUIButtonControl::SetPosition(posX, posY);
115 m_selectButton.SetPosition(posX, posY);
118 void CGUIToggleButtonControl::SetWidth(float width)
120 CGUIButtonControl::SetWidth(width);
121 m_selectButton.SetWidth(width);
124 void CGUIToggleButtonControl::SetHeight(float height)
126 CGUIButtonControl::SetHeight(height);
127 m_selectButton.SetHeight(height);
130 bool CGUIToggleButtonControl::UpdateColors()
132 bool changed = CGUIButtonControl::UpdateColors();
133 changed |= m_selectButton.SetColorDiffuse(m_diffuseColor);
134 changed |= m_selectButton.UpdateColors();
139 void CGUIToggleButtonControl::SetLabel(const string &strLabel)
141 CGUIButtonControl::SetLabel(strLabel);
142 m_selectButton.SetLabel(strLabel);
145 void CGUIToggleButtonControl::SetAltLabel(const string &label)
148 m_selectButton.SetLabel(label);
151 CStdString CGUIToggleButtonControl::GetDescription() const
154 return m_selectButton.GetDescription();
155 return CGUIButtonControl::GetDescription();
158 void CGUIToggleButtonControl::SetAltClickActions(const CGUIAction &clickActions)
160 m_selectButton.SetClickActions(clickActions);
163 void CGUIToggleButtonControl::OnClick()
165 // the ! is here as m_bSelected gets updated before this is called
166 if (!m_bSelected && m_selectButton.HasClickActions())
167 m_selectButton.OnClick();
169 CGUIButtonControl::OnClick();
172 void CGUIToggleButtonControl::SetToggleSelect(const CStdString &toggleSelect)
174 m_toggleSelect = g_infoManager.Register(toggleSelect, GetParentID());