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 "GUIListLabel.h"
24 CGUIListLabel::CGUIListLabel(int parentID, int controlID, float posX, float posY, float width, float height, const CLabelInfo& labelInfo, const CGUIInfoLabel &info, bool alwaysScroll)
25 : CGUIControl(parentID, controlID, posX, posY, width, height)
26 , m_label(posX, posY, width, height, labelInfo, alwaysScroll ? CGUILabel::OVER_FLOW_SCROLL : CGUILabel::OVER_FLOW_TRUNCATE)
29 m_alwaysScroll = alwaysScroll;
30 // TODO: Remove this "correction"
31 if (labelInfo.align & XBFONT_RIGHT)
32 m_label.SetMaxRect(m_posX - m_width, m_posY, m_width, m_height);
33 else if (labelInfo.align & XBFONT_CENTER_X)
34 m_label.SetMaxRect(m_posX - m_width*0.5f, m_posY, m_width, m_height);
35 if (m_info.IsConstant())
36 SetLabel(m_info.GetLabel(m_parentID, true));
37 ControlType = GUICONTROL_LISTLABEL;
40 CGUIListLabel::~CGUIListLabel(void)
44 void CGUIListLabel::SetScrolling(bool scrolling)
46 m_label.SetScrolling(scrolling || m_alwaysScroll);
49 void CGUIListLabel::SetSelected(bool selected)
51 if(m_label.SetColor(selected ? CGUILabel::COLOR_SELECTED : CGUILabel::COLOR_TEXT))
55 void CGUIListLabel::SetFocus(bool focus)
57 CGUIControl::SetFocus(focus);
62 CRect CGUIListLabel::CalcRenderRegion() const
64 return m_label.GetRenderRect();
67 bool CGUIListLabel::UpdateColors()
69 bool changed = CGUIControl::UpdateColors();
70 changed |= m_label.UpdateColors();
75 void CGUIListLabel::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
77 if (m_label.Process(currentTime))
80 CGUIControl::Process(currentTime, dirtyregions);
83 void CGUIListLabel::Render()
86 CGUIControl::Render();
89 void CGUIListLabel::UpdateInfo(const CGUIListItem *item)
91 if (m_info.IsConstant() && !m_bInvalidated)
92 return; // nothing to do
95 SetLabel(m_info.GetItemLabel(item));
97 SetLabel(m_info.GetLabel(m_parentID, true));
100 void CGUIListLabel::SetInvalid()
102 m_label.SetInvalid();
103 CGUIControl::SetInvalid();
106 void CGUIListLabel::SetWidth(float width)
109 if (m_label.GetLabelInfo().align & XBFONT_RIGHT)
110 m_label.SetMaxRect(m_posX - m_width, m_posY, m_width, m_height);
111 else if (m_label.GetLabelInfo().align & XBFONT_CENTER_X)
112 m_label.SetMaxRect(m_posX - m_width*0.5f, m_posY, m_width, m_height);
114 m_label.SetMaxRect(m_posX, m_posY, m_width, m_height);
115 CGUIControl::SetWidth(m_width);
118 void CGUIListLabel::SetLabel(const CStdString &label)
120 m_label.SetText(label);