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 "GUICheckMarkControl.h"
22 #include "GUIFontManager.h"
27 CGUICheckMarkControl::CGUICheckMarkControl(int parentID, int controlID, float posX, float posY, float width, float height, const CTextureInfo& textureCheckMark, const CTextureInfo& textureCheckMarkNF, float checkWidth, float checkHeight, const CLabelInfo &labelInfo)
28 : CGUIControl(parentID, controlID, posX, posY, width, height)
29 , m_imgCheckMark(posX, posY, checkWidth, checkHeight, textureCheckMark)
30 , m_imgCheckMarkNoFocus(posX, posY, checkWidth, checkHeight, textureCheckMarkNF)
31 , m_label(posX, posY, width, height, labelInfo)
35 m_label.GetLabelInfo().align |= XBFONT_CENTER_Y;
36 ControlType = GUICONTROL_CHECKMARK;
39 CGUICheckMarkControl::~CGUICheckMarkControl(void)
42 void CGUICheckMarkControl::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
46 changed |= m_imgCheckMark.Process(currentTime);
47 changed |= m_imgCheckMarkNoFocus.Process(currentTime);
48 changed |= m_label.Process(currentTime);
53 CGUIControl::Process(currentTime, dirtyregions);
56 void CGUICheckMarkControl::Render()
58 m_label.SetText(m_strLabel);
60 float textWidth = m_label.GetTextWidth();
61 m_width = textWidth + 5 + m_imgCheckMark.GetWidth();
62 m_height = m_imgCheckMark.GetHeight();
64 float textPosX = m_posX;
65 float checkMarkPosX = m_posX;
67 if (m_label.GetLabelInfo().align & (XBFONT_RIGHT | XBFONT_CENTER_X))
68 textPosX += m_imgCheckMark.GetWidth() + 5;
70 checkMarkPosX += textWidth + 5;
72 m_label.SetMaxRect(textPosX, m_posY, textWidth, m_height);
73 m_label.SetColor(GetTextColor());
78 m_imgCheckMark.SetPosition(checkMarkPosX, m_posY);
79 m_imgCheckMark.Render();
83 m_imgCheckMarkNoFocus.SetPosition(checkMarkPosX, m_posY);
84 m_imgCheckMarkNoFocus.Render();
86 CGUIControl::Render();
89 CGUILabel::COLOR CGUICheckMarkControl::GetTextColor() const
92 return CGUILabel::COLOR_DISABLED;
94 return CGUILabel::COLOR_FOCUSED;
95 return CGUILabel::COLOR_TEXT;
98 bool CGUICheckMarkControl::OnAction(const CAction &action)
100 if (action.GetID() == ACTION_SELECT_ITEM)
102 m_bSelected = !m_bSelected;
103 CGUIMessage msg(GUI_MSG_CLICKED, GetID(), GetParentID(), action.GetID());
104 SendWindowMessage(msg);
107 return CGUIControl::OnAction(action);
110 bool CGUICheckMarkControl::OnMessage(CGUIMessage& message)
112 if ( message.GetControlId() == GetID() )
114 if (message.GetMessage() == GUI_MSG_LABEL_SET)
116 m_strLabel = message.GetLabel();
120 if (CGUIControl::OnMessage(message)) return true;
124 void CGUICheckMarkControl::AllocResources()
126 CGUIControl::AllocResources();
127 m_imgCheckMark.AllocResources();
128 m_imgCheckMarkNoFocus.AllocResources();
131 void CGUICheckMarkControl::FreeResources(bool immediately)
133 CGUIControl::FreeResources(immediately);
134 m_imgCheckMark.FreeResources(immediately);
135 m_imgCheckMarkNoFocus.FreeResources(immediately);
138 void CGUICheckMarkControl::DynamicResourceAlloc(bool bOnOff)
140 CGUIControl::DynamicResourceAlloc(bOnOff);
141 m_imgCheckMark.DynamicResourceAlloc(bOnOff);
142 m_imgCheckMarkNoFocus.DynamicResourceAlloc(bOnOff);
145 void CGUICheckMarkControl::SetInvalid()
147 CGUIControl::SetInvalid();
148 m_label.SetInvalid();
149 m_imgCheckMark.SetInvalid();
150 m_imgCheckMarkNoFocus.SetInvalid();
153 void CGUICheckMarkControl::SetSelected(bool bOnOff)
155 m_bSelected = bOnOff;
158 bool CGUICheckMarkControl::GetSelected() const
163 EVENT_RESULT CGUICheckMarkControl::OnMouseEvent(const CPoint &point, const CMouseEvent &event)
165 if (event.m_id == ACTION_MOUSE_LEFT_CLICK)
167 OnAction(CAction(ACTION_SELECT_ITEM));
168 return EVENT_RESULT_HANDLED;
170 return EVENT_RESULT_UNHANDLED;
173 void CGUICheckMarkControl::SetLabel(const string &label)
175 if (m_strLabel != label)
182 void CGUICheckMarkControl::PythonSetLabel(const CStdString &strFont, const string &strText, color_t textColor)
184 m_label.GetLabelInfo().font = g_fontManager.GetFont(strFont);
185 m_label.GetLabelInfo().textColor = textColor;
186 m_label.GetLabelInfo().focusedColor = textColor;
187 m_strLabel = strText;
191 void CGUICheckMarkControl::PythonSetDisabledColor(color_t disabledColor)
193 m_label.GetLabelInfo().disabledColor = disabledColor;
196 bool CGUICheckMarkControl::UpdateColors()
198 bool changed = CGUIControl::UpdateColors();
199 changed |= m_label.UpdateColors();
200 changed |= m_imgCheckMark.SetDiffuseColor(m_diffuseColor);
201 changed |= m_imgCheckMarkNoFocus.SetDiffuseColor(m_diffuseColor);