2 * Copyright (C) 2005-2008 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, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 #include "GUIToggleButtonControl.h"
23 #include "GUIWindowManager.h"
24 #include "GUIDialog.h"
25 #include "utils/CharsetConverter.h"
26 #include "utils/GUIInfoManager.h"
30 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)
31 : CGUIButtonControl(parentID, controlID, posX, posY, width, height, textureFocus, textureNoFocus, labelInfo)
32 , m_selectButton(parentID, controlID, posX, posY, width, height, altTextureFocus, altTextureNoFocus, labelInfo)
35 ControlType = GUICONTROL_TOGGLEBUTTON;
38 CGUIToggleButtonControl::~CGUIToggleButtonControl(void)
42 void CGUIToggleButtonControl::Render()
44 // ask our infoManager whether we are selected or not...
46 m_bSelected = g_infoManager.GetBool(m_toggleSelect, m_parentID);
50 // render our Alternate textures...
51 m_selectButton.SetFocus(HasFocus());
52 m_selectButton.SetVisible(IsVisible());
53 m_selectButton.SetEnabled(!IsDisabled());
54 m_selectButton.SetPulseOnSelect(m_pulseOnSelect);
55 m_selectButton.Render();
56 CGUIControl::Render();
59 { // render our Normal textures...
60 CGUIButtonControl::Render();
64 bool CGUIToggleButtonControl::OnAction(const CAction &action)
66 if (action.GetID() == ACTION_SELECT_ITEM)
68 m_bSelected = !m_bSelected;
70 return CGUIButtonControl::OnAction(action);
73 void CGUIToggleButtonControl::AllocResources()
75 CGUIButtonControl::AllocResources();
76 m_selectButton.AllocResources();
79 void CGUIToggleButtonControl::FreeResources(bool immediately)
81 CGUIButtonControl::FreeResources(immediately);
82 m_selectButton.FreeResources(immediately);
85 void CGUIToggleButtonControl::DynamicResourceAlloc(bool bOnOff)
87 CGUIButtonControl::DynamicResourceAlloc(bOnOff);
88 m_selectButton.DynamicResourceAlloc(bOnOff);
91 void CGUIToggleButtonControl::SetInvalid()
93 CGUIButtonControl::SetInvalid();
94 m_selectButton.SetInvalid();
97 void CGUIToggleButtonControl::SetPosition(float posX, float posY)
99 CGUIButtonControl::SetPosition(posX, posY);
100 m_selectButton.SetPosition(posX, posY);
103 void CGUIToggleButtonControl::SetWidth(float width)
105 CGUIButtonControl::SetWidth(width);
106 m_selectButton.SetWidth(width);
109 void CGUIToggleButtonControl::SetHeight(float height)
111 CGUIButtonControl::SetHeight(height);
112 m_selectButton.SetHeight(height);
115 void CGUIToggleButtonControl::UpdateColors()
117 CGUIButtonControl::UpdateColors();
118 m_selectButton.UpdateColors();
121 void CGUIToggleButtonControl::SetLabel(const string &strLabel)
123 CGUIButtonControl::SetLabel(strLabel);
124 m_selectButton.SetLabel(strLabel);
127 void CGUIToggleButtonControl::SetAltLabel(const string &label)
130 m_selectButton.SetLabel(label);
133 CStdString CGUIToggleButtonControl::GetDescription() const
136 return m_selectButton.GetDescription();
137 return CGUIButtonControl::GetDescription();
140 void CGUIToggleButtonControl::SetAltClickActions(const vector<CGUIActionDescriptor> &clickActions)
142 m_selectButton.SetClickActions(clickActions);
145 void CGUIToggleButtonControl::OnClick()
147 // the ! is here as m_bSelected gets updated before this is called
148 if (!m_bSelected && m_selectButton.HasClickActions())
149 m_selectButton.OnClick();
151 CGUIButtonControl::OnClick();