Debian Codegraph @

grtext/grtext.cpp

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
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 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/grtext/grtext.cpp $
21 * $Revision: 38 $
22 * $Date: 11/16/99 3:18p $
23 * $Author: Samir $
24 *
25 *
26 *
27 * $Log: /DescentIII/Main/grtext/grtext.cpp $
28 *
29 * 38 11/16/99 3:18p Samir
30 * added new data to font file and kept compatibility with D3 fonts:
31 * tracking value.
32 *
33 * 37 10/21/99 9:27p Jeff
34 * B.A. Macintosh code merge
35 *
36 * 36 5/02/99 7:16p Samir
37 * fixed text line width problem with newline chars.
38 *
39 * 35 5/02/99 1:50a Samir
40 * fixed nasty bug where intrastring text colors weren't getting set due
41 * to a change in how we do color for text now.
42 *
43 * 34 4/26/99 6:56p Kevin
44 * doh! forgot the 0 termination
45 *
46 * 33 4/26/99 6:55p Kevin
47 * added some more naughty words
48 *
49 * 32 4/24/99 8:41p Samir
50 * fixed clipped text scaling probs.
51 *
52 * 31 4/17/99 6:16p Samir
53 * added kerning and 4444 alphaed font support.
54 *
55 * 30 4/13/99 4:39p Samir
56 * simplified color scheme.
57 *
58 * 29 4/09/99 3:16p Kevin
59 * Fixed a stupid memory leak
60 *
61 * 28 4/02/99 3:49p Kevin
62 * Added profanity filter code
63 *
64 * 27 3/02/99 6:26p Samir
65 * added font template width and height functions.
66 *
67 * 26 1/20/99 3:47a Jeff
68 * added function to get clipping parameters
69 *
70 * 25 11/03/98 7:04p Samir
71 * made Grtext_spacing global so word wrapper could access it.
72 *
73 * 24 11/01/98 1:58a Jeff
74 * converted the vsprintf calls to use the Pvsprintf, which is a safe
75 * vsprintf, no buffer overflows allowed
76 *
77 * 23 10/22/98 2:41p Samir
78 * made grtext_Puts public.
79 *
80 * 22 10/19/98 10:42p Jason
81 * made Int3s into breaks
82 *
83 * 21 9/24/98 2:56p Samir
84 * added ability to format strings inside string.
85 *
86 * 20 9/21/98 2:58p Samir
87 * may have fixed GetTextHeight function.
88 *
89 * 19 9/18/98 11:29a Samir
90 * use strchr instead of strtok.
91 *
92 * 18 9/08/98 5:42p Samir
93 * fixed memory leak
94 *
95 * 17 9/08/98 10:27a Samir
96 * added function to get text height.
97 *
98 * 16 9/04/98 3:22p Samir
99 * newlines handled a bit better.
100 *
101 * 15 8/24/98 3:12p Samir
102 * fixed text clipping
103 *
104 * 14 6/23/98 5:05p Samir
105 * streamlined strlen calls
106 *
107 * 13 5/15/98 5:35p Samir
108 * fixed instring text color formatting.
109 *
110 * 12 5/05/98 6:29p Samir
111 * spaces don't render, just width of it counts.
112 *
113 * 11 4/27/98 3:46p Samir
114 * scaling fonts.
115 *
116 * 10 4/18/98 2:08a Samir
117 * extended text buffer.
118 *
119 * 9 2/13/98 6:37p Samir
120 * Fixed tabs.
121 *
122 * 8 2/03/98 12:20p Samir
123 * Be sure to set alphatype when Grtext_SetFlags operation occurs.
124 *
125 * 7 2/03/98 12:13p Samir
126 * Font shadowing support added.
127 *
128 * 6 1/30/98 2:15p Samir
129 * Allow for text saturation.
130 *
131 * 5 1/23/98 6:53p Samir
132 * Added grtext_PutChar.
133 *
134 * 4 1/08/98 12:16p Samir
135 * GetLineWidth now takes a const char *
136 *
137 * 3 12/30/97 5:20p Samir
138 * Some stuff.
139 *
140 * 2 12/29/97 5:49p Samir
141 * Added centering text capability.
142 *
143 * 1 12/29/97 3:24p Samir
144 * Initial revision
145 *
146 * $NoKeywords: $
147 */
148
149 #include <cstdarg>
150 #include <cstdio>
151 #include <cstring>
152 #include <cctype>
153
154 #include "grtextlib.h"cxx . . $ `<file>/grtext/grtextlib.h`/
155 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
156 #include "renderer.h"cxx . . $ `<file>/lib/renderer.h`/
157
158 #define CLIP_LEFTcxx . . $ `grtext/grtext.cpp:158:9`! Grtext_left
159 #define CLIP_TOPcxx . . $ `grtext/grtext.cpp:159:9`! Grtext_top
160 #define CLIP_RIGHTcxx . . $ `grtext/grtext.cpp:160:9`! Grtext_right
161 #define CLIP_BOTTOMcxx . . $ `grtext/grtext.cpp:161:9`! Grtext_bottom
162
163 // Text opcodes
164 #define GRTEXTOP_PUTScxx . . $ `grtext/grtext.cpp:164:9`! 0x1 // 2 shorts, x and y
165 #define GRTEXTOP_SETCOLORcxx . . $ `grtext/grtext.cpp:165:9`! 0x2 // 1 ddgr_color
166 #define GRTEXTOP_FANCYCOLORcxx . . $ `grtext/grtext.cpp:166:9`! 0x3 // 4 ddgr_colors
167 #define GRTEXTOP_SETFONTcxx . . $ `grtext/grtext.cpp:167:9`! 0x4 // 1 font handle (int)
168 #define GRTEXTOP_SETALPHAcxx . . $ `grtext/grtext.cpp:168:9`! 0x5 // 1 uint8_t
169 #define GRTEXTOP_PUTCHARcxx . . $ `grtext/grtext.cpp:169:9`! 0x6 // (2 shorts) 1 uint8_t
170 #define GRTEXTOP_SETFLAGScxx . . $ `grtext/grtext.cpp:170:9`! 0x7 // (flags) = 1 int.
171 #define GRTEXTOP_SCALEcxx . . $ `grtext/grtext.cpp:171:9`! 0x8 // 1 float (scale) scale current font.
172
173 // Text execution buffer
174 int Grtext_spacingcxx . . $ Grtext_spacing. = 1;
175 static char Grtext_buffercxx . . $ Grtext_buffer.[GRTEXT_BUFLENcxx . . $ `grtext/grtext.h:115:9`!];
176 static int Grtext_ptrcxx . . $ Grtext_ptr. = 0;
177 static int Grtext_fontcxx . . $ Grtext_font. = 0;
178 static uint8_tcxx . . $ uint8_t# Grtext_alphacxx . . $ Grtext_alpha. = 255;
179 static int8_tcxx . . $ int8_t# Grtext_alphatypecxx . . $ Grtext_alphatype. = ATF_TEXTUREcxx . . $ `lib/renderer.h:395:9`! + ATF_CONSTANTcxx . . $ `lib/renderer.h:394:9`!;
180 static bool Grtext_shadowcxx . . $ Grtext_shadow. = false;
181 static int Grtext_line_spacingcxx . . $ Grtext_line_spacing. = 1;
182 static int Grtext_tabspacecxx . . $ Grtext_tabspace. = 0;
183 static int Grtext_leftcxx . . $ Grtext_left., Grtext_topcxx . . $ Grtext_top., Grtext_rightcxx . . $ Grtext_right., Grtext_bottomcxx . . $ Grtext_bottom.;
184 static ddgr_colorcxx . . $ ddgr_color# Grtext_colorscxx . . $ Grtext_colors.[2];
185 static float Grtext_scalecxx . . $ Grtext_scale. = 1.0f;
186 static ddgr_colorcxx . . $ ddgr_color# Grtext_colorcxx . . $ Grtext_color. = GR_BLACKcxx . . $ GR_BLACK.;
187
188 // draws a string
189 static void grtext_RenderStringcxx . . $ grtext_RenderString(1839e3b9b1397d59).(int x, int y, char *str);
190 static void grtext_DrawTextLinecxx . . $ grtext_DrawTextLine(1839e3b9b1397d59).(int x, int y, char *str);
191 static void grtext_DrawTextLineClipcxx . . $ grtext_DrawTextLineClip(1839e3b9b1397d59).(int x, int y, char *str);
192
193 #define XORVALcxx . . $ `grtext/grtext.cpp:193:9`! 205
194 #define MAX_BAD_WORD_LENcxx . . $ `grtext/grtext.cpp:194:9`! 10
195 typedef uint8_tcxx . . $ uint8_t# badwordcxx . . $ badword#[MAX_BAD_WORD_LENcxx . . $ `grtext/grtext.cpp:194:9`!];
196 // These all need to be lower case!
197 static badwordcxx . . $ badword# bad_wordscxx . . $ bad_words.[] = {
198 // These are just XOR'd with XORVAL
199 {0xab, 0xb8, 0xae, 0xa6, 0x00}, // = fuck
200 {0xbe, 0xa5, 0xa4, 0xb9, 0x00}, // = shit
201 {0xae, 0xb8, 0xa3, 0xb9, 0x00}, // = cunt
202 {0xba, 0xa5, 0xa2, 0xbf, 0xa8, 0x00}, // = whore
203 {0xac, 0xbe, 0xbe, 0xa5, 0xa2, 0xa1, 0xa8, 0x00}, // = asshole
204 {0xa9, 0xac, 0xa0, 0xa3, 0x00}, // = damn
205 {0xbd, 0xb8, 0xbe, 0xbe, 0xb4, 0x00}, // pussy
206 {0xaf, 0xa4, 0xb9, 0xae, 0xa5, 0x00}, // bitch
207 {0xa9, 0xac, 0xa0, 0xa3, 0x00}, // damn
208 {0xbd, 0xa4, 0xbe, 0xbe, 0x00} // piss
209 };
210
211 #define NUM_BAD_WORDScxx . . $ `grtext/grtext.cpp:211:9`! (sizeof(bad_words) / sizeof(badword))
212
213 static const char subst_charscxx . . $ subst_chars.[] = "#!&@&#%*";
214
215 #define NUM_SUBST_CHARScxx . . $ `grtext/grtext.cpp:215:9`! (sizeof(subst_chars) - 1)
216
217 static bool grtext_FilterProfanitycxx . . $ grtext_FilterProfanity. = false;
218
219 void grtext_SetProfanityFiltercxx . . $ grtext_SetProfanityFilter(b45ddcbc8423892c).(bool enabled) { grtext_FilterProfanitycxx . . $ grtext_FilterProfanity. = enabled; }
220 // Right now this just decrypts the bad words
221 void grtext_Initcxx . . $ grtext_Init(49f6e7a06ebc5aa8).() {
222 for (auto & bad_word : bad_wordscxx . . $ bad_words.) {
223 int pos = 0;
224
225 while (bad_word[pos]) {
226 bad_word[pos] = bad_word[pos] ^ XORVALcxx . . $ `grtext/grtext.cpp:193:9`!;
227 pos++;
228 }
229 }
230 }
231
•232 // macros to get character dimensions
233 static inline int GRCHAR_WIDTHcxx . . $ GRCHAR_WIDTH(9b79fb6aee4c0440).(int font, int ch) { return (int)(grfont_GetCharWidthcxx . . $ grfont_GetCharWidth(9b79fb6aee4c0440).(font, ch) * Grtext_scalecxx . . $ Grtext_scale.); }
234 static inline int GRCHAR_HEIGHTcxx . . $ GRCHAR_HEIGHT(7864480464b09eea).(int font) { return (int)(grfont_GetHeightcxx . . $ grfont_GetHeight(7864480464b09eea).(font) * Grtext_scalecxx . . $ Grtext_scale.); }
235 static inline int GRCHAR_SPACINGcxx . . $ GRCHAR_SPACING(2326284602b0bb2d).(int font, int ch1, int ch2) { return (int)(grfont_GetKernedSpacingcxx . . $ grfont_GetKernedSpacing(2326284602b0bb2d).(font, ch1, ch2)); }
236 static inline int GRCHAR_HEIGHT_TEMPcxx . . $ GRCHAR_HEIGHT_TEMP(d54be1c0b38addb8).(const tFontTemplatecxx . . $ tFontTemplate# *ft) { return (int)ft->ch_heightcxx . . $ tFontTemplate#ch_height.; }
237 static inline int GRCHAR_WIDTH_TEMPcxx . . $ GRCHAR_WIDTH_TEMP(7b9a34a34a762d11).(const tFontTemplatecxx . . $ tFontTemplate# *ft, int ch) {
238 if (ch > ft->max_asciicxx . . $ tFontTemplate#max_ascii. && ft->uppercasecxx . . $ tFontTemplate#uppercase.) {
239 ch = toupper(ch);
240 } else if (ch < ft->min_asciicxx . . $ tFontTemplate#min_ascii. || ch > ft->max_asciicxx . . $ tFontTemplate#max_ascii.) {
241 return 0;
242 }
243
244 return (int)((ft->proportionalcxx . . $ tFontTemplate#proportional.) ? ft->ch_widthscxx . . $ tFontTemplate#ch_widths.[ch - ft->min_asciicxx . . $ tFontTemplate#min_ascii.] : ft->ch_maxwidthcxx . . $ tFontTemplate#ch_maxwidth.);
245 }
•246 static inline int GRCHAR_SPACING_TEMPcxx . . $ GRCHAR_SPACING_TEMP(1511bff7f72f8bee).(const tFontTemplatecxx . . $ tFontTemplate# *ft, int ch1, int ch2) {
247 if (ch1 > ft->max_asciicxx . . $ tFontTemplate#max_ascii. && ft->uppercasecxx . . $ tFontTemplate#uppercase.) {
248 ch1 = toupper(ch1);
249 }
250 if (ch2 > ft->max_asciicxx . . $ tFontTemplate#max_ascii. && ft->uppercasecxx . . $ tFontTemplate#uppercase.) {
251 ch2 = toupper(ch2);
252 }
253
254 return (int)(grfont_GetKernedSpacingTempcxx . . $ grfont_GetKernedSpacingTemp(1511bff7f72f8bee).(ft, ch1, ch2));
255 }
256
257 // clears text buffer. doesn't render.
258 void grtext_Resetcxx . . $ grtext_Reset(49f6e7a06ebc5aa8).() {
259 Grtext_buffercxx . . $ Grtext_buffer.[0] = 0;
260 Grtext_ptrcxx . . $ Grtext_ptr. = 0;
261 Grtext_alphacxx . . $ Grtext_alpha. = 255;
262 Grtext_scalecxx . . $ Grtext_scale. = 1.0f;
263 Grtext_spacingcxx . . $ Grtext_spacing. = 1;
264 grtext_SetFlagscxx . . $ grtext_SetFlags(d4f767463ce0a6b3).(0);
265 grtext_SetColorcxx . . $ grtext_SetColor(cb2f890c2fdad230).(GR_BLACKcxx . . $ GR_BLACK.);
266 }
267
268 // sets text clipping parameters
269 void grtext_SetParameterscxx . . $ grtext_SetParameters(1559a299834bcdd5).(int left, int top, int right, int bottom, int tabspace) {
270 Grtext_leftcxx . . $ Grtext_left. = left;
271 Grtext_topcxx . . $ Grtext_top. = top;
272 Grtext_rightcxx . . $ Grtext_right. = right;
273 Grtext_bottomcxx . . $ Grtext_bottom. = bottom;
274 Grtext_tabspacecxx . . $ Grtext_tabspace. = tabspace;
275 }
276
277 // gets text clipping parameters
278 void grtext_GetParameterscxx . . $ grtext_GetParameters(adf20dddcf83aa52).(int *left, int *top, int *right, int *bottom, int *tabspace) {
279 if (left)
280 *left = Grtext_leftcxx . . $ Grtext_left.;
281 if (top)
282 *top = Grtext_topcxx . . $ Grtext_top.;
283 if (right)
284 *right = Grtext_rightcxx . . $ Grtext_right.;
285 if (bottom)
286 *bottom = Grtext_bottomcxx . . $ Grtext_bottom.;
287 if (tabspace)
288 *tabspace = Grtext_tabspacecxx . . $ Grtext_tabspace.;
289 }
290
291 // sets the color for text
292 void grtext_SetColorcxx . . $ grtext_SetColor(cb2f890c2fdad230).(ddgr_colorcxx . . $ ddgr_color# col) {
293 structcxx . . $ grtext_SetColor(cb2f890c2fdad230).$anonymous_type_0# {
294 char opcxx . . $ grtext_SetColor(cb2f890c2fdad230).$anonymous_type_0#op.;
295 ddgr_colorcxx . . $ ddgr_color# colcxx . . $ grtext_SetColor(cb2f890c2fdad230).$anonymous_type_0#col.;
296 } cmd;
297
298 ASSERTcxx . . $ `misc/pserror.h:246:9`!((Grtext_ptr + sizeof(cmd)) < GRTEXT_BUFLENcxx . . $ `grtext/grtext.h:115:9`!);
299
300 cmd.opcxx . . $ grtext_SetColor(cb2f890c2fdad230).$anonymous_type_0#op. = GRTEXTOP_SETCOLORcxx . . $ `grtext/grtext.cpp:165:9`!;
301 cmd.colcxx . . $ grtext_SetColor(cb2f890c2fdad230).$anonymous_type_0#col. = col;
302
303 memcpy(&Grtext_buffercxx . . $ Grtext_buffer.[Grtext_ptrcxx . . $ Grtext_ptr.], &cmd, sizeof(cmd));
304 Grtext_ptrcxx . . $ Grtext_ptr. += sizeof(cmd);
305 Grtext_colorcxx . . $ Grtext_color. = col;
306 }
307
308 // returns color set by grtext_SetColor (does not count intra-string color changes)
309 ddgr_colorcxx . . $ ddgr_color# grtext_GetColorcxx . . $ grtext_GetColor(db52760e79bf9054).() { return Grtext_colorcxx . . $ Grtext_color.; }
310
311 // sets font scale (1.0 = normal, 0.5 = 1/2, 2.0 = twice as large.
312 void grtext_SetFontScalecxx . . $ grtext_SetFontScale(9364e6e7bff7660).(float scale) {
313 structcxx . . $ grtext_SetFontScale(9364e6e7bff7660).$anonymous_type_1# {
314 char opcxx . . $ grtext_SetFontScale(9364e6e7bff7660).$anonymous_type_1#op.;
315 float scalecxx . . $ grtext_SetFontScale(9364e6e7bff7660).$anonymous_type_1#scale.;
316 } cmd;
317
318 ASSERTcxx . . $ `misc/pserror.h:246:9`!((Grtext_ptr + sizeof(cmd)) < GRTEXT_BUFLENcxx . . $ `grtext/grtext.h:115:9`!);
319
320 cmd.opcxx . . $ grtext_SetFontScale(9364e6e7bff7660).$anonymous_type_1#op. = GRTEXTOP_SCALEcxx . . $ `grtext/grtext.cpp:171:9`!;
321 cmd.scalecxx . . $ grtext_SetFontScale(9364e6e7bff7660).$anonymous_type_1#scale. = scale;
322
323 memcpy(&Grtext_buffercxx . . $ Grtext_buffer.[Grtext_ptrcxx . . $ Grtext_ptr.], &cmd, sizeof(cmd));
324 Grtext_ptrcxx . . $ Grtext_ptr. += sizeof(cmd);
325
326 Grtext_scalecxx . . $ Grtext_scale. = scale;
327 }
328
329 // sets fancy color for text
330 void grtext_SetFancyColorcxx . . $ grtext_SetFancyColor(eda338842932bf2b).(ddgr_colorcxx . . $ ddgr_color# col1, ddgr_colorcxx . . $ ddgr_color# col2, ddgr_colorcxx . . $ ddgr_color# col3, ddgr_colorcxx . . $ ddgr_color# col4) {
331 structcxx . . $ grtext_SetFancyColor(eda338842932bf2b).$anonymous_type_2# {
332 char opcxx . . $ grtext_SetFancyColor(eda338842932bf2b).$anonymous_type_2#op.;
333 ddgr_colorcxx . . $ ddgr_color# colcxx . . $ grtext_SetFancyColor(eda338842932bf2b).$anonymous_type_2#col.;
334 } cmd;
335
336 ASSERTcxx . . $ `misc/pserror.h:246:9`!((Grtext_ptr + sizeof(cmd)) < GRTEXT_BUFLENcxx . . $ `grtext/grtext.h:115:9`!);
337
338 cmd.opcxx . . $ grtext_SetFancyColor(eda338842932bf2b).$anonymous_type_2#op. = GRTEXTOP_FANCYCOLORcxx . . $ `grtext/grtext.cpp:166:9`!;
339 cmd.colcxx . . $ grtext_SetFancyColor(eda338842932bf2b).$anonymous_type_2#col. = col1;
340
341 memcpy(&Grtext_buffercxx . . $ Grtext_buffer.[Grtext_ptrcxx . . $ Grtext_ptr.], &cmd, sizeof(cmd));
342 Grtext_ptrcxx . . $ Grtext_ptr. += sizeof(cmd);
343 }
344
345 // sets the alpha value for text
346 void grtext_SetAlphacxx . . $ grtext_SetAlpha(ac50b47256ae7414).(uint8_tcxx . . $ uint8_t# alpha) {
347 structcxx . . $ grtext_SetAlpha(ac50b47256ae7414).$anonymous_type_3# {
348 char opcxx . . $ grtext_SetAlpha(ac50b47256ae7414).$anonymous_type_3#op.;
349 uint8_tcxx . . $ uint8_t# alphacxx . . $ grtext_SetAlpha(ac50b47256ae7414).$anonymous_type_3#alpha.;
350 } cmd;
351
352 ASSERTcxx . . $ `misc/pserror.h:246:9`!((Grtext_ptr + sizeof(cmd)) < GRTEXT_BUFLENcxx . . $ `grtext/grtext.h:115:9`!);
353 cmd.opcxx . . $ grtext_SetAlpha(ac50b47256ae7414).$anonymous_type_3#op. = GRTEXTOP_SETALPHAcxx . . $ `grtext/grtext.cpp:168:9`!;
354 cmd.alphacxx . . $ grtext_SetAlpha(ac50b47256ae7414).$anonymous_type_3#alpha. = alpha;
355 Grtext_alphacxx . . $ Grtext_alpha. = alpha;
356
357 memcpy(&Grtext_buffercxx . . $ Grtext_buffer.[Grtext_ptrcxx . . $ Grtext_ptr.], &cmd, sizeof(cmd));
358 Grtext_ptrcxx . . $ Grtext_ptr. += sizeof(cmd);
359 }
360
361 // gets font alpha
362 uint8_tcxx . . $ uint8_t# grtext_GetAlphacxx . . $ grtext_GetAlpha(7c4be072098b358f).() { return Grtext_alphacxx . . $ Grtext_alpha.; }
363
364 // toggles text saturation
365 void grtext_SetFlagscxx . . $ grtext_SetFlags(d4f767463ce0a6b3).(int flags) {
366 structcxx . . $ grtext_SetFlags(d4f767463ce0a6b3).$anonymous_type_4# {
367 char opcxx . . $ grtext_SetFlags(d4f767463ce0a6b3).$anonymous_type_4#op.;
368 int flagscxx . . $ grtext_SetFlags(d4f767463ce0a6b3).$anonymous_type_4#flags.;
369 } cmd;
370
371 ASSERTcxx . . $ `misc/pserror.h:246:9`!((Grtext_ptr + sizeof(cmd)) < GRTEXT_BUFLENcxx . . $ `grtext/grtext.h:115:9`!);
372
373 cmd.opcxx . . $ grtext_SetFlags(d4f767463ce0a6b3).$anonymous_type_4#op. = GRTEXTOP_SETFLAGScxx . . $ `grtext/grtext.cpp:170:9`!;
374 cmd.flagscxx . . $ grtext_SetFlags(d4f767463ce0a6b3).$anonymous_type_4#flags. = flags;
375
376 memcpy(&Grtext_buffercxx . . $ Grtext_buffer.[Grtext_ptrcxx . . $ Grtext_ptr.], &cmd, sizeof(cmd));
377 Grtext_ptrcxx . . $ Grtext_ptr. += sizeof(cmd);
378 }
379
380 // sets the font for text
381 void grtext_SetFontcxx . . $ grtext_SetFont(d4f767463ce0a6b3).(int font_handle) {
382 structcxx . . $ grtext_SetFont(d4f767463ce0a6b3).$anonymous_type_5# {
383 char opcxx . . $ grtext_SetFont(d4f767463ce0a6b3).$anonymous_type_5#op.;
384 int handlecxx . . $ grtext_SetFont(d4f767463ce0a6b3).$anonymous_type_5#handle.;
385 } cmd;
386
387 ASSERTcxx . . $ `misc/pserror.h:246:9`!((Grtext_ptr + sizeof(cmd)) < GRTEXT_BUFLENcxx . . $ `grtext/grtext.h:115:9`!);
388 cmd.opcxx . . $ grtext_SetFont(d4f767463ce0a6b3).$anonymous_type_5#op. = GRTEXTOP_SETFONTcxx . . $ `grtext/grtext.cpp:167:9`!;
389 cmd.handlecxx . . $ grtext_SetFont(d4f767463ce0a6b3).$anonymous_type_5#handle. = font_handle;
390 Grtext_fontcxx . . $ Grtext_font. = cmd.handlecxx . . $ grtext_SetFont(d4f767463ce0a6b3).$anonymous_type_5#handle.;
391 Grtext_spacingcxx . . $ Grtext_spacing. = 1 + grfont_GetTrackingcxx . . $ grfont_GetTracking(7864480464b09eea).(Grtext_fontcxx . . $ Grtext_font.);
392
393 memcpy(&Grtext_buffercxx . . $ Grtext_buffer.[Grtext_ptrcxx . . $ Grtext_ptr.], &cmd, sizeof(cmd));
394 Grtext_ptrcxx . . $ Grtext_ptr. += sizeof(cmd);
395 }
396
397 // puts a formatted string in the text buffer
398 void grtext_Printfcxx . . $ grtext_Printf(9514e36549094170).(int x, int y, const char *fmt, ...) {
399 stdcxx . . $ std/::va_listcxx . . $ std/va_list# arglist;
400 int len;
401 char buf[512];
402
403 va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(arglist, fmt);
404 len = stdcxx . . $ std/::vsnprintfcxx . . $ std/vsnprintf(348eb892742d8727).(buf, 512, fmt, arglist);
405 va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(arglist);
406 if (len < 0)
407 return;
408
409 grtext_Putscxx . . $ grtext_Puts(3139f19a0dbb8edf).(x, y, buf);
410 }
411
412 // gets the current font
413 int grtext_GetFontcxx . . $ grtext_GetFont(b126dc7c1de90089).() { return Grtext_fontcxx . . $ Grtext_font.; }
414
415 // puts a centered string in the text buffer.
416 void grtext_CenteredPrintfcxx . . $ grtext_CenteredPrintf(9514e36549094170).(int xoff, int y, const char *fmt, ...) {
417 int new_x;
418 stdcxx . . $ std/::va_listcxx . . $ std/va_list# arglist;
419 int len;
420 char buf[512];
421
422 va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(arglist, fmt);
423 len = stdcxx . . $ std/::vsnprintfcxx . . $ std/vsnprintf(348eb892742d8727).(buf, 512, fmt, arglist);
424 va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(arglist);
425 if (len < 0)
426 return;
427
428 new_x = Grtext_leftcxx . . $ Grtext_left. + (Grtext_rightcxx . . $ Grtext_right. - Grtext_leftcxx . . $ Grtext_left.) / 2 - grtext_GetTextLineWidthcxx . . $ grtext_GetTextLineWidth(5c4306d8553b3696).(buf) / 2;
429
430 grtext_Putscxx . . $ grtext_Puts(3139f19a0dbb8edf).(new_x + xoff, y, buf);
431 }
432
433 #define GR_STR_LENcxx . . $ `grtext/grtext.cpp:433:9`! 128
434 // draws a string
435 void grtext_Putscxx . . $ grtext_Puts(3139f19a0dbb8edf).(int x, int y, const char *str) {
436 structcxx . . $ grtext_Puts(3139f19a0dbb8edf).$anonymous_type_6# {
437 char opcxx . . $ grtext_Puts(3139f19a0dbb8edf).$anonymous_type_6#op.;
438 int16_tcxx . . $ int16_t# xcxx . . $ grtext_Puts(3139f19a0dbb8edf).$anonymous_type_6#x., ycxx . . $ grtext_Puts(3139f19a0dbb8edf).$anonymous_type_6#y.;
439 } cmd;
440
441 ASSERTcxx . . $ `misc/pserror.h:246:9`!((Grtext_ptr + sizeof(cmd) + strlen(str) + 1) < GRTEXT_BUFLENcxx . . $ `grtext/grtext.h:115:9`!);
442
443 cmd.opcxx . . $ grtext_Puts(3139f19a0dbb8edf).$anonymous_type_6#op. = GRTEXTOP_PUTScxx . . $ `grtext/grtext.cpp:164:9`!;
444 cmd.xcxx . . $ grtext_Puts(3139f19a0dbb8edf).$anonymous_type_6#x. = (int16_tcxx . . $ int16_t#)x;
445 cmd.ycxx . . $ grtext_Puts(3139f19a0dbb8edf).$anonymous_type_6#y. = (int16_tcxx . . $ int16_t#)y;
446
447 ASSERTcxx . . $ `misc/pserror.h:246:9`!((Grtext_ptr + sizeof(cmd) + strlen(str) + 1) < GRTEXT_BUFLENcxx . . $ `grtext/grtext.h:115:9`!);
448
449 cmd.opcxx . . $ grtext_Puts(3139f19a0dbb8edf).$anonymous_type_6#op. = GRTEXTOP_PUTScxx . . $ `grtext/grtext.cpp:164:9`!;
450 cmd.xcxx . . $ grtext_Puts(3139f19a0dbb8edf).$anonymous_type_6#x. = (int16_tcxx . . $ int16_t#)x;
451 cmd.ycxx . . $ grtext_Puts(3139f19a0dbb8edf).$anonymous_type_6#y. = (int16_tcxx . . $ int16_t#)y;
452 memcpy(&Grtext_buffercxx . . $ Grtext_buffer.[Grtext_ptrcxx . . $ Grtext_ptr.], &cmd, sizeof(cmd));
453 Grtext_ptrcxx . . $ Grtext_ptr. += sizeof(cmd);
454 strcpy(&Grtext_buffercxx . . $ Grtext_buffer.[Grtext_ptrcxx . . $ Grtext_ptr.], str);
455
456 if (grtext_FilterProfanitycxx . . $ grtext_FilterProfanity.) {
457 // DAJ changed to local to reduce memory thrashing
458 // DAJ char *lowerstr = (char *)mem_malloc(strlen(str)+1);
459 char lowerstr[GR_STR_LENcxx . . $ `grtext/grtext.cpp:433:9`!];
460
461 int slen = strlen(str);
462 if (slen >= GR_STR_LENcxx . . $ `grtext/grtext.cpp:433:9`!)
463 slen = GR_STR_LENcxx . . $ `grtext/grtext.cpp:433:9`! - 1;
464
465 for (int a = 0; a < slen; a++)
466 lowerstr[a] = tolower(str[a]);
467
468 lowerstr[slen] = '\0';
469
470 for (auto & bad_word : bad_wordscxx . . $ bad_words.) {
471 char *p = strstr(lowerstr, (char *)bad_word);
472 while (p) {
473 int len = strlen((char *)bad_word);
474 char *realp = (char *)((int)(p - lowerstr) + &Grtext_buffercxx . . $ Grtext_buffer.[Grtext_ptrcxx . . $ Grtext_ptr.]);
475 for (int a = 0; a < len; a++) {
476 ASSERTcxx . . $ `misc/pserror.h:246:9`!(p);
477 *realp = subst_charscxx . . $ subst_chars.[(*realp) % NUM_SUBST_CHARScxx . . $ `grtext/grtext.cpp:215:9`!];
478 *p = *realp;
479 realp++;
480 }
481 p = strstr(lowerstr, (char *)bad_word);
482 };
483 }
484 // DAJ mem_free(lowerstr);
485 }
486
487 Grtext_ptrcxx . . $ Grtext_ptr. += (strlen(str) + 1);
488 }
489
490 // puts a character down
491 void grtext_PutCharcxx . . $ grtext_PutChar(b1146eedae1e1d0b).(int x, int y, int ch) {
492 structcxx . . $ grtext_PutChar(b1146eedae1e1d0b).$anonymous_type_7# {
493 char opcxx . . $ grtext_PutChar(b1146eedae1e1d0b).$anonymous_type_7#op.;
494 int16_tcxx . . $ int16_t# xcxx . . $ grtext_PutChar(b1146eedae1e1d0b).$anonymous_type_7#x., ycxx . . $ grtext_PutChar(b1146eedae1e1d0b).$anonymous_type_7#y.;
495 uint8_tcxx . . $ uint8_t# chcxx . . $ grtext_PutChar(b1146eedae1e1d0b).$anonymous_type_7#ch.;
496 } cmd;
497
498 ASSERTcxx . . $ `misc/pserror.h:246:9`!((Grtext_ptr + sizeof(cmd)) < GRTEXT_BUFLENcxx . . $ `grtext/grtext.h:115:9`!);
499
500 cmd.opcxx . . $ grtext_PutChar(b1146eedae1e1d0b).$anonymous_type_7#op. = GRTEXTOP_PUTCHARcxx . . $ `grtext/grtext.cpp:169:9`!;
501 cmd.xcxx . . $ grtext_PutChar(b1146eedae1e1d0b).$anonymous_type_7#x. = (int16_tcxx . . $ int16_t#)x;
502 cmd.ycxx . . $ grtext_PutChar(b1146eedae1e1d0b).$anonymous_type_7#y. = (int16_tcxx . . $ int16_t#)y;
503 cmd.chcxx . . $ grtext_PutChar(b1146eedae1e1d0b).$anonymous_type_7#ch. = (uint8_tcxx . . $ uint8_t#)ch;
504 memcpy(&Grtext_buffercxx . . $ Grtext_buffer.[Grtext_ptrcxx . . $ Grtext_ptr.], &cmd, sizeof(cmd));
505 Grtext_ptrcxx . . $ Grtext_ptr. += sizeof(cmd);
506 }
507
508 // renders all text in buffer and clears buffer. USUALLY CALL THIS TO RENDER TEXT
509 void grtext_Flushcxx . . $ grtext_Flush(49f6e7a06ebc5aa8).() {
510 grtext_Rendercxx . . $ grtext_Render(49f6e7a06ebc5aa8).();
511 grtext_Resetcxx . . $ grtext_Reset(49f6e7a06ebc5aa8).();
512 }
513
514 // renders all text but DOESN'T flush buffer
515 void grtext_Rendercxx . . $ grtext_Render(49f6e7a06ebc5aa8).() {
516 // setup rendering of text.
517 rend_SetTextureTypecxx . . $ rend_SetTextureType(cccd9781d96f97ff).(TT_LINEARcxx . . $ TT_LINEAR.);
518 rend_SetOverlayTypecxx . . $ rend_SetOverlayType(ac50b47256ae7414).(OT_NONEcxx . . $ `lib/renderer.h:333:9`!);
519 rend_SetFilteringcxx . . $ rend_SetFiltering(4af4fd0e2b26c4ac).(0);
520 rend_SetLightingcxx . . $ rend_SetLighting(e55526c9d3dd1656).(LS_FLAT_GOURAUDcxx . . $ LS_FLAT_GOURAUD.);
521 rend_SetAlphaTypecxx . . $ rend_SetAlphaType(4af4fd0e2b26c4ac).(ATF_TEXTUREcxx . . $ `lib/renderer.h:395:9`! + ATF_CONSTANTcxx . . $ `lib/renderer.h:394:9`!);
522 rend_SetColorModelcxx . . $ rend_SetColorModel(e3c5062d5af601c7).(CM_MONOcxx . . $ CM_MONO.);
523 rend_SetZBufferStatecxx . . $ rend_SetZBufferState(4af4fd0e2b26c4ac).(0);
524 rend_SetAlphaValuecxx . . $ rend_SetAlphaValue(ac50b47256ae7414).(Grtext_alphacxx . . $ Grtext_alpha.);
525
526 // render text.
527 int pos = 0;
528
529 while (pos < Grtext_ptrcxx . . $ Grtext_ptr.) {
530 switch (Grtext_buffercxx . . $ Grtext_buffer.[pos]) {
531 case GRTEXTOP_SETCOLORcxx . . $ `grtext/grtext.cpp:165:9`!: {
532 structcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_8# {
533 char opcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_8#op.;
534 ddgr_colorcxx . . $ ddgr_color# colcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_8#col.;
535 } cmd;
536
537 memcpy(&cmd, &Grtext_buffercxx . . $ Grtext_buffer.[pos], sizeof(cmd));
538 pos += sizeof(cmd);
539 rend_SetFlatColorcxx . . $ rend_SetFlatColor(cb2f890c2fdad230).(cmd.colcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_8#col.);
540 // rend_SetCharacterParameters(cmd.col, cmd.col, cmd.col, cmd.col);
541 Grtext_colorscxx . . $ Grtext_colors.[0] = cmd.colcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_8#col.;
542 // Grtext_colors[1] = cmd.col[1];
543 // Grtext_colors[2] = cmd.col[2];
544 // Grtext_colors[3] = cmd.col[3];
545 } break;
546
547 case GRTEXTOP_SETFLAGScxx . . $ `grtext/grtext.cpp:170:9`!: {
548 structcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_9# {
549 char opcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_9#op.;
550 int flagscxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_9#flags.;
551 } cmd;
552
553 memcpy(&cmd, &Grtext_buffercxx . . $ Grtext_buffer.[pos], sizeof(cmd));
554 pos += sizeof(cmd);
555
556 if (cmd.flagscxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_9#flags. & GRTEXTFLAG_SATURATEcxx . . $ `grtext/grtext.h:119:9`!)
557 Grtext_alphatypecxx . . $ Grtext_alphatype. = AT_SATURATE_TEXTUREcxx . . $ `lib/renderer.h:408:9`!;
558 else
559 Grtext_alphatypecxx . . $ Grtext_alphatype. = ATF_CONSTANTcxx . . $ `lib/renderer.h:394:9`! + ATF_TEXTUREcxx . . $ `lib/renderer.h:395:9`!;
560 rend_SetAlphaTypecxx . . $ rend_SetAlphaType(4af4fd0e2b26c4ac).(Grtext_alphatypecxx . . $ Grtext_alphatype.);
561
562 if (cmd.flagscxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_9#flags. & GRTEXTFLAG_SHADOWcxx . . $ `grtext/grtext.h:120:9`!)
563 Grtext_shadowcxx . . $ Grtext_shadow. = true;
564 else
565 Grtext_shadowcxx . . $ Grtext_shadow. = false;
566 } break;
567
568 case GRTEXTOP_FANCYCOLORcxx . . $ `grtext/grtext.cpp:166:9`!: {
569 structcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_10# {
570 char opcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_10#op.;
571 // ddgr_color col[4];
572 ddgr_colorcxx . . $ ddgr_color# colcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_10#col.;
573 } cmd;
574
575 memcpy(&cmd, &Grtext_buffercxx . . $ Grtext_buffer.[pos], sizeof(cmd));
576 pos += sizeof(cmd);
577 rend_SetFlatColorcxx . . $ rend_SetFlatColor(cb2f890c2fdad230).(cmd.colcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_10#col.);
578 // rend_SetCharacterParameters(cmd.col[0], cmd.col[1], cmd.col[2], cmd.col[3]);
579 Grtext_colorscxx . . $ Grtext_colors.[0] = cmd.colcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_10#col.;
580 // Grtext_colors[1] = cmd.col[1];
581 // Grtext_colors[2] = cmd.col[2];
582 // Grtext_colors[3] = cmd.col[3];
583 } break;
584
585 case GRTEXTOP_SETALPHAcxx . . $ `grtext/grtext.cpp:168:9`!: {
586 structcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_11# {
587 char opcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_11#op.;
588 uint8_tcxx . . $ uint8_t# alphacxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_11#alpha.;
589 } cmd;
590
591 memcpy(&cmd, &Grtext_buffercxx . . $ Grtext_buffer.[pos], sizeof(cmd));
592 pos += sizeof(cmd);
593 rend_SetAlphaValuecxx . . $ rend_SetAlphaValue(ac50b47256ae7414).(cmd.alphacxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_11#alpha.);
594 } break;
595
596 case GRTEXTOP_SETFONTcxx . . $ `grtext/grtext.cpp:167:9`!: {
597 structcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_12# {
598 char opcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_12#op.;
599 int handlecxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_12#handle.;
600 } cmd;
601
602 memcpy(&cmd, &Grtext_buffercxx . . $ Grtext_buffer.[pos], sizeof(cmd));
603 pos += sizeof(cmd);
604 Grtext_fontcxx . . $ Grtext_font. = cmd.handlecxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_12#handle.;
605 } break;
606
607 case GRTEXTOP_PUTScxx . . $ `grtext/grtext.cpp:164:9`!: {
608 structcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_13# {
609 char opcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_13#op.;
610 int16_tcxx . . $ int16_t# xcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_13#x., ycxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_13#y.;
611 } cmd;
612
613 memcpy(&cmd, &Grtext_buffercxx . . $ Grtext_buffer.[pos], sizeof(cmd));
614 pos += sizeof(cmd);
615 if (Grtext_shadowcxx . . $ Grtext_shadow.) {
616 // rend_SetCharacterParameters(0,0,0,0);
617 rend_SetFlatColorcxx . . $ rend_SetFlatColor(cb2f890c2fdad230).(0);
618 grtext_RenderStringcxx . . $ grtext_RenderString(1839e3b9b1397d59).(cmd.xcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_13#x. + 1, cmd.ycxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_13#y. + 1, &Grtext_buffercxx . . $ Grtext_buffer.[pos]);
619 rend_SetFlatColorcxx . . $ rend_SetFlatColor(cb2f890c2fdad230).(Grtext_colorscxx . . $ Grtext_colors.[0]);
620 // rend_SetCharacterParameters(Grtext_colors[0],Grtext_colors[1],Grtext_colors[2],Grtext_colors[3]);
621 }
622 grtext_RenderStringcxx . . $ grtext_RenderString(1839e3b9b1397d59).(cmd.xcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_13#x., cmd.ycxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_13#y., &Grtext_buffercxx . . $ Grtext_buffer.[pos]);
623 pos += (strlen(&Grtext_buffercxx . . $ Grtext_buffer.[pos]) + 1);
624 } break;
625
626 case GRTEXTOP_PUTCHARcxx . . $ `grtext/grtext.cpp:169:9`!: {
627 tCharBltcxx . . $ tCharBlt# cbi;
628 structcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_14# {
629 char opcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_14#op.;
630 int16_tcxx . . $ int16_t# xcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_14#x., ycxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_14#y.;
631 uint8_tcxx . . $ uint8_t# chcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_14#ch.;
632 } cmd;
633
634 memcpy(&cmd, &Grtext_buffercxx . . $ Grtext_buffer.[pos], sizeof(cmd));
635 pos += sizeof(cmd);
636 cbi.chcxx . . $ tCharBlt#ch. = cmd.chcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_14#ch.;
637 cbi.clippedcxx . . $ tCharBlt#clipped. = false; // if =1, use sx,sy,sw,sh
638 cbi.xcxx . . $ tCharBlt#x. = cmd.xcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_14#x.;
639 cbi.ycxx . . $ tCharBlt#y. = cmd.ycxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_14#y.;
640 if (Grtext_shadowcxx . . $ Grtext_shadow.) {
641 // rend_SetCharacterParameters(0,0,0,0);
642 rend_SetFlatColorcxx . . $ rend_SetFlatColor(cb2f890c2fdad230).(0);
643 cbi.xcxx . . $ tCharBlt#x. += 1;
644 cbi.ycxx . . $ tCharBlt#y. += 1;
645 grfont_BltCharcxx . . $ grfont_BltChar(3fbed1af05ab96ff).(Grtext_fontcxx . . $ Grtext_font., &cbi);
646 rend_SetFlatColorcxx . . $ rend_SetFlatColor(cb2f890c2fdad230).(Grtext_colorscxx . . $ Grtext_colors.[0]);
647 // rend_SetCharacterParameters(Grtext_colors[0],Grtext_colors[1],Grtext_colors[2],Grtext_colors[3]);
648 cbi.xcxx . . $ tCharBlt#x. -= 1;
649 cbi.ycxx . . $ tCharBlt#y. -= 1;
650 }
651 grfont_BltCharcxx . . $ grfont_BltChar(3fbed1af05ab96ff).(Grtext_fontcxx . . $ Grtext_font., &cbi);
652 } break;
653
654 case GRTEXTOP_SCALEcxx . . $ `grtext/grtext.cpp:171:9`!: {
655 structcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_15# {
656 char opcxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_15#op.;
657 float scalecxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_15#scale.;
658 } cmd;
659
660 memcpy(&cmd, &Grtext_buffercxx . . $ Grtext_buffer.[pos], sizeof(cmd));
661 pos += sizeof(cmd);
662 Grtext_scalecxx . . $ Grtext_scale. = cmd.scalecxx . . $ grtext_Render(49f6e7a06ebc5aa8).$anonymous_type_15#scale.;
663 } break;
664
665 default:
666 Int3cxx . . $ `misc/pserror.h:247:9`!(); // Truly bad.
667 }
668 }
669
670 // restore original state
671 rend_SetFilteringcxx . . $ rend_SetFiltering(4af4fd0e2b26c4ac).(1);
672 rend_SetZBufferStatecxx . . $ rend_SetZBufferState(4af4fd0e2b26c4ac).(1);
673 }
674
675 // draws a string
676 void grtext_RenderStringcxx . . $ grtext_RenderString(1839e3b9b1397d59).(int x, int y, char *str) {
677 int cur_x = x, cur_y = y, gx, gy;
678 char *line = str, *save_pos;
679
680 do {
681 // Look for newline, and if found, put in a 0 to terminate the line
682 save_pos = strchr(line, '\n');
683 if (save_pos) // found an newline
684 *save_pos = 0; // terminate the line
685
686 int line_width;
687 int clipped;
688
689 line_width = grtext_GetTextLineWidthcxx . . $ grtext_GetTextLineWidth(5c4306d8553b3696).(line);
690
691 gy = cur_y;
692 gx = cur_x; // Clip function needs global coords.
693
694 clipped = 0;
•695 if ((CLIP_TOPcxx . . $ `grtext/grtext.cpp:159:9`! > (gy + GRCHAR_HEIGHTcxx . . $ GRCHAR_HEIGHT(7864480464b09eea).(Grtext_fontcxx . . $ Grtext_font.))) || (CLIP_BOTTOMcxx . . $ `grtext/grtext.cpp:161:9`! < gy))
696 clipped = 2;
697 else if ((CLIP_LEFTcxx . . $ `grtext/grtext.cpp:158:9`! > (gx + line_width)) || (CLIP_RIGHTcxx . . $ `grtext/grtext.cpp:160:9`! < gx))
698 clipped = 2;
699
700 if (clipped != 2) {
701 if (CLIP_LEFTcxx . . $ `grtext/grtext.cpp:158:9`! > gx || CLIP_RIGHTcxx . . $ `grtext/grtext.cpp:160:9`! < (gx + line_width))
702 clipped = 1;
•703 if (CLIP_TOPcxx . . $ `grtext/grtext.cpp:159:9`! > gy || CLIP_BOTTOMcxx . . $ `grtext/grtext.cpp:161:9`! < (gy + GRCHAR_HEIGHTcxx . . $ GRCHAR_HEIGHT(7864480464b09eea).(Grtext_fontcxx . . $ Grtext_font.)))
704 clipped = 1;
705
706 if (clipped == 0)
707 grtext_DrawTextLinecxx . . $ grtext_DrawTextLine(1839e3b9b1397d59).(gx, gy, line);
708 else if (clipped == 1)
709 grtext_DrawTextLineClipcxx . . $ grtext_DrawTextLineClip(1839e3b9b1397d59).(gx, gy, line);
710 }
•711 cur_y += (Grtext_line_spacingcxx . . $ Grtext_line_spacing. + GRCHAR_HEIGHTcxx . . $ GRCHAR_HEIGHT(7864480464b09eea).(Grtext_fontcxx . . $ Grtext_font.));
712 cur_x = CLIP_LEFTcxx . . $ `grtext/grtext.cpp:158:9`!;
713
714 // replace the newline, if there was one
715 if (save_pos)
716 *save_pos++ = '\n';
717
718 line = save_pos;
719
720 } while (line);
721 }
722
723 int grtext_GetTextHeightTemplatecxx . . $ grtext_GetTextHeightTemplate(93ac3d427ebf4f7a).(tFontTemplatecxx . . $ tFontTemplate# *ft, const char *str) {
724 int cur_h = 0;
725 const char *spos = str;
726
727 do {
•728 cur_h += (Grtext_line_spacingcxx . . $ Grtext_line_spacing. + GRCHAR_HEIGHT_TEMPcxx . . $ GRCHAR_HEIGHT_TEMP(d54be1c0b38addb8).(ft));
729
730 spos = strchr(spos, '\n');
731 if (spos)
732 spos++;
733 } while (spos);
734
735 return cur_h;
736 }
737
738 int grtext_GetTextHeightcxx . . $ grtext_GetTextHeight(5c4306d8553b3696).(const char *str) {
739 int cur_h = 0;
740 const char *spos = str;
741
742 do {
•743 cur_h += (Grtext_line_spacingcxx . . $ Grtext_line_spacing. + GRCHAR_HEIGHTcxx . . $ GRCHAR_HEIGHT(7864480464b09eea).(Grtext_fontcxx . . $ Grtext_font.));
744
745 spos = strchr(spos, '\n');
746 if (spos)
747 spos++;
748 } while (spos);
749
750 return cur_h;
751 }
752
753 int grtext_GetTextLineWidthcxx . . $ grtext_GetTextLineWidth(5c4306d8553b3696).(const char *str) {
754 int line_width = 0, max_width = 0;
755 int rgb_define_mode = 0;
756 int strsize = strlen(str);
757 int line_idx = 0;
758
759 for (int i = 0; i < strsize; i++) {
760 int width;
761 char ch = str[i], ch2 = str[i + 1];
762
763 // note that if we hit the GR_COLOR_CHAR then the next three values should
764 // not count when defining the width of the line.
765 if (rgb_define_mode == 3)
766 rgb_define_mode = 0;
767 else if (ch == GR_COLOR_CHARcxx . . $ `lib/grdefs.h:82:9`!)
768 rgb_define_mode = 1;
769 if (!rgb_define_mode) {
770 if (ch == '\t') { // tab char
•771 int space_width;
772 space_width = (GRCHAR_WIDTHcxx . . $ GRCHAR_WIDTH(9b79fb6aee4c0440).(Grtext_fontcxx . . $ Grtext_font., ' ') + Grtext_spacingcxx . . $ Grtext_spacing.) * Grtext_tabspacecxx . . $ Grtext_tabspace.;
773 line_width = (line_width + space_width) / space_width * space_width;
774 } else if (ch == GRTEXT_FORMAT_CHARcxx . . $ `grtext/grtext.h:116:9`!) {
775 if ((i + 1) >= strsize)
776 break;
777 line_width = ((int)str[i + 1] * GRTEXT_FORMAT_SCALARcxx . . $ `grtext/grtext.h:117:9`!);
778 i++;
779 } else if (ch == '\n') {
780 if (line_width > max_width) {
781 max_width = line_width;
782 }
783 line_width = 0;
•784 } else {
785 width = GRCHAR_WIDTHcxx . . $ GRCHAR_WIDTH(9b79fb6aee4c0440).(Grtext_fontcxx . . $ Grtext_font., ch);
786 line_width += (width + Grtext_spacingcxx . . $ Grtext_spacing. + GRCHAR_SPACINGcxx . . $ GRCHAR_SPACING(2326284602b0bb2d).(Grtext_fontcxx . . $ Grtext_font., ch, ch2));
787 }
788 } else
789 rgb_define_mode++;
790 }
791
792 if (line_width > max_width) {
793 max_width = line_width;
794 }
795 return (max_width) ? max_width - Grtext_spacingcxx . . $ Grtext_spacing. : 0;
796 }
797
798 // returns width of text using a font template
799 int grtext_GetTextLineWidthTemplatecxx . . $ grtext_GetTextLineWidthTemplate(1590a249ecc23cdb).(const tFontTemplatecxx . . $ tFontTemplate# *ft, const char *str) {
800 int max_width = 0, i, line_width = 0, strsize = strlen(str);
801 int rgb_define_mode = 0;
802
803 for (i = 0; i < strsize; i++) {
804 int width;
805 char ch = str[i], ch2 = str[i + 1];
806
807 // note that if we hit the GR_COLOR_CHAR then the next three values should
808 // not count when defining the width of the line.
809 if (rgb_define_mode == 3)
810 rgb_define_mode = 0;
811 else if (ch == GR_COLOR_CHARcxx . . $ `lib/grdefs.h:82:9`!)
812 rgb_define_mode = 1;
813 if (!rgb_define_mode) {
814 if (ch == '\t') { // tab char
•815 int space_width;
816 space_width = (GRCHAR_WIDTH_TEMPcxx . . $ GRCHAR_WIDTH_TEMP(7b9a34a34a762d11).(ft, ' ') + Grtext_spacingcxx . . $ Grtext_spacing.) * Grtext_tabspacecxx . . $ Grtext_tabspace.;
817 line_width = (line_width + space_width) / space_width * space_width;
818 } else if (ch == GRTEXT_FORMAT_CHARcxx . . $ `grtext/grtext.h:116:9`!) {
819 if ((i + 1) >= strsize)
820 break;
821 line_width = ((int)str[i + 1] * GRTEXT_FORMAT_SCALARcxx . . $ `grtext/grtext.h:117:9`!);
822 i++;
823 } else if (ch == '\n') {
824 if (line_width > max_width) {
825 max_width = line_width;
826 }
827 line_width = 0;
•828 } else {
829 width = GRCHAR_WIDTH_TEMPcxx . . $ GRCHAR_WIDTH_TEMP(7b9a34a34a762d11).(ft, ch);
830 line_width += (width + Grtext_spacingcxx . . $ Grtext_spacing. + GRCHAR_SPACING_TEMPcxx . . $ GRCHAR_SPACING_TEMP(1511bff7f72f8bee).(ft, ch, ch2));
831 }
832 } else
833 rgb_define_mode++;
834 }
835
836 if (max_width < line_width) {
837 max_width = line_width;
838 }
839 return (max_width) ? max_width - Grtext_spacingcxx . . $ Grtext_spacing. : 0;
840 }
841
842 /* These internal routines just draw a line of text. depending on the function
843 we clip or don't clip
844 */
845 void grtext_DrawTextLineClipcxx . . $ grtext_DrawTextLineClip(1839e3b9b1397d59).(int x, int y, char *str) {
846 int ch_y, ch_x, ch_w, ch_h; // what part of the character to draw
847 int i, cur_x, draw_x, draw_y; // where to draw character section
848 int h;
849 tCharBltcxx . . $ tCharBlt# cbi;
850 int strsize = strlen(str);
851
852 /* by clipping, we should first determine what our vertical clipping is. then
853 go through each character in the line and determine what is totally clipped,
854 partially clipped and by how much, and not clipped at all and draw accordingly
•855 */
856 h = GRCHAR_HEIGHTcxx . . $ GRCHAR_HEIGHT(7864480464b09eea).(Grtext_fontcxx . . $ Grtext_font.);
857 ch_y = 0;
858 ch_h = h;
859 draw_y = y;
860 // determine each character bitmap y and height to blt.
861 if (CLIP_TOPcxx . . $ `grtext/grtext.cpp:159:9`! >= y) {
862 ch_y = CLIP_TOPcxx . . $ `grtext/grtext.cpp:159:9`! - y;
863 draw_y = CLIP_TOPcxx . . $ `grtext/grtext.cpp:159:9`!;
•864 }
865 if (CLIP_BOTTOMcxx . . $ `grtext/grtext.cpp:161:9`! < (y + GRCHAR_HEIGHTcxx . . $ GRCHAR_HEIGHT(7864480464b09eea).(Grtext_fontcxx . . $ Grtext_font.))) {
866 ch_h = CLIP_BOTTOMcxx . . $ `grtext/grtext.cpp:161:9`! - y;
867 }
868 ch_h = ch_h - ch_y; // do this to clip both top and bottom
869
870 cur_x = x;
871 for (i = 0; i < strsize; i++) {
872 uint8_tcxx . . $ uint8_t# ch, ch2;
873 int w;
874 ch = (uint8_tcxx . . $ uint8_t#)str[i];
875 ch2 = (uint8_tcxx . . $ uint8_t#)str[i + 1];
•876
877 w = GRCHAR_WIDTHcxx . . $ GRCHAR_WIDTH(9b79fb6aee4c0440).(Grtext_fontcxx . . $ Grtext_font., ch);
878
879 if (ch == GR_COLOR_CHARcxx . . $ `lib/grdefs.h:82:9`!) {
880 ddgr_colorcxx . . $ ddgr_color# col;
881 if ((i + 3) >= strsize)
882 break; // This shouldn't happen! bad string!
883 col = GR_RGBcxx . . $ GR_RGB(530956271a9518a5).(str[i + 1], str[i + 2], str[i + 3]);
884 rend_SetFlatColorcxx . . $ rend_SetFlatColor(cb2f890c2fdad230).(col);
885 // rend_SetCharacterParameters(col, col, col, col);
886 i += 3;
887 } else if (ch == '\t') { // tab char
•888 int space_width;
889 space_width = (GRCHAR_WIDTHcxx . . $ GRCHAR_WIDTH(9b79fb6aee4c0440).(Grtext_fontcxx . . $ Grtext_font., ' ') + Grtext_spacingcxx . . $ Grtext_spacing.) * Grtext_tabspacecxx . . $ Grtext_tabspace.;
890 cur_x = (cur_x + space_width) / space_width * space_width;
891 } else if (((cur_x + w) < CLIP_LEFTcxx . . $ `grtext/grtext.cpp:158:9`!) || (cur_x > CLIP_RIGHTcxx . . $ `grtext/grtext.cpp:160:9`!)) {
892 cur_x += (Grtext_spacingcxx . . $ Grtext_spacing. + w);
893 } else if (ch == GRTEXT_FORMAT_CHARcxx . . $ `grtext/grtext.h:116:9`!) {
894 if ((i + 1) >= strsize)
895 break; // This shouldn't happen! bad string!
896 cur_x = x + ((int)str[i + 1] * GRTEXT_FORMAT_SCALARcxx . . $ `grtext/grtext.h:117:9`!);
897 i++;
•898 } else if (ch == ' ') {
899 cur_x += (GRCHAR_WIDTHcxx . . $ GRCHAR_WIDTH(9b79fb6aee4c0440).(Grtext_fontcxx . . $ Grtext_font., ' ') + Grtext_spacingcxx . . $ Grtext_spacing. + GRCHAR_SPACINGcxx . . $ GRCHAR_SPACING(2326284602b0bb2d).(Grtext_fontcxx . . $ Grtext_font., ch, ch2));
900 } else {
901 ch_x = 0;
902 ch_w = w;
903 draw_x = cur_x;
904 if (CLIP_LEFTcxx . . $ `grtext/grtext.cpp:158:9`! > cur_x) {
905 ch_x = CLIP_LEFTcxx . . $ `grtext/grtext.cpp:158:9`! - cur_x;
906 draw_x = CLIP_LEFTcxx . . $ `grtext/grtext.cpp:158:9`!;
907 }
908 if (CLIP_RIGHTcxx . . $ `grtext/grtext.cpp:160:9`! < (cur_x + w)) {
909 ch_w = CLIP_RIGHTcxx . . $ `grtext/grtext.cpp:160:9`! - cur_x;
910 }
911 ch_w = ch_w - ch_x;
912
913 if (ch_x == 0 && ch_w == w && ch_y == 0 && ch_h == h) {
914 cbi.chcxx . . $ tCharBlt#ch. = ch;
915 cbi.clippedcxx . . $ tCharBlt#clipped. = false; // if =1, use sx,sy,sw,sh
916 cbi.xcxx . . $ tCharBlt#x. = draw_x;
917 cbi.ycxx . . $ tCharBlt#y. = draw_y;
918 cbi.dswcxx . . $ tCharBlt#dsw. = cbi.dshcxx . . $ tCharBlt#dsh. = Grtext_scalecxx . . $ Grtext_scale.;
919 } else {
920 cbi.chcxx . . $ tCharBlt#ch. = ch;
921 cbi.clippedcxx . . $ tCharBlt#clipped. = true; // if =1, use sx,sy,sw,sh
922 cbi.xcxx . . $ tCharBlt#x. = draw_x;
923 cbi.ycxx . . $ tCharBlt#y. = draw_y;
924 cbi.dswcxx . . $ tCharBlt#dsw. = cbi.dshcxx . . $ tCharBlt#dsh. = Grtext_scalecxx . . $ Grtext_scale.; // this should be useless since ch_w and ch_h are scaled values
925 cbi.sxcxx . . $ tCharBlt#sx. = ch_x;
926 cbi.sycxx . . $ tCharBlt#sy. = ch_y;
927 cbi.swcxx . . $ tCharBlt#sw. = ch_w;
928 cbi.shcxx . . $ tCharBlt#sh. = ch_h;
929 }
•930 cur_x = grfont_BltCharcxx . . $ grfont_BltChar(3fbed1af05ab96ff).(Grtext_fontcxx . . $ Grtext_font., &cbi);
931 cur_x += (Grtext_spacingcxx . . $ Grtext_spacing. + GRCHAR_SPACINGcxx . . $ GRCHAR_SPACING(2326284602b0bb2d).(Grtext_fontcxx . . $ Grtext_font., ch, ch2));
932 }
933 }
934 }
935
936 void grtext_DrawTextLinecxx . . $ grtext_DrawTextLine(1839e3b9b1397d59).(int x, int y, char *str) {
937 int i, cur_x;
938 tCharBltcxx . . $ tCharBlt# cbi;
939 int strsize = strlen(str);
940
941 /* by clipping, we should first determine what our vertical clipping is. then
942 go through each character in the line and determine what is totally clipped,
943 partially clipped and by how much, and not clipped at all and draw accordingly
944
945 perform string drawing without viewport clipping.
946 supports bitmap fonts or color(alpha) mapped fonts.
947 */
948 cur_x = x;
949 for (i = 0; i < strsize; i++) {
950 uint8_tcxx . . $ uint8_t# ch, ch2;
951 int w;
952 ch = (uint8_tcxx . . $ uint8_t#)str[i];
•953 ch2 = (uint8_tcxx . . $ uint8_t#)str[i + 1];
954 w = GRCHAR_WIDTHcxx . . $ GRCHAR_WIDTH(9b79fb6aee4c0440).(Grtext_fontcxx . . $ Grtext_font., ch);
955
956 if (ch == GR_COLOR_CHARcxx . . $ `lib/grdefs.h:82:9`!) {
957 ddgr_colorcxx . . $ ddgr_color# col;
958 if ((i + 3) >= strsize)
959 break; // This shouldn't happen! bad string!
960 col = GR_RGBcxx . . $ GR_RGB(530956271a9518a5).(str[i + 1], str[i + 2], str[i + 3]);
961 rend_SetFlatColorcxx . . $ rend_SetFlatColor(cb2f890c2fdad230).(col);
962 // rend_SetCharacterParameters(col, col, col, col);
963 i += 3;
964 } else if (ch == '\t') { // tab char
•965 int space_width;
966 space_width = (GRCHAR_WIDTHcxx . . $ GRCHAR_WIDTH(9b79fb6aee4c0440).(Grtext_fontcxx . . $ Grtext_font., ' ') + Grtext_spacingcxx . . $ Grtext_spacing.) * Grtext_tabspacecxx . . $ Grtext_tabspace.;
967 cur_x = (cur_x + space_width) / space_width * space_width;
968 } else if (ch == GRTEXT_FORMAT_CHARcxx . . $ `grtext/grtext.h:116:9`!) {
969 if ((i + 1) >= strsize)
970 break; // This shouldn't happen! bad string!
971 cur_x = x + ((int)str[i + 1] * GRTEXT_FORMAT_SCALARcxx . . $ `grtext/grtext.h:117:9`!);
972 i++;
•973 } else if (ch == ' ') {
974 cur_x += (GRCHAR_WIDTHcxx . . $ GRCHAR_WIDTH(9b79fb6aee4c0440).(Grtext_fontcxx . . $ Grtext_font., ' ') + Grtext_spacingcxx . . $ Grtext_spacing.);
975 } else {
976 cbi.chcxx . . $ tCharBlt#ch. = ch;
977 cbi.clippedcxx . . $ tCharBlt#clipped. = false; // if =1, use sx,sy,sw,sh
978 cbi.xcxx . . $ tCharBlt#x. = cur_x;
979 cbi.ycxx . . $ tCharBlt#y. = y;
980 cbi.dswcxx . . $ tCharBlt#dsw. = cbi.dshcxx . . $ tCharBlt#dsh. = Grtext_scalecxx . . $ Grtext_scale.;
•981 cur_x = grfont_BltCharcxx . . $ grfont_BltChar(3fbed1af05ab96ff).(Grtext_fontcxx . . $ Grtext_font., &cbi);
982 cur_x += (Grtext_spacingcxx . . $ Grtext_spacing. + GRCHAR_SPACINGcxx . . $ GRCHAR_SPACING(2326284602b0bb2d).(Grtext_fontcxx . . $ Grtext_font., ch, ch2));
983 }
984 }
985 }