From 4aecbda252b71eff9480d73fd8ec5100819da63b Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 30 May 2018 09:19:31 +0200 Subject: Change font, change text spacing --- src/Text.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/Text.cpp') diff --git a/src/Text.cpp b/src/Text.cpp index 5c8db41..c8ee731 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -33,6 +33,8 @@ namespace dchat editable(false), visible(true), caretMoveDirection(CaretMoveDirection::NONE), + lineSpacing(0.0f), + characterSpacing(0.0f), caretIndex(0) { @@ -53,6 +55,7 @@ namespace dchat visible(true), caretMoveDirection(CaretMoveDirection::NONE), lineSpacing(0.0f), + characterSpacing(0.0f), caretIndex(0) { setString(_str); @@ -145,6 +148,15 @@ namespace dchat } } + void Text::setCharacterSpacing(float characterSpacing) + { + if(fabs(characterSpacing - this->characterSpacing) > 0.001f) + { + this->characterSpacing = characterSpacing; + dirty = true; + } + } + void Text::setEditable(bool editable) { if(editable != this->editable) @@ -320,7 +332,7 @@ namespace dchat void Text::updateGeometry() { vertices.clear(); - float hspace = font->getGlyph(' ', characterSize, false).advance; + float hspace = font->getGlyph(' ', characterSize, false).advance + characterSpacing; float vspace = font->getLineSpacing(characterSize); boundingBox = sf::FloatRect(); @@ -371,7 +383,7 @@ namespace dchat { textElement.position.y = glyphPos.y + vspace * 0.5f - emojiSize * 0.5f; } - glyphPos.x += emojiSize + EMOJI_PADDING; + glyphPos.x += emojiSize + EMOJI_PADDING + characterSpacing; if(glyphPos.x > maxWidth) { glyphPos.x = 0.0f; @@ -489,7 +501,7 @@ namespace dchat vertices[vertexStart + 2] = { vertexBottomRight, fontColor, textureBottomRight }; vertices[vertexStart + 3] = { vertexBottomLeft, fontColor, textureBottomLeft }; - glyphPos.x += glyph.advance; + glyphPos.x += glyph.advance + characterSpacing; } vertices[vertices.getVertexCount() - 4] = { sf::Vector2f(glyphPos.x, glyphPos.y - vspace), sf::Color::Transparent, sf::Vector2f() }; -- cgit v1.2.3