Utility/*TextDrawer: Use float internally
+ some fixes
This commit is contained in:
@@ -110,7 +110,7 @@ namespace Nz
|
||||
ClearGlyphs();
|
||||
}
|
||||
|
||||
const Recti& RichTextDrawer::GetBounds() const
|
||||
const Rectf& RichTextDrawer::GetBounds() const
|
||||
{
|
||||
if (!m_glyphUpdated)
|
||||
UpdateGlyphs();
|
||||
@@ -260,7 +260,6 @@ namespace Nz
|
||||
m_glyphs = std::move(m_glyphs);
|
||||
m_lines = std::move(m_lines);
|
||||
m_glyphUpdated = std::move(m_glyphUpdated);
|
||||
m_workingBounds = std::move(m_workingBounds);
|
||||
|
||||
drawer.DisconnectFontSlots();
|
||||
ConnectFontSlots();
|
||||
@@ -268,21 +267,21 @@ namespace Nz
|
||||
return *this;
|
||||
}
|
||||
|
||||
void RichTextDrawer::AppendNewLine(const Font* font, unsigned int characterSize, std::size_t glyphIndex, unsigned int glyphPosition) const
|
||||
void RichTextDrawer::AppendNewLine(const Font* font, unsigned int characterSize, std::size_t glyphIndex, float glyphPosition) const
|
||||
{
|
||||
// Ensure we're appending from last line
|
||||
Line& lastLine = m_lines.back();
|
||||
|
||||
const Font::SizeInfo& sizeInfo = font->GetSizeInfo(characterSize);
|
||||
|
||||
unsigned int previousDrawPos = m_drawPos.x;
|
||||
float previousDrawPos = m_drawPos.x;
|
||||
|
||||
// Reset cursor
|
||||
m_drawPos.x = 0;
|
||||
m_drawPos.y += sizeInfo.lineHeight;
|
||||
m_lastSeparatorGlyph = InvalidGlyph;
|
||||
|
||||
m_workingBounds.ExtendTo(lastLine.bounds);
|
||||
m_bounds.ExtendTo(lastLine.bounds);
|
||||
m_lines.emplace_back(Line{ Rectf(0.f, float(sizeInfo.lineHeight * m_lines.size()), 0.f, float(sizeInfo.lineHeight)), m_glyphs.size() + 1 });
|
||||
|
||||
if (glyphIndex != InvalidGlyph && glyphIndex > lastLine.glyphIndex)
|
||||
@@ -310,10 +309,10 @@ namespace Nz
|
||||
|
||||
lastLine.bounds.width -= lastLine.bounds.GetMaximum().x - glyphPosition;
|
||||
|
||||
// Regenerate working bounds
|
||||
m_workingBounds.MakeZero();
|
||||
for (std::size_t i = 0; i < m_lines.size(); ++i)
|
||||
m_workingBounds.ExtendTo(m_lines[i].bounds);
|
||||
// Regenerate bounds
|
||||
m_bounds.MakeZero();
|
||||
for (auto& line : m_lines)
|
||||
m_bounds.ExtendTo(line.bounds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -403,16 +402,16 @@ namespace Nz
|
||||
previousCharacter = character;
|
||||
|
||||
bool whitespace = true;
|
||||
int advance = 0;
|
||||
float advance = 0.f;
|
||||
switch (character)
|
||||
{
|
||||
case ' ':
|
||||
case '\n':
|
||||
advance = sizeInfo.spaceAdvance;
|
||||
advance = float(sizeInfo.spaceAdvance);
|
||||
break;
|
||||
|
||||
case '\t':
|
||||
advance = sizeInfo.spaceAdvance * 4;
|
||||
advance = float(sizeInfo.spaceAdvance) * 4.f;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -423,27 +422,26 @@ namespace Nz
|
||||
Glyph glyph;
|
||||
if (!whitespace)
|
||||
{
|
||||
if (!GenerateGlyph(glyph, character, 0.f, true, font, color, style, characterSize, 0, &advance))
|
||||
int iAdvance;
|
||||
if (!GenerateGlyph(glyph, character, 0.f, true, font, color, style, characterSize, 0, &iAdvance))
|
||||
continue; // Glyph failed to load, just skip it (can't do much)
|
||||
|
||||
advance = float(iAdvance);
|
||||
|
||||
if (outlineThickness > 0.f)
|
||||
{
|
||||
Glyph outlineGlyph;
|
||||
if (GenerateGlyph(outlineGlyph, character, outlineThickness, false, font, outlineColor, style, characterSize, -1, nullptr))
|
||||
{
|
||||
m_glyphs.push_back(outlineGlyph);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float glyphAdvance = float(advance);
|
||||
|
||||
if (ShouldLineWrap(glyphAdvance))
|
||||
if (ShouldLineWrap(advance))
|
||||
AppendNewLine(font, characterSize, m_lastSeparatorGlyph, m_lastSeparatorPosition);
|
||||
|
||||
glyph.atlas = nullptr;
|
||||
glyph.bounds.Set(float(m_drawPos.x), m_lines.back().bounds.y, glyphAdvance, float(sizeInfo.lineHeight));
|
||||
glyph.bounds.Set(m_drawPos.x, m_lines.back().bounds.y, advance, float(sizeInfo.lineHeight));
|
||||
|
||||
glyph.corners[0].Set(glyph.bounds.GetCorner(RectCorner_LeftTop));
|
||||
glyph.corners[1].Set(glyph.bounds.GetCorner(RectCorner_RightTop));
|
||||
@@ -475,9 +473,7 @@ namespace Nz
|
||||
m_glyphs.push_back(glyph);
|
||||
}
|
||||
|
||||
m_workingBounds.ExtendTo(m_lines.back().bounds);
|
||||
|
||||
m_bounds.Set(Rectf(std::floor(m_workingBounds.x), std::floor(m_workingBounds.y), std::ceil(m_workingBounds.width), std::ceil(m_workingBounds.height)));
|
||||
m_bounds.ExtendTo(m_lines.back().bounds);
|
||||
|
||||
m_glyphUpdated = true;
|
||||
}
|
||||
@@ -553,7 +549,7 @@ namespace Nz
|
||||
else
|
||||
m_lines.emplace_back(Line{ Rectf::Zero(), 0 });
|
||||
|
||||
m_drawPos.Set(0, firstBlock.characterSize);
|
||||
m_drawPos.Set(0, float(firstBlock.characterSize));
|
||||
|
||||
for (const Block& block : m_blocks)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user