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