From 9cde35c64c9f569055b101a80419d900f58806a9 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 3 May 2018 07:35:39 +0200 Subject: Adding theming, add new theme 'simple' --- src/Text.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/Text.cpp') diff --git a/src/Text.cpp b/src/Text.cpp index 3cafc69..b22a27d 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -31,7 +31,8 @@ namespace dchat color(sf::Color::White), dirty(true), plainText(_plainText), - totalHeight(0.0f) + totalHeight(0.0f), + lineSpacing(0.0f) { setString(_str); } @@ -94,6 +95,15 @@ namespace dchat } } + void Text::setLineSpacing(float lineSpacing) + { + if(lineSpacing != this->lineSpacing) + { + this->lineSpacing = lineSpacing; + dirty = true; + } + } + float Text::getHeight() const { return totalHeight; @@ -203,7 +213,7 @@ namespace dchat if(glyphPos.x > maxWidth) { glyphPos.x = 0.0f; - glyphPos.y += vspace; + glyphPos.y += vspace + lineSpacing; } continue; @@ -244,12 +254,12 @@ namespace dchat case '\n': { glyphPos.x = 0.0f; - glyphPos.y += vspace; + glyphPos.y += vspace + lineSpacing; continue; } case '\v': { - glyphPos.y += (vspace * TAB_WIDTH); + glyphPos.y += (vspace * TAB_WIDTH) + lineSpacing; continue; } } @@ -268,7 +278,7 @@ namespace dchat { sf::Vector2f &vertexPos = vertices[vertexOffset + j * 4 + k].position; vertexPos.x -= lastSpacingAccumulatedOffset; - vertexPos.y += vspace; + vertexPos.y += vspace + lineSpacing; } } @@ -279,7 +289,7 @@ namespace dchat else glyphPos.x = 0.0f; - glyphPos.y += vspace; + glyphPos.y += vspace + lineSpacing; } sf::Vector2f vertexTopLeft(glyphPos.x + glyph.bounds.left, glyphPos.y + glyph.bounds.top); @@ -300,7 +310,7 @@ namespace dchat glyphPos.x += glyph.advance; } } - totalHeight = glyphPos.y + vspace; + totalHeight = glyphPos.y + lineSpacing + vspace; } void Text::draw(sf::RenderTarget &target, Cache &cache) -- cgit v1.2.3