textwindow.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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/Combat/textwindow.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 8/28/01 7:00p $*
  29. * *
  30. * $Revision:: 7 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __TEXT_WINDOW_H
  39. #define __TEXT_WINDOW_H
  40. #include "wwstring.h"
  41. #include "widestring.h"
  42. #include "vector.h"
  43. #include "vector3.h"
  44. #include "bittype.h"
  45. #include "rect.h"
  46. #include "render2d.h"
  47. ////////////////////////////////////////////////////////////////
  48. // Forward declarations
  49. ////////////////////////////////////////////////////////////////
  50. class Render2DSentenceClass;
  51. class RenderObjClass;
  52. class TextColumnClass;
  53. class SceneClass;
  54. ////////////////////////////////////////////////////////////////
  55. //
  56. // TextWindowClass
  57. //
  58. ////////////////////////////////////////////////////////////////
  59. class TextWindowClass
  60. {
  61. public:
  62. ////////////////////////////////////////////////////////////////
  63. // Public constructors/destructors
  64. ////////////////////////////////////////////////////////////////
  65. TextWindowClass (void);
  66. ~TextWindowClass (void);
  67. ////////////////////////////////////////////////////////////////
  68. // Public methods
  69. ////////////////////////////////////////////////////////////////
  70. //
  71. // Initialization
  72. //
  73. static void Initialize (SceneClass *scene);
  74. static void Shutdown (void);
  75. //
  76. // Backdrop methods
  77. //
  78. void Set_Backdrop (const char *texture_name, const RectClass &screen_rect, const Vector2 &texture_size, const RectClass &endcap_rect, const RectClass &fadeout_rect, const RectClass &textback_rect);
  79. void Set_Text_Area (const RectClass &rect) { TextRect = rect; }
  80. //
  81. // Font control
  82. //
  83. void Set_Heading_Font (const char *font_name) { HeadingFontName = font_name; }
  84. void Set_Text_Font (const char *font_name) { TextFontName = font_name; }
  85. //
  86. // Column support
  87. //
  88. void Add_Column (const WCHAR *column_name, float width, const Vector3 &color);
  89. bool Remove_Column (int index);
  90. void Delete_All_Columns (void);
  91. bool Are_Columns_Displayed (void) const { return AreColumnsDisplayed; }
  92. void Display_Columns (bool onoff) { AreColumnsDisplayed = onoff; IsViewDirty = true; IsWindowDirty = true; }
  93. //
  94. // Content control
  95. //
  96. int Insert_Item (int index, const WCHAR *text);
  97. bool Set_Item_Text (int index, int col_index, const WCHAR *text);
  98. bool Set_Item_Color (int index, int col_index, const Vector3 &color);
  99. bool Set_Item_Data (int index, uint32 user_data);
  100. uint32 Get_Item_Data (int index);
  101. bool Delete_Item (int index);
  102. void Delete_All_Items (void);
  103. int Get_Item_Count (void) const;
  104. //
  105. // Scrolling support
  106. //
  107. void Scroll_To_Top (void);
  108. void Page_Down (void);
  109. void Page_Up (void);
  110. //
  111. // Visibility methods
  112. //
  113. bool Is_Displayed (void) const { return IsDisplayed; }
  114. void Display (bool onoff);
  115. int Get_Display_Count (void);
  116. float Get_Total_Display_Height (void);
  117. //
  118. // Rendering methods
  119. //
  120. void On_Frame_Update (void);
  121. void Render (void);
  122. private:
  123. ////////////////////////////////////////////////////////////////
  124. // Private methods
  125. ////////////////////////////////////////////////////////////////
  126. void Free_Backdrop (void);
  127. void Free_Contents (void);
  128. void Free_Renderers (void);
  129. void Build_View (void);
  130. void Update_View (float *total_height = NULL, bool info_only = false);
  131. void Update_Row (int item_index, float y_pos, float *row_height);
  132. ////////////////////////////////////////////////////////////////
  133. // Private data types
  134. ////////////////////////////////////////////////////////////////
  135. typedef DynamicVectorClass<TextColumnClass *> COLUMN_LIST;
  136. ////////////////////////////////////////////////////////////////
  137. // Static member data
  138. ////////////////////////////////////////////////////////////////
  139. static SceneClass * Scene;
  140. ////////////////////////////////////////////////////////////////
  141. // Private member data
  142. ////////////////////////////////////////////////////////////////
  143. int FirstLineIndex;
  144. int CurrentDisplayCount;
  145. bool IsDisplayed;
  146. bool AreColumnsDisplayed;
  147. bool IsViewDirty;
  148. bool IsWindowDirty;
  149. COLUMN_LIST Columns;
  150. Render2DSentenceClass * TextRenderers[2];
  151. Render2DClass Backdrop;
  152. RectClass TextRect;
  153. float ColumnHeight;
  154. float LineSpacing;
  155. StringClass HeadingFontName;
  156. StringClass TextFontName;
  157. };
  158. ////////////////////////////////////////////////////////////////
  159. //
  160. // TextItemClass
  161. //
  162. ////////////////////////////////////////////////////////////////
  163. class TextItemClass
  164. {
  165. public:
  166. ////////////////////////////////////////////////////////////////
  167. // Public constructors/destructors
  168. ////////////////////////////////////////////////////////////////
  169. TextItemClass (void) :
  170. Name (L""),
  171. Color (1, 1, 1),
  172. UserData (0) {}
  173. TextItemClass (const WCHAR *name) :
  174. Name (name),
  175. Color (1, 1, 1),
  176. UserData (0) {}
  177. ~TextItemClass (void) {}
  178. ////////////////////////////////////////////////////////////////
  179. // Public methods
  180. ////////////////////////////////////////////////////////////////
  181. //
  182. // Name access
  183. //
  184. const WCHAR * Get_Name (void) const { return Name; }
  185. void Set_Name (const WCHAR *name) { Name = name; }
  186. //
  187. // Color access
  188. //
  189. const Vector3 & Get_Color (void) const { return Color; }
  190. void Set_Color (const Vector3 &color) { Color = color; }
  191. //
  192. // Color access
  193. //
  194. uint32 Get_User_Data (void) const { return UserData; }
  195. void Set_User_Data (uint32 user_data) { UserData = user_data; }
  196. private:
  197. ////////////////////////////////////////////////////////////////
  198. // Private member data
  199. ////////////////////////////////////////////////////////////////
  200. WideStringClass Name;
  201. Vector3 Color;
  202. uint32 UserData;
  203. };
  204. ////////////////////////////////////////////////////////////////
  205. //
  206. // TextColumnClass
  207. //
  208. ////////////////////////////////////////////////////////////////
  209. class TextColumnClass
  210. {
  211. public:
  212. ////////////////////////////////////////////////////////////////
  213. // Public constructors/destructors
  214. ////////////////////////////////////////////////////////////////
  215. TextColumnClass (void) :
  216. Width (0) { Reset_Contents (); }
  217. ~TextColumnClass (void) { Free_Data (); }
  218. ////////////////////////////////////////////////////////////////
  219. // Public methods
  220. ////////////////////////////////////////////////////////////////
  221. //
  222. // Name access
  223. //
  224. const WCHAR * Get_Name (void) const { return Header.Get_Name (); }
  225. void Set_Name (const WCHAR *name) { Header.Set_Name (name); }
  226. //
  227. // Width access
  228. //
  229. float Get_Width (void) const { return Width; }
  230. void Set_Width (float width) { Width = width; }
  231. //
  232. // Color access
  233. //
  234. const Vector3 & Get_Color (void) const { return Header.Get_Color (); }
  235. void Set_Color (const Vector3 &color) { Header.Set_Color (color); }
  236. //
  237. // Item access
  238. //
  239. int Insert_Item (int index, const WCHAR *item_name);
  240. int Get_Item_Count (void) const { return Items.Count (); }
  241. bool Delete_Item (int index);
  242. void Delete_All_Items (void);
  243. void Set_Item_Text (int index, const WCHAR *text) { Items[index]->Set_Name (text); }
  244. const WCHAR * Get_Item_Text (int index) const { return Items[index]->Get_Name (); }
  245. void Set_Item_Color (int index, const Vector3 &color) { Items[index]->Set_Color (color); }
  246. const Vector3 & Get_Item_Color (int index) const { return Items[index]->Get_Color (); }
  247. void Set_Item_Data (int index, uint32 data) { Items[index]->Set_User_Data (data); }
  248. uint32 Get_Item_Data (int index) const { return Items[index]->Get_User_Data (); }
  249. //
  250. // Cleanup
  251. //
  252. void Reset_Contents (void);
  253. private:
  254. ////////////////////////////////////////////////////////////////
  255. // Private methods
  256. ////////////////////////////////////////////////////////////////
  257. void Free_Data (void);
  258. ////////////////////////////////////////////////////////////////
  259. // Private data types
  260. ////////////////////////////////////////////////////////////////
  261. typedef DynamicVectorClass <TextItemClass *> ITEM_LIST;
  262. ////////////////////////////////////////////////////////////////
  263. // Private member data
  264. ////////////////////////////////////////////////////////////////
  265. TextItemClass Header;
  266. ITEM_LIST Items;
  267. float Width;
  268. };
  269. #endif //__TEXT_WINDOW_H