dialogtext.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. ** Command & Conquer Renegade(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. /***********************************************************************************************
  19. *** 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 ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/wwui/dialogtext.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 11/08/01 12:14a $*
  29. * *
  30. * $Revision:: 19 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "dialogtext.h"
  36. #include "stylemgr.h"
  37. ////////////////////////////////////////////////////////////////
  38. //
  39. // DialogButtonClass
  40. //
  41. ////////////////////////////////////////////////////////////////
  42. DialogTextClass::DialogTextClass (void) :
  43. IsTitle (false)
  44. {
  45. Set_Wants_Focus (false);
  46. //
  47. // Set the font for the text renderer
  48. //
  49. StyleMgrClass::Assign_Font (&TextRenderer, StyleMgrClass::FONT_CONTROLS);
  50. StyleMgrClass::Configure_Renderer (&ControlRenderer);
  51. return ;
  52. }
  53. ////////////////////////////////////////////////////////////////
  54. //
  55. // Render
  56. //
  57. ////////////////////////////////////////////////////////////////
  58. void
  59. DialogTextClass::Render (void)
  60. {
  61. if (Style & WS_VISIBLE) {
  62. //
  63. // Update the text renderer (if necessary)
  64. //
  65. if (IsDirty) {
  66. Create_Text_Renderer ();
  67. }
  68. if (IsTitle) {
  69. GlowRenderer.Render ();
  70. }
  71. //
  72. // Render the control
  73. //
  74. TextRenderer.Render ();
  75. ControlRenderer.Render ();
  76. DialogControlClass::Render ();
  77. }
  78. return ;
  79. }
  80. ////////////////////////////////////////////////////////////////
  81. //
  82. // Create_Text_Renderer
  83. //
  84. ////////////////////////////////////////////////////////////////
  85. void
  86. DialogTextClass::Create_Text_Renderer (void)
  87. {
  88. TextRenderer.Reset ();
  89. ControlRenderer.Reset ();
  90. if ((Style & SS_TYPEMASK) == SS_ETCHEDHORZ) {
  91. //
  92. // Determine which color to draw the outline in
  93. //
  94. int color = StyleMgrClass::Get_Line_Color ();
  95. if (IsEnabled == false) {
  96. color = StyleMgrClass::Get_Disabled_Line_Color ();
  97. }
  98. //
  99. // Draw the line
  100. //
  101. ControlRenderer.Add_Line (Rect.Upper_Left (), Rect.Upper_Right (), 1.0F, color);
  102. } else if ((Style & SS_TYPEMASK) == SS_BLACKFRAME) {
  103. //
  104. // Determine which color to draw the outline in
  105. //
  106. int color = StyleMgrClass::Get_Line_Color ();
  107. if (IsEnabled == false) {
  108. color = StyleMgrClass::Get_Disabled_Line_Color ();
  109. }
  110. //
  111. // Draw the outline
  112. //
  113. ControlRenderer.Add_Outline (Rect, 1.0F, color);
  114. } else {
  115. //
  116. // Determine how to justify the text
  117. //
  118. StyleMgrClass::JUSTIFICATION justification = StyleMgrClass::LEFT_JUSTIFY;
  119. if ((Style & 0xF) == SS_RIGHT) {
  120. justification = StyleMgrClass::RIGHT_JUSTIFY;
  121. } else if ((Style & 0xF) == SS_CENTER) {
  122. justification = StyleMgrClass::CENTER_JUSTIFY;
  123. }
  124. //
  125. // Determine if the text should be centered vertically
  126. //
  127. bool is_vcentered = ((Style & SS_CENTERIMAGE) == SS_CENTERIMAGE);
  128. //
  129. // Draw the text
  130. //
  131. if (IsTitle) {
  132. //
  133. // Render the title text using a glow
  134. //
  135. GlowRenderer.Reset_Polys ();
  136. StyleMgrClass::Render_Glow (Title, &GlowRenderer, Rect, 5, 5, RGB_TO_INT32 (14, 0, 0), StyleMgrClass::CENTER_JUSTIFY);
  137. StyleMgrClass::Render_Text (Title, &TextRenderer, RGB_TO_INT32 (255, 255, 36), 0, Rect, false, false, StyleMgrClass::CENTER_JUSTIFY, true);
  138. } else if ((Style & 0x0F) == SS_LEFTNOWORDWRAP) {
  139. //
  140. // Render the text using the default color scheme or the overriden
  141. // color scheme
  142. //
  143. if (IsTextColorOverridden == false) {
  144. StyleMgrClass::Render_Text (Title, &TextRenderer, Rect, true, true,
  145. justification, IsEnabled, is_vcentered);
  146. } else {
  147. StyleMgrClass::Render_Text (Title, &TextRenderer, VRGB_TO_INT32 (TextColor),
  148. RGB_TO_INT32 (0, 0, 0), Rect, true, true, justification, is_vcentered);
  149. }
  150. } else {
  151. //
  152. // Render the text using the default color scheme or the overriden
  153. // color scheme
  154. //
  155. if (IsTextColorOverridden == false) {
  156. StyleMgrClass::Render_Wrapped_Text_Ex (Title, &TextRenderer, Rect, true, is_vcentered, IsEnabled, justification);
  157. } else {
  158. StyleMgrClass::Render_Wrapped_Text_Ex (Title, &TextRenderer, VRGB_TO_INT32 (TextColor),
  159. RGB_TO_INT32 (0, 0, 0), Rect, true, is_vcentered, justification);
  160. }
  161. }
  162. }
  163. return ;
  164. }
  165. ////////////////////////////////////////////////////////////////
  166. //
  167. // On_Create
  168. //
  169. ////////////////////////////////////////////////////////////////
  170. void
  171. DialogTextClass::On_Create (void)
  172. {
  173. if (Title.Get_Length () >= 2) {
  174. //
  175. // Does this string have special formatting?
  176. //
  177. if (Title[0] == L'%' && Title[1] == L't') {
  178. //
  179. // Strip off the preceding format specifier
  180. //
  181. WideStringClass text = Title.Peek_Buffer () + 2;
  182. Title = text;
  183. //
  184. // Keep in mind that this is a "Title"
  185. //
  186. IsTitle = true;
  187. StyleMgrClass::Assign_Font (&TextRenderer, StyleMgrClass::FONT_TITLE);
  188. StyleMgrClass::Assign_Font (&GlowRenderer, StyleMgrClass::FONT_TITLE);
  189. GlowRenderer.Build_Sentence (Title);
  190. } else if (Title[0] == L'%' && Title[1] == L'h') {
  191. //
  192. // Support a "header" style font
  193. //
  194. StyleMgrClass::Assign_Font (&TextRenderer, StyleMgrClass::FONT_LG_CONTROLS);
  195. //
  196. // Strip off the preceding format specifier
  197. //
  198. WideStringClass text = Title.Peek_Buffer () + 2;
  199. Title = text;
  200. } else if (Title[0] == L'%' && Title[1] == L's') {
  201. //
  202. // Support a "small" style font
  203. //
  204. StyleMgrClass::Assign_Font (&TextRenderer, StyleMgrClass::FONT_TOOLTIPS);
  205. //
  206. // Strip off the preceding format specifier
  207. //
  208. WideStringClass text = Title.Peek_Buffer () + 2;
  209. Title = text;
  210. }
  211. }
  212. return ;
  213. }