[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / guilib / GUISpinControlEx.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 "GUISpinControlEx.h"
22
23 CGUISpinControlEx::CGUISpinControlEx(int parentID, int controlID, float posX, float posY, float width, float height, float spinWidth, float spinHeight, const CLabelInfo& spinInfo, const CTextureInfo &textureFocus, const CTextureInfo &textureNoFocus, const CTextureInfo& textureUp, const CTextureInfo& textureDown, const CTextureInfo& textureUpFocus, const CTextureInfo& textureDownFocus, const CLabelInfo& labelInfo, int iType)
24     : CGUISpinControl(parentID, controlID, posX, posY, spinWidth, spinHeight, textureUp, textureDown, textureUpFocus, textureDownFocus, spinInfo, iType)
25     , m_buttonControl(parentID, controlID, posX, posY, width, height, textureFocus, textureNoFocus, labelInfo)
26 {
27   ControlType = GUICONTROL_SPINEX;
28   m_spinPosX = 0;
29 }
30
31 CGUISpinControlEx::~CGUISpinControlEx(void)
32 {
33 }
34
35 void CGUISpinControlEx::AllocResources()
36 {
37   // Correct alignment - we always align the spincontrol on the right
38   m_label.GetLabelInfo().align = (m_label.GetLabelInfo().align & XBFONT_CENTER_Y) | XBFONT_RIGHT;
39   CGUISpinControl::AllocResources();
40   m_buttonControl.AllocResources();
41   if (m_height == 0)
42     m_height = GetSpinHeight();
43 }
44
45 void CGUISpinControlEx::FreeResources(bool immediately)
46 {
47   CGUISpinControl::FreeResources(immediately);
48   m_buttonControl.FreeResources(immediately);
49 }
50
51 void CGUISpinControlEx::DynamicResourceAlloc(bool bOnOff)
52 {
53   CGUISpinControl::DynamicResourceAlloc(bOnOff);
54   m_buttonControl.DynamicResourceAlloc(bOnOff);
55 }
56
57
58 void CGUISpinControlEx::SetInvalid()
59 {
60   CGUISpinControl::SetInvalid();
61   m_buttonControl.SetInvalid();
62 }
63
64 void CGUISpinControlEx::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
65 {
66   // make sure the button has focus if it should have...
67   m_buttonControl.SetFocus(HasFocus());
68   m_buttonControl.SetPulseOnSelect(m_pulseOnSelect);
69   m_buttonControl.SetEnabled(m_enabled);
70   if (m_bInvalidated)
71   {
72     float spinPosX = m_buttonControl.GetXPosition() + m_buttonControl.GetWidth() - GetSpinWidth() * 2 - (m_spinPosX ? m_spinPosX : m_buttonControl.GetLabelInfo().offsetX);
73     float spinPosY = m_buttonControl.GetYPosition() + (m_buttonControl.GetHeight() - GetSpinHeight()) * 0.5f;
74     CGUISpinControl::SetPosition(spinPosX, spinPosY);
75   }
76   m_buttonControl.DoProcess(currentTime, dirtyregions);
77   CGUISpinControl::Process(currentTime, dirtyregions);
78 }
79
80 void CGUISpinControlEx::Render()
81 {
82   m_buttonControl.Render();
83   CGUISpinControl::Render();
84 }
85
86 void CGUISpinControlEx::SetPosition(float posX, float posY)
87 {
88   m_buttonControl.SetPosition(posX, posY);
89   CGUISpinControl::SetInvalid();
90 }
91
92 void CGUISpinControlEx::SetWidth(float width)
93 {
94   m_buttonControl.SetWidth(width);
95   CGUISpinControl::SetInvalid();
96 }
97
98 void CGUISpinControlEx::SetHeight(float height)
99 {
100   m_buttonControl.SetHeight(height);
101   CGUISpinControl::SetInvalid();
102 }
103
104 bool CGUISpinControlEx::UpdateColors()
105 {
106   bool changed = CGUISpinControl::UpdateColors();
107   changed |= m_buttonControl.SetColorDiffuse(m_diffuseColor);
108   changed |= m_buttonControl.UpdateColors();
109
110   return changed;
111 }
112
113 void CGUISpinControlEx::SetEnabled(bool bEnable)
114 {
115   m_buttonControl.SetEnabled(bEnable);
116   CGUISpinControl::SetEnabled(bEnable);
117 }
118
119 const CStdString CGUISpinControlEx::GetCurrentLabel() const
120 {
121   return CGUISpinControl::GetLabel();
122 }
123
124 CStdString CGUISpinControlEx::GetDescription() const
125 {
126   CStdString strLabel;
127   strLabel.Format("%s (%s)", m_buttonControl.GetDescription(), GetLabel());
128   return strLabel;
129 }
130
131 void CGUISpinControlEx::SetItemInvalid(bool invalid)
132 {
133   if (invalid)
134   {
135     m_label.GetLabelInfo().textColor = m_buttonControl.GetLabelInfo().disabledColor;
136     m_label.GetLabelInfo().focusedColor = m_buttonControl.GetLabelInfo().disabledColor;
137   }
138   else
139   {
140     m_label.GetLabelInfo().textColor = m_buttonControl.GetLabelInfo().textColor;
141     m_label.GetLabelInfo().focusedColor = m_buttonControl.GetLabelInfo().focusedColor;
142   }
143 }
144
145 void CGUISpinControlEx::SetSpinPosition(float spinPosX)
146 {
147   m_spinPosX = spinPosX;
148   SetPosition(m_buttonControl.GetXPosition(), m_buttonControl.GetYPosition());
149 }
150
151 void CGUISpinControlEx::RenderText(float posX, float posY, float width, float height)
152 {
153   const float spaceWidth = 10;
154   // check our limits from the button control
155   float x = std::max(m_buttonControl.m_label.GetRenderRect().x2 + spaceWidth, posX);
156   m_label.SetScrolling(HasFocus());
157   CGUISpinControl::RenderText(x, m_buttonControl.GetYPosition(), width + posX - x, m_buttonControl.GetHeight());
158 }