2825: Fix entity text & improve Grow r=def- a=Jupeyy

fixes #2822

@BannZay wanna check?

Co-authored-by: Jupeyy <jupjopjap@gmail.com>
This commit is contained in:
bors[bot] 2020-09-14 15:12:37 +00:00 committed by GitHub
commit c0f7a2bf03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 39 deletions

View file

@ -261,15 +261,15 @@ class CTextRender : public IEngineTextRender
m_RenderFlags = Flags;
}
void Grow(unsigned char *pIn, unsigned char *pOut, int w, int h)
void Grow(unsigned char *pIn, unsigned char *pOut, int w, int h, int OutlineCount)
{
for(int y = 0; y < h; y++)
for(int x = 0; x < w; x++)
{
int c = pIn[y*w+x];
for(int sy = -1; sy <= 1; sy++)
for(int sx = -1; sx <= 1; sx++)
for(int sy = -OutlineCount; sy <= OutlineCount; sy++)
for(int sx = -OutlineCount; sx <= OutlineCount; sx++)
{
int GetX = x+sx;
int GetY = y+sy;
@ -511,28 +511,13 @@ class CTextRender : public IEngineTextRender
}
UploadGlyph(pFont, 0, X, Y, (int)Width, (int)Height, ms_aGlyphData);
if(OutlineThickness == 1)
Grow(ms_aGlyphData, ms_aGlyphDataOutlined, Width, Height, OutlineThickness);
while(!GetCharacterSpace(pFont, 1, (int)Width, (int)Height, X, Y))
{
Grow(ms_aGlyphData, ms_aGlyphDataOutlined, Width, Height);
while(!GetCharacterSpace(pFont, 1, (int)Width, (int)Height, X, Y))
{
IncreaseFontTexture(pFont, 1);
}
UploadGlyph(pFont, 1, X, Y, (int)Width, (int)Height, ms_aGlyphDataOutlined);
}
else
{
for(int i = OutlineThickness; i > 0; i-=2)
{
Grow(ms_aGlyphData, ms_aGlyphDataOutlined, Width, Height);
Grow(ms_aGlyphDataOutlined, ms_aGlyphData, Width, Height);
}
while(!GetCharacterSpace(pFont, 1, (int)Width, (int)Height, X, Y))
{
IncreaseFontTexture(pFont, 1);
}
UploadGlyph(pFont, 1, X, Y, (int)Width, (int)Height, ms_aGlyphData);
IncreaseFontTexture(pFont, 1);
}
UploadGlyph(pFont, 1, X, Y, (int)Width, (int)Height, ms_aGlyphDataOutlined);
// set char info
{
@ -1768,7 +1753,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 +1805,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)

View file

@ -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;

View file

@ -385,17 +385,15 @@ void CMapImages::UpdateEntityLayerText(void* pTexBuffer, int ImageColorChannelCo
int CurrentNumber = pow(10, NumbersPower);
if (MaxNumber == -1)
MaxNumber = CurrentNumber*10-1;
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 UniversalSuitableFontSize = CurrentNumberSuitableFontSize * 0.92f; // 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);
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);
}
}