Subversion Repositories spk

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
79 cycrow 1
//************************************************************************
2
//
3
// LCDProgressBar.cpp
4
//
5
// The CLCDProgressBar class draws a progress bar onto the LCD.
6
// 
7
// Logitech LCD SDK
8
//
9
// Copyright 2005 Logitech Inc.
10
//************************************************************************
11
 
12
#include "LCDProgressBar.h"
13
 
14
 
15
//************************************************************************
16
//
17
// CLCDProgressBar::CLCDProgressBar
18
//
19
//************************************************************************
20
 
21
CLCDProgressBar::CLCDProgressBar()
22
{
23
    m_fPos = 0.0f;
24
    m_eStyle = STYLE_CURSOR;
25
    m_Range.nMin = 0;
26
    m_Range.nMax = 100;
27
    m_nCursorWidth = 5;
28
	m_hPen = NULL;
29
}
30
 
31
 
32
//************************************************************************
33
//
34
// CLCDProgressBar::~CLCDProgressBar
35
//
36
//************************************************************************
37
 
38
CLCDProgressBar::~CLCDProgressBar()
39
{
40
	if (m_hPen != NULL)
41
	{
42
		::DeleteObject(m_hPen);
43
		m_hPen = NULL;
44
	}
45
}
46
 
47
 
48
//************************************************************************
49
//
50
// CLCDProgressBar:Initialize
51
//
52
//************************************************************************
53
 
54
HRESULT CLCDProgressBar::Initialize()
55
{
56
 
57
    m_hBrush = (HBRUSH)GetStockObject(WHITE_BRUSH);
58
	m_hPen = ::CreatePen(PS_DOT, 1, RGB(255, 255, 255));
59
 
60
    return CLCDBase::Initialize();
61
}
62
 
63
 
64
//************************************************************************
65
//
66
// CLCDProgressBar::OnDraw
67
//
68
//************************************************************************
69
 
70
void CLCDProgressBar::OnDraw(CLCDGfx &rGfx)
71
{  
72
	HPEN	hOldPen;
73
 
74
    rGfx.ClearScreen();
75
 
76
    // draw the border
77
    RECT r = { 0, 0, GetWidth(), GetHeight() };
78
 
79
    FrameRect(rGfx.GetHDC(), &r, m_hBrush);
80
 
81
    // draw the progress
82
    switch(m_eStyle)
83
    {
84
    case STYLE_CURSOR:
85
        {
86
            int nCursorPos = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax,
87
                                   (float)1, (float)(GetWidth() - m_nCursorWidth-1),
88
                                   m_fPos);
89
            r.left = nCursorPos;
90
            r.right = r.left + m_nCursorWidth;
91
            FillRect(rGfx.GetHDC(), &r, m_hBrush);
92
        }
93
        break;
94
    case STYLE_FILLED:
95
        {
96
            int nBarWidth = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax,
97
                                  0.0f, (float)GetWidth(),
98
                                  m_fPos);
99
            r.right = nBarWidth;
100
            FillRect(rGfx.GetHDC(), &r, m_hBrush);
101
        }
102
        break;
103
    case STYLE_DASHED_CURSOR:
104
        {
105
            int nCursorPos = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax,
106
                                   (float)1, (float)(GetWidth() - m_nCursorWidth-1),
107
                                   m_fPos);
108
            r.left = nCursorPos;
109
            r.right = r.left + m_nCursorWidth;
110
            FillRect(rGfx.GetHDC(), &r, m_hBrush);
111
			hOldPen = (HPEN)::SelectObject(rGfx.GetHDC(), m_hPen);
112
 
113
			::MoveToEx(rGfx.GetHDC(), 0, (r.bottom - r.top)/2, NULL);
114
			::LineTo(rGfx.GetHDC(), nCursorPos, (r.bottom - r.top)/2);
115
			::SelectObject(rGfx.GetHDC(), hOldPen);
116
       }
117
        break;
118
    default:
119
        break;
120
    }
121
}
122
 
123
 
124
//************************************************************************
125
//
126
// CLCDProgressBar::ResetUpdate
127
//
128
//************************************************************************
129
 
130
void CLCDProgressBar::ResetUpdate()
131
{
132
 
133
}
134
 
135
 
136
//************************************************************************
137
//
138
// CLCDProgressBar::SetRange
139
//
140
//************************************************************************
141
 
142
void CLCDProgressBar::SetRange(int nMin, int nMax)
143
{
144
    m_Range.nMin = nMin;
145
    m_Range.nMax = nMax;
146
}
147
 
148
 
149
//************************************************************************
150
//
151
// CLCDProgressBar::SetRange
152
//
153
//************************************************************************
154
 
155
void CLCDProgressBar::SetRange(RANGE& Range)
156
{
157
    m_Range = Range;
158
}
159
 
160
 
161
//************************************************************************
162
//
163
// CLCDProgressBar::GetRange
164
//
165
//************************************************************************
166
 
167
RANGE& CLCDProgressBar::GetRange()
168
{
169
    return m_Range;
170
}
171
 
172
 
173
//************************************************************************
174
//
175
// CLCDProgressBar::SetPos
176
//
177
//************************************************************************
178
 
179
float CLCDProgressBar::SetPos(float fPos)
180
{
181
    return ( m_fPos = max((float)m_Range.nMin, min(fPos, (float)m_Range.nMax)) );
182
}
183
 
184
 
185
//************************************************************************
186
//
187
// CLCDProgressBar::GetPos
188
//
189
//************************************************************************
190
 
191
float CLCDProgressBar::GetPos()
192
{
193
    return m_fPos;
194
}
195
 
196
 
197
//************************************************************************
198
//
199
// CLCDProgressBar::EnableCursor
200
//
201
//************************************************************************
202
 
203
void CLCDProgressBar::EnableCursor(BOOL bEnable)
204
{
205
    m_eStyle = bEnable ? STYLE_CURSOR : STYLE_FILLED;
206
}
207
 
208
//************************************************************************
209
//
210
// CLCDProgressBar::SetProgressStyle
211
//
212
//************************************************************************
213
 
214
void CLCDProgressBar::SetProgressStyle(ePROGRESS_STYLE eStyle)
215
{
216
	m_eStyle = eStyle;
217
}
218
 
219
//************************************************************************
220
//
221
// CLCDProgressBar::Scalef
222
//
223
//************************************************************************
224
 
225
float CLCDProgressBar::Scalef(float fFromMin, float fFromMax,
226
                             float fToMin, float fToMax, float fFromValue)
227
{
228
 
229
    // normalize the input
230
    float fFromValueN = (fFromValue - fFromMin) / (fFromMax - fFromMin);
231
 
232
    // now scale to the output
233
    float fToRange = fToMax - fToMin;
234
 
235
    return ( fToMin + (fFromValueN * fToRange) );
236
}
237
 
238
 
239
//************************************************************************
240
//
241
// CLCDProgressBar::Scale
242
//
243
//************************************************************************
244
 
245
int CLCDProgressBar::Scale(int nFromMin, int nFromMax,
246
                           int nToMin, int nToMax, int nFromValue)
247
{
248
    return (int)Scalef(
249
        (float)nFromMin,
250
        (float)nFromMax,
251
        (float)nToMin,
252
        (float)nToMax,
253
        (float)nFromValue
254
        );
255
}
256
 
257
 
258
//** end of LCDProgressBar.cpp *******************************************