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