2
0

render2dsentence.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 : WW3D *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/render2dsentence.h $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 10/08/01 10:16p $*
  29. * *
  30. * $Revision:: 10 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef RENDER2DSENTENCE_H
  39. #define RENDER2DSENTENCE_H
  40. #include "render2d.h"
  41. #include "refcount.h"
  42. #include "vector.h"
  43. #include "vector2i.h"
  44. #include "wwstring.h"
  45. #include "win.h"
  46. /*
  47. ** FontCharsClass
  48. */
  49. class SurfaceClass;
  50. class FontCharsClass : public RefCountClass {
  51. public:
  52. FontCharsClass( void );
  53. ~FontCharsClass();
  54. void Initialize_GDI_Font( const char *font_name, int point_size, bool is_bold );
  55. bool Is_Font( const char *font_name, int point_size, bool is_bold );
  56. const char * Get_Name( void ) { return Name; }
  57. int Get_Char_Height( void ) { return CharHeight; }
  58. int Get_Char_Width( WCHAR ch );
  59. int Get_Char_Spacing( WCHAR ch );
  60. void Blit_Char( WCHAR ch, uint16 *dest_ptr, int dest_stride, int x, int y );
  61. private:
  62. //
  63. // Private data structures
  64. //
  65. struct CharDataStruct {
  66. WCHAR Value;
  67. short Width;
  68. uint16 * Buffer;
  69. };
  70. //
  71. // Private methods
  72. //
  73. void Create_GDI_Font( const char *font_name );
  74. void Free_GDI_Font( void );
  75. const CharDataStruct * Store_GDI_Char( WCHAR ch );
  76. void Update_Current_Buffer( int char_width );
  77. const CharDataStruct * Get_Char_Data( WCHAR ch );
  78. void Grow_Unicode_Array( WCHAR ch );
  79. void Free_Character_Arrays( void );
  80. //
  81. // Private member data
  82. //
  83. StringClass Name;
  84. DynamicVectorClass<uint16 *> BufferList;
  85. uint16* PreAllocatedBufferList[16]; // We'll use this with BufferList first
  86. int CurrPixelOffset;
  87. int CharHeight;
  88. int PointSize;
  89. StringClass GDIFontName;
  90. HFONT OldGDIFont;
  91. HBITMAP OldGDIBitmap;
  92. HBITMAP GDIBitmap;
  93. HFONT GDIFont;
  94. uint8 * GDIBitmapBits;
  95. HDC MemDC;
  96. CharDataStruct * ASCIICharArray[256];
  97. CharDataStruct ** UnicodeCharArray;
  98. uint16 FirstUnicodeChar;
  99. uint16 LastUnicodeChar;
  100. bool IsBold;
  101. };
  102. /*
  103. ** Render2DSentenceClass
  104. */
  105. class Render2DSentenceClass {
  106. public:
  107. //Render2DSentenceClass( FontCharsClass * font );
  108. Render2DSentenceClass( void );
  109. ~Render2DSentenceClass();
  110. void Render (void);
  111. virtual void Reset (void);
  112. void Reset_Polys (void);
  113. FontCharsClass * Peek_Font( void ) { return Font; }
  114. void Set_Font( FontCharsClass *font );
  115. void Set_Location( const Vector2 & loc );
  116. void Set_Base_Location( const Vector2 & loc );
  117. void Set_Wrapping_Width (float width) { WrapWidth = width; }
  118. void Set_Tabstop(float stop);
  119. //
  120. // Clipping support
  121. //
  122. void Set_Clipping_Rect( const RectClass &rect ) { ClipRect = rect; IsClippedEnabled = true; }
  123. bool Is_Clipping_Enabled( void ) const { return IsClippedEnabled; }
  124. void Enable_Clipping( bool onoff ) { IsClippedEnabled = onoff; }
  125. //
  126. // Shader modification support
  127. //
  128. void Make_Additive (void);
  129. ShaderClass Get_Shader (void) const { return Shader; }
  130. void Set_Shader (ShaderClass shader);
  131. // void Draw_Block( const RectClass & screen, unsigned long color = 0xFFFFFFFF );
  132. const RectClass & Get_Draw_Extents( void ) { return DrawExtents; }
  133. // const RectClass & Get_Total_Extents( void ) { return TotalExtents; }
  134. // const Vector2 & Get_Cursor( void ) { return Cursor; }
  135. Vector2 Get_Text_Extents( const WCHAR * text );
  136. Vector2 Get_Formatted_Text_Extents( const WCHAR * text, int *row_count = NULL );
  137. const WCHAR * Find_Row_Start( const WCHAR * text, int row_index );
  138. //
  139. // Sentence control
  140. //
  141. void Build_Sentence (const WCHAR *text);
  142. void Draw_Sentence (uint32 color = 0xFFFFFFFF);
  143. //
  144. // Texture hint
  145. //
  146. void Set_Texture_Size_Hint( int hint ) { TextureSizeHint = hint; }
  147. int Get_Texture_Size_Hint( void ) const { return TextureSizeHint; }
  148. void Set_Mono_Spaced( bool onoff ) { MonoSpaced = onoff; }
  149. // Force all alphas
  150. void Force_Alpha( float alpha );
  151. private:
  152. //
  153. // Private structures
  154. //
  155. struct SentenceDataStruct {
  156. SurfaceClass * Surface;
  157. RectClass ScreenRect;
  158. RectClass UVRect;
  159. bool operator== (const SentenceDataStruct &src) { return false; }
  160. bool operator!= (const SentenceDataStruct &src) { return true; }
  161. };
  162. struct PendingSurfaceStruct {
  163. SurfaceClass * Surface;
  164. DynamicVectorClass<Render2DClass *> Renderers;
  165. Render2DClass * PreAllocatedRenderers[16]; // Use this with Renderers at first
  166. PendingSurfaceStruct() : Renderers(sizeof(PreAllocatedRenderers)/sizeof(Render2DClass*),PreAllocatedRenderers) {}
  167. bool operator== (const PendingSurfaceStruct &src) { return false; }
  168. bool operator!= (const PendingSurfaceStruct &src) { return true; }
  169. };
  170. struct RendererDataStruct {
  171. Render2DClass * Renderer;
  172. SurfaceClass * Surface;
  173. bool operator== (const RendererDataStruct &src) { return false; }
  174. bool operator!= (const RendererDataStruct &src) { return true; }
  175. };
  176. //
  177. // Private methods
  178. //
  179. void Reset_Sentence_Data (void);
  180. void Build_Textures (void);
  181. void Record_Sentence_Chunk (void);
  182. void Allocate_New_Surface (const WCHAR *text);
  183. void Release_Pending_Surfaces (void);
  184. //
  185. // Private member data
  186. //
  187. DynamicVectorClass<SentenceDataStruct> SentenceData;
  188. DynamicVectorClass<PendingSurfaceStruct> PendingSurfaces;
  189. DynamicVectorClass<RendererDataStruct> Renderers;
  190. RendererDataStruct PreAllocatedRenderers[16]; // Use this with Renderers at first
  191. FontCharsClass * Font;
  192. Vector2 BaseLocation;
  193. Vector2 Location;
  194. Vector2 Cursor;
  195. Vector2i TextureOffset;
  196. int TextureStartX;
  197. int CurrTextureSize;
  198. int TextureSizeHint;
  199. SurfaceClass * CurSurface;
  200. bool MonoSpaced;
  201. float WrapWidth;
  202. float TabStop;
  203. RectClass ClipRect;
  204. RectClass DrawExtents;
  205. bool IsClippedEnabled;
  206. uint16 * LockedPtr;
  207. int LockedStride;
  208. TextureClass * CurTexture;
  209. ShaderClass Shader;
  210. };
  211. #endif // RENDER2DSENTENCE_H