2 /* INCLUDES *****************************************************************/
9 /* FUNCTIONS ****************************************************************/
13 DrawBorder(PPROGRESSBAR Bar
)
19 /* draw upper left corner */
21 coPos
.Y
= Bar
->Top
+ 1;
22 FillConsoleOutputCharacterA(StdOutput
,
29 coPos
.X
= Bar
->Left
+ 1;
30 coPos
.Y
= Bar
->Top
+ 1;
31 FillConsoleOutputCharacterA(StdOutput
,
33 Bar
->Right
- Bar
->Left
- 1,
37 /* draw upper right corner */
39 coPos
.Y
= Bar
->Top
+ 1;
40 FillConsoleOutputCharacterA(StdOutput
,
46 /* draw left and right edge */
47 for (i
= Bar
->Top
+ 2; i
< Bar
->Bottom
; i
++)
51 FillConsoleOutputCharacterA(StdOutput
,
58 FillConsoleOutputCharacterA(StdOutput
,
65 /* draw lower left corner */
67 coPos
.Y
= Bar
->Bottom
;
68 FillConsoleOutputCharacterA(StdOutput
,
75 coPos
.X
= Bar
->Left
+ 1;
76 coPos
.Y
= Bar
->Bottom
;
77 FillConsoleOutputCharacterA(StdOutput
,
79 Bar
->Right
- Bar
->Left
- 1,
83 /* draw lower right corner */
85 coPos
.Y
= Bar
->Bottom
;
86 FillConsoleOutputCharacterA(StdOutput
,
94 DrawThickBorder(PPROGRESSBAR Bar
)
100 /* draw upper left corner */
102 coPos
.Y
= Bar
->Top
+ 1;
103 FillConsoleOutputCharacterA(StdOutput
,
109 /* draw upper edge */
110 coPos
.X
= Bar
->Left
+ 1;
111 coPos
.Y
= Bar
->Top
+ 1;
112 FillConsoleOutputCharacterA(StdOutput
,
114 Bar
->Right
- Bar
->Left
- 1,
118 /* draw upper right corner */
119 coPos
.X
= Bar
->Right
;
120 coPos
.Y
= Bar
->Top
+ 1;
121 FillConsoleOutputCharacterA(StdOutput
,
127 /* draw left and right edge */
128 for (i
= Bar
->Top
+ 2; i
< Bar
->Bottom
; i
++)
132 FillConsoleOutputCharacterA(StdOutput
,
138 coPos
.X
= Bar
->Right
;
139 FillConsoleOutputCharacterA(StdOutput
,
146 /* draw lower left corner */
148 coPos
.Y
= Bar
->Bottom
;
149 FillConsoleOutputCharacterA(StdOutput
,
155 /* draw lower edge */
156 coPos
.X
= Bar
->Left
+ 1;
157 coPos
.Y
= Bar
->Bottom
;
158 FillConsoleOutputCharacterA(StdOutput
,
160 Bar
->Right
- Bar
->Left
- 1,
164 /* draw lower right corner */
165 coPos
.X
= Bar
->Right
;
166 coPos
.Y
= Bar
->Bottom
;
167 FillConsoleOutputCharacterA(StdOutput
,
175 DrawProgressBar(PPROGRESSBAR Bar
)
180 PROGRESSBAR BarBorder
= *Bar
;
182 /* Print percentage */
183 sprintf(TextBuffer
, "%-3lu%%", Bar
->Percent
);
185 coPos
.X
= Bar
->Left
+ (Bar
->Width
- 2) / 2;
187 WriteConsoleOutputCharacterA(StdOutput
,
193 /* Draw the progress bar border */
196 /* Write Text Associated with Bar */
197 CONSOLE_SetTextXY(Bar
->TextTop
, Bar
->TextRight
, Bar
->Text
);
199 /* Draw the progress bar "border" border */
203 BarBorder
.Bottom
+= 2;
204 BarBorder
.Right
+= 5;
206 DrawThickBorder(&BarBorder
);
210 coPos
.X
= Bar
->Left
+ 1;
211 for (coPos
.Y
= Bar
->Top
+ 2; coPos
.Y
<= Bar
->Bottom
- 1; coPos
.Y
++)
213 FillConsoleOutputAttribute(StdOutput
,
214 FOREGROUND_YELLOW
| BACKGROUND_BLUE
,
219 FillConsoleOutputCharacterA(StdOutput
,
231 CreateProgressBar(SHORT Left
,
237 IN BOOLEAN DoubleEdge
,
242 Bar
= (PPROGRESSBAR
)RtlAllocateHeap(ProcessHeap
,
244 sizeof(PROGRESSBAR
));
251 Bar
->Bottom
= Bottom
;
252 Bar
->TextTop
= TextTop
;
253 Bar
->TextRight
= TextRight
;
254 Bar
->Double
= DoubleEdge
;
257 Bar
->Width
= Bar
->Right
- Bar
->Left
+ 1;
263 Bar
->CurrentStep
= 0;
265 DrawProgressBar(Bar
);
272 DestroyProgressBar(PPROGRESSBAR Bar
)
274 RtlFreeHeap(ProcessHeap
,
280 ProgressSetStepCount(PPROGRESSBAR Bar
,
283 Bar
->CurrentStep
= 0;
284 Bar
->StepCount
= StepCount
;
286 DrawProgressBar(Bar
);
291 ProgressNextStep(PPROGRESSBAR Bar
)
299 if ((Bar
->StepCount
== 0) ||
300 (Bar
->CurrentStep
== Bar
->StepCount
))
305 /* Calculate new percentage */
306 NewPercent
= (ULONG
)(((100.0 * (float)Bar
->CurrentStep
) / (float)Bar
->StepCount
) + 0.5);
308 /* Redraw precentage if changed */
309 if (Bar
->Percent
!= NewPercent
)
311 Bar
->Percent
= NewPercent
;
313 sprintf(TextBuffer
, "%-3lu%%", Bar
->Percent
);
315 coPos
.X
= Bar
->Left
+ (Bar
->Width
- 2) / 2;
317 WriteConsoleOutputCharacterA(StdOutput
,
324 /* Calculate bar position */
325 NewPos
= (ULONG
)((((float)(Bar
->Width
- 2) * 2.0 * (float)Bar
->CurrentStep
) / (float)Bar
->StepCount
) + 0.5);
327 /* Redraw bar if changed */
328 if (Bar
->Pos
!= NewPos
)
332 for (coPos
.Y
= Bar
->Top
+ 2; coPos
.Y
<= Bar
->Bottom
- 1; coPos
.Y
++)
334 coPos
.X
= Bar
->Left
+ 1;
335 FillConsoleOutputCharacterA(StdOutput
,
340 coPos
.X
+= Bar
->Pos
/2;
344 FillConsoleOutputCharacterA(StdOutput
,
352 if (coPos
.X
<= Bar
->Right
- 1)
354 FillConsoleOutputCharacterA(StdOutput
,
356 Bar
->Right
- coPos
.X
,
366 ProgressSetStep (PPROGRESSBAR Bar
,
375 if (Step
> Bar
->StepCount
)
378 Bar
->CurrentStep
= Step
;
380 /* Calculate new percentage */
381 NewPercent
= (ULONG
)(((100.0 * (float)Bar
->CurrentStep
) / (float)Bar
->StepCount
) + 0.5);
383 /* Redraw precentage if changed */
384 if (Bar
->Percent
!= NewPercent
)
386 Bar
->Percent
= NewPercent
;
388 sprintf(TextBuffer
, "%-3lu%%", Bar
->Percent
);
390 coPos
.X
= Bar
->Left
+ (Bar
->Width
- 2) / 2;
392 WriteConsoleOutputCharacterA(StdOutput
,
399 /* Calculate bar position */
400 NewPos
= (ULONG
)((((float)(Bar
->Width
- 2) * 2.0 * (float)Bar
->CurrentStep
) / (float)Bar
->StepCount
) + 0.5);
402 /* Redraw bar if changed */
403 if (Bar
->Pos
!= NewPos
)
407 for (coPos
.Y
= Bar
->Top
+ 2; coPos
.Y
<= Bar
->Bottom
- 1; coPos
.Y
++)
409 coPos
.X
= Bar
->Left
+ 1;
410 FillConsoleOutputCharacterA(StdOutput
,
415 coPos
.X
+= Bar
->Pos
/2;
419 FillConsoleOutputCharacterA(StdOutput
,
427 if (coPos
.X
<= Bar
->Right
- 1)
429 FillConsoleOutputCharacterA(StdOutput
,
431 Bar
->Right
- coPos
.X
,