mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Fix entity text
This commit is contained in:
parent
5d64ed34aa
commit
8923116324
|
@ -1768,7 +1768,7 @@ public:
|
|||
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
|
||||
}
|
||||
|
||||
virtual void UploadEntityLayerText(void* pTexBuff, int ImageColorChannelCount, int TexWidth, int TexHeight, const char *pText, int Length, float x, float y, int FontSize)
|
||||
virtual void UploadEntityLayerText(void *pTexBuff, int ImageColorChannelCount, int TexWidth, int TexHeight, int TexSubWidth, int TexSubHeight, const char *pText, int Length, float x, float y, int FontSize)
|
||||
{
|
||||
if (FontSize < 1)
|
||||
return;
|
||||
|
@ -1820,8 +1820,10 @@ public:
|
|||
{
|
||||
for(int OffX = 0; OffX < SlotW; ++OffX)
|
||||
{
|
||||
size_t ImageOffset = (y + OffY) * (TexWidth * ImageColorChannelCount) + ((x + OffX) + WidthLastChars) * ImageColorChannelCount;
|
||||
size_t GlyphOffset = (OffY) * SlotW + OffX;
|
||||
int ImgOffX = clamp(x + OffX + WidthLastChars, x, (x + TexSubWidth) - 1);
|
||||
int ImgOffY = clamp(y + OffY, y, (y + TexSubHeight) - 1);
|
||||
size_t ImageOffset = ImgOffY * (TexWidth * ImageColorChannelCount) + ImgOffX * ImageColorChannelCount;
|
||||
size_t GlyphOffset = (OffY)*SlotW + OffX;
|
||||
for(size_t i = 0; i < (size_t)ImageColorChannelCount; ++i)
|
||||
{
|
||||
if(i != (size_t)ImageColorChannelCount - 1)
|
||||
|
|
|
@ -102,7 +102,7 @@ public:
|
|||
virtual void RenderTextContainer(int TextContainerIndex, STextRenderColor *pTextColor, STextRenderColor *pTextOutlineColor) = 0;
|
||||
virtual void RenderTextContainer(int TextContainerIndex, STextRenderColor *pTextColor, STextRenderColor *pTextOutlineColor, float X, float Y) = 0;
|
||||
|
||||
virtual void UploadEntityLayerText(void* pTexBuff, int ImageColorChannelCount, int TexWidth, int TexHeight, const char *pText, int Length, float x, float y, int FontHeight) = 0;
|
||||
virtual void UploadEntityLayerText(void *pTexBuff, int ImageColorChannelCount, int TexWidth, int TexHeight, int TexSubWidth, int TexSubHeight, const char *pText, int Length, float x, float y, int FontHeight) = 0;
|
||||
virtual int AdjustFontSize(const char *pText, int TextLength, int MaxSize, int MaxWidth) = 0;
|
||||
virtual int CalculateTextWidth(const char *pText, int TextLength, int FontWidth, int FontHeight) = 0;
|
||||
|
||||
|
|
|
@ -384,18 +384,16 @@ void CMapImages::UpdateEntityLayerText(void* pTexBuffer, int ImageColorChannelCo
|
|||
int DigitsCount = NumbersPower+1;
|
||||
|
||||
int CurrentNumber = pow(10, NumbersPower);
|
||||
|
||||
if (MaxNumber == -1)
|
||||
MaxNumber = CurrentNumber*10-1;
|
||||
|
||||
str_format(aBuf, 4, "%d", CurrentNumber);
|
||||
|
||||
int CurrentNumberSuitableFontSize = TextRender()->AdjustFontSize(aBuf, DigitsCount, TextureSize, MaxWidth);
|
||||
int UniversalSuitableFontSize = CurrentNumberSuitableFontSize*0.95f; // should be smoothed enough to fit any digits combination
|
||||
|
||||
int ApproximateTextWidth = TextRender()->CalculateTextWidth(aBuf, DigitsCount, 0, UniversalSuitableFontSize);
|
||||
int XOffSet = (64-ApproximateTextWidth)/2;
|
||||
YOffset += ((TextureSize - UniversalSuitableFontSize)/2);
|
||||
if(MaxNumber == -1)
|
||||
MaxNumber = CurrentNumber * 10 - 1;
|
||||
|
||||
str_format(aBuf, 4, "%d", CurrentNumber);
|
||||
|
||||
int CurrentNumberSuitableFontSize = TextRender()->AdjustFontSize(aBuf, DigitsCount, TextureSize, MaxWidth);
|
||||
int UniversalSuitableFontSize = CurrentNumberSuitableFontSize * 0.92f; // should be smoothed enough to fit any digits combination
|
||||
|
||||
YOffset += ((TextureSize - UniversalSuitableFontSize) / 2);
|
||||
|
||||
for (; CurrentNumber <= MaxNumber; ++CurrentNumber)
|
||||
{
|
||||
|
@ -404,7 +402,10 @@ void CMapImages::UpdateEntityLayerText(void* pTexBuffer, int ImageColorChannelCo
|
|||
float x = (CurrentNumber%16)*64;
|
||||
float y = (CurrentNumber/16)*64;
|
||||
|
||||
TextRender()->UploadEntityLayerText(pTexBuffer, ImageColorChannelCount, TexWidth, TexHeight, aBuf, DigitsCount, x+XOffSet, y+YOffset, UniversalSuitableFontSize);
|
||||
int ApproximateTextWidth = TextRender()->CalculateTextWidth(aBuf, DigitsCount, 0, UniversalSuitableFontSize);
|
||||
int XOffSet = (MaxWidth - clamp(ApproximateTextWidth, 0, MaxWidth)) / 2;
|
||||
|
||||
TextRender()->UploadEntityLayerText(pTexBuffer, ImageColorChannelCount, TexWidth, TexHeight, (TexWidth / 16) - XOffSet, (TexHeight / 16) - YOffset, aBuf, DigitsCount, x + XOffSet, y + YOffset, UniversalSuitableFontSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue