mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge #2825
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:
commit
c0f7a2bf03
|
@ -261,15 +261,15 @@ class CTextRender : public IEngineTextRender
|
||||||
m_RenderFlags = Flags;
|
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 y = 0; y < h; y++)
|
||||||
for(int x = 0; x < w; x++)
|
for(int x = 0; x < w; x++)
|
||||||
{
|
{
|
||||||
int c = pIn[y*w+x];
|
int c = pIn[y*w+x];
|
||||||
|
|
||||||
for(int sy = -1; sy <= 1; sy++)
|
for(int sy = -OutlineCount; sy <= OutlineCount; sy++)
|
||||||
for(int sx = -1; sx <= 1; sx++)
|
for(int sx = -OutlineCount; sx <= OutlineCount; sx++)
|
||||||
{
|
{
|
||||||
int GetX = x+sx;
|
int GetX = x+sx;
|
||||||
int GetY = y+sy;
|
int GetY = y+sy;
|
||||||
|
@ -511,28 +511,13 @@ class CTextRender : public IEngineTextRender
|
||||||
}
|
}
|
||||||
UploadGlyph(pFont, 0, X, Y, (int)Width, (int)Height, ms_aGlyphData);
|
UploadGlyph(pFont, 0, X, Y, (int)Width, (int)Height, ms_aGlyphData);
|
||||||
|
|
||||||
if(OutlineThickness == 1)
|
Grow(ms_aGlyphData, ms_aGlyphDataOutlined, Width, Height, OutlineThickness);
|
||||||
{
|
|
||||||
Grow(ms_aGlyphData, ms_aGlyphDataOutlined, Width, Height);
|
|
||||||
while(!GetCharacterSpace(pFont, 1, (int)Width, (int)Height, X, Y))
|
while(!GetCharacterSpace(pFont, 1, (int)Width, (int)Height, X, Y))
|
||||||
{
|
{
|
||||||
IncreaseFontTexture(pFont, 1);
|
IncreaseFontTexture(pFont, 1);
|
||||||
}
|
}
|
||||||
UploadGlyph(pFont, 1, X, Y, (int)Width, (int)Height, ms_aGlyphDataOutlined);
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set char info
|
// set char info
|
||||||
{
|
{
|
||||||
|
@ -1768,7 +1753,7 @@ public:
|
||||||
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
|
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)
|
if (FontSize < 1)
|
||||||
return;
|
return;
|
||||||
|
@ -1820,7 +1805,9 @@ public:
|
||||||
{
|
{
|
||||||
for(int OffX = 0; OffX < SlotW; ++OffX)
|
for(int OffX = 0; OffX < SlotW; ++OffX)
|
||||||
{
|
{
|
||||||
size_t ImageOffset = (y + OffY) * (TexWidth * ImageColorChannelCount) + ((x + OffX) + WidthLastChars) * ImageColorChannelCount;
|
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;
|
size_t GlyphOffset = (OffY)*SlotW + OffX;
|
||||||
for(size_t i = 0; i < (size_t)ImageColorChannelCount; ++i)
|
for(size_t i = 0; i < (size_t)ImageColorChannelCount; ++i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -102,7 +102,7 @@ public:
|
||||||
virtual void RenderTextContainer(int TextContainerIndex, STextRenderColor *pTextColor, STextRenderColor *pTextOutlineColor) = 0;
|
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 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 AdjustFontSize(const char *pText, int TextLength, int MaxSize, int MaxWidth) = 0;
|
||||||
virtual int CalculateTextWidth(const char *pText, int TextLength, int FontWidth, int FontHeight) = 0;
|
virtual int CalculateTextWidth(const char *pText, int TextLength, int FontWidth, int FontHeight) = 0;
|
||||||
|
|
||||||
|
|
|
@ -391,10 +391,8 @@ void CMapImages::UpdateEntityLayerText(void* pTexBuffer, int ImageColorChannelCo
|
||||||
str_format(aBuf, 4, "%d", CurrentNumber);
|
str_format(aBuf, 4, "%d", CurrentNumber);
|
||||||
|
|
||||||
int CurrentNumberSuitableFontSize = TextRender()->AdjustFontSize(aBuf, DigitsCount, TextureSize, MaxWidth);
|
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)
|
for (; CurrentNumber <= MaxNumber; ++CurrentNumber)
|
||||||
|
@ -404,7 +402,10 @@ void CMapImages::UpdateEntityLayerText(void* pTexBuffer, int ImageColorChannelCo
|
||||||
float x = (CurrentNumber%16)*64;
|
float x = (CurrentNumber%16)*64;
|
||||||
float y = (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