1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
/*
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "GUICheckMarkControl.h"
#include "utils/CharsetConverter.h"
#include "GUIFontManager.h"
#include "Key.h"
using namespace std;
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)
: CGUIControl(parentID, controlID, posX, posY, width, height)
, m_imgCheckMark(posX, posY, checkWidth, checkHeight, textureCheckMark)
, m_imgCheckMarkNoFocus(posX, posY, checkWidth, checkHeight, textureCheckMarkNF)
, m_label(posX, posY, width, height, labelInfo)
{
m_strLabel = "";
m_bSelected = false;
m_label.GetLabelInfo().align |= XBFONT_CENTER_Y;
ControlType = GUICONTROL_CHECKMARK;
}
CGUICheckMarkControl::~CGUICheckMarkControl(void)
{}
void CGUICheckMarkControl::Render()
{
m_label.SetText(m_strLabel);
float textWidth = m_label.GetTextWidth();
m_width = textWidth + 5 + m_imgCheckMark.GetWidth();
m_height = m_imgCheckMark.GetHeight();
float textPosX = m_posX;
float checkMarkPosX = m_posX;
if (m_label.GetLabelInfo().align & (XBFONT_RIGHT | XBFONT_CENTER_X))
textPosX += m_imgCheckMark.GetWidth() + 5;
else
checkMarkPosX += textWidth + 5;
m_label.SetMaxRect(textPosX, m_posY, textWidth, m_height);
m_label.SetColor(GetTextColor());
m_label.Render();
if (m_bSelected)
{
m_imgCheckMark.SetPosition(checkMarkPosX, m_posY);
m_imgCheckMark.Render();
}
else
{
m_imgCheckMarkNoFocus.SetPosition(checkMarkPosX, m_posY);
m_imgCheckMarkNoFocus.Render();
}
CGUIControl::Render();
}
CGUILabel::COLOR CGUICheckMarkControl::GetTextColor() const
{
if (IsDisabled())
return CGUILabel::COLOR_DISABLED;
else if (HasFocus())
return CGUILabel::COLOR_FOCUSED;
return CGUILabel::COLOR_TEXT;
}
bool CGUICheckMarkControl::OnAction(const CAction &action)
{
if (action.GetID() == ACTION_SELECT_ITEM)
{
m_bSelected = !m_bSelected;
CGUIMessage msg(GUI_MSG_CLICKED, GetID(), GetParentID(), action.GetID());
SendWindowMessage(msg);
return true;
}
return CGUIControl::OnAction(action);
}
bool CGUICheckMarkControl::OnMessage(CGUIMessage& message)
{
if ( message.GetControlId() == GetID() )
{
if (message.GetMessage() == GUI_MSG_LABEL_SET)
{
m_strLabel = message.GetLabel();
return true;
}
}
if (CGUIControl::OnMessage(message)) return true;
return false;
}
void CGUICheckMarkControl::AllocResources()
{
CGUIControl::AllocResources();
m_imgCheckMark.AllocResources();
m_imgCheckMarkNoFocus.AllocResources();
}
void CGUICheckMarkControl::FreeResources(bool immediately)
{
CGUIControl::FreeResources(immediately);
m_imgCheckMark.FreeResources(immediately);
m_imgCheckMarkNoFocus.FreeResources(immediately);
}
void CGUICheckMarkControl::DynamicResourceAlloc(bool bOnOff)
{
CGUIControl::DynamicResourceAlloc(bOnOff);
m_imgCheckMark.DynamicResourceAlloc(bOnOff);
m_imgCheckMarkNoFocus.DynamicResourceAlloc(bOnOff);
}
void CGUICheckMarkControl::SetInvalid()
{
CGUIControl::SetInvalid();
m_label.SetInvalid();
m_imgCheckMark.SetInvalid();
m_imgCheckMarkNoFocus.SetInvalid();
}
void CGUICheckMarkControl::SetSelected(bool bOnOff)
{
m_bSelected = bOnOff;
}
bool CGUICheckMarkControl::GetSelected() const
{
return m_bSelected;
}
EVENT_RESULT CGUICheckMarkControl::OnMouseEvent(const CPoint &point, const CMouseEvent &event)
{
if (event.m_id == ACTION_MOUSE_LEFT_CLICK)
{
OnAction(CAction(ACTION_SELECT_ITEM));
return EVENT_RESULT_HANDLED;
}
return EVENT_RESULT_UNHANDLED;
}
void CGUICheckMarkControl::SetLabel(const string &label)
{
m_strLabel = label;
}
void CGUICheckMarkControl::PythonSetLabel(const CStdString &strFont, const string &strText, color_t textColor)
{
m_label.GetLabelInfo().font = g_fontManager.GetFont(strFont);
m_label.GetLabelInfo().textColor = textColor;
m_label.GetLabelInfo().focusedColor = textColor;
m_strLabel = strText;
}
void CGUICheckMarkControl::PythonSetDisabledColor(color_t disabledColor)
{
m_label.GetLabelInfo().disabledColor = disabledColor;
}
void CGUICheckMarkControl::UpdateColors()
{
m_label.UpdateColors();
CGUIControl::UpdateColors();
m_imgCheckMark.SetDiffuseColor(m_diffuseColor);
m_imgCheckMarkNoFocus.SetDiffuseColor(m_diffuseColor);
}
|