TEXTBTN.CPP 20 KB

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