add: Rect font rendering
This commit is contained in:
@@ -182,6 +182,48 @@ namespace frame::render
|
||||
}
|
||||
}
|
||||
|
||||
void RenderTarget::DrawText(Rect rect,
|
||||
std::string pText,
|
||||
font::Font const& pFont,
|
||||
uint32_t size,
|
||||
AlignHorizontal alignHorizontal,
|
||||
AlignVertical alignVertical)
|
||||
{
|
||||
auto const lineSpacing = pFont.getLineSpacing(size);
|
||||
auto const lineSpacing_3 = lineSpacing / 3;
|
||||
|
||||
Vector start{rect.top, rect.left};
|
||||
auto text_height = pFont.getHeight(pText, size);
|
||||
auto length = pFont.getLength(pText, size);
|
||||
auto y_offset = pFont.getMaxYOffset(pText, size);
|
||||
|
||||
switch(alignVertical)
|
||||
{
|
||||
case AlignVertical::TOP: start.y += lineSpacing_3 * 2; break;
|
||||
case AlignVertical::CENTER:
|
||||
start.y += rect.height / 2;
|
||||
start.y += text_height / 2;
|
||||
start.y -= y_offset + text_height;
|
||||
break;
|
||||
case AlignVertical::BOTTOM:
|
||||
start.y += rect.height;
|
||||
start.y += text_height + y_offset;
|
||||
break;
|
||||
}
|
||||
|
||||
switch(alignHorizontal)
|
||||
{
|
||||
case AlignHorizontal::CENTER:
|
||||
start.x += rect.width / 2;
|
||||
start.x -= length / 2;
|
||||
break;
|
||||
|
||||
case AlignHorizontal::RIGHT: start.x += rect.width - length; break;
|
||||
}
|
||||
|
||||
DrawText(pText, start, pFont, size);
|
||||
}
|
||||
|
||||
void RenderTarget::DrawTextGlyphBounds(std::string_view pText,
|
||||
Vector pCenterLineStart,
|
||||
font::Font const& pFont,
|
||||
|
||||
Reference in New Issue
Block a user