TEXTBTN.CPP 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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/TEXTBTN.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. * TextButtonClass::Draw_Background -- Draws the background to the text button. *
  36. * TextButtonClass::Draw_Me -- Draws the text buttons as indicated. *
  37. * TextButtonClass::Draw_Text -- This draws the text for the text button. *
  38. * TextButtonClass::Set_Text -- Assigns a new text string to this button. *
  39. * TextButtonClass::Set_Text -- Sets the text for this text button. *
  40. * TextButtonClass::TextButtonClass -- Normal constructor for a text button. *
  41. * TextButtonClass::TextButtonClass -- Normal constructor for a text button. *
  42. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  43. #include "function.h"
  44. #include "textbtn.h"
  45. /***********************************************************************************************
  46. * TextButtonClass::TextButtonClass -- 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. * border-- If the button is to be surrounded by a black border, then this flag *
  63. * should be set to true. *
  64. * *
  65. * OUTPUT: none *
  66. * *
  67. * WARNINGS: Call Set_Text & Set_Style, & init X,Y,Width,Height,ID before using this button. *
  68. * *
  69. * HISTORY: 01/15/1995 JLB : Created. *
  70. *=============================================================================================*/
  71. TextButtonClass::TextButtonClass(unsigned id, char const * text, TextPrintType style, int x, int y, int w, int h, int blackborder) :
  72. ToggleClass(id, x, y, w, h),
  73. String(text)
  74. {
  75. PrintFlags = style;
  76. IsBlackBorder = blackborder;
  77. if (w == -1 || h == -1) {
  78. Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, PrintFlags);
  79. if (w == -1) {
  80. Width = String_Pixel_Width(String)+8;
  81. }
  82. if (h == -1) {
  83. Height = FontHeight + FontYSpacing + 2;
  84. }
  85. }
  86. }
  87. /***********************************************************************************************
  88. * TextButtonClass::TextButtonClass -- Default constructor for a text button. *
  89. * *
  90. * INPUT: none *
  91. * *
  92. * OUTPUT: none *
  93. * *
  94. * WARNINGS: none *
  95. * *
  96. * HISTORY: 01/15/1995 JLB : Created. *
  97. *=============================================================================================*/
  98. TextButtonClass::TextButtonClass(void) :
  99. ToggleClass(0, 0, 0, 0, 0)
  100. {
  101. IsBlackBorder = false;
  102. String = NULL;
  103. PrintFlags = TPF_8POINT;
  104. }
  105. /***********************************************************************************************
  106. * TextButtonClass::TextButtonClass -- Normal constructor for a text button. *
  107. * *
  108. * This is the constructor for text buttons if the text is provided as a string pointer. *
  109. * *
  110. * INPUT: id -- The ID number to assign to this button. *
  111. * *
  112. * text -- The text number to use for displaying on top of the button. *
  113. * *
  114. * x,y -- Pixel coordinate of button's upper left corner. *
  115. * *
  116. * w,h -- Dimensions of the button. If these are not filled in (or with -1), then *
  117. * the dimensions are adapted to fit the text assigned to the button. *
  118. * *
  119. * *
  120. * style -- The print style for the text in the button. These are the TPF_ flags *
  121. * used by Fancy_Text_Print(). *
  122. * *
  123. * border-- If the button is to be surrounded by a black border, then this flag *
  124. * should be set to true. *
  125. * *
  126. * OUTPUT: none *
  127. * *
  128. * WARNINGS: none *
  129. * *
  130. * HISTORY: *
  131. * 01/15/1995 JLB : Created. *
  132. *=============================================================================================*/
  133. TextButtonClass::TextButtonClass (unsigned id, int text, TextPrintType style, int x, int y, int w, int h, int blackborder) :
  134. ToggleClass (id, x, y, w, h),
  135. String(0)
  136. {
  137. PrintFlags = style;
  138. IsBlackBorder = blackborder;
  139. Set_Text(text);
  140. if (w == -1 || h == -1) {
  141. Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, PrintFlags);
  142. if (w == -1) {
  143. Width = String_Pixel_Width(String)+8;
  144. }
  145. if (h == -1) {
  146. Height = FontHeight + FontYSpacing + 2;
  147. }
  148. }
  149. }
  150. /***********************************************************************************************
  151. * TextButtonClass::Draw_Me -- Draws the text buttons as indicated. *
  152. * *
  153. * This routine will draw the text button. *
  154. * *
  155. * INPUT: forced -- If the button is to be redrawn regardless of the state of the redraw *
  156. * flag, then this parameter will be true. *
  157. * *
  158. * OUTPUT: bool; Was the button redrawn? *
  159. * *
  160. * WARNINGS: none *
  161. * *
  162. * HISTORY: *
  163. * 01/03/1995 MML : Created. *
  164. * 01/16/1995 JLB : Modified *
  165. *=============================================================================================*/
  166. int TextButtonClass::Draw_Me(int forced)
  167. {
  168. if (ControlClass::Draw_Me(forced)) {
  169. /*
  170. ** Hide the mouse.
  171. */
  172. if (LogicPage == &SeenBuff) {
  173. Conditional_Hide_Mouse(X, Y, X+Width-1, Y+Height-1);
  174. }
  175. /*
  176. ** Draw the background and overlaying text. These are virtual function
  177. ** calls so that they may be overridden.
  178. */
  179. Draw_Background();
  180. Draw_Text(String);
  181. /*
  182. ** Display the mouse.
  183. */
  184. if (LogicPage == &SeenBuff) {
  185. Conditional_Show_Mouse();
  186. }
  187. return(true);
  188. }
  189. return(false);
  190. }
  191. /***********************************************************************************************
  192. * TextButtonClass::Set_Text -- Assigns a new text string to this button. *
  193. * *
  194. * Use this routine to assign a new text string to this button. By using this function it *
  195. * is possible to dynamically change the button's text. An example of this would be an *
  196. * on/off button that every time it is clicked, the text toggles between "on" and "off". *
  197. * *
  198. * INPUT: text -- Pointer to the text string to assign to this button. *
  199. * *
  200. * OUTPUT: none *
  201. * *
  202. * WARNINGS: The text is NOT copied to this button. You must make sure that the text *
  203. * remains valid throughout the lifetime of this text button. *
  204. * *
  205. * HISTORY: *
  206. * 01/16/1995 JLB : Created. *
  207. *=============================================================================================*/
  208. void TextButtonClass::Set_Text(char const * text, bool resize)
  209. {
  210. String = text;
  211. Flag_To_Redraw();
  212. if (resize && String) {
  213. Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, PrintFlags);
  214. Width = String_Pixel_Width(String)+8;
  215. Height = FontHeight + FontYSpacing + 2;
  216. }
  217. }
  218. /***********************************************************************************************
  219. * TextButtonClass::Set_Text -- Sets the text for this text button. *
  220. * *
  221. * This will set the text for this button. The text is provided as a text number. This *
  222. * number is automatically converted to the appropriate text string before being stored *
  223. * in the button's structure. *
  224. * *
  225. * INPUT: text -- The text number to assign to this button. *
  226. * *
  227. * OUTPUT: none *
  228. * *
  229. * WARNINGS: The text number information is lost when it is assigned to the button. Once *
  230. * the assignment takes place, the text number is NOT remembered by the button. *
  231. * Only the associated text string is. *
  232. * *
  233. * HISTORY: *
  234. * 01/16/1995 JLB : Created. *
  235. *=============================================================================================*/
  236. void TextButtonClass::Set_Text(int text, bool resize)
  237. {
  238. if (text != TXT_NONE) {
  239. Set_Text(Text_String(text), resize);
  240. }
  241. }
  242. /***********************************************************************************************
  243. * TextButtonClass::Draw_Background -- Draws the background to the text button. *
  244. * *
  245. * This localizes the drawing of the background for the text button. By overriding this *
  246. * function you can give a different background to the button. The text is drawn using *
  247. * a different routine. The mouse is hidden, if necessary, before this routine is called. *
  248. * *
  249. * INPUT: none *
  250. * *
  251. * OUTPUT: none *
  252. * *
  253. * WARNINGS: none *
  254. * *
  255. * HISTORY: *
  256. * 01/19/1995 JLB : Created. *
  257. *=============================================================================================*/
  258. void TextButtonClass::Draw_Background(void)
  259. {
  260. /*
  261. ** Draw a border if selected style.
  262. */
  263. if (IsBlackBorder) {
  264. LogicPage->Draw_Rect (X-1, Y-1, X+Width+2, Y+Height+2, BLACK);
  265. }
  266. /*
  267. ** Draw the body & set text color.
  268. */
  269. BoxStyleEnum style;
  270. if (IsDisabled) {
  271. #ifdef WOLAPI_INTEGRATION
  272. style = BOXSTYLE_BOX;
  273. #else
  274. style = BOXSTYLE_DIS_RAISED;
  275. #endif
  276. } else {
  277. if (IsPressed) {
  278. style = BOXSTYLE_DOWN;
  279. } else {
  280. style = BOXSTYLE_RAISED;
  281. }
  282. }
  283. Draw_Box(X, Y, Width, Height, style, true);
  284. }
  285. /***********************************************************************************************
  286. * TextButtonClass::Draw_Text -- This draws the text for the text button. *
  287. * *
  288. * This routine draws the text for the text button. You can override this routine if you *
  289. * wish different text rendering styles or colors. The background has already been drawn *
  290. * by the time this function is called. The mouse is hidden, if necessary, as well. *
  291. * *
  292. * INPUT: text -- Pointer to the text string to print over the button. *
  293. * *
  294. * OUTPUT: none *
  295. * *
  296. * WARNINGS: none *
  297. * *
  298. * HISTORY: *
  299. * 01/19/1995 JLB : Created. *
  300. *=============================================================================================*/
  301. void TextButtonClass::Draw_Text(char const * text)
  302. {
  303. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  304. /*
  305. ** Display the text.
  306. */
  307. if (String) {
  308. TextPrintType flags;
  309. if (IsDisabled) {
  310. flags = (TextPrintType)0;
  311. } else {
  312. if (IsPressed || IsOn) {
  313. flags = TPF_USE_GRAD_PAL|TPF_BRIGHT_COLOR;
  314. } else {
  315. flags = TPF_USE_GRAD_PAL|TPF_MEDIUM_COLOR;
  316. }
  317. }
  318. Fancy_Text_Print(text, X+(Width>>1)-1, Y+1, scheme, TBLACK, PrintFlags|flags|TPF_CENTER);
  319. }
  320. }