Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

220 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. dngauge.c
  5. Abstract:
  6. Code implementing a gas gauge for file copies for DOS-hosted NT Setup.
  7. Author:
  8. Ted Miller (tedm) 14-April-1992
  9. Revision History:
  10. --*/
  11. #include "enduser.h"
  12. #define THERM_WIDTH 500
  13. #define THERM_HEIGHT 18
  14. #define FRAME_THICK 2
  15. #define MARGIN_LEFT 5
  16. #define MARGIN_RIGHT 5
  17. #define MARGIN_TOP 6
  18. #define MARGIN_BOTTOM (CharHeight+4)
  19. #define FRAME_WIDTH (THERM_WIDTH+(2*FRAME_THICK)+MARGIN_LEFT+MARGIN_RIGHT)
  20. #define FRAME_HEIGHT (THERM_HEIGHT+(2*FRAME_THICK)+MARGIN_TOP+MARGIN_BOTTOM)
  21. #define FRAME_X ((640-FRAME_WIDTH)/2)
  22. #define FRAME_Y 300
  23. #define THERM_X (FRAME_X + FRAME_THICK + MARGIN_LEFT)
  24. #define THERM_Y (FRAME_Y + FRAME_THICK + MARGIN_TOP)
  25. #define FRAME_COLOR VGAPIX_LIGHT_GRAY
  26. #define MARGIN_COLOR VGAPIX_BLUE
  27. #define THERM_COLOR VGAPIX_LIGHT_YELLOW
  28. ULONG TickCount;
  29. ULONG TickedSoFar;
  30. unsigned CurrentPercent;
  31. unsigned CurrentThermWidth;
  32. extern BYTE CharWidth;
  33. extern BYTE CharHeight;
  34. VOID
  35. pGaugeDraw(
  36. VOID
  37. );
  38. VOID
  39. GaugeInit(
  40. IN ULONG RangeMax
  41. )
  42. /*++
  43. Routine Description:
  44. Initialize the gas gauge. This includes drawing the gas gauge at 0%
  45. and setting some global variables.
  46. Arguments:
  47. RangeMax - supplies maximum tick count that 100% represents.
  48. Return Value:
  49. None.
  50. --*/
  51. {
  52. TickCount = RangeMax;
  53. TickedSoFar = 0;
  54. CurrentPercent = 0;
  55. CurrentThermWidth = 0;
  56. pGaugeDraw();
  57. }
  58. VOID
  59. DnpRepaintGaugeTherm(
  60. IN BOOL ForceRepaint
  61. )
  62. /*++
  63. Routine Description:
  64. Draw the entire gauge in its current state.
  65. Arguments:
  66. ForceRepaint - if TRUE, the gauge is redrawn even if the percentage
  67. hasn't changed since the last time the gauge was redrawn.
  68. Return Value:
  69. None.
  70. --*/
  71. {
  72. unsigned PercentComplete;
  73. unsigned Width;
  74. char text[10];
  75. if(!TickCount) {
  76. return;
  77. }
  78. //
  79. // Figure out the percent complete and how many pixels
  80. // of width the current tick count represents on-screen.
  81. //
  82. PercentComplete = (unsigned)(100L * TickedSoFar / TickCount);
  83. Width = (unsigned)(THERM_WIDTH * TickedSoFar / TickCount);
  84. if(ForceRepaint || (Width != CurrentThermWidth)) {
  85. CurrentThermWidth = Width;
  86. VgaClearRegion(THERM_X,THERM_Y,Width,THERM_HEIGHT,THERM_COLOR);
  87. if(ForceRepaint || (CurrentPercent != PercentComplete)) {
  88. CurrentPercent = PercentComplete;
  89. Width = sprintf(text,"%u%%",CurrentPercent);
  90. FontWriteString(
  91. text,
  92. (640-(CharWidth*Width))/2,
  93. THERM_Y + THERM_HEIGHT + ((MARGIN_BOTTOM-CharHeight)/2) + 1,
  94. VGAPIX_LIGHT_GRAY,
  95. VGAPIX_BLUE
  96. );
  97. }
  98. }
  99. }
  100. VOID
  101. GaugeDelta(
  102. IN ULONG Delta
  103. )
  104. /*++
  105. Routine Description:
  106. 'Tick' the gas gauge by adding a given delta to the progress so far.
  107. Adjust the thermometer and percent-complete readouts.
  108. Arguments:
  109. Delta - supplies additional progress units.
  110. Return Value:
  111. None.
  112. --*/
  113. {
  114. TickedSoFar += Delta;
  115. if(TickedSoFar > TickCount) {
  116. TickedSoFar = TickCount;
  117. }
  118. DnpRepaintGaugeTherm(FALSE);
  119. }
  120. VOID
  121. pGaugeDraw(
  122. VOID
  123. )
  124. /*++
  125. Routine Description:
  126. Redraw the gas gauge in its current state.
  127. Arguments:
  128. None.
  129. Return Value:
  130. None.
  131. --*/
  132. {
  133. VgaClearRegion(FRAME_X,FRAME_Y,FRAME_WIDTH,FRAME_HEIGHT,FRAME_COLOR);
  134. VgaClearRegion(
  135. FRAME_X + FRAME_THICK,
  136. FRAME_Y + FRAME_THICK,
  137. FRAME_WIDTH - (2*FRAME_THICK),
  138. FRAME_HEIGHT - (2*FRAME_THICK),
  139. MARGIN_COLOR
  140. );
  141. DnpRepaintGaugeTherm(TRUE);
  142. }