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"
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)
27 ControlType = GUICONTROL_SPINEX;
31 CGUISpinControlEx::~CGUISpinControlEx(void)
35 void CGUISpinControlEx::AllocResources()
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();
42 m_height = GetSpinHeight();
45 void CGUISpinControlEx::FreeResources(bool immediately)
47 CGUISpinControl::FreeResources(immediately);
48 m_buttonControl.FreeResources(immediately);
51 void CGUISpinControlEx::DynamicResourceAlloc(bool bOnOff)
53 CGUISpinControl::DynamicResourceAlloc(bOnOff);
54 m_buttonControl.DynamicResourceAlloc(bOnOff);
58 void CGUISpinControlEx::SetInvalid()
60 CGUISpinControl::SetInvalid();
61 m_buttonControl.SetInvalid();
64 void CGUISpinControlEx::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
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);
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);
76 m_buttonControl.DoProcess(currentTime, dirtyregions);
77 CGUISpinControl::Process(currentTime, dirtyregions);
80 void CGUISpinControlEx::Render()
82 m_buttonControl.Render();
83 CGUISpinControl::Render();
86 void CGUISpinControlEx::SetPosition(float posX, float posY)
88 m_buttonControl.SetPosition(posX, posY);
89 CGUISpinControl::SetInvalid();
92 void CGUISpinControlEx::SetWidth(float width)
94 m_buttonControl.SetWidth(width);
95 CGUISpinControl::SetInvalid();
98 void CGUISpinControlEx::SetHeight(float height)
100 m_buttonControl.SetHeight(height);
101 CGUISpinControl::SetInvalid();
104 bool CGUISpinControlEx::UpdateColors()
106 bool changed = CGUISpinControl::UpdateColors();
107 changed |= m_buttonControl.SetColorDiffuse(m_diffuseColor);
108 changed |= m_buttonControl.UpdateColors();
113 void CGUISpinControlEx::SetEnabled(bool bEnable)
115 m_buttonControl.SetEnabled(bEnable);
116 CGUISpinControl::SetEnabled(bEnable);
119 const CStdString CGUISpinControlEx::GetCurrentLabel() const
121 return CGUISpinControl::GetLabel();
124 CStdString CGUISpinControlEx::GetDescription() const
127 strLabel.Format("%s (%s)", m_buttonControl.GetDescription(), GetLabel());
131 void CGUISpinControlEx::SetItemInvalid(bool invalid)
135 m_label.GetLabelInfo().textColor = m_buttonControl.GetLabelInfo().disabledColor;
136 m_label.GetLabelInfo().focusedColor = m_buttonControl.GetLabelInfo().disabledColor;
140 m_label.GetLabelInfo().textColor = m_buttonControl.GetLabelInfo().textColor;
141 m_label.GetLabelInfo().focusedColor = m_buttonControl.GetLabelInfo().focusedColor;
145 void CGUISpinControlEx::SetSpinPosition(float spinPosX)
147 m_spinPosX = spinPosX;
148 SetPosition(m_buttonControl.GetXPosition(), m_buttonControl.GetYPosition());
151 void CGUISpinControlEx::RenderText(float posX, float posY, float width, float height)
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());