Fix keymap.
[vuplus_xbmc] / xbmc / guilib / GUIListLabel.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 "GUIListLabel.h"
22 #include <limits>
23
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)
27     , m_info(info)
28 {
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;
38 }
39
40 CGUIListLabel::~CGUIListLabel(void)
41 {
42 }
43
44 void CGUIListLabel::SetScrolling(bool scrolling)
45 {
46   m_label.SetScrolling(scrolling || m_alwaysScroll);
47 }
48
49 void CGUIListLabel::SetSelected(bool selected)
50 {
51   if(m_label.SetColor(selected ? CGUILabel::COLOR_SELECTED : CGUILabel::COLOR_TEXT))
52     SetInvalid();
53 }
54
55 void CGUIListLabel::SetFocus(bool focus)
56 {
57   CGUIControl::SetFocus(focus);
58   if (!focus)
59     SetScrolling(false);
60 }
61
62 CRect CGUIListLabel::CalcRenderRegion() const
63 {
64   return m_label.GetRenderRect();
65 }
66
67 bool CGUIListLabel::UpdateColors()
68 {
69   bool changed = CGUIControl::UpdateColors();
70   changed |= m_label.UpdateColors();
71
72   return changed;
73 }
74
75 void CGUIListLabel::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
76 {
77   if (m_label.Process(currentTime))
78     MarkDirtyRegion();
79
80   CGUIControl::Process(currentTime, dirtyregions);
81 }
82
83 void CGUIListLabel::Render()
84 {
85   m_label.Render();
86   CGUIControl::Render();
87 }
88
89 void CGUIListLabel::UpdateInfo(const CGUIListItem *item)
90 {
91   if (m_info.IsConstant() && !m_bInvalidated)
92     return; // nothing to do
93
94   if (item)
95     SetLabel(m_info.GetItemLabel(item));
96   else
97     SetLabel(m_info.GetLabel(m_parentID, true));
98 }
99
100 void CGUIListLabel::SetInvalid()
101 {
102   m_label.SetInvalid();
103   CGUIControl::SetInvalid();
104 }
105
106 void CGUIListLabel::SetWidth(float width)
107 {
108   m_width = 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);
113   else
114     m_label.SetMaxRect(m_posX, m_posY, m_width, m_height);
115   CGUIControl::SetWidth(m_width);
116 }
117
118 void CGUIListLabel::SetLabel(const CStdString &label)
119 {
120   m_label.SetText(label);
121 }