Finish 2.0.1
commit
70ec0ef8eb
|
@ -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
|
||||
|
@ -20,6 +20,10 @@ 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.
|
||||
|
||||
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
|
||||
----------
|
||||
|
|
26
RichText.cpp
26
RichText.cpp
|
@ -43,11 +43,7 @@ const std::vector<sf::Text> &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,12 +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, text.getGlobalBounds().height);
|
||||
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<float>(lineSpacing));
|
||||
m_bounds.width += text.getGlobalBounds().width;
|
||||
}
|
||||
|
||||
|
||||
|
@ -308,6 +313,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);
|
||||
|
||||
|
|
|
@ -74,6 +74,11 @@ public:
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
void updateGeometry() const;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Update geometry for a given text
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
void updateTextAndGeometry(sf::Text &text) const;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue