comparison GUIFont.cpp @ 1163:3d96daa7e069

Merge
author Grumpy7
date Tue, 04 Jun 2013 01:41:12 +0200
parents 502b8b2e36b4
children 29a8defbad9e
comparison
equal deleted inserted replaced
1162:79fd2fb7a3ab 1163:3d96daa7e069
25 25
26 char temp_string[2048]; 26 char temp_string[2048];
27 27
28 char pTmpBuf3[10000]; 28 char pTmpBuf3[10000];
29 29
30 void DrawCharToBuff(unsigned short* uXpos,unsigned char* pCharPixels, int uCharWidth, int uCharHeight, unsigned __int16* pFontPalette, __int16 draw_color, int line_width);
31
32
30 //----- (0044C448) -------------------------------------------------------- 33 //----- (0044C448) --------------------------------------------------------
31 GUIFont *LoadFont(const char *pFontFile, const char *pFontPalette, ...) 34 GUIFont *LoadFont(const char *pFontFile, const char *pFontPalette, ...)
32 { 35 {
33 36 int pallete_index; // eax@3
34 int pallete_index; // eax@3 37 GUIFont *pFont;
35 GUIFont *pFont; 38 unsigned int palletes_count =0;
36 unsigned int palletes_count =0; 39 va_list palettes_ptr;
37 va_list palettes_ptr; 40
38 41 pFont = (GUIFont *)pIcons_LOD->LoadRaw(pFontFile, 0);
39 pFont = (GUIFont *)pIcons_LOD->LoadRaw(pFontFile, 0); 42 va_start(palettes_ptr, pFontFile);
40 va_start(palettes_ptr, pFontFile); 43
41 44 while (NULL!=(pFontPalette=va_arg(palettes_ptr, const char *)))
42 while (NULL!=(pFontPalette=va_arg(palettes_ptr, const char *))) 45 {
43 { 46 pallete_index =pIcons_LOD->LoadTexture(pFontPalette, TEXTURE_16BIT_PALETTE);
44 pallete_index =pIcons_LOD->LoadTexture(pFontPalette, TEXTURE_16BIT_PALETTE); 47 if (pallete_index == -1)
45 if (pallete_index == -1) 48 {
46 { 49 wsprintfA(pTmpBuf, "Unable to open %s", pFontPalette);
47 wsprintfA(pTmpBuf, "Unable to open %s", pFontPalette); 50 Abortf(pTmpBuf);
48 Abortf(pTmpBuf); 51 }
49 } 52 pFont->pFontPalettes[palletes_count] = pIcons_LOD->pTextures[pallete_index].pPalette16;
50 pFont->pFontPalettes[palletes_count] = pIcons_LOD->pTextures[pallete_index].pPalette16; 53 ++palletes_count;
51 ++palletes_count; 54 }
52 } 55 va_end(palettes_ptr);
53 va_end(palettes_ptr); 56 pFont->palletes_count = palletes_count;
54 pFont->palletes_count = palletes_count; 57 return pFont;
55 return pFont; 58 }
56 }
57 59
58 60
59 61
60 //----- (0044D2FD) -------------------------------------------------------- 62 //----- (0044D2FD) --------------------------------------------------------
61 void GUIFont::_44D2FD_prolly_draw_credits_entry(GUIFont *pFont, int Str, int a4, unsigned int w, unsigned int h, unsigned __int16 a7, unsigned __int16 a8, const char *pString, unsigned __int16 *pPixels, unsigned int uPixelsWidth) 63 void GUIFont::_44D2FD_prolly_draw_credits_entry(GUIFont *pFont, int Str, int a4, unsigned int w, unsigned int h,
64 unsigned __int16 a7, unsigned __int16 a8, const char *pString,
65 unsigned __int16 *pPixels, unsigned int uPixelsWidth)
62 { 66 {
63 int v11; // ebx@1 67 int v11; // ebx@1
64 int v12; // edi@1 68 int v12; // edi@1
65 char *v13; // eax@1 69 char *v13; // eax@1
66 char *v14; // eax@1 70 char *v14; // eax@1
112 v17 = 1; 116 v17 = 1;
113 } 117 }
114 v18 = (signed int)(w - v16->GetLineWidth(&v14[v17])) >> 1; 118 v18 = (signed int)(w - v16->GetLineWidth(&v14[v17])) >> 1;
115 if ( v18 < 0 ) 119 if ( v18 < 0 )
116 v18 = 0; 120 v18 = 0;
117 v16->_44D0B5(a4a, a8, (int)&v15[v18 + a7a], Stra, uPixelsWidth); 121 v16->DrawTextLineToBuff(a4a, a8, &v15[v18 + a7a], Stra, uPixelsWidth);
118 v15 += uPixelsWidth * (LOBYTE(v16->uFontHeight) - 3); 122 v15 += uPixelsWidth * (LOBYTE(v16->uFontHeight) - 3);
119 Stra = strtok(0, "\n"); 123 Stra = strtok(0, "\n");
120 if ( !Stra ) 124 if ( !Stra )
121 break; 125 break;
122 v14 = Stra; 126 v14 = Stra;
125 } 129 }
126 // 5C6DB4: using guessed type int ui_current_text_color; 130 // 5C6DB4: using guessed type int ui_current_text_color;
127 131
128 132
129 //----- (0044D1E7) -------------------------------------------------------- 133 //----- (0044D1E7) --------------------------------------------------------
130 void GUIFont::DrawTextLine(unsigned int uDefaultColor, signed int uX, signed int uY, const char *Str, int a6) 134 void GUIFont::DrawTextLine( unsigned int uDefaultColor, signed int uX, signed int uY,
135 const char *text, int max_len_pix )
131 { 136 {
132 size_t v6; // ebx@1 137 signed int uX_pos; // edi@3
133 GUIFont *pFont; // esi@1 138 unsigned char c; // cl@4
134 signed int v8; // edi@3 139 unsigned __int16 draw_color; // cx@12
135 unsigned __int8 v9; // cl@4 140 unsigned __int8 *pCharPixels; // eax@12
136 int v10; // eax@5 141 char color_code[20]; // [sp+Ch] [bp-1Ch]@16
137 int v11; // ecx@5 142 int text_length; // [sp+20h] [bp-8h]@2
138 int v12; // ecx@6 143 int text_color; // [sp+24h] [bp-4h]@1
139 int v13; // ecx@7 144 int uCharWidth; // [sp+30h] [bp+8h]@9
140 int v14; // ecx@9 145
141 unsigned int v15; // edx@9 146 if ( !text )
142 unsigned __int16 v16; // cx@12 147 return;
143 unsigned __int8 *v17; // eax@12 148 text_color = ui_current_text_color;
144 char Dest[20]; // [sp+Ch] [bp-1Ch]@16 149 text_length = strlen(text);
145 //char v19; // [sp+11h] [bp-17h]@16 150 uX_pos=uX;
146 size_t v20; // [sp+20h] [bp-8h]@2 151 for (int i=0; i<text_length; ++i )
147 int v21; // [sp+24h] [bp-4h]@1 152 {
148 int uXa; // [sp+30h] [bp+8h]@9 153 c = text[i];
149 154 if ( IsCharValid(c) )
150 v6 = 0; 155 {
151 v21 = uDefaultColor; 156 switch (c)
152 pFont = this; 157 {
153 if ( Str ) 158 case '\n': //Line Feed 0A 10:
154 { 159 return;
155 v21 = ui_current_text_color; 160 break;
156 v20 = strlen(Str); 161 case '\f': //Form Feed, page eject 0C 12
157 if ( (signed int)v20 > 0 ) 162 strncpy(color_code, &text[i + 1], 5);
163 color_code[5] = 0;
164 text_color = atoi(color_code);
165 ui_current_text_color = text_color;
166 i += 5;
167 break;
168 case '\t': // Horizontal tab 09
169 case '\r': //Carriage Return 0D 13
170 break;
171 default:
172 uCharWidth = pMetrics[c].uWidth;
173 if ( uCharWidth )
174 {
175 if ( i > 0 )
176 uX_pos += pMetrics[c].uLeftSpacing;
177 draw_color = text_color;
178 pCharPixels = &pFontData[font_pixels_offset[c]];
179 if ( !text_color )
180 draw_color = -1;
181 pRenderer->DrawText(uX_pos, uY, pCharPixels, uCharWidth, uFontHeight, pFontPalettes[0], draw_color, 0);
182 uX_pos += uCharWidth;
183 if ( i < text_length )
184 uX_pos += pMetrics[c].uRightSpacing;
185 }
186 }
187 }
188 }
189
190 }
191
192 //----- (0040F845) --------------------------------------------------------
193 void DrawCharToBuff( unsigned short* uXpos,unsigned char* pCharPixels, int uCharWidth, int uCharHeight,
194 unsigned __int16* pFontPalette, __int16 draw_color, int line_width )
158 { 195 {
159 v8 = uX; 196 unsigned __int16* draw_buff; // edi@1
160 do 197 unsigned char* pPixels; // esi@1
198 unsigned char char_pxl; // eax@3
199
200 draw_buff = uXpos;
201 pPixels = pCharPixels;
202 for(int i=0; i<uCharHeight; ++i)
203 {
204 for(int j=0; j<uCharWidth; ++j)
205 {
206 char_pxl = *pPixels++;
207 if ( char_pxl )
208 {
209 if ( char_pxl == 1 )
210 *draw_buff = pFontPalette[1];
211 else
212 *draw_buff = draw_color;
213 }
214 ++draw_buff;
215 }
216 draw_buff+=line_width-uCharWidth;
217 }
218
219 }
220
221 //----- (0044D0B5) --------------------------------------------------------
222 void GUIFont::DrawTextLineToBuff( int uColor, int a3, unsigned short* uX_buff_pos, const char *text, int line_width )
223 {
224
225 unsigned short* uX_pos; // edi@3
226 unsigned char c; // cl@4
227 unsigned __int16 draw_color; // cx@12
228 unsigned __int8 *pCharPixels; // eax@12
229 char color_code[20]; // [sp+Ch] [bp-1Ch]@16
230 int text_length; // [sp+20h] [bp-8h]@2
231 int text_color; // [sp+24h] [bp-4h]@1
232 int uCharWidth; // [sp+30h] [bp+8h]@9
233
234 if ( !text )
235 return;
236 text_color = ui_current_text_color;
237 text_length = strlen(text);
238 uX_pos=uX_buff_pos;
239 for (int i=0; i<text_length; ++i )
161 { 240 {
162 if ( pFont->IsCharValid(v9 = Str[v6]) ) 241 c = text[i];
163 { 242 if ( IsCharValid(c) )
164 v10 = v9;
165 v11 = v9 - 9;
166 if ( v11 )
167 { 243 {
168 v12 = v11 - 1; 244 switch (c)
169 if ( !v12 ) 245 {
246 case '\n': //Line Feed 0A 10:
170 return; 247 return;
171 v13 = v12 - 2; 248 break;
172 if ( v13 ) 249 case '\f': //Form Feed, page eject 0C 12
173 { 250 strncpy(color_code, &text[i + 1], 5);
174 if ( v13 != 1 ) 251 color_code[5] = 0;
175 { 252 text_color = atoi(color_code);
176 v14 = 3 * v10 + 9; 253 ui_current_text_color = text_color;
177 v15 = *((int *)&pFont->cFirstChar + v14); 254 i += 5;
178 uXa = *((int *)&pFont->cFirstChar + v14); 255 break;
179 if ( v15 ) 256 case '\t': // Horizontal tab 09
180 { 257 case '\r': //Carriage Return 0D 13
181 if ( (signed int)v6 > 0 ) 258 break;
182 v8 += pFont->pMetrics[v10].uLeftSpacing; 259 default:
183 v16 = v21; 260 uCharWidth = pMetrics[c].uWidth;
184 v17 = (unsigned __int8 *)((char *)&pFont[1] + pFont->field_C20[v10]); 261 if ( uCharWidth )
185 if ( !v21 ) 262 {
186 v16 = -1; 263 if ( i > 0 )
187 pRenderer->DrawText(v8, uY, v17, v15, pFont->uFontHeight, pFont->pFontPalettes[0], v16, 0); 264 uX_pos += pMetrics[c].uLeftSpacing;
188 v8 += uXa; 265 draw_color = text_color;
189 if ( (signed int)v6 < (signed int)v20 ) 266 pCharPixels = &pFontData[font_pixels_offset[c]];
190 v8 += pFont->pMetrics[(unsigned __int8)Str[v6]].uRightSpacing; 267 if ( !text_color )
191 } 268 draw_color = -1;
269 DrawCharToBuff(uX_pos, pCharPixels, uCharWidth, uFontHeight, pFontPalettes[0], draw_color, line_width);
270 uX_pos += uCharWidth;
271 if ( i < text_length )
272 uX_pos += pMetrics[c].uRightSpacing;
273 }
192 } 274 }
193 }
194 else
195 {
196 strncpy(Dest, &Str[v6 + 1], 5u);
197 Dest[5] = 0;
198 v21 = atoi(Dest);
199 ui_current_text_color = v21;
200 v6 += 5;
201 }
202 } 275 }
203 }
204 ++v6;
205 } 276 }
206 while ( (signed int)v6 < (signed int)v20 ); 277 }
207 } 278
208 }
209 }
210 // 5C6DB4: using guessed type int ui_current_text_color;
211
212
213 //----- (0044D0B5) --------------------------------------------------------
214 void GUIFont::_44D0B5(int a2, int a3, int a4, const char *pString, int a6)
215 {
216 int v6; // ebx@1
217 GUIFont *v7; // esi@1
218 int v8; // edi@3
219 unsigned __int8 v9; // cl@4
220 int v10; // eax@5
221 int v11; // ecx@5
222 int v12; // ecx@6
223 int v13; // ecx@7
224 int v14; // ecx@8
225 int v15; // ebx@10
226 int v16; // edx@13
227 __int16 v17; // ax@13
228 char Dest; // [sp+Ch] [bp-20h]@17
229 char v19; // [sp+11h] [bp-1Bh]@17
230 size_t v20; // [sp+20h] [bp-Ch]@2
231 int v21; // [sp+24h] [bp-8h]@1
232 int v22; // [sp+28h] [bp-4h]@2
233 const char *v23; // [sp+38h] [bp+Ch]@4
234
235 v6 = 0;
236 v21 = a2;
237 v7 = this;
238 if ( pString )
239 {
240 v21 = ui_current_text_color;
241 v20 = strlen(pString);
242 v22 = 0;
243 if ( (signed int)v20 > 0 )
244 {
245 v8 = a4;
246 do
247 {
248 v23 = &pString[v6];
249 if ( v7->IsCharValid(v9 = pString[v6]) )
250 {
251 v10 = v9;
252 v11 = v9 - 9;
253 if ( v11 )
254 {
255 v12 = v11 - 1;
256 if ( !v12 )
257 return;
258 v13 = v12 - 2;
259 if ( v13 )
260 {
261 v14 = v13 - 1;
262 if ( v14 )
263 {
264 if ( v14 != 82 )
265 {
266 v15 = *((int *)&v7->cFirstChar + 3 * v10 + 9);
267 if ( v15 )
268 {
269 if ( v22 > 0 )
270 v8 += 2 * v7->pMetrics[v10].uLeftSpacing;
271 v16 = (int)((char *)&v7[1] + v7->field_C20[v10]);
272 v17 = v21;
273 if ( !v21 )
274 v17 = -1;
275 sub_40F845(v8, v16, v15, LOBYTE(v7->uFontHeight), (int)v7->pFontPalettes[0], v17, 2 * a6);
276 v8 += 2 * v15;
277 if ( v22 < (signed int)v20 )
278 v8 += 2 * v7->pMetrics[(unsigned __int8)*v23].uRightSpacing;
279 }
280 }
281 }
282 }
283 else
284 {
285 strncpy(&Dest, &pString[v6 + 1], 5u);
286 v19 = 0;
287 v21 = atoi(&Dest);
288 ui_current_text_color = v21;
289 v22 = v6 + 5;
290 }
291 }
292 }
293 v6 = v22++ + 1;
294 }
295 while ( v22 < (signed int)v20 );
296 }
297 }
298 }
299 // 5C6DB4: using guessed type int ui_current_text_color;
300 279
301 280
302 //----- (0044C933) -------------------------------------------------------- 281 //----- (0044C933) --------------------------------------------------------
303 char * GUIFont::_44C933(const char *pString, GUIFont *pFont, GUIFont *a3, int a4, int a5, int a6) 282 char * GUIFont::_44C933(const char *pString, GUIFont *pFont, GUIFont *a3, int a4, int a5, int a6)
304 { 283 {
488 return pTmpBuf3; 467 return pTmpBuf3;
489 } 468 }
490 469
491 470
492 //----- (0044C6C2) -------------------------------------------------------- 471 //----- (0044C6C2) --------------------------------------------------------
493 int GUIFont::_44C6C2(const char *pInString, GUIWindow *pWindow, unsigned int uX, int a5) 472 char* GUIFont::_44C6C2( const char *pInString, GUIWindow *pWindow, unsigned int uX, int a5 )
494 { 473 {
495 const char *v5; // esi@1 474 int text_height; // edi@1
496 int v6; // edi@1 475 char *text_str; // ebx@3
497 unsigned __int8 *v8; // ebx@3 476 int i;
498 size_t v9; // eax@3 477 unsigned char c; // cl@4
499 signed int v10; // esi@3 478 int text_length;
500 int v11; // edx@4 479
501 unsigned int v12; // cl@4 480 text_height = 0;
502 GUIFont *v13; // [sp+Ch] [bp-4h]@1 481
503 size_t uXa; // [sp+1Ch] [bp+Ch]@3
504
505 auto pFont = this;
506 v5 = pInString;
507 v6 = 0;
508 v13 = pFont;
509 if ( !pInString ) 482 if ( !pInString )
510 return 0; 483 return 0;
511 v8 = (unsigned __int8 *)FitTextInAWindow(pInString, pFont, pWindow, uX, 0); 484 text_str = FitTextInAWindow(pInString, this, pWindow, uX, 0);
512 v9 = strlen(v5); 485 text_length = strlen(text_str);
513 v10 = 0; 486 //uX_pos=uX_buff_pos;
514 uXa = v9; 487 for (i=0; i<text_length; ++i )
515 if ( (signed int)v9 > 0 ) 488 {
516 { 489 c = text_str[i];
517 while ( v10 < (signed int)uXa ) 490 if ( IsCharValid(c) )
518 { 491 {
519 if(IsCharValid(*v8)) 492 switch (c)
520 { 493 {
521 v12=(unsigned int)v8; 494 case '\n': //Line Feed 0A 10:
522 if ( v12 != 9 ) 495 text_height = text_height + uFontHeight - 3;
523 { 496 if ( text_height >= (signed int)(a5 * pWindow->uFrameHeight) )
524 if ( v12 == 10 ) 497 return &text_str[i+1];
525 { 498 break;
526 v6 = v6 + *(char *)(v11 + 5) - 3; 499 case '\f': //Form Feed, page eject 0C 12
527 if ( v6 >= (signed int)(a5 * pWindow->uFrameHeight) ) 500 i += 5;
528 return (int)(v8 + 1); 501 break;
529 if ( v6 >= (signed int)(a5 * pWindow->uFrameHeight) ) 502 case '\t': // Horizontal tab 09
530 return (int)v8; 503 case '\r': //Carriage Return 0D 13
531 } 504 i += 3;
532 else if ( v12 == 12 ) 505 break;
533 { 506 }
534 v8 += 5; 507 if ( text_height >= (signed int)(a5 * pWindow->uFrameHeight) )
535 v10 += 5; 508 return &text_str[i];
536 if ( v6 >= (signed int)(a5 * pWindow->uFrameHeight) ) 509 }
537 return (int)v8; 510 }
538 } 511 return &text_str[i];
539 else if ( v12 != 13 )
540 {
541 if ( v6 >= (signed int)(a5 * pWindow->uFrameHeight) )
542 return (int)v8;
543 }
544 }
545 if(v12 == 13 || v12 == 9)
546 {
547 v8 += 3;
548 v10 += 3;
549 }
550 if ( v6 >= (signed int)(a5 * pWindow->uFrameHeight) )
551 return (int)v8;
552 }
553 ++v10;
554 ++v8;
555 }
556 }
557 return (int)v8;
558 } 512 }
559 513
560 514
561 515
562 //----- (0044C62E) -------------------------------------------------------- 516 //----- (0044C62E) --------------------------------------------------------
609 } 563 }
610 return v8; 564 return v8;
611 } 565 }
612 566
613 //----- (0044C59D) -------------------------------------------------------- 567 //----- (0044C59D) --------------------------------------------------------
614 int GUIFont::CalcTextHeight(const char *pString, GUIWindow *pWindow, int uXOffset, int a5) 568 int GUIFont::CalcTextHeight( const char *pString, struct GUIWindow *pWindow, int uXOffset, int a5 )
615 { 569 {
616 int uAllHeght; 570 int uAllHeght;
617 unsigned int uStringLen; 571 int uStringLen;
618 char c; 572 unsigned char c;
619 char *test_string; 573 char *test_string;
620 574
621 if (!pString) 575 if (!pString)
622 return 0; 576 return 0;
623 uAllHeght = this->uFontHeight - 3; 577 uAllHeght = this->uFontHeight - 3;
649 603
650 604
651 //----- (0044C51E) -------------------------------------------------------- 605 //----- (0044C51E) --------------------------------------------------------
652 int GUIFont::GetLineWidth(const char *pString) 606 int GUIFont::GetLineWidth(const char *pString)
653 { 607 {
654 unsigned int str_len; // ebp@3 608 int str_len; // ebp@3
655 int string_line_width; // esi@3 609 int string_line_width; // esi@3
656 unsigned char c; 610 unsigned char c;
657 611
658 if (!pString) 612 if (!pString)
659 return 0; 613 return 0;
701 655
702 //----- (0044C768) -------------------------------------------------------- 656 //----- (0044C768) --------------------------------------------------------
703 char * FitTextInAWindow( const char *pInString, GUIFont *pFont, GUIWindow *pWindow, signed int uX, int a5 ) 657 char * FitTextInAWindow( const char *pInString, GUIFont *pFont, GUIWindow *pWindow, signed int uX, int a5 )
704 { 658 {
705 unsigned char c; 659 unsigned char c;
706 unsigned int uInStrLen; 660 int uInStrLen;
707 char digits[4]; 661 char digits[4];
708 int possible_transition_point; 662 int possible_transition_point;
709 int string_pixel_Width; 663 int string_pixel_Width;
710 int start_pixel_offset; 664 int start_pixel_offset;
711 665