forked from mpc-hc/mpc-hc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCDProgressBar.cpp
More file actions
263 lines (210 loc) · 7.07 KB
/
LCDProgressBar.cpp
File metadata and controls
263 lines (210 loc) · 7.07 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
//************************************************************************
// 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.
//************************************************************************
//************************************************************************
//
// LCDProgressBar.cpp
//
// The CLCDProgressBar class draws a progress bar onto the LCD.
//
// Logitech LCD SDK
//
// Copyright 2010 Logitech Inc.
//************************************************************************
#include "LCDUI.h"
//************************************************************************
//
// CLCDProgressBar::CLCDProgressBar
//
//************************************************************************
CLCDProgressBar::CLCDProgressBar(void)
: m_fPos(0.0f),
m_eStyle(STYLE_CURSOR),
m_hBrush(NULL),
m_hPen(NULL),
m_nCursorWidth(5)
{
m_Range.nMin = 0;
m_Range.nMax = 100;
}
//************************************************************************
//
// CLCDProgressBar::~CLCDProgressBar
//
//************************************************************************
CLCDProgressBar::~CLCDProgressBar(void)
{
if (m_hPen != NULL)
{
::DeleteObject(m_hPen);
m_hPen = NULL;
}
}
//************************************************************************
//
// CLCDProgressBar:Initialize
//
//************************************************************************
HRESULT CLCDProgressBar::Initialize(void)
{
m_hBrush = (HBRUSH)GetStockObject(WHITE_BRUSH);
m_hPen = ::CreatePen(PS_DOT, 1, RGB(255, 255, 255));
return S_OK;
}
//************************************************************************
//
// CLCDProgressBar::OnDraw
//
//************************************************************************
void CLCDProgressBar::OnDraw(CLCDGfxBase &rGfx)
{
// draw the border
RECT r = { 0, 0, GetWidth(), GetHeight() };
FrameRect(rGfx.GetHDC(), &r, m_hBrush);
// draw the progress
switch(m_eStyle)
{
case STYLE_CURSOR:
{
int nCursorPos = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax,
(float)1, (float)(GetWidth() - m_nCursorWidth-1),
m_fPos);
r.left = nCursorPos;
r.right = r.left + m_nCursorWidth;
FillRect(rGfx.GetHDC(), &r, m_hBrush);
}
break;
case STYLE_FILLED:
{
int nBarWidth = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax,
0.0f, (float)GetWidth(),
m_fPos);
r.right = nBarWidth;
FillRect(rGfx.GetHDC(), &r, m_hBrush);
}
break;
case STYLE_DASHED_CURSOR:
{
int nCursorPos = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax,
(float)1, (float)(GetWidth() - m_nCursorWidth-1),
m_fPos);
r.left = nCursorPos;
r.right = r.left + m_nCursorWidth;
FillRect(rGfx.GetHDC(), &r, m_hBrush);
HPEN hOldPen = (HPEN)::SelectObject(rGfx.GetHDC(), m_hPen);
::MoveToEx(rGfx.GetHDC(), 0, (r.bottom - r.top)/2, NULL);
::LineTo(rGfx.GetHDC(), nCursorPos, (r.bottom - r.top)/2);
::SelectObject(rGfx.GetHDC(), hOldPen);
}
break;
default:
break;
}
}
//************************************************************************
//
// CLCDProgressBar::ResetUpdate
//
//************************************************************************
void CLCDProgressBar::ResetUpdate(void)
{
}
//************************************************************************
//
// CLCDProgressBar::SetRange
//
//************************************************************************
void CLCDProgressBar::SetRange(int nMin, int nMax)
{
m_Range.nMin = nMin;
m_Range.nMax = nMax;
}
//************************************************************************
//
// CLCDProgressBar::SetRange
//
//************************************************************************
void CLCDProgressBar::SetRange(RANGE& Range)
{
m_Range = Range;
}
//************************************************************************
//
// CLCDProgressBar::GetRange
//
//************************************************************************
RANGE& CLCDProgressBar::GetRange(void)
{
return m_Range;
}
//************************************************************************
//
// CLCDProgressBar::SetPos
//
//************************************************************************
float CLCDProgressBar::SetPos(float fPos)
{
return ( m_fPos = max((float)m_Range.nMin, min(fPos, (float)m_Range.nMax)) );
}
//************************************************************************
//
// CLCDProgressBar::GetPos
//
//************************************************************************
float CLCDProgressBar::GetPos(void)
{
return m_fPos;
}
//************************************************************************
//
// CLCDProgressBar::EnableCursor
//
//************************************************************************
void CLCDProgressBar::EnableCursor(BOOL bEnable)
{
m_eStyle = bEnable ? STYLE_CURSOR : STYLE_FILLED;
}
//************************************************************************
//
// CLCDProgressBar::SetProgressStyle
//
//************************************************************************
void CLCDProgressBar::SetProgressStyle(ePROGRESS_STYLE eStyle)
{
m_eStyle = eStyle;
}
//************************************************************************
//
// CLCDProgressBar::Scalef
//
//************************************************************************
float CLCDProgressBar::Scalef(float fFromMin, float fFromMax,
float fToMin, float fToMax, float fFromValue)
{
// normalize the input
float fFromValueN = (fFromValue - fFromMin) / (fFromMax - fFromMin);
// now scale to the output
float fToRange = fToMax - fToMin;
return ( fToMin + (fFromValueN * fToRange) );
}
//************************************************************************
//
// CLCDProgressBar::Scale
//
//************************************************************************
int CLCDProgressBar::Scale(int nFromMin, int nFromMax,
int nToMin, int nToMax, int nFromValue)
{
return (int)Scalef(
(float)nFromMin,
(float)nFromMax,
(float)nToMin,
(float)nToMax,
(float)nFromValue
);
}
//** end of LCDProgressBar.cpp *******************************************