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 "GUISpinControlEx.h"
22 #include "utils/StringUtils.h"
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)
28 ControlType = GUICONTROL_SPINEX;
32 CGUISpinControlEx::~CGUISpinControlEx(void)
36 void CGUISpinControlEx::AllocResources()
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();
43 m_height = GetSpinHeight();
46 void CGUISpinControlEx::FreeResources(bool immediately)
48 CGUISpinControl::FreeResources(immediately);
49 m_buttonControl.FreeResources(immediately);
52 void CGUISpinControlEx::DynamicResourceAlloc(bool bOnOff)
54 CGUISpinControl::DynamicResourceAlloc(bOnOff);
55 m_buttonControl.DynamicResourceAlloc(bOnOff);
59 void CGUISpinControlEx::SetInvalid()
61 CGUISpinControl::SetInvalid();
62 m_buttonControl.SetInvalid();
65 void CGUISpinControlEx::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
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);
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);
77 m_buttonControl.DoProcess(currentTime, dirtyregions);
78 CGUISpinControl::Process(currentTime, dirtyregions);
81 void CGUISpinControlEx::Render()
83 m_buttonControl.Render();
84 CGUISpinControl::Render();
87 void CGUISpinControlEx::SetPosition(float posX, float posY)
89 m_buttonControl.SetPosition(posX, posY);
90 CGUISpinControl::SetInvalid();
93 void CGUISpinControlEx::SetWidth(float width)
95 m_buttonControl.SetWidth(width);
96 CGUISpinControl::SetInvalid();
99 void CGUISpinControlEx::SetHeight(float height)
101 m_buttonControl.SetHeight(height);
102 CGUISpinControl::SetInvalid();
105 bool CGUISpinControlEx::UpdateColors()
107 bool changed = CGUISpinControl::UpdateColors();
108 changed |= m_buttonControl.SetColorDiffuse(m_diffuseColor);
109 changed |= m_buttonControl.UpdateColors();
114 void CGUISpinControlEx::SetEnabled(bool bEnable)
116 m_buttonControl.SetEnabled(bEnable);
117 CGUISpinControl::SetEnabled(bEnable);
120 const CStdString CGUISpinControlEx::GetCurrentLabel() const
122 return CGUISpinControl::GetLabel();
125 CStdString CGUISpinControlEx::GetDescription() const
127 return StringUtils::Format("%s (%s)", m_buttonControl.GetDescription().c_str(), GetLabel().c_str());
130 void CGUISpinControlEx::SetItemInvalid(bool invalid)
134 m_label.GetLabelInfo().textColor = m_buttonControl.GetLabelInfo().disabledColor;
135 m_label.GetLabelInfo().focusedColor = m_buttonControl.GetLabelInfo().disabledColor;
139 m_label.GetLabelInfo().textColor = m_buttonControl.GetLabelInfo().textColor;
140 m_label.GetLabelInfo().focusedColor = m_buttonControl.GetLabelInfo().focusedColor;
144 void CGUISpinControlEx::SetSpinPosition(float spinPosX)
146 m_spinPosX = spinPosX;
147 SetPosition(m_buttonControl.GetXPosition(), m_buttonControl.GetYPosition());
150 void CGUISpinControlEx::RenderText(float posX, float posY, float width, float height)
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());