From 795620c2108adf4364a82421c63ea90bb4b8a108 Mon Sep 17 00:00:00 2001 From: Skyrpex Date: Mon, 24 Feb 2014 19:52:13 +0100 Subject: [PATCH 1/7] Small readme file change --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a151e65..93ca008 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ License This code is licensed under public domain. -Author ------- +Authors +------- * [Cristian Pallarés](https://github.com/Skyrpex) - Original code * [Lukas Dürrenberger](https://github.com/eXpl0it3r/) - Conversion to the new SFML2 API From 0c5a2256bc817e902cc97b20b52e5f067cd337af Mon Sep 17 00:00:00 2001 From: Skyrpex Date: Mon, 24 Feb 2014 19:52:38 +0100 Subject: [PATCH 2/7] Readme file mentions the C++11 usage --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 93ca008..5f85565 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ How to use 1. Include the header and the source to your project. 2. Link to SFML2 (obviously :P!). +3. Use a C++11 ready compiler. Repository ---------- From 3043913c905fb2e1109c5f91b3a294049ecab66c Mon Sep 17 00:00:00 2001 From: Skyrpex Date: Mon, 24 Feb 2014 20:01:41 +0100 Subject: [PATCH 3/7] Readme file mentions the support branch --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 5f85565..ffe373a 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,9 @@ How to use 2. Link to SFML2 (obviously :P!). 3. Use a C++11 ready compiler. +Note: For a non C++11 ready compilers, there is a [support branch](https://github.com/Skyrpex/RichText/tree/support/no-c%2B%2B11). +However, it's not guaranteed to be fully updated. + Repository ---------- From dc3a19624acf774bfbcc4454ec67a28a6975abf1 Mon Sep 17 00:00:00 2001 From: Stuart Allan Rutherford Date: Thu, 27 Feb 2014 22:06:16 +1100 Subject: [PATCH 4/7] Fixed createText to set the sf::Text's size --- RichText.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/RichText.cpp b/RichText.cpp index 121b2b0..343afb7 100644 --- a/RichText.cpp +++ b/RichText.cpp @@ -308,6 +308,7 @@ sf::Text RichText::createText(const sf::String &string) const text.setString(string); text.setColor(m_currentColor); text.setStyle(m_currentStyle); + text.setCharacterSize(m_characterSize); if (m_font) text.setFont(*m_font); From 69f6a9abded2d2b7f3ea45cebabcf0d637669468 Mon Sep 17 00:00:00 2001 From: Stuart Allan Rutherford Date: Sat, 1 Mar 2014 12:52:47 +1100 Subject: [PATCH 5/7] Solved issue #9 in master repo --- RichText.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RichText.cpp b/RichText.cpp index 121b2b0..c616f99 100644 --- a/RichText.cpp +++ b/RichText.cpp @@ -323,7 +323,7 @@ void RichText::updateGeometry() const for (Line &line : m_lines) { line.setPosition(0.f, m_bounds.height); - m_bounds.height += line.getGlobalBounds().height; + m_bounds.height += m_font->getLineSpacing(m_characterSize); m_bounds.width = std::max(m_bounds.width, line.getGlobalBounds().width); } } From d3c7c2a23ac1d5046606a28e9f830580cbbf4134 Mon Sep 17 00:00:00 2001 From: Stuart Allan Rutherford Date: Sat, 1 Mar 2014 13:13:46 +1100 Subject: [PATCH 6/7] A cleaner fix for #9 Fixed the line geometry calculations to use the font spacing instead of the text's bounding box. Reverted the previous commit. --- RichText.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/RichText.cpp b/RichText.cpp index c616f99..cb8e503 100644 --- a/RichText.cpp +++ b/RichText.cpp @@ -86,7 +86,8 @@ void RichText::Line::updateGeometry() const for (sf::Text &text : m_texts) { text.setPosition(m_bounds.width, 0.f); - m_bounds.height = std::max(m_bounds.height, text.getGlobalBounds().height); + m_bounds.height = std::max(m_bounds.height, + float(text.getFont()->getLineSpacing(text.getCharacterSize()))); m_bounds.width += text.getGlobalBounds().width; } } @@ -323,7 +324,7 @@ void RichText::updateGeometry() const for (Line &line : m_lines) { line.setPosition(0.f, m_bounds.height); - m_bounds.height += m_font->getLineSpacing(m_characterSize); + m_bounds.height += line.getGlobalBounds().height; m_bounds.width = std::max(m_bounds.width, line.getGlobalBounds().width); } } From db41807aaf9567ca5b0e31b05f9240930e29afea Mon Sep 17 00:00:00 2001 From: Skyrpex Date: Sun, 2 Mar 2014 03:18:24 +0100 Subject: [PATCH 7/7] Used C++ static_cast in favor of C-style cast Refactored text geometry update into a single function --- RichText.cpp | 26 +++++++++++++++----------- RichText.hpp | 5 +++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/RichText.cpp b/RichText.cpp index 8a6a08f..a4a13f1 100644 --- a/RichText.cpp +++ b/RichText.cpp @@ -43,11 +43,7 @@ const std::vector &RichText::Line::getTexts() const void RichText::Line::appendText(sf::Text text) { // Set text offset - text.setPosition(m_bounds.width, 0.f); - - // Update bounds - m_bounds.height = std::max(m_bounds.height, text.getGlobalBounds().height); - m_bounds.width += text.getGlobalBounds().width; + updateTextAndGeometry(text); // Push back m_texts.push_back(std::move(text)); @@ -83,13 +79,21 @@ void RichText::Line::updateGeometry() const { m_bounds = sf::FloatRect(); - for (sf::Text &text : m_texts) { - text.setPosition(m_bounds.width, 0.f); + for (sf::Text &text : m_texts) + updateTextAndGeometry(text); +} - m_bounds.height = std::max(m_bounds.height, - float(text.getFont()->getLineSpacing(text.getCharacterSize()))); - m_bounds.width += text.getGlobalBounds().width; - } + +//////////////////////////////////////////////////////////////////////////////// +void RichText::Line::updateTextAndGeometry(sf::Text &text) const +{ + // Set text offset + text.setPosition(m_bounds.width, 0.f); + + // Update bounds + int lineSpacing = text.getFont()->getLineSpacing(text.getCharacterSize()); + m_bounds.height = std::max(m_bounds.height, static_cast(lineSpacing)); + m_bounds.width += text.getGlobalBounds().width; } diff --git a/RichText.hpp b/RichText.hpp index d355eb1..51d4103 100644 --- a/RichText.hpp +++ b/RichText.hpp @@ -74,6 +74,11 @@ public: ////////////////////////////////////////////////////////////////////// void updateGeometry() const; + ////////////////////////////////////////////////////////////////////// + // Update geometry for a given text + ////////////////////////////////////////////////////////////////////// + void updateTextAndGeometry(sf::Text &text) const; + ////////////////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////////////////