tooltip.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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/tooltip.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/24/02 4:05p $*
  29. * *
  30. * $Revision:: 5 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "tooltip.h"
  36. #include "assetmgr.h"
  37. #include "refcount.h"
  38. #include "font3d.h"
  39. #include "stylemgr.h"
  40. ////////////////////////////////////////////////////////////////
  41. //
  42. // ToolTipClass
  43. //
  44. ////////////////////////////////////////////////////////////////
  45. ToolTipClass::ToolTipClass (void) :
  46. Rect (0, 0, 0, 0),
  47. TextColor (0, 0, 0),
  48. BkColor (1.0F, 0.956F, 0.733F)
  49. {
  50. //
  51. // Set the font for the text renderers
  52. //
  53. StyleMgrClass::Assign_Font (&TextRenderer, StyleMgrClass::FONT_TOOLTIPS);
  54. return ;
  55. }
  56. ////////////////////////////////////////////////////////////////
  57. //
  58. // ~ToolTipClass
  59. //
  60. ////////////////////////////////////////////////////////////////
  61. ToolTipClass::~ToolTipClass (void)
  62. {
  63. return ;
  64. }
  65. ////////////////////////////////////////////////////////////////
  66. //
  67. // Create_Text_Renderer
  68. //
  69. ////////////////////////////////////////////////////////////////
  70. void
  71. ToolTipClass::Create_Text_Renderer (void)
  72. {
  73. Render2DSentenceClass &renderer = TextRenderer;
  74. //
  75. // Setup the coordinate system of the renderer
  76. //
  77. renderer.Reset ();
  78. //
  79. // Calculate where to draw the text
  80. //
  81. Vector2 text_extent = renderer.Get_Text_Extents (Text);
  82. int x_pos = int(Rect.Left + ((Rect.Width() - text_extent.X) / 2));
  83. int y_pos = int(Rect.Top + ((Rect.Height() - text_extent.Y) / 2));
  84. //
  85. // Draw the text
  86. //
  87. renderer.Set_Location(Vector2 (x_pos, y_pos));
  88. renderer.Set_Clipping_Rect (Rect);
  89. renderer.Build_Sentence(Text);
  90. renderer.Draw_Sentence(VRGB_TO_INT32(TextColor));
  91. return ;
  92. }
  93. ////////////////////////////////////////////////////////////////
  94. //
  95. // Create_Background_Renderer
  96. //
  97. ////////////////////////////////////////////////////////////////
  98. void
  99. ToolTipClass::Create_Background_Renderer (void)
  100. {
  101. Render2DClass &renderer = BackgroundRenderer;
  102. //
  103. // Configure this renderer
  104. //
  105. renderer.Reset ();
  106. renderer.Enable_Texturing (false);
  107. renderer.Set_Coordinate_Range (Render2DClass::Get_Screen_Resolution());
  108. //
  109. // Make a hilight color by brightening the background color
  110. //
  111. Vector3 temp = BkColor * 2;
  112. temp.X = min (255.0F, temp.X);
  113. temp.Y = min (255.0F, temp.Y);
  114. temp.Z = min (255.0F, temp.Z);
  115. //
  116. // Make two int's representing the hilight and shadow colors
  117. //
  118. int hilight_color = VRGB_TO_INT32 (temp);
  119. int shadow_color = VRGB_TO_INT32 (Vector3 (0, 0, 0));
  120. //
  121. // Draw the box outline
  122. //
  123. RectClass rect = Rect;
  124. renderer.Add_Line (Vector2 (rect.Left, rect.Bottom), Vector2 (rect.Left, rect.Top-1), 1, hilight_color);
  125. renderer.Add_Line (Vector2 (rect.Left, rect.Top), Vector2 (rect.Right, rect.Top), 1, hilight_color);
  126. renderer.Add_Line (Vector2 (rect.Right, rect.Top), Vector2 (rect.Right, rect.Bottom), 1, shadow_color);
  127. renderer.Add_Line (Vector2 (rect.Right, rect.Bottom), Vector2 (rect.Left, rect.Bottom), 1, shadow_color);
  128. //
  129. // Now draw the background
  130. //
  131. rect.Right -= 1;
  132. rect.Bottom -= 1;
  133. renderer.Add_Quad (rect, VRGB_TO_INT32 (BkColor));
  134. return ;
  135. }
  136. ////////////////////////////////////////////////////////////////
  137. //
  138. // Render
  139. //
  140. ////////////////////////////////////////////////////////////////
  141. void
  142. ToolTipClass::Render (void)
  143. {
  144. //
  145. // Render the background and text
  146. //
  147. BackgroundRenderer.Render ();
  148. TextRenderer.Render ();
  149. return ;
  150. }
  151. ////////////////////////////////////////////////////////////////
  152. //
  153. // Set_Position
  154. //
  155. ////////////////////////////////////////////////////////////////
  156. void
  157. ToolTipClass::Set_Position (const Vector2 &pos)
  158. {
  159. Rect.Left = pos.X;
  160. Rect.Top = pos.Y;
  161. Update_Rect ();
  162. return ;
  163. }
  164. ////////////////////////////////////////////////////////////////
  165. //
  166. // Set_Text
  167. //
  168. ////////////////////////////////////////////////////////////////
  169. void
  170. ToolTipClass::Set_Text (const WCHAR *text)
  171. {
  172. Text = text;
  173. //
  174. // Force the renderer's to be repositioned and resized
  175. //
  176. Update_Rect ();
  177. return ;
  178. }
  179. ////////////////////////////////////////////////////////////////
  180. //
  181. // Update_Rect
  182. //
  183. ////////////////////////////////////////////////////////////////
  184. void
  185. ToolTipClass::Update_Rect (void)
  186. {
  187. //
  188. // Get the dimensions of the string
  189. //
  190. const RectClass &screen_rect = Render2DClass::Get_Screen_Resolution ();
  191. Vector2 text_extent = TextRenderer.Get_Text_Extents (Text);
  192. if (text_extent.X <= 0.0f) {
  193. BackgroundRenderer.Reset();
  194. TextRenderer.Reset();
  195. return;
  196. }
  197. //
  198. // Update the rectangle's width and height
  199. //
  200. Rect.Right = Rect.Left + (text_extent.X + 5); //10);
  201. Rect.Bottom = Rect.Top + (text_extent.Y + 4); //* 2);
  202. //
  203. // Clip the rectangle to the right side of the screen
  204. //
  205. if (Rect.Right > screen_rect.Right) {
  206. float delta = Rect.Right - screen_rect.Right;
  207. Rect.Left -= delta;
  208. Rect.Right -= delta;
  209. }
  210. //
  211. // Clip the rectangle to the bottom of the screen
  212. //
  213. if (Rect.Bottom > screen_rect.Bottom) {
  214. float delta = Rect.Bottom - screen_rect.Bottom;
  215. Rect.Top -= delta;
  216. Rect.Bottom -= delta;
  217. }
  218. //
  219. // Update the renderer's
  220. //
  221. Create_Text_Renderer ();
  222. Create_Background_Renderer ();
  223. return ;
  224. }