diff options
Diffstat (limited to 'src/Text.cpp')
-rw-r--r-- | src/Text.cpp | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/src/Text.cpp b/src/Text.cpp index c8ee731..39e339f 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -6,8 +6,8 @@ #include "../include/ImagePreview.hpp" #include "../include/StringUtils.hpp" #include <SFML/Graphics/RectangleShape.hpp> +#include <SFML/Window/Clipboard.hpp> #include <cmath> -#include <process.hpp> namespace dchat { @@ -341,6 +341,7 @@ namespace dchat sf::Uint32 prevCodePoint = 0; size_t lastSpacingWordWrapIndex = -1; float lastSpacingAccumulatedOffset = 0.0f; + bool lineHasEmoji = false; for(usize textElementIndex = 0; textElementIndex < textElements.size(); ++textElementIndex) { TextElement &textElement = textElements[textElementIndex]; @@ -377,11 +378,12 @@ namespace dchat { textElement.position.y = glyphPos.y; // TODO: Find a better way to do this, @totalHeight is wrong because we add emojiSize and then vspace - glyphPos.y += floor(emojiSize - vspace); + glyphPos.y += floor(emojiSize - vspace) + lineSpacing; } else { textElement.position.y = glyphPos.y + vspace * 0.5f - emojiSize * 0.5f; + lineHasEmoji = true; } glyphPos.x += emojiSize + EMOJI_PADDING + characterSpacing; if(glyphPos.x > maxWidth) @@ -443,16 +445,13 @@ namespace dchat vertices[vertexStart + 2] = { sf::Vector2f(0.0f, glyphPos.y), sf::Color::Transparent, sf::Vector2f() }; vertices[vertexStart + 3] = { sf::Vector2f(0.0f, glyphPos.y), sf::Color::Transparent, sf::Vector2f() }; glyphPos.x = 0.0f; - glyphPos.y += floor(vspace + lineSpacing); - continue; - } - case '\v': - { - vertices[vertexStart + 0] = { sf::Vector2f(glyphPos.x, glyphPos.y - vspace), sf::Color::Transparent, sf::Vector2f() }; - vertices[vertexStart + 1] = { sf::Vector2f(0.0f, glyphPos.y), sf::Color::Transparent, sf::Vector2f() }; - vertices[vertexStart + 2] = { sf::Vector2f(0.0f, glyphPos.y), sf::Color::Transparent, sf::Vector2f() }; - vertices[vertexStart + 3] = { sf::Vector2f(0.0f, glyphPos.y), sf::Color::Transparent, sf::Vector2f() }; - glyphPos.y += floor(vspace * TAB_WIDTH + lineSpacing); + if(lineHasEmoji) + { + lineHasEmoji = false; + glyphPos.y += floor(vspace * EMOJI_SCALE_WITH_TEXT + lineSpacing); + } + else + glyphPos.y += floor(vspace + lineSpacing); continue; } } @@ -481,7 +480,13 @@ namespace dchat else glyphPos.x = 0.0f; - glyphPos.y += floor(vspace + lineSpacing); + if(lineHasEmoji) + { + lineHasEmoji = false; + glyphPos.y += floor(vspace * EMOJI_SCALE_WITH_TEXT + lineSpacing); + } + else + glyphPos.y += floor(vspace + lineSpacing); } sf::Vector2f vertexTopLeft(glyphPos.x + glyph.bounds.left, glyphPos.y + glyph.bounds.top); @@ -513,7 +518,7 @@ namespace dchat if(textElement.type == TextElement::Type::URL) { - glyphPos.y += vspace + lineSpacing; + glyphPos.y += floor(vspace + lineSpacing); textElement.position.y = glyphPos.y; glyphPos.x = 0.0f; @@ -521,7 +526,12 @@ namespace dchat } } - boundingBox.height = glyphPos.y + vspace + lineSpacing; + boundingBox.height = glyphPos.y + lineSpacing; + if(lineHasEmoji) + boundingBox.height += vspace * EMOJI_SCALE_WITH_TEXT; + else + boundingBox.height += vspace; + usize numVertices = vertices.getVertexCount(); for(usize i = 0; i < numVertices; i += 4) { @@ -708,18 +718,6 @@ namespace dchat return static_cast<int>(1.0f + position.y / (vspace + lineSpacing)); } - static std::string getClipboard() - { - std::string result; - TinyProcessLib::Process process("xsel -o -b", "", [&result](const char *bytes, size_t n) - { - result.append(bytes, n); - }); - if(process.get_exit_status() != 0) - fprintf(stderr, "Failed to get clipboard content\n"); - return result; - } - void Text::onMouseClick(const sf::Event::MouseButtonEvent &event, Cache &cache) { if(event.button != sf::Mouse::Button::Left) return; @@ -869,8 +867,7 @@ namespace dchat sf::String stringToAdd; if(event.text.unicode == 22) // ctrl+v { - auto clipboardString = getClipboard(); - stringToAdd = sf::String::fromUtf8(clipboardString.begin(), clipboardString.end()); + stringToAdd = sf::Clipboard::getString(); } else if(event.text.unicode >= 32 || event.text.unicode == 9) // 9 == tab stringToAdd = event.text.unicode; |