From 6b825a084cd64ccd4593b0ba1eb7cc6f5288cd3a Mon Sep 17 00:00:00 2001 From: Lynix Date: Sat, 25 Jan 2020 19:08:36 +0100 Subject: [PATCH] Utility/SimpleTextDrawer: Add line spacing factor --- include/Nazara/Utility/SimpleTextDrawer.hpp | 6 ++++-- include/Nazara/Utility/SimpleTextDrawer.inl | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/Nazara/Utility/SimpleTextDrawer.hpp b/include/Nazara/Utility/SimpleTextDrawer.hpp index 304142d6e..ef838e6b8 100644 --- a/include/Nazara/Utility/SimpleTextDrawer.hpp +++ b/include/Nazara/Utility/SimpleTextDrawer.hpp @@ -39,6 +39,7 @@ namespace Nz const Line& GetLine(std::size_t index) const override; std::size_t GetLineCount() const override; inline float GetLineHeight() const; + inline float GetLineSpacingFactor() const; float GetMaxLineWidth() const override; inline const Color& GetOutlineColor() const; inline float GetOutlineThickness() const; @@ -69,8 +70,8 @@ namespace Nz void ClearGlyphs() const; - void ConnectFontSlots(); - void DisconnectFontSlots(); + inline void ConnectFontSlots(); + inline void DisconnectFontSlots(); bool GenerateGlyph(Glyph& glyph, char32_t character, float outlineThickness, bool lineWrap, Nz::Color color, int renderOrder, int* advance) const; void GenerateGlyphs(const String& text) const; @@ -110,6 +111,7 @@ namespace Nz mutable bool m_colorUpdated; mutable bool m_glyphUpdated; mutable float m_lastSeparatorPosition; + float m_lineSpacingFactor; float m_maxLineWidth; float m_outlineThickness; unsigned int m_characterSize; diff --git a/include/Nazara/Utility/SimpleTextDrawer.inl b/include/Nazara/Utility/SimpleTextDrawer.inl index 3f8e1ae52..088664fc8 100644 --- a/include/Nazara/Utility/SimpleTextDrawer.inl +++ b/include/Nazara/Utility/SimpleTextDrawer.inl @@ -13,6 +13,7 @@ namespace Nz m_style(TextStyle_Regular), m_colorUpdated(true), m_glyphUpdated(true), + m_lineSpacingFactor(1.f), m_maxLineWidth(std::numeric_limits::infinity()), m_outlineThickness(0.f), m_characterSize(24) @@ -27,6 +28,7 @@ namespace Nz m_colorUpdated(false), m_glyphUpdated(false), m_outlineColor(drawer.m_outlineColor), + m_lineSpacingFactor(drawer.m_lineSpacingFactor), m_maxLineWidth(drawer.m_maxLineWidth), m_outlineThickness(drawer.m_outlineThickness), m_characterSize(drawer.m_characterSize) @@ -67,6 +69,11 @@ namespace Nz return GetLineHeight(m_font->GetSizeInfo(m_characterSize)); } + inline float SimpleTextDrawer::GetLineSpacingFactor() const + { + return m_lineSpacingFactor; + } + inline const Color& SimpleTextDrawer::GetOutlineColor() const { return m_outlineColor; @@ -122,6 +129,16 @@ namespace Nz } } + inline void SimpleTextDrawer::SetLineSpacingFactor(float factor) + { + if (m_lineSpacingFactor != factor) + { + m_lineSpacingFactor = factor; + + InvalidateGlyphs(); + } + } + inline void SimpleTextDrawer::SetMaxLineWidth(float lineWidth) { if (m_maxLineWidth != lineWidth) @@ -180,6 +197,7 @@ namespace Nz { m_characterSize = drawer.m_characterSize; m_color = drawer.m_color; + m_lineSpacingFactor = drawer.m_lineSpacingFactor; m_maxLineWidth = drawer.m_maxLineWidth; m_outlineColor = drawer.m_outlineColor; m_outlineThickness = drawer.m_outlineThickness; @@ -203,6 +221,7 @@ namespace Nz m_glyphs = std::move(drawer.m_glyphs); m_glyphUpdated = std::move(drawer.m_glyphUpdated); m_font = std::move(drawer.m_font); + m_lineSpacingFactor = drawer.m_lineSpacingFactor; m_maxLineWidth = drawer.m_maxLineWidth; m_outlineColor = std::move(drawer.m_outlineColor); m_outlineThickness = std::move(drawer.m_outlineThickness); @@ -210,7 +229,6 @@ namespace Nz m_text = std::move(drawer.m_text); // Update slot pointers (TODO: Improve the way of doing this) - ConnectFontSlots(); if (m_font) { drawer.DisconnectFontSlots();