Improve text rendering inside tele tiles in editor

This commit is contained in:
Corantin H 2023-12-27 00:16:44 +01:00
parent 8ce103f04f
commit fcc095b675

View file

@ -724,7 +724,6 @@ void CRenderTools::RenderTeleOverlay(CTeleTile *pTele, int w, int h, float Scale
return; // its useless to render text at this distance return; // its useless to render text at this distance
float Size = g_Config.m_ClTextEntitiesSize / 100.f; float Size = g_Config.m_ClTextEntitiesSize / 100.f;
float ToCenterOffset = (1 - Size) / 2.f;
for(int y = StartY; y < EndY; y++) for(int y = StartY; y < EndY; y++)
for(int x = StartX; x < EndX; x++) for(int x = StartX; x < EndX; x++)
@ -749,7 +748,14 @@ void CRenderTools::RenderTeleOverlay(CTeleTile *pTele, int w, int h, float Scale
char aBuf[16]; char aBuf[16];
str_from_int(Index, aBuf); str_from_int(Index, aBuf);
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha); TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
TextRender()->Text(mx * Scale - 3.f, (my + ToCenterOffset) * Scale, Size * Scale, aBuf, -1.0f);
// Auto-resize text to fit inside the tile
float ScaledWidth = TextRender()->TextWidth(Size * Scale, aBuf, -1);
float Factor = clamp(Scale / ScaledWidth, 0.0f, 1.0f);
float LocalSize = Size * Factor;
float ToCenterOffset = (1 - LocalSize) / 2.f;
TextRender()->Text((mx + 0.5f) * Scale - (ScaledWidth * Factor) / 2.0f, (my + ToCenterOffset) * Scale, LocalSize * Scale, aBuf, -1.0f);
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f); TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
} }
} }