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