mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 22:18:19 +00:00
numbers dynamically centered for OpenGL 3.3
This commit is contained in:
parent
0fa23a2c47
commit
1671e6fbfc
|
@ -100,6 +100,7 @@ public:
|
|||
|
||||
virtual void UploadEntityLayerText(int TextureID, const char *pText, int Length, float x, float y, int FontHeight) = 0;
|
||||
virtual int AdjustFontSize(const char *pText, int TextLength, int MaxSize = -1) = 0;
|
||||
virtual int CalculateTextWidth(const char *pText, int TextLength, int FontWidth, int FontHeight) = 0;
|
||||
|
||||
// old foolish interface
|
||||
virtual void TextColor(float r, float g, float b, float a) = 0;
|
||||
|
|
|
@ -175,33 +175,47 @@ int CMapImages::UploadEntityLayerText(int TextureSize, int YOffset)
|
|||
int TextureID = Graphics()->LoadTextureRaw(1024, 1024, CImageInfo::FORMAT_ALPHA, pMem, CImageInfo::FORMAT_ALPHA, IGraphics::TEXLOAD_NOMIPMAPS);
|
||||
free(pMem);
|
||||
|
||||
char aBuf[4];
|
||||
int Len = str_format(aBuf, 4, "%d", 255);
|
||||
|
||||
int FontSize = TextRender()->AdjustFontSize(aBuf, Len, TextureSize)-1;
|
||||
|
||||
if (FontSize < 1)
|
||||
{
|
||||
dbg_msg("pFont", "texture with id '%d' will not be loaded. Reason - font is too small", TextureID);
|
||||
return TextureID;
|
||||
}
|
||||
|
||||
YOffset += ((TextureSize - FontSize)/2);
|
||||
|
||||
for(int i = 0; i < 256; ++i)
|
||||
{
|
||||
int Len = str_format(aBuf, 4, "%d", i);
|
||||
int XOffSet = (64-((TextureSize/3)*Len))/2;
|
||||
|
||||
float x = (i%16)*64;
|
||||
float y = (i/16)*64;
|
||||
|
||||
TextRender()->UploadEntityLayerText(TextureID, aBuf, Len, x+XOffSet, y+YOffset, FontSize);
|
||||
}
|
||||
UpdateEntityLayerText(TextureID, TextureSize, YOffset, 0);
|
||||
UpdateEntityLayerText(TextureID, TextureSize, YOffset, 1);
|
||||
UpdateEntityLayerText(TextureID, TextureSize, YOffset, 2, 255);
|
||||
|
||||
return TextureID;
|
||||
}
|
||||
|
||||
void CMapImages::UpdateEntityLayerText(int TextureID, int TextureSize, int YOffset, int NumbersPower, int MaxNumber)
|
||||
{
|
||||
char aBuf[4];
|
||||
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);
|
||||
int UniversalSuitableFontSize = CurrentNumberSuitableFontSize*0.9; // should be smoothed enough to fit any digits combination
|
||||
|
||||
if (UniversalSuitableFontSize < 1)
|
||||
{
|
||||
dbg_msg("pFont", "texture with id '%d' will not be loaded. Reason - font is too small", TextureID);
|
||||
}
|
||||
|
||||
int ApproximateTextWidth = TextRender()->CalculateTextWidth(aBuf, DigitsCount, 0, UniversalSuitableFontSize);
|
||||
int XOffSet = (64-ApproximateTextWidth)/2;
|
||||
YOffset += ((TextureSize - UniversalSuitableFontSize)/2);
|
||||
|
||||
for (; CurrentNumber <= MaxNumber; ++CurrentNumber)
|
||||
{
|
||||
str_format(aBuf, 4, "%d", CurrentNumber);
|
||||
|
||||
float x = (CurrentNumber%16)*64;
|
||||
float y = (CurrentNumber/16)*64;
|
||||
|
||||
TextRender()->UploadEntityLayerText(TextureID, aBuf, DigitsCount, x+XOffSet, y+YOffset, UniversalSuitableFontSize);
|
||||
}
|
||||
}
|
||||
|
||||
void CMapImages::InitOverlayTextures()
|
||||
{
|
||||
|
|
|
@ -43,6 +43,7 @@ private:
|
|||
|
||||
void InitOverlayTextures();
|
||||
int UploadEntityLayerText(int TextureSize, int YOffset);
|
||||
void UpdateEntityLayerText(int TextureID, int TextureSize, int YOffset, int NumbersPower, int MaxNumber = -1);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue