forked from mpc-hc/mpc-hc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCDColorProgressBar.cpp
More file actions
203 lines (165 loc) · 6.29 KB
/
LCDColorProgressBar.cpp
File metadata and controls
203 lines (165 loc) · 6.29 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//************************************************************************
// The Logitech LCD SDK, including all acompanying documentation,
// is protected by intellectual property laws. All use of the Logitech
// LCD SDK is subject to the License Agreement found in the
// "Logitech LCD SDK License Agreement" file and in the Reference Manual.
// All rights not expressly granted by Logitech are reserved.
//************************************************************************
//************************************************************************
//
// LCDColorProgressBar.cpp
//
// The CLCDColorProgressBar class draws a progress bar onto the color LCD.
//
// Logitech LCD SDK
//
// Copyright 2010 Logitech Inc.
//************************************************************************
#include "LCDUI.h"
//************************************************************************
//
// CLCDColorProgressBar::CLCDColorProgressBar
//
//************************************************************************
CLCDColorProgressBar::CLCDColorProgressBar(void)
: CLCDProgressBar()
{
SetProgressStyle(STYLE_FILLED);
SetCursorWidth(25);
SetBackgroundColor(RGB(0, 255, 100));
SetBorderThickness(3);
// Show a border by default
EnableBorder(FALSE);
SetBorderColor(RGB(0, 100, 150));
}
//************************************************************************
//
// CLCDColorProgressBar::~CLCDColorProgressBar
//
//************************************************************************
CLCDColorProgressBar::~CLCDColorProgressBar(void)
{
}
//************************************************************************
//
// CLCDColorProgressBar::OnDraw
//
//************************************************************************
void CLCDColorProgressBar::OnDraw(CLCDGfxBase &rGfx)
{
HBRUSH hCursorBrush = CreateSolidBrush(m_crForegroundColor);
HBRUSH hBackBrush = CreateSolidBrush(m_crBackgroundColor);
RECT rBoundary = { 0, 0, GetWidth(), GetHeight() };
// Draw the background/border or just background
if (m_bBorderOn && (m_nBorderThickness > 0))
{
HBRUSH hOldBrush = (HBRUSH)SelectObject(rGfx.GetHDC(), hBackBrush);
HPEN hBorderPen = CreatePen(PS_INSIDEFRAME, m_nBorderThickness, m_crBorderColor);
HPEN hOldPen = (HPEN)SelectObject(rGfx.GetHDC(), hBorderPen);
Rectangle(rGfx.GetHDC(), rBoundary.left, rBoundary.top, rBoundary.right, rBoundary.bottom);
SelectObject(rGfx.GetHDC(), hOldPen);
SelectObject(rGfx.GetHDC(), hOldBrush);
DeleteObject(hBorderPen);
// adjust the progress boundary by the thickness
rBoundary.top += m_nBorderThickness;
rBoundary.bottom -= m_nBorderThickness;
rBoundary.left += m_nBorderThickness;
rBoundary.right -= m_nBorderThickness;
}
else
{
FillRect(rGfx.GetHDC(), &rBoundary, hBackBrush);
}
//Drawing the cursor
switch(m_eStyle)
{
case STYLE_CURSOR:
{
RECT r = rBoundary;
int nCursorPos = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax,
(float)rBoundary.left, (float)(rBoundary.right - m_nCursorWidth),
m_fPos);
r.left = nCursorPos;
r.right = nCursorPos + m_nCursorWidth;
FillRect(rGfx.GetHDC(), &r, hCursorBrush);
break;
}
case STYLE_FILLED:
{
RECT r = rBoundary;
int nBarWidth = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax,
(float)rBoundary.left, (float)(rBoundary.right),
m_fPos);
r.right = nBarWidth ? nBarWidth : r.left;
FillRect(rGfx.GetHDC(), &r, hCursorBrush);
break;
}
case STYLE_DASHED_CURSOR:
{
RECT r = rBoundary;
int nCursorPos = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax,
(float)rBoundary.left, (float)(rBoundary.right - m_nCursorWidth),
m_fPos);
r.left = nCursorPos;
r.right = nCursorPos + m_nCursorWidth;
FillRect(rGfx.GetHDC(), &r, hCursorBrush);
HPEN hCursorPen = ::CreatePen(PS_DOT, 1, m_crForegroundColor);
HPEN hOldPen = (HPEN)::SelectObject(rGfx.GetHDC(), hCursorPen);
::MoveToEx(rGfx.GetHDC(), rBoundary.left, (r.bottom - r.top)/2, NULL);
::LineTo(rGfx.GetHDC(), nCursorPos, (r.bottom - r.top)/2);
DeleteObject(hCursorPen);
::SelectObject(rGfx.GetHDC(), hOldPen);
break;
}
default:
break;
}
DeleteObject(hBackBrush);
DeleteObject(hCursorBrush);
}
//************************************************************************
//
// CLCDColorProgressBar::SetCursorColor
//
//************************************************************************
void CLCDColorProgressBar::SetCursorColor(COLORREF color)
{
SetForegroundColor(color);
}
//************************************************************************
//
// CLCDColorProgressBar::EnableBorder
//
//************************************************************************
void CLCDColorProgressBar::EnableBorder(BOOL bEnable)
{
m_bBorderOn = bEnable;
}
//************************************************************************
//
// CLCDColorProgressBar::SetBorderColor
//
//************************************************************************
void CLCDColorProgressBar::SetBorderColor(COLORREF color)
{
m_crBorderColor = color;
}
//************************************************************************
//
// CLCDColorProgressBar::SetBorderThickness
//
//************************************************************************
void CLCDColorProgressBar::SetBorderThickness(int thickness)
{
m_nBorderThickness = thickness;
}
//************************************************************************
//
// CLCDColorProgressBar::SetCursorWidth
//
//************************************************************************
void CLCDColorProgressBar::SetCursorWidth(int width)
{
m_nCursorWidth = width;
}
//** end of LCDColorProgressBar.cpp **************************************