Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /***************************************************************************** |
2 | * Module for Microchip Graphics Library |
||
3 | * GOL Layer |
||
4 | * Progress Bar |
||
5 | ***************************************************************************** |
||
6 | * FileName: ProgressBar.c |
||
7 | * Dependencies: Graphics.h |
||
8 | * Processor: PIC24F, PIC24H, dsPIC, PIC32 |
||
9 | * Compiler: MPLAB C30 V3.00, MPLAB C32 |
||
10 | * Linker: MPLAB LINK30, MPLAB LINK32 |
||
11 | * Company: Microchip Technology Incorporated |
||
12 | * |
||
13 | * Software License Agreement |
||
14 | * |
||
15 | * Copyright © 2008 Microchip Technology Inc. All rights reserved. |
||
16 | * Microchip licenses to you the right to use, modify, copy and distribute |
||
17 | * Software only when embedded on a Microchip microcontroller or digital |
||
18 | * signal controller, which is integrated into your product or third party |
||
19 | * product (pursuant to the sublicense terms in the accompanying license |
||
20 | * agreement). |
||
21 | * |
||
22 | * You should refer to the license agreement accompanying this Software |
||
23 | * for additional information regarding your rights and obligations. |
||
24 | * |
||
25 | * SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY |
||
26 | * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY |
||
27 | * OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR |
||
28 | * PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR |
||
29 | * OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, |
||
30 | * BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT |
||
31 | * DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, |
||
32 | * INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, |
||
33 | * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY |
||
34 | * CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), |
||
35 | * OR OTHER SIMILAR COSTS. |
||
36 | * |
||
37 | * Author Date Comment |
||
38 | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
39 | * Anton Alkhimenok 11/12/07 Version 1.0 release |
||
40 | *****************************************************************************/ |
||
41 | #include "Graphics\Graphics.h" |
||
42 | |||
43 | #ifdef USE_PROGRESSBAR |
||
44 | |||
45 | /********************************************************************* |
||
46 | * Function: void PbWordToString(WORD value, XCHAR* buffer) |
||
47 | * |
||
48 | * Input: value - value to be converted (from 0 - 100) |
||
49 | * buffer - buffer receiving string (must be at least 5 bytes) |
||
50 | * |
||
51 | * Output: none |
||
52 | * |
||
53 | * Overview: converts SHORT into string with % at the end |
||
54 | * |
||
55 | ********************************************************************/ |
||
56 | void PbWordToString(WORD value, XCHAR *buffer) |
||
57 | { |
||
58 | WORD result; |
||
59 | BYTE pos; |
||
60 | |||
61 | if(value > 99) |
||
62 | { |
||
63 | buffer[0] = '1'; |
||
64 | buffer[1] = '0'; |
||
65 | buffer[2] = '0'; |
||
66 | buffer[3] = '%'; |
||
67 | buffer[4] = 0; |
||
68 | return; |
||
69 | } |
||
70 | |||
71 | pos = 0; |
||
72 | result = value / 10; |
||
73 | if(result) |
||
74 | buffer[pos++] = result + '0'; |
||
75 | result = value - 10 * result; |
||
76 | |||
77 | buffer[pos++] = result + '0'; |
||
78 | buffer[pos++] = '%'; |
||
79 | buffer[pos++] = 0; |
||
80 | } |
||
81 | |||
82 | /********************************************************************* |
||
83 | * Function: PROGRESSBAR *PbCreate(WORD ID, SHORT left, SHORT top, SHORT right, |
||
84 | * SHORT bottom, WORD state, WORD pos, WORD range, |
||
85 | * GOL_SCHEME *pScheme) |
||
86 | * |
||
87 | * Overview: creates the progress bar |
||
88 | * |
||
89 | ********************************************************************/ |
||
90 | PROGRESSBAR *PbCreate |
||
91 | ( |
||
92 | WORD ID, |
||
93 | SHORT left, |
||
94 | SHORT top, |
||
95 | SHORT right, |
||
96 | SHORT bottom, |
||
97 | WORD state, |
||
98 | WORD pos, |
||
99 | WORD range, |
||
100 | GOL_SCHEME *pScheme |
||
101 | ) |
||
102 | { |
||
103 | PROGRESSBAR *pPb = NULL; |
||
104 | |||
105 | pPb = (PROGRESSBAR *)GFX_malloc(sizeof(PROGRESSBAR)); |
||
106 | if(pPb == NULL) |
||
107 | return (pPb); |
||
108 | |||
109 | pPb->hdr.ID = ID; |
||
110 | pPb->hdr.pNxtObj = NULL; |
||
111 | pPb->hdr.type = OBJ_PROGRESSBAR; |
||
112 | pPb->hdr.left = left; |
||
113 | pPb->hdr.top = top; |
||
114 | pPb->hdr.right = right; |
||
115 | pPb->hdr.bottom = bottom; |
||
116 | pPb->pos = pos; |
||
117 | pPb->range = (range == 0) ? 100 : range; |
||
118 | pPb->prevPos = 0; |
||
119 | pPb->hdr.state = state; |
||
120 | |||
121 | // Set the style scheme to be used |
||
122 | if(pScheme == NULL) |
||
123 | pPb->hdr.pGolScheme = _pDefaultGolScheme; |
||
124 | else |
||
125 | pPb->hdr.pGolScheme = (GOL_SCHEME *)pScheme; |
||
126 | |||
127 | GOLAddObject((OBJ_HEADER *)pPb); |
||
128 | |||
129 | return (pPb); |
||
130 | } |
||
131 | |||
132 | /********************************************************************* |
||
133 | * Function: void PbSetPos(PROGRESSBAR *pPb, SHORT position) |
||
134 | * |
||
135 | * Overview: sets the current position of the progress bar |
||
136 | * |
||
137 | ********************************************************************/ |
||
138 | void PbSetPos(PROGRESSBAR *pPb, WORD position) |
||
139 | { |
||
140 | if(pPb->range < position) |
||
141 | position = pPb->range; |
||
142 | |||
143 | pPb->pos = position; |
||
144 | } |
||
145 | |||
146 | /********************************************************************* |
||
147 | * Function: void PbSetRange(PROGRESSBAR *pPb, WORD range) |
||
148 | * |
||
149 | * Overview: sets the range of the progress bar |
||
150 | * |
||
151 | ********************************************************************/ |
||
152 | void PbSetRange(PROGRESSBAR *pPb, WORD range) |
||
153 | { |
||
154 | |||
155 | // range cannot be assigned a zero value |
||
156 | if(range != 0) |
||
157 | pPb->range = range; |
||
158 | pPb->pos = range; |
||
159 | pPb->prevPos = 0; |
||
160 | } |
||
161 | |||
162 | /********************************************************************* |
||
163 | * Function: WORD PbTranslateMsg(PROGRESSBAR *pPb, GOL_MSG *pMsg) |
||
164 | * |
||
165 | * Overview: translates the GOL message for the progress bar |
||
166 | * |
||
167 | ********************************************************************/ |
||
168 | WORD PbTranslateMsg(PROGRESSBAR *pPb, GOL_MSG *pMsg) |
||
169 | { |
||
170 | |||
171 | // Evaluate if the message is for the progress bar |
||
172 | // Check if disabled first |
||
173 | if(GetState(pPb, PB_DISABLED)) |
||
174 | return (OBJ_MSG_INVALID); |
||
175 | |||
176 | #ifdef USE_TOUCHSCREEN |
||
177 | if(pMsg->type == TYPE_TOUCHSCREEN) |
||
178 | { |
||
179 | |||
180 | // Check if it falls in the progress bar border |
||
181 | if |
||
182 | ( |
||
183 | (pPb->hdr.left < pMsg->param1) && |
||
184 | (pPb->hdr.right > pMsg->param1) && |
||
185 | (pPb->hdr.top < pMsg->param2) && |
||
186 | (pPb->hdr.bottom > pMsg->param2) |
||
187 | ) |
||
188 | { |
||
189 | return (PB_MSG_SELECTED); |
||
190 | } |
||
191 | } |
||
192 | |||
193 | #endif |
||
194 | return (OBJ_MSG_INVALID); |
||
195 | } |
||
196 | |||
197 | /********************************************************************* |
||
198 | * Function: WORD PbDraw(PROGRESSBAR *pPb) |
||
199 | * |
||
200 | * Output: returns the status of the drawing |
||
201 | * 0 - not complete |
||
202 | * 1 - done |
||
203 | * |
||
204 | * Overview: draws progress bar |
||
205 | * |
||
206 | ********************************************************************/ |
||
207 | WORD PbDraw(PROGRESSBAR *pPb) |
||
208 | { |
||
209 | typedef enum |
||
210 | { |
||
211 | REMOVE, |
||
212 | BOX_DRAW, |
||
213 | RUN_DRAW, |
||
214 | BAR_DRAW, |
||
215 | TEXT_DRAW1, |
||
216 | TEXT_DRAW2, |
||
217 | TEXT_DRAW3 |
||
218 | } PB_DRAW_STATES; |
||
219 | |||
220 | static PB_DRAW_STATES state = REMOVE; |
||
221 | static DWORD x1; |
||
222 | volatile DWORD x2; |
||
223 | static XCHAR text[5] = {'0','0','%',0}; |
||
224 | |||
225 | if(IsDeviceBusy()) |
||
226 | return (0); |
||
227 | |||
228 | switch(state) |
||
229 | { |
||
230 | case REMOVE: |
||
231 | if(GetState(pPb, PB_HIDE)) |
||
232 | { |
||
233 | SetColor(pPb->hdr.pGolScheme->CommonBkColor); |
||
234 | if(!Bar(pPb->hdr.left, pPb->hdr.top, pPb->hdr.right, pPb->hdr.bottom)) |
||
235 | return (0); |
||
236 | return (1); |
||
237 | } |
||
238 | |||
239 | state = BOX_DRAW; |
||
240 | |||
241 | case BOX_DRAW: |
||
242 | if(GetState(pPb, PB_DRAW)) |
||
243 | { |
||
244 | GOLPanelDraw |
||
245 | ( |
||
246 | pPb->hdr.left, |
||
247 | pPb->hdr.top, |
||
248 | pPb->hdr.right, |
||
249 | pPb->hdr.bottom, |
||
250 | 0, |
||
251 | pPb->hdr.pGolScheme->Color0, |
||
252 | pPb->hdr.pGolScheme->EmbossDkColor, |
||
253 | pPb->hdr.pGolScheme->EmbossLtColor, |
||
254 | NULL, |
||
255 | GOL_EMBOSS_SIZE |
||
256 | ); |
||
257 | |||
258 | state = RUN_DRAW; |
||
259 | |||
260 | case RUN_DRAW: |
||
261 | if(!GOLPanelDrawTsk()) |
||
262 | return (0); |
||
263 | } |
||
264 | |||
265 | state = BAR_DRAW; |
||
266 | |||
267 | case BAR_DRAW: |
||
268 | if(GetState(pPb, PB_VERTICAL)) |
||
269 | { |
||
270 | x2 = ((DWORD) (pPb->range-pPb->pos)) * (pPb->hdr.bottom - pPb->hdr.top - (2 * GOL_EMBOSS_SIZE)) / pPb->range; |
||
271 | x1 = ((DWORD) (pPb->range-pPb->prevPos)) * (pPb->hdr.bottom - pPb->hdr.top - (2 * GOL_EMBOSS_SIZE)) / pPb->range; |
||
272 | x1 += (pPb->hdr.top + GOL_EMBOSS_SIZE); |
||
273 | x2 += (pPb->hdr.top + GOL_EMBOSS_SIZE); |
||
274 | } |
||
275 | else |
||
276 | { |
||
277 | x1 = ((DWORD) pPb->pos) * (pPb->hdr.right - pPb->hdr.left - (2 * GOL_EMBOSS_SIZE)) / pPb->range; |
||
278 | x2 = ((DWORD) pPb->prevPos) * (pPb->hdr.right - pPb->hdr.left - (2 * GOL_EMBOSS_SIZE)) / pPb->range; |
||
279 | x1 += (pPb->hdr.left + GOL_EMBOSS_SIZE); |
||
280 | x2 += (pPb->hdr.left + GOL_EMBOSS_SIZE); |
||
281 | } |
||
282 | |||
283 | if(pPb->prevPos > pPb->pos) |
||
284 | { |
||
285 | SetColor(pPb->hdr.pGolScheme->Color0); |
||
286 | if(GetState(pPb, PB_VERTICAL)) |
||
287 | { |
||
288 | if(!Bar(pPb->hdr.left + GOL_EMBOSS_SIZE, x1, pPb->hdr.right - GOL_EMBOSS_SIZE, x2)) |
||
289 | return (0); |
||
290 | } |
||
291 | else |
||
292 | { |
||
293 | if(!Bar(x1, pPb->hdr.top + GOL_EMBOSS_SIZE, x2, pPb->hdr.bottom - GOL_EMBOSS_SIZE)) |
||
294 | return (0); |
||
295 | } |
||
296 | } |
||
297 | else |
||
298 | { |
||
299 | SetColor(pPb->hdr.pGolScheme->Color1); |
||
300 | if(GetState(pPb, PB_VERTICAL)) |
||
301 | { |
||
302 | if(!Bar(pPb->hdr.left + GOL_EMBOSS_SIZE, x2, pPb->hdr.right - GOL_EMBOSS_SIZE, x1)) |
||
303 | return (0); |
||
304 | } |
||
305 | else |
||
306 | { |
||
307 | if(!Bar(x2, pPb->hdr.top + GOL_EMBOSS_SIZE, x1, pPb->hdr.bottom - GOL_EMBOSS_SIZE)) |
||
308 | return (0); |
||
309 | } |
||
310 | } |
||
311 | |||
312 | state = TEXT_DRAW1; |
||
313 | |||
314 | case TEXT_DRAW1: |
||
315 | if(GetState(pPb, PB_VERTICAL)) |
||
316 | { |
||
317 | SetColor(pPb->hdr.pGolScheme->Color0); |
||
318 | if |
||
319 | ( |
||
320 | !Bar |
||
321 | ( |
||
322 | pPb->hdr.left + GOL_EMBOSS_SIZE, |
||
323 | (pPb->hdr.top + pPb->hdr.bottom - GetTextHeight(pPb->hdr.pGolScheme->pFont)) >> 1, |
||
324 | pPb->hdr.right - GOL_EMBOSS_SIZE, |
||
325 | x2 |
||
326 | ) |
||
327 | ) return (0); |
||
328 | } |
||
329 | else |
||
330 | { |
||
331 | SetColor(pPb->hdr.pGolScheme->Color1); |
||
332 | if |
||
333 | ( |
||
334 | !Bar |
||
335 | ( |
||
336 | (pPb->hdr.left + pPb->hdr.right - GetTextWidth(text, pPb->hdr.pGolScheme->pFont)) >> 1, |
||
337 | pPb->hdr.top + GOL_EMBOSS_SIZE, |
||
338 | x1, |
||
339 | pPb->hdr.bottom - GOL_EMBOSS_SIZE |
||
340 | ) |
||
341 | ) return (0); |
||
342 | } |
||
343 | |||
344 | state = TEXT_DRAW2; |
||
345 | |||
346 | case TEXT_DRAW2: |
||
347 | if(GetState(pPb, PB_VERTICAL)) |
||
348 | { |
||
349 | SetColor(pPb->hdr.pGolScheme->Color1); |
||
350 | if |
||
351 | ( |
||
352 | !Bar |
||
353 | ( |
||
354 | pPb->hdr.left + GOL_EMBOSS_SIZE, |
||
355 | x2, |
||
356 | pPb->hdr.right - GOL_EMBOSS_SIZE, |
||
357 | (pPb->hdr.top + pPb->hdr.bottom + GetTextHeight(pPb->hdr.pGolScheme->pFont)) >> 1 |
||
358 | ) |
||
359 | ) return (0); |
||
360 | } |
||
361 | else |
||
362 | { |
||
363 | SetColor(pPb->hdr.pGolScheme->Color0); |
||
364 | if |
||
365 | ( |
||
366 | !Bar |
||
367 | ( |
||
368 | x1, |
||
369 | pPb->hdr.top + GOL_EMBOSS_SIZE, |
||
370 | (pPb->hdr.left + pPb->hdr.right + GetTextWidth(text, pPb->hdr.pGolScheme->pFont)) >> 1, |
||
371 | pPb->hdr.bottom - GOL_EMBOSS_SIZE |
||
372 | ) |
||
373 | ) return (0); |
||
374 | } |
||
375 | |||
376 | PbWordToString((DWORD) pPb->pos * 100 / pPb->range, text); |
||
377 | SetColor(pPb->hdr.pGolScheme->TextColor0); |
||
378 | |||
379 | MoveTo |
||
380 | ( |
||
381 | (pPb->hdr.left + pPb->hdr.right - GetTextWidth(text, pPb->hdr.pGolScheme->pFont)) >> 1, |
||
382 | (pPb->hdr.top + pPb->hdr.bottom - GetTextHeight(pPb->hdr.pGolScheme->pFont)) >> 1 |
||
383 | ); |
||
384 | |||
385 | SetFont(pPb->hdr.pGolScheme->pFont); |
||
386 | state = TEXT_DRAW3; |
||
387 | |||
388 | case TEXT_DRAW3: |
||
389 | if(!OutText(text)) |
||
390 | return (0); |
||
391 | |||
392 | pPb->prevPos = pPb->pos; |
||
393 | state = REMOVE; |
||
394 | return (1); |
||
395 | } |
||
396 | |||
397 | return (1); |
||
398 | } |
||
399 | |||
400 | #endif // USE_PROGRESSBAR |
Powered by WebSVN v2.8.3