annotate GUI/GUIFont.cpp @ 2563:65c97624c047

Saving & loading works from both main menu and game
author a.parshin
date Tue, 19 May 2015 22:00:56 +0200
parents a902abdfc7f2
children
rev   line source
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1 #define _CRTDBG_MAP_ALLOC
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
2 #include <stdlib.h>
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
3 #include <crtdbg.h>
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
4
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
5 #define _CRT_SECURE_NO_WARNINGS
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
6 #include <string>
2541
a902abdfc7f2 1. Renamed class Game to class Engine.
a.parshin
parents: 2502
diff changeset
7
a902abdfc7f2 1. Renamed class Game to class Engine.
a.parshin
parents: 2502
diff changeset
8 #include "Engine/Engine.h"
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
9
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
10 #include "Engine/LOD.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
11 #include "GUIFont.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
12 #include "GUIWindow.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
13 #include "Engine/Graphics/Render.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
14
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
15
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
16 extern LODFile_IconsBitmaps *pIcons_LOD;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
17
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
18
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
19 struct GUIFont *pAutonoteFont;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
20 struct GUIFont *pSpellFont;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
21 struct GUIFont *pFontArrus;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
22 struct GUIFont *pFontLucida;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
23 struct GUIFont *pBook2Font;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
24 struct GUIFont *pBookFont;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
25 struct GUIFont *pFontCreate;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
26 struct GUIFont *pFontCChar;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
27 struct GUIFont *pFontComic;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
28 struct GUIFont *pFontSmallnum;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
29
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
30 char temp_string[2048];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
31
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
32 std::array<char, 10000> pTmpBuf3;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
33
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
34 void DrawCharToBuff(unsigned short* uXpos,unsigned char* pCharPixels, int uCharWidth, int uCharHeight, unsigned __int16* pFontPalette, __int16 draw_color, int line_width);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
35
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
36
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
37 //----- (0044C448) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
38 GUIFont *LoadFont(const char *pFontFile, const char *pFontPalette, ...)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
39 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
40 int pallete_index; // eax@3
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
41 GUIFont *pFont;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
42 unsigned int palletes_count =0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
43 va_list palettes_ptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
44
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
45 pFont = (GUIFont *)pIcons_LOD->LoadRaw(pFontFile, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
46 va_start(palettes_ptr, pFontFile);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
47
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
48 while (NULL!=(pFontPalette=va_arg(palettes_ptr, const char *)))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
49 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
50 pallete_index =pIcons_LOD->LoadTexture(pFontPalette, TEXTURE_16BIT_PALETTE);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
51 if (pallete_index == -1)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
52 Error("Unable to open %s", pFontPalette);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
53
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
54 pFont->pFontPalettes[palletes_count] = pIcons_LOD->pTextures[pallete_index].pPalette16;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
55 ++palletes_count;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
56 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
57 va_end(palettes_ptr);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
58 pFont->palletes_count = palletes_count;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
59 return pFont;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
60 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
61
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
62 //----- (0044D2FD) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
63 void GUIFont::_44D2FD_prolly_draw_credits_entry( GUIFont *pSecondFont, int uFrameX, int uFrameY, unsigned int w, unsigned int h,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
64 unsigned __int16 firstColor, unsigned __int16 secondColor, const char *pString,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
65 unsigned __int16 *pPixels, unsigned int uPixelsWidth )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
66 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
67 char *work_string; // eax@1
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
68 unsigned __int16 *curr_pixel_pos; // esi@1
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
69 GUIFont *currentFont; // edi@4
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
70 signed int start_str_pos; // ecx@4
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
71 signed int line_w; // eax@6
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
72 GUIWindow draw_window; // [sp+Ch] [bp-5Ch]@
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
73 int currentColor; // [sp+74h] [bp+Ch]@4
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
74 int half_frameX; // [sp+80h] [bp+18h]@2
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
75
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
76 draw_window.uFrameHeight = h;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
77 draw_window.uFrameW = uFrameY + h - 1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
78 draw_window.uFrameWidth = w;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
79 draw_window.uFrameZ = uFrameX + w - 1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
80 ui_current_text_color = firstColor;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
81 draw_window.uFrameX = uFrameX;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
82 draw_window.uFrameY = uFrameY;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
83
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
84 work_string = GUIFont::FitTwoFontStringINWindow(pString, this, pSecondFont, &draw_window, 0, 1);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
85 work_string = strtok(work_string, "\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
86 curr_pixel_pos = &pPixels[uPixelsWidth * uFrameY];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
87 if ( work_string )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
88 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
89 half_frameX = uFrameX >> 1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
90 while ( 1 )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
91 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
92 currentFont = this;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
93 ui_current_text_color = firstColor;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
94 start_str_pos = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
95 currentColor = firstColor;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
96 if ( *work_string == '_' )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
97 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
98 currentFont = pSecondFont;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
99 currentColor = secondColor;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
100 ui_current_text_color = secondColor;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
101 start_str_pos = 1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
102 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
103 line_w = (signed int)(w - currentFont->GetLineWidth(&work_string[start_str_pos]))/2;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
104 if ( line_w < 0 )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
105 line_w = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
106 currentFont->DrawTextLineToBuff(currentColor, secondColor, &curr_pixel_pos[line_w + half_frameX], work_string, uPixelsWidth);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
107 curr_pixel_pos += uPixelsWidth * (currentFont->uFontHeight - 3);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
108 work_string = strtok(0, "\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
109 if ( !work_string )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
110 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
111 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
112 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
113 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
114
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
115 //----- (0044D1E7) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
116 void GUIFont::DrawTextLine( unsigned int uDefaultColor, signed int uX, signed int uY,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
117 const char *text, int max_len_pix )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
118 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
119 signed int uX_pos; // edi@3
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
120 unsigned char c; // cl@4
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
121 unsigned __int16 draw_color; // cx@12
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
122 unsigned __int8 *pCharPixels; // eax@12
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
123 char color_code[20]; // [sp+Ch] [bp-1Ch]@16
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
124 int text_length; // [sp+20h] [bp-8h]@2
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
125 int text_color; // [sp+24h] [bp-4h]@1
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
126 int uCharWidth; // [sp+30h] [bp+8h]@9
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
127
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
128 if ( !text )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
129 return;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
130 text_color = ui_current_text_color;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
131 text_length = strlen(text);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
132 uX_pos=uX;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
133 for (int i=0; i<text_length; ++i )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
134 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
135 c = text[i];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
136 if ( IsCharValid(c) )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
137 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
138 switch (c)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
139 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
140 case '\n': //Line Feed 0A 10:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
141 return;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
142 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
143 case '\f': //Form Feed, page eject 0C 12
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
144 strncpy(color_code, &text[i + 1], 5);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
145 color_code[5] = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
146 text_color = atoi(color_code);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
147 ui_current_text_color = text_color;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
148 i += 5;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
149 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
150 case '\t': // Horizontal tab 09
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
151 case '\r': //Carriage Return 0D 13
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
152 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
153 default:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
154 uCharWidth = pMetrics[c].uWidth;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
155 if ( uCharWidth )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
156 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
157 if ( i > 0 )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
158 uX_pos += pMetrics[c].uLeftSpacing;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
159 draw_color = text_color;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
160 pCharPixels = &pFontData[font_pixels_offset[c]];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
161 if ( !text_color )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
162 draw_color = -1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
163 pRenderer->DrawText(uX_pos, uY, pCharPixels, uCharWidth, uFontHeight, pFontPalettes[0], draw_color, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
164 uX_pos += uCharWidth;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
165 if ( i < text_length )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
166 uX_pos += pMetrics[c].uRightSpacing;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
167 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
168 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
169 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
170 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
171
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
172 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
173
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
174 //----- (0040F845) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
175 void DrawCharToBuff( unsigned short* uXpos,unsigned char* pCharPixels, int uCharWidth, int uCharHeight,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
176 unsigned __int16* pFontPalette, __int16 draw_color, int line_width )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
177 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
178 unsigned __int16* draw_buff; // edi@1
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
179 unsigned char* pPixels; // esi@1
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
180 unsigned char char_pxl; // eax@3
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
181
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
182 draw_buff = uXpos;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
183 pPixels = pCharPixels;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
184 for(int i=0; i<uCharHeight; ++i)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
185 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
186 for(int j=0; j<uCharWidth; ++j)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
187 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
188 char_pxl = *pPixels++;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
189 if ( char_pxl )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
190 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
191 if ( char_pxl == 1 )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
192 *draw_buff = pFontPalette[1];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
193 else
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
194 *draw_buff = draw_color;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
195 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
196 ++draw_buff;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
197 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
198 draw_buff+=line_width-uCharWidth;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
199 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
200
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
201 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
202
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
203 //----- (0044D0B5) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
204 void GUIFont::DrawTextLineToBuff( int uColor, int a3, unsigned short* uX_buff_pos, const char *text, int line_width )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
205 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
206
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
207 unsigned short* uX_pos; // edi@3
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
208 unsigned char c; // cl@4
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
209 unsigned __int16 draw_color; // cx@12
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
210 unsigned __int8 *pCharPixels; // eax@12
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
211 char color_code[20]; // [sp+Ch] [bp-1Ch]@16
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
212 int text_length; // [sp+20h] [bp-8h]@2
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
213 int text_color; // [sp+24h] [bp-4h]@1
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
214 int uCharWidth; // [sp+30h] [bp+8h]@9
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
215
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
216 if ( !text )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
217 return;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
218 text_color = ui_current_text_color;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
219 text_length = strlen(text);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
220 uX_pos=uX_buff_pos;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
221 for (int i=0; i<text_length; ++i )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
222 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
223 c = text[i];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
224 if ( IsCharValid(c) )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
225 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
226 switch (c)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
227 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
228 case '\n': //Line Feed 0A 10:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
229 return;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
230 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
231 case '\f': //Form Feed, page eject 0C 12
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
232 strncpy(color_code, &text[i + 1], 5);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
233 color_code[5] = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
234 text_color = atoi(color_code);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
235 ui_current_text_color = text_color;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
236 i += 5;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
237 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
238 case '\t': // Horizontal tab 09
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
239 case '_':
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
240 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
241 default:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
242 uCharWidth = pMetrics[c].uWidth;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
243 if ( uCharWidth )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
244 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
245 if ( i > 0 )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
246 uX_pos += pMetrics[c].uLeftSpacing;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
247 draw_color = text_color;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
248 pCharPixels = &pFontData[font_pixels_offset[c]];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
249 if ( !text_color )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
250 draw_color = -1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
251 DrawCharToBuff(uX_pos, pCharPixels, uCharWidth, uFontHeight, pFontPalettes[0], draw_color, line_width);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
252 uX_pos += uCharWidth;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
253 if ( i < text_length )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
254 uX_pos += pMetrics[c].uRightSpacing;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
255 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
256 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
257 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
258 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
259 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
260
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
261
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
262
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
263 //----- (0044C933) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
264 char * GUIFont::FitTwoFontStringINWindow( const char *pString, GUIFont *pFontMain, GUIFont *pFontSecond, GUIWindow* pWindow, int startPixlOff, int a6 )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
265 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
266
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
267 GUIFont *currentFont; // esi@3
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
268 unsigned char c;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
269 int uInStrLen;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
270 char digits[4];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
271 int possible_transition_point;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
272 int string_pixel_Width;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
273 int start_pixel_offset;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
274
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
275 if (!pString)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
276 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
277 MessageBoxW(nullptr, L"Invalid string passed !", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Font.cpp:445", 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
278 return 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
279 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
280 currentFont=pFontMain; // esi@3
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
281 uInStrLen = strlen(pString);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
282 Assert(uInStrLen < sizeof(pTmpBuf3));
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
283 strcpy(pTmpBuf3.data(), pString);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
284 if (uInStrLen==0)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
285 return pTmpBuf3.data();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
286
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
287 start_pixel_offset=string_pixel_Width=startPixlOff;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
288 possible_transition_point=0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
289 for(int i=0; i<uInStrLen; ++i)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
290 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
291 c=pTmpBuf3[i];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
292 if (pFontMain->IsCharValid(c))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
293 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
294 switch (c)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
295 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
296 case '\t': // Horizontal tab 09
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
297 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
298 strncpy(digits, &pTmpBuf3[i+1],3);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
299 digits[3]=0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
300 string_pixel_Width = atoi(digits)+startPixlOff;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
301 i+=3;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
302 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
303 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
304 case '\n': //Line Feed 0A 10
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
305 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
306 string_pixel_Width=start_pixel_offset;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
307 possible_transition_point=i;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
308 currentFont=pFontMain;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
309 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
310 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
311 case '\f': //Form Feed, page eject 0C 12
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
312 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
313 i+=5;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
314 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
315 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
316 case '\r': //Carriage Return 0D 13
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
317 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
318 if (!a6)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
319 return (char*)pString;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
320 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
321 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
322 case ' ' :
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
323 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
324 string_pixel_Width+=currentFont->pMetrics[c].uWidth;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
325 possible_transition_point=i;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
326 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
327 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
328 case '_' :
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
329 currentFont=pFontSecond;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
330 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
331 default:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
332
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
333 if ((string_pixel_Width+currentFont->pMetrics[c].uWidth+ currentFont->pMetrics[c].uLeftSpacing+
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
334 currentFont->pMetrics[c].uRightSpacing)<pWindow->uFrameWidth)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
335 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
336 if(i>possible_transition_point)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
337 string_pixel_Width+=currentFont->pMetrics[c].uLeftSpacing;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
338 string_pixel_Width+=currentFont->pMetrics[c].uWidth;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
339 if (i<uInStrLen)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
340 string_pixel_Width+=currentFont->pMetrics[c].uRightSpacing;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
341 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
342 else
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
343 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
344 pTmpBuf3[possible_transition_point]='\n';
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
345
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
346 if ( currentFont== pFontSecond)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
347 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
348
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
349 for(int k=uInStrLen-1; k>=possible_transition_point+1; --k)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
350 pTmpBuf3[k] = pTmpBuf3[k-1];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
351
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
352 ++uInStrLen;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
353 ++possible_transition_point;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
354 pTmpBuf3[possible_transition_point] = '_';
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
355
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
356 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
357 string_pixel_Width=start_pixel_offset;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
358
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
359 for(int j=possible_transition_point;j<i; ++j )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
360 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
361 c=pTmpBuf3[j];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
362 if (pFontMain->IsCharValid(c))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
363 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
364 if(j>possible_transition_point)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
365 string_pixel_Width+=pFontMain->pMetrics[c].uLeftSpacing;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
366 string_pixel_Width+=pFontMain->pMetrics[c].uWidth;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
367 if (j<i)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
368 string_pixel_Width+=pFontMain->pMetrics[c].uRightSpacing;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
369
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
370 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
371 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
372 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
373 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
374 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
375 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
376 return pTmpBuf3.data();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
377
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
378 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
379
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
380
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
381 //----- (0044C6C2) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
382 char* GUIFont::GetPageTop( const char *pInString, GUIWindow *pWindow, unsigned int uX, int a5 )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
383 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
384 int text_height; // edi@1
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
385 char *text_str; // ebx@3
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
386 unsigned char c; // cl@4
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
387 int text_length;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
388
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
389 text_height = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
390
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
391 if ( !pInString )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
392 return 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
393 text_str = FitTextInAWindow(pInString, this, pWindow, uX, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
394 text_length = strlen(text_str);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
395 for ( int i = 0; i < text_length; ++i )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
396 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
397 c = text_str[i];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
398 if ( IsCharValid(c) )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
399 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
400 switch (c)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
401 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
402 case '\n': //Line Feed 0A 10:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
403 text_height = text_height + (uFontHeight - 3);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
404 if ( text_height >= (signed int)(a5 * (pWindow->uFrameHeight - (uFontHeight - 3))) )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
405 return &text_str[i];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
406 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
407 case '\f': //Form Feed, page eject 0C 12
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
408 i += 5;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
409 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
410 case '\t': // Horizontal tab 09
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
411 case '\r': //Carriage Return 0D 13
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
412 i += 3;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
413 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
414 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
415 if ( text_height >= (signed int)(a5 * pWindow->uFrameHeight) )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
416 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
417 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
418 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
419 return &text_str[0];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
420 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
421
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
422 //----- (0044C62E) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
423 int GUIFont::GetStringHeight2( GUIFont *secondFont, const char *text_str, GUIWindow* pWindow, int startX, int a6 )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
424 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
425
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
426 int uAllHeght;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
427 int uStringLen;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
428 unsigned char c;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
429 char *test_string;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
430
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
431 if ( !text_str )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
432 return 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
433 uAllHeght = uFontHeight - 3;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
434 test_string = FitTwoFontStringINWindow(text_str, this, secondFont, pWindow, startX, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
435 uStringLen = strlen(test_string);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
436 for (int i = 0; i < uStringLen; ++i)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
437 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
438 c = test_string[i];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
439 if (IsCharValid(c))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
440 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
441 switch (c)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
442 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
443 case '\n': //Line Feed 0A 10:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
444 uAllHeght+= uFontHeight - 3;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
445 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
446 case '\f': //Form Feed, page eject 0C 12
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
447 i += 5;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
448 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
449 case '\t': // Horizontal tab 09
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
450 case '\r': //Carriage Return 0D 13
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
451 if (a6 != 1)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
452 i += 3;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
453 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
454 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
455 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
456 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
457
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
458 return uAllHeght;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
459 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
460
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
461 //----- (0044C59D) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
462 int GUIFont::CalcTextHeight( const char *pString, struct GUIWindow *pWindow, int uXOffset, int a5 )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
463 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
464 int uAllHeght;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
465 int uStringLen;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
466 unsigned char c;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
467 char *test_string;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
468
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
469 if (!pString)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
470 return 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
471 uAllHeght = uFontHeight - 6;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
472 test_string = FitTextInAWindow(pString, this, pWindow, uXOffset, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
473 uStringLen = strlen(pString);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
474 for (int i = 0; i < uStringLen; ++i)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
475 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
476 c = test_string[i];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
477 if (IsCharValid(c))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
478 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
479 switch (c)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
480 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
481 case '\n': //Line Feed 0A 10:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
482 uAllHeght += uFontHeight - 3;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
483 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
484 case '\f': //Form Feed, page eject 0C 12
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
485 i += 5;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
486 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
487 case '\t': // Horizontal tab 09
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
488 case '\r': //Carriage Return 0D 13
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
489 if (a5 != 1)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
490 i += 3;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
491 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
492 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
493 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
494 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
495 return uAllHeght;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
496 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
497
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
498 //----- (0044C51E) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
499 int GUIFont::GetLineWidth(const char *pString)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
500 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
501 int str_len; // ebp@3
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
502 int string_line_width; // esi@3
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
503 unsigned char c;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
504
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
505 if (!pString)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
506 return 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
507 str_len = strlen(pString);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
508 string_line_width = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
509 for ( int i = 0; i < str_len; ++i )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
510 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
511 c = pString[i];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
512 if (IsCharValid(c))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
513 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
514 switch (c)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
515 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
516 case '\t':
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
517 case '\n':
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
518 case '\r':
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
519 return string_line_width;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
520 case '\f':
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
521 i += 5;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
522 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
523 default:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
524 if (i > 0)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
525 string_line_width += pMetrics[c].uLeftSpacing;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
526 string_line_width += pMetrics[c].uWidth;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
527 if (i < str_len)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
528 string_line_width +=pMetrics[c].uRightSpacing;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
529 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
530 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
531 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
532 return string_line_width;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
533 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
534
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
535
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
536 //----- (0044C502) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
537 int GUIFont::AlignText_Center(unsigned int uCenterX, const char *pString)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
538 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
539 signed int position; // esi@1
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
540
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
541 position = (signed int)(uCenterX - GetLineWidth(pString)) >> 1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
542 if ( position >= 0 )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
543 return position;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
544 else
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
545 return 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
546 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
547
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
548 //----- (0044C768) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
549 char * FitTextInAWindow( const char *pInString, GUIFont *pFont, GUIWindow *pWindow, signed int uX, int a5 )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
550 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
551 unsigned char c;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
552 int uInStrLen;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
553 char digits[4];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
554 int possible_transition_point;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
555 int string_pixel_Width;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
556 int start_pixel_offset;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
557
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
558 if (!pInString)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
559 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
560 MessageBoxW(nullptr, L"Invalid string passed !", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Font.cpp:445", 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
561 return 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
562 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
563 uInStrLen = strlen(pInString);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
564 strcpy(&temp_string[0], pInString);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
565 if (uInStrLen == 0)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
566 return &temp_string[0];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
567
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
568 start_pixel_offset = string_pixel_Width=uX;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
569 possible_transition_point = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
570 for ( int i = 0; i < uInStrLen; ++i )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
571 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
572 c = temp_string[i];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
573 if (pFont->IsCharValid(c))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
574 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
575 switch (c)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
576 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
577 case '\t': // Horizontal tab 09
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
578 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
579 strncpy(digits, &temp_string[i + 1],3);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
580 digits[3] = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
581 string_pixel_Width = atoi(digits)+uX;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
582 i += 3;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
583 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
584 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
585 case '\n': //Line Feed 0A 10 (конец строки)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
586 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
587 string_pixel_Width = start_pixel_offset;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
588 possible_transition_point = i;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
589 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
590 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
591 case '\f': //Form Feed, page eject 0C 12
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
592 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
593 i += 5;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
594 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
595 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
596 case '\r': //Carriage Return 0D 13
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
597 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
598 if ( !a5 )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
599 return (char*)pInString;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
600 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
601 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
602 case ' '://пробел
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
603 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
604 string_pixel_Width += pFont->pMetrics[c].uWidth;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
605 possible_transition_point = i;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
606 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
607 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
608 default:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
609 if ((string_pixel_Width + pFont->pMetrics[c].uWidth + pFont->pMetrics[c].uLeftSpacing +
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
610 pFont->pMetrics[c].uRightSpacing) < pWindow->uFrameWidth )//наращивание длины строки или перенос
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
611 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
612 if ( i > possible_transition_point )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
613 string_pixel_Width += pFont->pMetrics[c].uLeftSpacing;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
614 string_pixel_Width += pFont->pMetrics[c].uWidth;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
615 if (i < uInStrLen)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
616 string_pixel_Width += pFont->pMetrics[c].uRightSpacing;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
617 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
618 else//перенос строки и слова
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
619 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
620 temp_string[possible_transition_point] ='\n';
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
621 string_pixel_Width = start_pixel_offset;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
622 if ( i > possible_transition_point )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
623 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
624 for ( int j = possible_transition_point; j < i; ++j )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
625 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
626 c = temp_string[j];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
627 if (pFont->IsCharValid(c))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
628 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
629 if ( j > possible_transition_point )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
630 string_pixel_Width += pFont->pMetrics[c].uLeftSpacing;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
631 string_pixel_Width += pFont->pMetrics[c].uWidth;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
632 if ( j < i )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
633 string_pixel_Width += pFont->pMetrics[c].uRightSpacing;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
634 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
635 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
636 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
637 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
638 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
639 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
640 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
641 return &temp_string[0];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
642 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
643 //----- (00414162) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
644 void uGameUIFontMain_initialize()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
645 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
646 uGameUIFontMain = Color16(0xAu, 0, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
647 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
648
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
649 //----- (00414174) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
650 void uGameUIFontShadow_initialize()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
651 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
652 uGameUIFontShadow = Color16(0xE6u, 214, 193);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
653 }