BAR.CPP 13 KB

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