36 auto pFontDef = m_pFontDef;
38 if ( a_wszText && a_wszText[ 0 ] !=
'\0' && pFontDef )
40 auto pTextBuffer = a_wszText;
44 auto pTextBuffer2 = pTextBuffer;
46 while ( *pTextBuffer2 != L
'\0' && std::iswspace( *pTextBuffer2 ) != 0 )
48 if ( *pTextBuffer2 == L
'\n' )
break;
52 auto wChar = *pTextBuffer2;
56 pTextBuffer = pTextBuffer2 + 1;
60 if ( wChar == L
'\0' )
return;
65 auto pTextBuffer3 = pTextBuffer2;
68 if ( pFontDef->ui16MinCharacter <= wChar && ( wChar <= pFontDef->ui16MaxCharacter ) )
70 TINT iCharIndex = pFontDef->pCharactersMap[ wChar - pFontDef->ui16MinCharacter ];
72 if ( iCharIndex >= 0 )
74 auto& pCharData = pFontDef->pCharactersData[ iCharIndex ];
75 fWidth1 += ( pFontDef->iLetterSpacing + pCharData.iRightPadding + pCharData.iLeftPadding + pCharData.ui8CharWidth ) * a_fScale;
82 pTextBuffer = pTextBuffer3;
86 if ( std::iswspace( wChar ) != 0 && *pTextBuffer3 != L
'\xA0' )
89 pTextBuffer = pTextBuffer3;
92 wChar = pTextBuffer3[ 1 ];
93 if ( wChar == L
'\0' )
break;
96 }
while ( fWidth1 < a_fWidth || pTextBuffer ==
TNULL );
98 if ( pTextBuffer3[ 1 ] == L
'\0' )
100 pTextBuffer = pTextBuffer3 + 1;
109 fPosX = ( a_fWidth - fWidth2 ) * 0.5f + a_fX;
111 fPosX = ( a_fWidth - fWidth2 ) + a_fX;
115 DrawTextSingleLine( pTextBuffer2, pTextBuffer - pTextBuffer2, fPosX, a_fY, a_uiColour, a_fScale, a_fnCallback );
118 a_fY += ( pFontDef->uiLineHeight + pFontDef->uiLinesMargin ) * a_fScale;
120 }
while ( *pTextBuffer != L
'\0' );
127 pRenderer->SetColour( a_uiColour );
135 for (
TINT i = 0; i < a_iTextLength; i++ )
137 auto pFontDef = m_pFontDef;
138 auto wChar = a_wszText[ i ];
140 if ( pFontDef->ui16MinCharacter <= wChar && wChar <= pFontDef->ui16MaxCharacter )
142 TINT iCharIndex = pFontDef->pCharactersMap[ wChar - pFontDef->ui16MinCharacter ];
144 if ( iCharIndex >= 0 )
146 auto& pCharData = pFontDef->pCharactersData[ iCharIndex ];
147 TFLOAT fPos1X = pCharData.iLeftPadding * a_fScale + a_fX;
149 if ( pCharData.ui8CharWidth != 0 && pCharData.ui8CharHeight != 0 )
151 AGUI2Material* pMaterial = ( pFontDef->uiNumMaterials > 1 ) ?
152 m_ppMaterials[ ( wChar >> 8 ) ] :
155 if ( pMaterial != pPrevMaterial )
157 pPrevMaterial = pMaterial;
158 pRenderer->SetMaterial( pMaterial );
159 fXToUV = 1.0f / pRenderer->GetWidth( pMaterial );
160 fYToUV = 1.0f / pRenderer->GetHeight( pMaterial );
163 TFIXME(
"Call a_fnCallback(i, fOffsetX, fOffsetY)" );
165 TFLOAT fPos1Y = ( ( pFontDef->uiLineHeight + pCharData.Unk5 ) - pCharData.ui8CharHeight ) * a_fScale + a_fY;
166 TFLOAT fPos2Y = fPos1Y + ( pCharData.ui8CharHeight + 1 ) * a_fScale;
167 TFLOAT fPos2X = fPos1X + ( pCharData.ui8CharWidth + 1 ) * a_fScale;
169 pRenderer->RenderRectangle(
170 { fPos1X + fOffsetX, fPos1Y + fOffsetY },
171 { fPos2X + fOffsetX, fPos2Y + fOffsetY },
172 { ( pCharData.ui16PosX ) * fXToUV, ( pCharData.ui16PosY ) * fYToUV },
173 { ( pCharData.ui16PosX + pCharData.ui8CharWidth + 1 ) * fXToUV, ( pCharData.ui16PosY + pCharData.ui8CharHeight + 1 ) * fYToUV }
177 TFLOAT fPos2X =
TFLOAT( pFontDef->iLetterSpacing + pCharData.iRightPadding + pCharData.ui8CharWidth );
178 a_fX = fPos2X * a_fScale + fPos1X;
186 auto pFontDef = m_pFontDef;
188 if ( a_wszText && a_wszText[ 0 ] !=
'\0' && pFontDef )
191 auto pTextBuffer = a_wszText;
195 auto pTextBuffer2 = pTextBuffer;
197 while ( *pTextBuffer2 != L
'\0' && std::iswspace( *pTextBuffer2 ) != 0 )
199 if ( *pTextBuffer2 == L
'\n' )
break;
203 auto wChar = *pTextBuffer2;
205 if ( wChar == L
'\n' )
207 pTextBuffer = pTextBuffer2 + 1;
211 if ( wChar == L
'\0' )
break;
216 auto pTextBuffer3 = pTextBuffer2;
219 if ( pFontDef->ui16MinCharacter <= wChar && ( wChar <= pFontDef->ui16MaxCharacter ) )
221 TINT iCharIndex = pFontDef->pCharactersMap[ wChar - pFontDef->ui16MinCharacter ];
223 if ( iCharIndex >= 0 )
225 auto& pCharData = pFontDef->pCharactersData[ iCharIndex ];
226 fWidth1 += ( pFontDef->iLetterSpacing + pCharData.iRightPadding + pCharData.iLeftPadding + pCharData.ui8CharWidth ) * a_fScale;
230 if ( wChar == L
'\n' )
233 pTextBuffer = pTextBuffer3;
237 if ( std::iswspace( wChar ) != 0 && *pTextBuffer3 != L
'\xA0' )
240 pTextBuffer = pTextBuffer3;
243 wChar = pTextBuffer3[ 1 ];
244 if ( wChar == L
'\0' )
break;
247 }
while ( fWidth1 < a_fMaxWidth || pTextBuffer ==
TNULL );
249 if ( pTextBuffer3[ 1 ] == L
'\0' )
251 pTextBuffer = pTextBuffer3 + 1;
256 fHeight += ( pFontDef->uiLineHeight + pFontDef->uiLinesMargin ) * a_fScale;
258 }
while ( *pTextBuffer != L
'\0' );
286 for (
TINT i = 0; i < a_iTextLength; i++ )
288 auto pFontDef = m_pFontDef;
289 auto wChar = a_wszText[ i ];
291 if ( pFontDef->ui16MinCharacter <= wChar && wChar <= pFontDef->ui16MaxCharacter )
293 TINT iCharIndex = pFontDef->pCharactersMap[ wChar - pFontDef->ui16MinCharacter ];
295 if ( iCharIndex >= 0 )
297 auto& pCharData = pFontDef->pCharactersData[ iCharIndex ];
298 iWidth += pFontDef->iLetterSpacing + pCharData.iRightPadding + pCharData.iLeftPadding + pCharData.ui8CharWidth;
303 return iWidth * a_fScale;
void DrawTextWrapped(const TWCHAR *a_wszText, TFLOAT a_fX, TFLOAT a_fY, TFLOAT a_fWidth, TFLOAT a_fHeight, TUINT32 a_uiColour, TFLOAT a_fScale, TextAlign a_eAlign, void *a_fnCallback=nullptr)
void DrawTextSingleLine(const TWCHAR *a_wszText, TINT a_iTextLength, TFLOAT a_fX, TFLOAT a_fY, TUINT32 a_uiColour, TFLOAT a_fScale, void *a_fnCallback=nullptr)