aboutsummaryrefslogtreecommitdiff
path: root/src/Text.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-30 09:19:31 +0200
committerdec05eba <dec05eba@protonmail.com>2018-05-30 09:19:34 +0200
commit4aecbda252b71eff9480d73fd8ec5100819da63b (patch)
tree16f2c7feab0d7a626dce7470c7ca45adcecbe171 /src/Text.cpp
parentaab52eb9561966977dc158abdc99bb599ea1e989 (diff)
Change font, change text spacing
Diffstat (limited to 'src/Text.cpp')
-rw-r--r--src/Text.cpp18
1 files changed, 15 insertions, 3 deletions
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() };