STATBTN.CPP 15 KB

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