STATBTN.CPP (15323B)
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/STATBTN.CPP 1 3/03/97 10:25a 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 : TEXTBTN.CPP * 24 * * 25 * Programmer : Joe L. Bostic * 26 * * 27 * Start Date : 01/15/95 * 28 * * 29 * Last Update : January 19, 1995 [JLB] * 30 * * 31 *---------------------------------------------------------------------------------------------* 32 * Functions: * 33 * StaticButtonClass::Draw_Background -- Draws the background to the text button. * 34 * StaticButtonClass::Draw_Me -- Draws the text buttons as indicated. * 35 * StaticButtonClass::Draw_Text -- This draws the text for the text button. * 36 * StaticButtonClass::Set_Text -- Assigns a new text string to this button. * 37 * StaticButtonClass::StaticButtonClass -- Normal constructor for a text button. * 38 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 39 40 41 #include "function.h" 42 #include "statbtn.h" 43 44 45 /*********************************************************************************************** 46 * StaticButtonClass::StaticButtonClass -- Normal constructor for a text button. * 47 * * 48 * This is the constructor for text buttons if the text is provided as a string pointer. * 49 * * 50 * INPUT: id -- The ID number to assign to this button. * 51 * * 52 * text -- Pointer to the text string to display on top of the button. * 53 * * 54 * x,y -- Pixel coordinate of button's upper left corner. * 55 * * 56 * w,h -- Dimensions of the button. If these are not filled in (or with -1), then * 57 * the dimensions are adapted to fit the text assigned to the button. * 58 * * 59 * style -- The print style for the text in the button. These are the TPF_ flags * 60 * used by Fancy_Text_Print(). * 61 * * 62 * OUTPUT: none * 63 * * 64 * WARNINGS: Call Set_Text & Set_Style, & init X,Y,Width,Height,ID before using this button. * 65 * * 66 * HISTORY: 01/15/1995 JLB : Created. * 67 *=============================================================================================*/ 68 StaticButtonClass::StaticButtonClass(unsigned , char const * text, TextPrintType style, int x, int y, int w, int h) : 69 GadgetClass(x, y, w, h, FlagEnum(0)), 70 String(NULL), 71 PrintFlags(style) 72 { 73 /* 74 ** Make a duplicate of the string to display. 75 */ 76 Set_Text(text, false); 77 78 if (w == -1 || h == -1) { 79 //PG_TO_FIX 80 //Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, PrintFlags); 81 if (w == -1) { 82 Width = String_Pixel_Width(String); 83 } 84 if (h == -1) { 85 Height = FontHeight; 86 } 87 } 88 } 89 90 91 /*********************************************************************************************** 92 * StaticButtonClass::StaticButtonClass -- Default constructor for a text button. * 93 * * 94 * INPUT: none * 95 * * 96 * OUTPUT: none * 97 * * 98 * WARNINGS: none * 99 * * 100 * HISTORY: 01/15/1995 JLB : Created. * 101 *=============================================================================================*/ 102 StaticButtonClass::StaticButtonClass(void) : 103 GadgetClass(0, 0, 0, 0, FlagEnum(0)), 104 String(NULL), 105 PrintFlags(TPF_8POINT) 106 { 107 } 108 109 110 /*********************************************************************************************** 111 * StaticButtonClass::Draw_Me -- Draws the text buttons as indicated. * 112 * * 113 * This routine will draw the text button. * 114 * * 115 * INPUT: forced -- If the button is to be redrawn regardless of the state of the redraw * 116 * flag, then this parameter will be true. * 117 * * 118 * OUTPUT: bool; Was the button redrawn? * 119 * * 120 * WARNINGS: none * 121 * * 122 * HISTORY: * 123 * 01/03/1995 MML : Created. * 124 * 01/16/1995 JLB : Modified * 125 *=============================================================================================*/ 126 int StaticButtonClass::Draw_Me(int forced) 127 { 128 if (GadgetClass::Draw_Me(forced)) { 129 /* 130 ** Hide the mouse. 131 */ 132 if (LogicPage == &SeenBuff) { 133 Conditional_Hide_Mouse(X, Y, X+Width-1, Y+Height-1); 134 } 135 136 /* 137 ** Draw the background and overlaying text. These are virtual function 138 ** calls so that they may be overridden. 139 */ 140 Draw_Background(); 141 Draw_Text(String); 142 143 /* 144 ** Display the mouse. 145 */ 146 if (LogicPage == &SeenBuff) { 147 Conditional_Show_Mouse(); 148 } 149 return(true); 150 } 151 return(false); 152 } 153 154 155 /*********************************************************************************************** 156 * StaticButtonClass::Set_Text -- Assigns a new text string to this button. * 157 * * 158 * Use this routine to assign a new text string to this button. By using this function it * 159 * is possible to dynamically change the button's text. An example of this would be an * 160 * on/off button that every time it is clicked, the text toggles between "on" and "off". * 161 * * 162 * INPUT: text -- Pointer to the text string to assign to this button. * 163 * * 164 * OUTPUT: none * 165 * * 166 * WARNINGS: The text is NOT copied to this button. You must make sure that the text * 167 * remains valid throughout the lifetime of this text button. * 168 * * 169 * HISTORY: * 170 * 01/16/1995 JLB : Created. * 171 *=============================================================================================*/ 172 void StaticButtonClass::Set_Text(char const * text, bool resize) 173 { 174 if (String != NULL) { 175 delete [] String; 176 String = NULL; 177 } 178 179 if (text != NULL) { 180 String = new char[strlen(text)+1]; 181 if (String != NULL) { 182 strcpy(String, text); 183 } 184 } 185 186 Flag_To_Redraw(); 187 if (resize && String != NULL) { 188 Draw_Background(); 189 //PG_TO_FIX 190 //Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, PrintFlags); 191 Width = String_Pixel_Width(String); 192 Height = FontHeight + FontYSpacing; 193 Background = Buffer(); 194 } 195 } 196 197 198 /*********************************************************************************************** 199 * StaticButtonClass::Draw_Background -- Draws the background to the text button. * 200 * * 201 * This localizes the drawing of the background for the text button. By overriding this * 202 * function you can give a different background to the button. The text is drawn using * 203 * a different routine. The mouse is hidden, if necessary, before this routine is called. * 204 * * 205 * INPUT: none * 206 * * 207 * OUTPUT: none * 208 * * 209 * WARNINGS: none * 210 * * 211 * HISTORY: * 212 * 01/19/1995 JLB : Created. * 213 *=============================================================================================*/ 214 void StaticButtonClass::Draw_Background(void) 215 { 216 /* 217 ** If the background hasn't been recorded from the buffer, then 218 ** allocate and record the background image now. 219 */ 220 if (Background.Get_Buffer() == NULL && Width > 0 && Height > 0) { 221 new(&Background) Buffer(Width*Height); 222 if (Background.Get_Buffer() != NULL) { 223 LogicPage->To_Buffer(X, Y, Width, Height, Background, Background.Get_Size()); 224 } 225 } 226 227 /* 228 ** If there is a background image present, then restore it to the buffer now. 229 */ 230 if (Background.Get_Buffer() != NULL && LogicPage->Lock()) { 231 Buffer_To_Page(X, Y, Width, Height, Background, *LogicPage); 232 LogicPage->Unlock(); 233 } 234 } 235 236 237 /*********************************************************************************************** 238 * StaticButtonClass::Draw_Text -- This draws the text for the text button. * 239 * * 240 * This routine draws the text for the text button. You can override this routine if you * 241 * wish different text rendering styles or colors. The background has already been drawn * 242 * by the time this function is called. The mouse is hidden, if necessary, as well. * 243 * * 244 * INPUT: text -- Pointer to the text string to print over the button. * 245 * * 246 * OUTPUT: none * 247 * * 248 * WARNINGS: none * 249 * * 250 * HISTORY: * 251 * 01/19/1995 JLB : Created. * 252 *=============================================================================================*/ 253 void StaticButtonClass::Draw_Text(char const * text) 254 { 255 /* 256 ** Display the text. 257 */ 258 if (String != NULL) { 259 int x = X; 260 261 if (PrintFlags & TPF_CENTER) { 262 x += Width/2; 263 } 264 if (PrintFlags & TPF_RIGHT) { 265 x += Width-1; 266 } 267 268 Fancy_Text_Print(text, x, Y, GadgetClass::Get_Color_Scheme(), TBLACK, PrintFlags); 269 } 270 }