STATBTN.CPP 15 KB

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