[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / guilib / GUISettingsSliderControl.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.xbmc.org
4  *
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)
8  *  any later version.
9  *
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.
14  *
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/>.
18  *
19  */
20
21 #include "GUISettingsSliderControl.h"
22
23 CGUISettingsSliderControl::CGUISettingsSliderControl(int parentID, int controlID, float posX, float posY, float width, float height, float sliderWidth, float sliderHeight, const CTextureInfo &textureFocus, const CTextureInfo &textureNoFocus, const CTextureInfo& backGroundTexture, const CTextureInfo& nibTexture, const CTextureInfo& nibTextureFocus, const CLabelInfo &labelInfo, int iType)
24     : CGUISliderControl(parentID, controlID, posX, posY, sliderWidth, sliderHeight, backGroundTexture, nibTexture,nibTextureFocus, iType)
25     , m_buttonControl(parentID, controlID, posX, posY, width, height, textureFocus, textureNoFocus, labelInfo)
26     , m_label(posX, posY, width, height, labelInfo)
27 {
28   m_label.SetAlign((labelInfo.align & XBFONT_CENTER_Y) | XBFONT_RIGHT);  
29   ControlType = GUICONTROL_SETTINGS_SLIDER;
30 }
31
32 CGUISettingsSliderControl::~CGUISettingsSliderControl(void)
33 {
34 }
35
36 void CGUISettingsSliderControl::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
37 {
38   if (m_bInvalidated)
39   {
40     float sliderPosX = m_buttonControl.GetXPosition() + m_buttonControl.GetWidth() - m_width - m_buttonControl.GetLabelInfo().offsetX;
41     float sliderPosY = m_buttonControl.GetYPosition() + (m_buttonControl.GetHeight() - m_height) * 0.5f;
42     CGUISliderControl::SetPosition(sliderPosX, sliderPosY);
43   }
44   m_buttonControl.SetFocus(HasFocus());
45   m_buttonControl.SetPulseOnSelect(m_pulseOnSelect);
46   m_buttonControl.SetEnabled(m_enabled);
47   m_buttonControl.DoProcess(currentTime, dirtyregions);
48   ProcessText();
49   CGUISliderControl::Process(currentTime, dirtyregions);
50 }
51
52 void CGUISettingsSliderControl::Render()
53 {
54   m_buttonControl.Render();
55   CGUISliderControl::Render();
56   m_label.Render();
57 }
58
59 void CGUISettingsSliderControl::ProcessText()
60 {
61   bool changed = false;
62
63   changed |= m_label.SetMaxRect(m_buttonControl.GetXPosition(), m_buttonControl.GetYPosition(), m_posX - m_buttonControl.GetXPosition(), m_buttonControl.GetHeight());
64   changed |= m_label.SetText(CGUISliderControl::GetDescription());
65   if (IsDisabled())
66     changed |= m_label.SetColor(CGUILabel::COLOR_DISABLED);
67   else if (HasFocus())
68     changed |= m_label.SetColor(CGUILabel::COLOR_FOCUSED);
69   else
70     changed |= m_label.SetColor(CGUILabel::COLOR_TEXT);
71
72   if (changed)
73     MarkDirtyRegion();
74 }
75
76 bool CGUISettingsSliderControl::OnAction(const CAction &action)
77 {
78   return CGUISliderControl::OnAction(action);
79 }
80
81 void CGUISettingsSliderControl::FreeResources(bool immediately)
82 {
83   CGUISliderControl::FreeResources(immediately);
84   m_buttonControl.FreeResources(immediately);
85 }
86
87 void CGUISettingsSliderControl::DynamicResourceAlloc(bool bOnOff)
88 {
89   CGUISliderControl::DynamicResourceAlloc(bOnOff);
90   m_buttonControl.DynamicResourceAlloc(bOnOff);
91 }
92
93 void CGUISettingsSliderControl::AllocResources()
94 {
95   CGUISliderControl::AllocResources();
96   m_buttonControl.AllocResources();
97 }
98
99 void CGUISettingsSliderControl::SetInvalid()
100 {
101   CGUISliderControl::SetInvalid();
102   m_buttonControl.SetInvalid();
103 }
104
105 void CGUISettingsSliderControl::SetPosition(float posX, float posY)
106 {
107   m_buttonControl.SetPosition(posX, posY);
108   CGUISliderControl::SetInvalid();
109 }
110
111 void CGUISettingsSliderControl::SetWidth(float width)
112 {
113   m_buttonControl.SetWidth(width);
114   CGUISliderControl::SetInvalid();
115 }
116
117 void CGUISettingsSliderControl::SetHeight(float height)
118 {
119   m_buttonControl.SetHeight(height);
120   CGUISliderControl::SetInvalid();
121 }
122
123 void CGUISettingsSliderControl::SetEnabled(bool bEnable)
124 {
125   CGUISliderControl::SetEnabled(bEnable);
126   m_buttonControl.SetEnabled(bEnable);
127 }
128
129 CStdString CGUISettingsSliderControl::GetDescription() const
130 {
131   return m_buttonControl.GetDescription() + " " + CGUISliderControl::GetDescription();
132 }
133
134 bool CGUISettingsSliderControl::UpdateColors()
135 {
136   bool changed = CGUISliderControl::UpdateColors();
137   changed |= m_buttonControl.SetColorDiffuse(m_diffuseColor);
138   changed |= m_buttonControl.UpdateColors();
139
140   return changed;
141 }