popupdialog.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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/popupdialog.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/02/02 11:25a $*
  29. * *
  30. * $Revision:: 14 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. // Disable warning about exception handling not being enabled. It's used as part of STL - in a part of STL we don't use.
  36. #pragma warning(disable : 4530)
  37. #include "popupdialog.h"
  38. #include "assetmgr.h"
  39. #include "texture.h"
  40. #include "stylemgr.h"
  41. ////////////////////////////////////////////////////////////////
  42. // Local constants
  43. ////////////////////////////////////////////////////////////////
  44. const int TITLE_BORDER_WIDTH = 10;
  45. const int TITLE_BORDER_HEIGHT = 8;
  46. ////////////////////////////////////////////////////////////////
  47. //
  48. // PopupDialogClass
  49. //
  50. ////////////////////////////////////////////////////////////////
  51. PopupDialogClass::PopupDialogClass (int res_id) :
  52. DialogBaseClass (res_id)
  53. {
  54. //
  55. // Configure the renderers
  56. //
  57. StyleMgrClass::Configure_Renderer (&BackgroundRenderer);
  58. StyleMgrClass::Configure_Renderer (&BlackoutRenderer);
  59. StyleMgrClass::Assign_Font (&TextRenderer, StyleMgrClass::FONT_HEADER);
  60. //
  61. // Force this renderer to always render
  62. //
  63. BlackoutRenderer.Get_Shader ()->Set_Depth_Compare (ShaderClass::PASS_ALWAYS);
  64. //
  65. // By default, popup backgrounds are dark
  66. //
  67. IsBackgroundDarkened = true;
  68. return ;
  69. }
  70. ////////////////////////////////////////////////////////////////
  71. //
  72. // ~PopupDialogClass
  73. //
  74. ////////////////////////////////////////////////////////////////
  75. PopupDialogClass::~PopupDialogClass (void)
  76. {
  77. return ;
  78. }
  79. void PopupDialogClass::Set_Title(const WCHAR* title)
  80. {
  81. DialogBaseClass::Set_Title(title);
  82. Build_Background_Renderers();
  83. }
  84. ////////////////////////////////////////////////////////////////
  85. //
  86. // On_Init_Dialog
  87. //
  88. ////////////////////////////////////////////////////////////////
  89. void
  90. PopupDialogClass::On_Init_Dialog (void)
  91. {
  92. //
  93. // Generate the backdrop
  94. //
  95. Build_Background_Renderers ();
  96. DialogBaseClass::On_Init_Dialog ();
  97. //
  98. // Play the sound effect
  99. //
  100. StyleMgrClass::Play_Sound (StyleMgrClass::EVENT_POPUP);
  101. return ;
  102. }
  103. ////////////////////////////////////////////////////////////////
  104. //
  105. // Build_Background_Renderers
  106. //
  107. ////////////////////////////////////////////////////////////////
  108. void
  109. PopupDialogClass::Build_Background_Renderers (void)
  110. {
  111. //
  112. // Configure this renderer
  113. //
  114. TextRenderer.Reset();
  115. BackgroundRenderer.Reset ();
  116. BlackoutRenderer.Reset ();
  117. BackgroundRenderer.Enable_Texturing (false);
  118. BlackoutRenderer.Enable_Texturing (false);
  119. //
  120. // Darken the background if IsBackgroundDarkened is set
  121. //
  122. if (IsBackgroundDarkened) {
  123. BlackoutRenderer.Add_Quad (Render2DClass::Get_Screen_Resolution(), RGBA_TO_INT32 (0, 0, 0, 236));
  124. }
  125. //
  126. // Determine which color to draw the outline in
  127. //
  128. int color = StyleMgrClass::Get_Line_Color ();
  129. int bkcolor = StyleMgrClass::Get_Bk_Color ();
  130. //
  131. // Draw the control outline
  132. //
  133. RectClass rect = Rect;
  134. BackgroundRenderer.Add_Rect (rect, 1.0F, color, bkcolor);
  135. if (Title.Get_Length () > 0) {
  136. //
  137. // Determine what scale to use
  138. //
  139. float scale_x = Render2DClass::Get_Screen_Resolution().Width () / 800;
  140. float scale_y = Render2DClass::Get_Screen_Resolution().Height () / 600;
  141. //
  142. // Calculate the title bar rectangle
  143. //
  144. Vector2 text_extent = TextRenderer.Get_Text_Extents (Title);
  145. if (text_extent != Vector2(0,0)) {
  146. RectClass text_rect;
  147. text_rect.Left = Rect.Left;
  148. text_rect.Right = Rect.Left + int(text_extent.X + (TITLE_BORDER_WIDTH * 2 * scale_x));
  149. text_rect.Top = Rect.Top - int(text_extent.Y + (TITLE_BORDER_HEIGHT * 2 * scale_y));
  150. text_rect.Bottom = Rect.Top;
  151. //
  152. // Draw the title bar
  153. //
  154. BackgroundRenderer.Add_Rect (text_rect, 1.0F, color, bkcolor);
  155. //
  156. // Draw the title text
  157. //
  158. StyleMgrClass::Render_Text (Title, &TextRenderer, text_rect, true, true, StyleMgrClass::CENTER_JUSTIFY);
  159. }
  160. }
  161. return ;
  162. }
  163. ////////////////////////////////////////////////////////////////
  164. //
  165. // Render
  166. //
  167. ////////////////////////////////////////////////////////////////
  168. void
  169. PopupDialogClass::Render (void)
  170. {
  171. //
  172. // Render the backdrop
  173. //
  174. BlackoutRenderer.Render ();
  175. BackgroundRenderer.Render ();
  176. TextRenderer.Render ();
  177. //
  178. // Render the controls
  179. //
  180. DialogBaseClass::Render ();
  181. return ;
  182. }