From d68346ca1722ed693c42c1b454fb6ecc8094b9d8 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 15 Apr 2018 02:42:12 +0200 Subject: [PATCH] Utility/SimpleTextDrawer: Fix line bounds --- ChangeLog.md | 1 + src/Nazara/Utility/SimpleTextDrawer.cpp | 46 +++++++++++-------------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 51476899b..92b2acd6a 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -89,6 +89,7 @@ Nazara Engine: - Added AbstractTextDrawer::GetLineGlyphCount, which returns the number of glyph part of the line - Fixed Font handling of whitespace glyphs (which were triggering an error) - ⚠️ Translucent2D pipeline no longer has depth sorting +- Fixed SimpleTextDrawer line bounds Nazara Development Kit: - Added ImageWidget (#139) diff --git a/src/Nazara/Utility/SimpleTextDrawer.cpp b/src/Nazara/Utility/SimpleTextDrawer.cpp index 62df4412b..89accf012 100644 --- a/src/Nazara/Utility/SimpleTextDrawer.cpp +++ b/src/Nazara/Utility/SimpleTextDrawer.cpp @@ -354,42 +354,38 @@ namespace Nz { glyph.atlas = nullptr; - glyph.bounds.Set(float(m_drawPos.x), float(0.f), float(advance), float(sizeInfo.lineHeight)); + glyph.bounds.Set(float(m_drawPos.x), m_lines.back().bounds.y, float(advance), float(sizeInfo.lineHeight)); glyph.corners[0].Set(glyph.bounds.GetCorner(RectCorner_LeftTop)); glyph.corners[1].Set(glyph.bounds.GetCorner(RectCorner_RightTop)); glyph.corners[2].Set(glyph.bounds.GetCorner(RectCorner_LeftBottom)); glyph.corners[3].Set(glyph.bounds.GetCorner(RectCorner_RightBottom)); - - switch (character) - { - case '\n': - { - // Extend the line bounding rect to the last glyph it contains, thus extending upon all glyphs of the line - if (!m_glyphs.empty()) - { - Glyph& lastGlyph = m_glyphs.back(); - m_lines.back().bounds.ExtendTo(lastGlyph.bounds); - } - - // Reset cursor - advance = 0; - m_drawPos.x = 0; - m_drawPos.y += sizeInfo.lineHeight; - - m_workingBounds.ExtendTo(m_lines.back().bounds); - m_lines.emplace_back(Line{Rectf(0.f, float(sizeInfo.lineHeight * m_lines.size()), 0.f, float(sizeInfo.lineHeight)), m_glyphs.size() + 1}); - break; - } - } } m_lines.back().bounds.ExtendTo(glyph.bounds); + + switch (character) + { + case '\n': + { + // Reset cursor + advance = 0; + m_drawPos.x = 0; + m_drawPos.y += sizeInfo.lineHeight; + + m_workingBounds.ExtendTo(m_lines.back().bounds); + m_lines.emplace_back(Line{Rectf(0.f, float(sizeInfo.lineHeight * m_lines.size()), 0.f, float(sizeInfo.lineHeight)), m_glyphs.size() + 1}); + break; + } + + default: + m_drawPos.x += advance; + break; + } - m_drawPos.x += advance; m_glyphs.push_back(glyph); } - m_lines.back().bounds.ExtendTo(m_glyphs.back().bounds); + 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)));