BAR.CPP 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/BAR.CPP 1 3/03/97 10:24a Joe_bostic $ */
  15. /***********************************************************************************************
  16. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : BAR.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 08/16/96 *
  26. * *
  27. * Last Update : August 16, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * ProgressBarClass::Is_Horizontal -- Determines if the bargraph is horizontal or not. *
  32. * ProgressBarClass::Outline -- Draw an outline around the bargraph if supposed to. *
  33. * ProgressBarClass::ProgressBarClass -- Constructor for the bargraph object. *
  34. * ProgressBarClass::Redraw -- Redraw the bargraph. *
  35. * ProgressBarClass::Set_Limit -- Set the logic tracking value. *
  36. * ProgressBarClass::Update -- Update the value and redraw as necessary. *
  37. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  38. #include "function.h"
  39. #include "bar.h"
  40. #include "fixed.h"
  41. /***********************************************************************************************
  42. * ProgressBarClass::ProgressBarClass -- Constructor for the bargraph object. *
  43. * *
  44. * This is the constructor for the bargraph object. It establishes the dimensions and *
  45. * coordinate of the bargraph as well as the colors it will use when drawn. *
  46. * *
  47. * INPUT: w,y -- Pixel coordinate of the upper left corner of the bargraph. *
  48. * *
  49. * width,height -- Dimensions of the bargraph. *
  50. * *
  51. * forecolor -- The color to use for the filled portion of the bargraph. *
  52. * *
  53. * backcolor -- The color to use for the non-filled portion of the bargraph. *
  54. * *
  55. * bordercolor -- Optional border color. If not zero, then the bargraph will be *
  56. * outlined with this color. *
  57. * *
  58. * OUTPUT: none *
  59. * *
  60. * WARNINGS: none *
  61. * *
  62. * HISTORY: *
  63. * 08/16/1996 JLB : Created. *
  64. *=============================================================================================*/
  65. ProgressBarClass::ProgressBarClass(int x, int y, int width, int height, int forecolor, int backcolor, int bordercolor) :
  66. X(x),
  67. Y(y),
  68. Width(width),
  69. Height(height),
  70. BarColor(forecolor),
  71. BackColor(backcolor),
  72. BorderColor(bordercolor),
  73. CurrentValue(0),
  74. LastDisplayCurrent(0),
  75. IsDrawn(false)
  76. {
  77. }
  78. /***********************************************************************************************
  79. * ProgressBarClass::Is_Horizontal -- Determines if the bargraph is horizontal or not. *
  80. * *
  81. * If the bargraph is oriented horizontally, then this function will return TRUE. *
  82. * *
  83. * INPUT: none *
  84. * *
  85. * OUTPUT: bool; Is this bargraph horizontal? *
  86. * *
  87. * WARNINGS: none *
  88. * *
  89. * HISTORY: *
  90. * 08/16/1996 JLB : Created. *
  91. *=============================================================================================*/
  92. bool ProgressBarClass::Is_Horizontal(void) const
  93. {
  94. if (Width > Height) return(true);
  95. return(false);
  96. }
  97. /***********************************************************************************************
  98. * ProgressBarClass::Update -- Update the value and redraw as necessary. *
  99. * *
  100. * This will update the value of the bargraph to the fill ratio specified and then *
  101. * redraw it if required. Very small changes to the bargraph value might not result in a *
  102. * visual change. *
  103. * *
  104. * INPUT: value -- The new value to assign to this bargraph. *
  105. * *
  106. * OUTPUT: none *
  107. * *
  108. * WARNINGS: bool; Did this update result in a redraw? *
  109. * *
  110. * HISTORY: *
  111. * 08/16/1996 JLB : Created. *
  112. *=============================================================================================*/
  113. bool ProgressBarClass::Update(fixed value)
  114. {
  115. CurrentValue = value;
  116. if (!IsDrawn || value - LastDisplayCurrent >= fixed(1, 10)) {
  117. Redraw();
  118. return(true);
  119. }
  120. return(false);
  121. }
  122. /***********************************************************************************************
  123. * ProgressBarClass::Outline -- Draw an outline around the bargraph if supposed to. *
  124. * *
  125. * This routine will draw a border around the bargraph if this bargraph has a color *
  126. * specified for the border. *
  127. * *
  128. * INPUT: none *
  129. * *
  130. * OUTPUT: none *
  131. * *
  132. * WARNINGS: none *
  133. * *
  134. * HISTORY: *
  135. * 08/16/1996 JLB : Created. *
  136. *=============================================================================================*/
  137. void ProgressBarClass::Outline(void) const
  138. {
  139. if (Is_Outlined()) {
  140. LogicPage->Draw_Line(X, Y, X+Width, Y, BorderColor);
  141. LogicPage->Draw_Line(X, Y, X, Y+Height, BorderColor);
  142. LogicPage->Draw_Line(X, Y+Height, X, Y+Height, BorderColor);
  143. LogicPage->Draw_Line(X+Width, Y, X+Width, Y+Height, BorderColor);
  144. }
  145. }
  146. /***********************************************************************************************
  147. * ProgressBarClass::Redraw -- Redraw the bargraph. *
  148. * *
  149. * This will redraw the entire bargraph. *
  150. * *
  151. * INPUT: none *
  152. * *
  153. * OUTPUT: none *
  154. * *
  155. * WARNINGS: none *
  156. * *
  157. * HISTORY: *
  158. * 08/16/1996 JLB : Created. *
  159. *=============================================================================================*/
  160. void ProgressBarClass::Redraw(void) const
  161. {
  162. Hide_Mouse();
  163. Outline();
  164. /*
  165. ** Determine the inner dimensions of the bargraph. This will be
  166. ** somewhat smaller than indicated if it has a border.
  167. */
  168. int x = X;
  169. int y = Y;
  170. int w = Width;
  171. int h = Height;
  172. if (Is_Outlined()) {
  173. x += 1;
  174. y += 1;
  175. w -= 2;
  176. h -= 2;
  177. }
  178. /*
  179. ** The working "length" of the bargraph is dependant on whether the
  180. ** bargraph is horizontal or vertical.
  181. */
  182. int size = Is_Horizontal() ? w : h;
  183. /*
  184. ** Determine the number of pixels to fill in the bargraph depending on the
  185. ** size of the internal value. The larger the internal value the more
  186. ** filled the bargraph becomes.
  187. */
  188. int fill = CurrentValue * size;
  189. /*
  190. ** Draw the filled portion of the bargraph if there is any pixels to draw.
  191. */
  192. if (fill > 0) {
  193. if (Is_Horizontal()) {
  194. LogicPage->Fill_Rect(x, y, x+fill, y+h, BarColor);
  195. } else {
  196. LogicPage->Fill_Rect(x, y+fill, x+w, y+h, BarColor);
  197. }
  198. }
  199. /*
  200. ** Draw the unfilled portion of the bargraph if there are any pixels to
  201. ** draw of it.
  202. */
  203. if (w-fill > 0) {
  204. if (Is_Horizontal()) {
  205. LogicPage->Fill_Rect(x+fill, y, x+w, y+h, BackColor);
  206. } else {
  207. LogicPage->Fill_Rect(x, y, x+w, y+fill-1, BackColor);
  208. }
  209. }
  210. Show_Mouse();
  211. ProgressBarClass * me = (ProgressBarClass *)this;
  212. me->LastDisplayCurrent = CurrentValue;
  213. me->IsDrawn = true;
  214. }