mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2026-01-06 05:59:51 +01:00
Fixing text alignment issues. PageBuilder is still incorrectly calculating offsets for yOrigin on verticalList.
This commit is contained in:
parent
bf7a347511
commit
2e9f82b16e
@ -67,26 +67,36 @@ void Text::Draw()
|
||||
Font::GlyphInfo glyph;
|
||||
if(FontInst->GetRect(TextData[i], glyph))
|
||||
{
|
||||
if(glyph.MinX < 0)
|
||||
{
|
||||
imageWidth += glyph.MinX;
|
||||
}
|
||||
|
||||
imageWidth += glyph.Advance;
|
||||
imageHeight = (imageHeight >= glyph.Rect.h) ? imageHeight : glyph.Rect.h;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
imageHeight = (float)FontInst->GetHeight();
|
||||
float scale = (float)info->GetFontSize() / (float)imageHeight;
|
||||
|
||||
|
||||
float width = info->GetRawWidth();
|
||||
float height = info->GetRawHeight();
|
||||
float oldWidth = info->GetRawWidth();
|
||||
float oldHeight = info->GetRawHeight();
|
||||
float oldImageWidth = info->GetImageHeight();
|
||||
float oldImageHeight = info->GetImageWidth();
|
||||
|
||||
info->SetWidth(imageWidth*scale);
|
||||
info->SetHeight(imageHeight*scale);
|
||||
info->SetHeight(info->GetFontSize());
|
||||
info->SetImageWidth(imageWidth);
|
||||
info->SetImageHeight(imageHeight);
|
||||
|
||||
float xOrigin = info->GetXRelativeToOrigin();
|
||||
float yOrigin = info->GetYRelativeToOrigin();
|
||||
|
||||
info->SetWidth(width);
|
||||
info->SetHeight(height);
|
||||
info->SetWidth(oldWidth);
|
||||
info->SetHeight(oldHeight);
|
||||
info->SetImageWidth(oldImageWidth);
|
||||
info->SetImageHeight(oldImageHeight);
|
||||
|
||||
|
||||
SDL_Rect rect;
|
||||
@ -105,7 +115,18 @@ void Text::Draw()
|
||||
rect.w = static_cast<int>(w);
|
||||
rect.y = static_cast<int>(yOrigin);
|
||||
|
||||
if(glyph.MinX < 0)
|
||||
{
|
||||
rect.x += static_cast<int>((float)(glyph.MinX) * scale);
|
||||
}
|
||||
if(FontInst->GetAscent() < glyph.MaxY)
|
||||
{
|
||||
rect.y += static_cast<int>((FontInst->GetAscent() - glyph.MaxY)*scale);
|
||||
}
|
||||
|
||||
|
||||
SDL::RenderCopy(t, static_cast<char>(info->GetAlpha() * 255), &charRect, &rect, info->GetAngle());
|
||||
|
||||
rect.x += static_cast<int>(glyph.Advance * scale);
|
||||
|
||||
if((static_cast<float>(rect.x) - xOrigin) > info->GetMaxWidth())
|
||||
|
||||
@ -66,6 +66,8 @@ bool Font::Initialize(std::string fontPath, int fontSize, SDL_Color color)
|
||||
int y = 0;
|
||||
int atlasHeight = 0;
|
||||
int atlasWidth = 0;
|
||||
Height = TTF_FontHeight(font);
|
||||
Ascent = TTF_FontAscent(font);
|
||||
|
||||
for(unsigned short int i = 32; i < 128; ++i)
|
||||
{
|
||||
@ -159,3 +161,13 @@ void Font::DeInitialize()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int Font::GetHeight()
|
||||
{
|
||||
return Height;
|
||||
}
|
||||
int Font::GetAscent()
|
||||
{
|
||||
return Ascent;
|
||||
}
|
||||
|
||||
|
||||
@ -38,7 +38,8 @@ public:
|
||||
void DeInitialize();
|
||||
SDL_Texture *GetTexture();
|
||||
bool GetRect(unsigned int charCode, GlyphInfo &glyph);
|
||||
|
||||
int GetHeight();
|
||||
int GetAscent();
|
||||
|
||||
private:
|
||||
struct GlyphInfoBuild
|
||||
@ -47,6 +48,8 @@ private:
|
||||
SDL_Surface *Surface;
|
||||
};
|
||||
|
||||
int Height;
|
||||
int Ascent;
|
||||
std::map<unsigned int, GlyphInfoBuild *> Atlas;
|
||||
SDL_Texture *Texture;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user