Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
render2dsentence.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(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 /***********************************************************************************************
20 *** 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 ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WW3D *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/render2dsentence.h $*
26 * *
27 * Author:: Greg Hjelstrom *
28 * *
29 * $Modtime:: 8/29/01 10:58a $*
30 * *
31 * $Revision:: 6 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37#if defined(_MSC_VER)
38#pragma once
39#endif
40
41#ifndef RENDER2DSENTENCE_H
42#define RENDER2DSENTENCE_H
43
44#include "render2d.h"
45#include "refcount.h"
46#include "vector.h"
47#include "vector2i.h"
48#include "wwstring.h"
49#include "win.h"
50
51/*
52** FontCharsClass
53*/
54class SurfaceClass;
55
56//
57// Private data structures
58//
67
68enum { CHAR_BUFFER_LEN = 32768 };
69
76
77
78class FontCharsClass : public W3DMPO, public RefCountClass
79{
81
82public:
83 FontCharsClass( void );
85
86 // TR: Hack for unicode font support
88
89
90 void Initialize_GDI_Font( const char *font_name, int point_size, bool is_bold );
91 bool Is_Font( const char *font_name, int point_size, bool is_bold );
92 const char * Get_Name( void ) { return Name; }
93
94 int Get_Char_Height( void ) { return CharHeight; }
95 int Get_Char_Width( WCHAR ch );
96 int Get_Char_Spacing( WCHAR ch );
97
98 int Get_Extra_Overlap(void) {return PixelOverlap;}
99
100 void Blit_Char( WCHAR ch, uint16 *dest_ptr, int dest_stride, int x, int y );
101
102private:
103
104 //
105 // Private methods
106 //
107 void Create_GDI_Font( const char *font_name );
108 void Free_GDI_Font( void );
109 const FontCharsClassCharDataStruct * Store_GDI_Char( WCHAR ch );
110 void Update_Current_Buffer( int char_width );
111 const FontCharsClassCharDataStruct * Get_Char_Data( WCHAR ch );
112
113 void Grow_Unicode_Array( WCHAR ch );
114 void Free_Character_Arrays( void );
115
116 //
117 // Private member data
118 //
119 StringClass Name;
121 int CurrPixelOffset;
122 int CharHeight;
123 int CharAscent;
124 int CharOverhang;
125 int PixelOverlap;
126 int PointSize;
127 StringClass GDIFontName;
128 HFONT OldGDIFont;
129 HBITMAP OldGDIBitmap;
130 HBITMAP GDIBitmap;
131 HFONT GDIFont;
132 uint8 * GDIBitmapBits;
133 HDC MemDC;
134 FontCharsClassCharDataStruct * ASCIICharArray[256];
135 FontCharsClassCharDataStruct ** UnicodeCharArray;
136 uint16 FirstUnicodeChar;
137 uint16 LastUnicodeChar;
138 bool IsBold;
139};
140
141/*
142** Render2DSentenceClass
143*/
145public:
146 //Render2DSentenceClass( FontCharsClass * font );
147 Render2DSentenceClass( void );
149
150 void Render (void);
151 virtual void Reset (void);
152 void Reset_Polys (void);
153
154 FontCharsClass * Peek_Font( void ) { return Font; }
155 void Set_Font( FontCharsClass *font );
156
157 void Set_Location( const Vector2 & loc );
158 void Set_Base_Location( const Vector2 & loc );
159 bool Set_Wrapping_Width (float width) { if(WrapWidth == width)
160 return false;
161 WrapWidth = width;
162 return true; }
163 bool Set_Word_Wrap_Centered( bool isCentered ) { if(Centered == isCentered)
164 return false;
165 Centered = isCentered;
166 return true;}
167 void Set_Hot_Key_Parse( bool parseHotKey ){ ParseHotKey = parseHotKey; }
168 void Set_Use_Hard_Word_Wrap( bool useHardWrap){ useHardWordWrap = useHardWrap; }
169 //
170 // Clipping support
171 //
172 void Set_Clipping_Rect( const RectClass &rect ) { ClipRect = rect; IsClippedEnabled = true; }
173 bool Is_Clipping_Enabled( void ) const { return IsClippedEnabled; }
174 void Enable_Clipping( bool onoff ) { IsClippedEnabled = onoff; }
175
176 //
177 // Shader modification support
178 //
179 void Make_Additive (void);
180 ShaderClass Get_Shader (void) const { return Shader; }
181 void Set_Shader (ShaderClass shader);
182
183// void Draw_Block( const RectClass & screen, unsigned long color = 0xFFFFFFFF );
184
185 const RectClass & Get_Draw_Extents( void ) { return DrawExtents; }
186// const RectClass & Get_Total_Extents( void ) { return TotalExtents; }
187// const Vector2 & Get_Cursor( void ) { return Cursor; }
188
189 Vector2 Get_Text_Extents( const WCHAR * text );
190 Vector2 Get_Formatted_Text_Extents( const WCHAR * text );
191
192 //
193 // Sentence control
194 //
195 void Build_Sentence (const WCHAR *text, int *hkX, int *hkY);
196 void Draw_Sentence (uint32 color = 0xFFFFFFFF);
197
198 //
199 // Texture hint
200 //
201 void Set_Texture_Size_Hint( int hint ) { TextureSizeHint = hint; }
202 int Get_Texture_Size_Hint( void ) const { return TextureSizeHint; }
203
204 void Set_Mono_Spaced( bool onoff ) { MonoSpaced = onoff; }
205
206private:
207
208 //
209 // Private structures
210 //
211 struct SentenceDataStruct {
213 RectClass ScreenRect;
214 RectClass UVRect;
215
216 bool operator== (const SentenceDataStruct &src) { return false; }
217 bool operator!= (const SentenceDataStruct &src) { return true; }
218 };
219
220 struct PendingSurfaceStruct {
221 SurfaceClass * Surface;
222 DynamicVectorClass<Render2DClass *> Renderers;
223
224 bool operator== (const PendingSurfaceStruct &src) { return false; }
225 bool operator!= (const PendingSurfaceStruct &src) { return true; }
226 };
227
228 struct RendererDataStruct {
229 Render2DClass * Renderer;
230 SurfaceClass * Surface;
231
232 bool operator== (const RendererDataStruct &src) { return false; }
233 bool operator!= (const RendererDataStruct &src) { return true; }
234 };
235
236 //
237 // Private methods
238 //
239 void Reset_Sentence_Data (void);
240 void Build_Textures (void);
241 void Record_Sentence_Chunk (void);
242 void Allocate_New_Surface (const WCHAR *text, bool justCalcExtents = false);
243 void Release_Pending_Surfaces (void);
244 void Build_Sentence_Centered (const WCHAR *text, int *hkX, int *hkY);
245 Vector2 Build_Sentence_Not_Centered (const WCHAR *text, int *hkX, int *hkY,bool justCalcExtents = false );
246 //
247 // Private member data
248 //
249 DynamicVectorClass<SentenceDataStruct> SentenceData;
250 DynamicVectorClass<PendingSurfaceStruct> PendingSurfaces;
251 DynamicVectorClass<RendererDataStruct> Renderers;
252 FontCharsClass * Font;
253 Vector2 BaseLocation;
254 Vector2 Location;
255 Vector2 Cursor;
256 Vector2i TextureOffset;
257 int TextureStartX;
258 int CurrTextureSize;
259 int TextureSizeHint;
260 SurfaceClass * CurSurface;
261 bool MonoSpaced;
262 float WrapWidth;
263 bool Centered; // Determines whether or not to center each line
264 RectClass ClipRect;
265 RectClass DrawExtents;
266 bool IsClippedEnabled;
267 bool ParseHotKey;
268 bool useHardWordWrap;
269
270 uint16 * LockedPtr;
271 int LockedStride;
272 TextureClass * CurTexture;
273 ShaderClass Shader;
274};
275
276#endif // RENDER2DSENTENCE_H
#define W3DMPO_GLUE(ARGCLASS)
Definition always.h:120
unsigned short uint16
Definition bittype.h:45
unsigned long uint32
Definition bittype.h:46
unsigned char uint8
Definition bittype.h:44
uint16 Buffer[CHAR_BUFFER_LEN]
int Get_Char_Height(void)
void Initialize_GDI_Font(const char *font_name, int point_size, bool is_bold)
const char * Get_Name(void)
void Blit_Char(WCHAR ch, uint16 *dest_ptr, int dest_stride, int x, int y)
FontCharsClass * AlternateUnicodeFont
int Get_Extra_Overlap(void)
bool Is_Font(const char *font_name, int point_size, bool is_bold)
int Get_Char_Spacing(WCHAR ch)
int Get_Char_Width(WCHAR ch)
RefCountClass(void)
Definition refcount.h:108
bool Is_Clipping_Enabled(void) const
void Set_Base_Location(const Vector2 &loc)
Vector2 Get_Formatted_Text_Extents(const WCHAR *text)
void Build_Sentence(const WCHAR *text, int *hkX, int *hkY)
const RectClass & Get_Draw_Extents(void)
void Set_Mono_Spaced(bool onoff)
void Set_Clipping_Rect(const RectClass &rect)
void Enable_Clipping(bool onoff)
Vector2 Get_Text_Extents(const WCHAR *text)
void Set_Font(FontCharsClass *font)
FontCharsClass * Peek_Font(void)
void Draw_Sentence(uint32 color=0xFFFFFFFF)
void Set_Texture_Size_Hint(int hint)
void Set_Hot_Key_Parse(bool parseHotKey)
void Set_Shader(ShaderClass shader)
ShaderClass Get_Shader(void) const
int Get_Texture_Size_Hint(void) const
bool Set_Wrapping_Width(float width)
void Set_Location(const Vector2 &loc)
void Set_Use_Hard_Word_Wrap(bool useHardWrap)
virtual void Reset(void)
bool Set_Word_Wrap_Centered(bool isCentered)
@ CHAR_BUFFER_LEN