Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenprogress.c
Go to the documentation of this file.
00001 00002 /* INCLUDES *****************************************************************/ 00003 00004 #include "usetup.h" 00005 00006 #define NDEBUG 00007 #include <debug.h> 00008 00009 /* FUNCTIONS ****************************************************************/ 00010 00011 00012 static VOID 00013 DrawBorder(PPROGRESSBAR Bar) 00014 { 00015 COORD coPos; 00016 DWORD Written; 00017 SHORT i; 00018 00019 /* draw upper left corner */ 00020 coPos.X = Bar->Left; 00021 coPos.Y = Bar->Top + 1; 00022 FillConsoleOutputCharacterA(StdOutput, 00023 0xDA, // '+', 00024 1, 00025 coPos, 00026 &Written); 00027 00028 /* draw upper edge */ 00029 coPos.X = Bar->Left + 1; 00030 coPos.Y = Bar->Top + 1; 00031 FillConsoleOutputCharacterA(StdOutput, 00032 0xC4, // '-', 00033 Bar->Right - Bar->Left - 1, 00034 coPos, 00035 &Written); 00036 00037 /* draw upper right corner */ 00038 coPos.X = Bar->Right; 00039 coPos.Y = Bar->Top + 1; 00040 FillConsoleOutputCharacterA(StdOutput, 00041 0xBF, // '+', 00042 1, 00043 coPos, 00044 &Written); 00045 00046 /* draw left and right edge */ 00047 for (i = Bar->Top + 2; i < Bar->Bottom; i++) 00048 { 00049 coPos.X = Bar->Left; 00050 coPos.Y = i; 00051 FillConsoleOutputCharacterA(StdOutput, 00052 0xB3, // '|', 00053 1, 00054 coPos, 00055 &Written); 00056 00057 coPos.X = Bar->Right; 00058 FillConsoleOutputCharacterA(StdOutput, 00059 0xB3, //'|', 00060 1, 00061 coPos, 00062 &Written); 00063 } 00064 00065 /* draw lower left corner */ 00066 coPos.X = Bar->Left; 00067 coPos.Y = Bar->Bottom; 00068 FillConsoleOutputCharacterA(StdOutput, 00069 0xC0, // '+', 00070 1, 00071 coPos, 00072 &Written); 00073 00074 /* draw lower edge */ 00075 coPos.X = Bar->Left + 1; 00076 coPos.Y = Bar->Bottom; 00077 FillConsoleOutputCharacterA(StdOutput, 00078 0xC4, // '-', 00079 Bar->Right - Bar->Left - 1, 00080 coPos, 00081 &Written); 00082 00083 /* draw lower right corner */ 00084 coPos.X = Bar->Right; 00085 coPos.Y = Bar->Bottom; 00086 FillConsoleOutputCharacterA(StdOutput, 00087 0xD9, // '+', 00088 1, 00089 coPos, 00090 &Written); 00091 } 00092 00093 static VOID 00094 DrawThickBorder(PPROGRESSBAR Bar) 00095 { 00096 COORD coPos; 00097 DWORD Written; 00098 SHORT i; 00099 00100 /* draw upper left corner */ 00101 coPos.X = Bar->Left; 00102 coPos.Y = Bar->Top + 1; 00103 FillConsoleOutputCharacterA(StdOutput, 00104 0xC9, // '+', 00105 1, 00106 coPos, 00107 &Written); 00108 00109 /* draw upper edge */ 00110 coPos.X = Bar->Left + 1; 00111 coPos.Y = Bar->Top + 1; 00112 FillConsoleOutputCharacterA(StdOutput, 00113 0xCD, // '-', 00114 Bar->Right - Bar->Left - 1, 00115 coPos, 00116 &Written); 00117 00118 /* draw upper right corner */ 00119 coPos.X = Bar->Right; 00120 coPos.Y = Bar->Top + 1; 00121 FillConsoleOutputCharacterA(StdOutput, 00122 0xBB, // '+', 00123 1, 00124 coPos, 00125 &Written); 00126 00127 /* draw left and right edge */ 00128 for (i = Bar->Top + 2; i < Bar->Bottom; i++) 00129 { 00130 coPos.X = Bar->Left; 00131 coPos.Y = i; 00132 FillConsoleOutputCharacterA(StdOutput, 00133 0xBA, // '|', 00134 1, 00135 coPos, 00136 &Written); 00137 00138 coPos.X = Bar->Right; 00139 FillConsoleOutputCharacterA(StdOutput, 00140 0xBA, //'|', 00141 1, 00142 coPos, 00143 &Written); 00144 } 00145 00146 /* draw lower left corner */ 00147 coPos.X = Bar->Left; 00148 coPos.Y = Bar->Bottom; 00149 FillConsoleOutputCharacterA(StdOutput, 00150 0xC8, // '+', 00151 1, 00152 coPos, 00153 &Written); 00154 00155 /* draw lower edge */ 00156 coPos.X = Bar->Left + 1; 00157 coPos.Y = Bar->Bottom; 00158 FillConsoleOutputCharacterA(StdOutput, 00159 0xCD, // '-', 00160 Bar->Right - Bar->Left - 1, 00161 coPos, 00162 &Written); 00163 00164 /* draw lower right corner */ 00165 coPos.X = Bar->Right; 00166 coPos.Y = Bar->Bottom; 00167 FillConsoleOutputCharacterA(StdOutput, 00168 0xBC, // '+', 00169 1, 00170 coPos, 00171 &Written); 00172 } 00173 00174 static VOID 00175 DrawProgressBar(PPROGRESSBAR Bar) 00176 { 00177 CHAR TextBuffer[8]; 00178 COORD coPos; 00179 DWORD Written; 00180 PROGRESSBAR BarBorder = *Bar; 00181 00182 /* Print percentage */ 00183 sprintf(TextBuffer, "%-3lu%%", Bar->Percent); 00184 00185 coPos.X = Bar->Left + (Bar->Width - 2) / 2; 00186 coPos.Y = Bar->Top; 00187 WriteConsoleOutputCharacterA(StdOutput, 00188 TextBuffer, 00189 4, 00190 coPos, 00191 &Written); 00192 00193 /* Draw the progress bar border */ 00194 DrawBorder(Bar); 00195 00196 /* Write Text Associated with Bar */ 00197 CONSOLE_SetTextXY(Bar->TextTop, Bar->TextRight, Bar->Text); 00198 00199 /* Draw the progress bar "border" border */ 00200 if (Bar->Double) 00201 { 00202 BarBorder.Top -= 5; 00203 BarBorder.Bottom += 2; 00204 BarBorder.Right += 5; 00205 BarBorder.Left -= 5; 00206 DrawThickBorder(&BarBorder); 00207 } 00208 00209 /* Draw the bar */ 00210 coPos.X = Bar->Left + 1; 00211 for (coPos.Y = Bar->Top + 2; coPos.Y <= Bar->Bottom - 1; coPos.Y++) 00212 { 00213 FillConsoleOutputAttribute(StdOutput, 00214 FOREGROUND_YELLOW | BACKGROUND_BLUE, 00215 Bar->Width - 2, 00216 coPos, 00217 &Written); 00218 00219 FillConsoleOutputCharacterA(StdOutput, 00220 ' ', 00221 Bar->Width - 2, 00222 coPos, 00223 &Written); 00224 } 00225 00226 } 00227 00228 00229 00230 PPROGRESSBAR 00231 CreateProgressBar(SHORT Left, 00232 SHORT Top, 00233 SHORT Right, 00234 SHORT Bottom, 00235 SHORT TextTop, 00236 SHORT TextRight, 00237 IN BOOLEAN DoubleEdge, 00238 char* Text) 00239 { 00240 PPROGRESSBAR Bar; 00241 00242 Bar = (PPROGRESSBAR)RtlAllocateHeap(ProcessHeap, 00243 0, 00244 sizeof(PROGRESSBAR)); 00245 if (Bar == NULL) 00246 return(NULL); 00247 00248 Bar->Left = Left; 00249 Bar->Top = Top; 00250 Bar->Right = Right; 00251 Bar->Bottom = Bottom; 00252 Bar->TextTop = TextTop; 00253 Bar->TextRight = TextRight; 00254 Bar->Double = DoubleEdge; 00255 Bar->Text = Text; 00256 00257 Bar->Width = Bar->Right - Bar->Left + 1; 00258 00259 Bar->Percent = 0; 00260 Bar->Pos = 0; 00261 00262 Bar->StepCount = 0; 00263 Bar->CurrentStep = 0; 00264 00265 DrawProgressBar(Bar); 00266 00267 return(Bar); 00268 } 00269 00270 00271 VOID 00272 DestroyProgressBar(PPROGRESSBAR Bar) 00273 { 00274 RtlFreeHeap(ProcessHeap, 00275 0, 00276 Bar); 00277 } 00278 00279 VOID 00280 ProgressSetStepCount(PPROGRESSBAR Bar, 00281 ULONG StepCount) 00282 { 00283 Bar->CurrentStep = 0; 00284 Bar->StepCount = StepCount; 00285 00286 DrawProgressBar(Bar); 00287 } 00288 00289 00290 VOID 00291 ProgressNextStep(PPROGRESSBAR Bar) 00292 { 00293 ProgressSetStep(Bar, Bar->CurrentStep + 1); 00294 } 00295 00296 00297 VOID 00298 ProgressSetStep (PPROGRESSBAR Bar, 00299 ULONG Step) 00300 { 00301 CHAR TextBuffer[8]; 00302 COORD coPos; 00303 DWORD Written; 00304 ULONG NewPercent; 00305 ULONG NewPos; 00306 00307 if (Step > Bar->StepCount) 00308 return; 00309 00310 Bar->CurrentStep = Step; 00311 00312 /* Calculate new percentage */ 00313 NewPercent = (ULONG)(((100.0 * (float)Bar->CurrentStep) / (float)Bar->StepCount) + 0.5); 00314 00315 /* Redraw precentage if changed */ 00316 if (Bar->Percent != NewPercent) 00317 { 00318 Bar->Percent = NewPercent; 00319 00320 sprintf(TextBuffer, "%-3lu%%", Bar->Percent); 00321 00322 coPos.X = Bar->Left + (Bar->Width - 2) / 2; 00323 coPos.Y = Bar->Top; 00324 WriteConsoleOutputCharacterA(StdOutput, 00325 TextBuffer, 00326 4, 00327 coPos, 00328 &Written); 00329 } 00330 00331 /* Calculate bar position */ 00332 NewPos = (ULONG)((((float)(Bar->Width - 2) * 2.0 * (float)Bar->CurrentStep) / (float)Bar->StepCount) + 0.5); 00333 00334 /* Redraw bar if changed */ 00335 if (Bar->Pos != NewPos) 00336 { 00337 Bar->Pos = NewPos; 00338 00339 for (coPos.Y = Bar->Top + 2; coPos.Y <= Bar->Bottom - 1; coPos.Y++) 00340 { 00341 coPos.X = Bar->Left + 1; 00342 FillConsoleOutputCharacterA(StdOutput, 00343 0xDB, 00344 Bar->Pos / 2, 00345 coPos, 00346 &Written); 00347 coPos.X += Bar->Pos/2; 00348 00349 if (NewPos & 1) 00350 { 00351 FillConsoleOutputCharacterA(StdOutput, 00352 0xDD, 00353 1, 00354 coPos, 00355 &Written); 00356 coPos.X++; 00357 } 00358 00359 if (coPos.X <= Bar->Right - 1) 00360 { 00361 FillConsoleOutputCharacterA(StdOutput, 00362 ' ', 00363 Bar->Right - coPos.X, 00364 coPos, 00365 &Written); 00366 } 00367 } 00368 } 00369 } 00370 00371 /* EOF */ Generated on Mon May 28 2012 04:16:57 for ReactOS by
1.7.6.1
|