Changed the implementation from offsets to factors.
This commit is contained in:
parent
73892dfa12
commit
65d26be74d
@ -145,34 +145,32 @@ public:
|
||||
void setCharacterSize(unsigned int size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the additional line spacing offset
|
||||
/// \brief Set the line spacing factor
|
||||
///
|
||||
/// The spacing between lines is defined by the font.
|
||||
/// This method enables you to set an additional spacing
|
||||
/// between lines. By default the additional line
|
||||
/// spacing offset is 0.
|
||||
/// The default spacing between lines is defined by the font.
|
||||
/// This method enables you to set a factor for the spacing
|
||||
/// between lines. By default the line spacing offset is 1.
|
||||
///
|
||||
/// \param spacing New additional line spacing offset, in pixel
|
||||
/// \param spacing New line spacing factor
|
||||
///
|
||||
/// \see getLineSpacing
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setLineSpacing(float spacing);
|
||||
void setLineSpacing(float spacingFactor);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the additional letter spacing offset
|
||||
/// \brief Set the letter spacing factor
|
||||
///
|
||||
/// The spacing between letters is defined by the font.
|
||||
/// This method enables you to set an additional spacing
|
||||
/// between letters. By default the additional letter
|
||||
/// spacing offset is 0.
|
||||
/// The default spacing between letters is defined by the font.
|
||||
/// This method enables you to set a factor to the spacing
|
||||
/// between letters. By default the letter spacing factor is 1.
|
||||
///
|
||||
/// \param spacing New additional letter spacing offset, in pixel
|
||||
/// \param spacing New letter spacing factor
|
||||
///
|
||||
/// \see getLetterSpacing
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setLetterSpacing(float spacing);
|
||||
void setLetterSpacing(float spacingFactor);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the text's style
|
||||
@ -291,9 +289,9 @@ public:
|
||||
unsigned int getCharacterSize() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the size of the additional letter spacing offset
|
||||
/// \brief Get the size of the letter spacing factor
|
||||
///
|
||||
/// \return Size of the additional letter spacing offset, in pixel
|
||||
/// \return Size of the letter spacing factor
|
||||
///
|
||||
/// \see setLetterSpacing
|
||||
///
|
||||
@ -301,9 +299,9 @@ public:
|
||||
float getLetterSpacing() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the size of the additional line spacing offset
|
||||
/// \brief Get the size of the line spacing factor
|
||||
///
|
||||
/// \return Size of the additional line spacing offset, in pixel
|
||||
/// \return Size of the line spacing factor
|
||||
///
|
||||
/// \see setLineSpacing
|
||||
///
|
||||
@ -432,20 +430,20 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
String m_string; ///< String to display
|
||||
const Font* m_font; ///< Font used to display the string
|
||||
unsigned int m_characterSize; ///< Base size of characters, in pixels
|
||||
float m_letterSpacing; ///< Additional spacing offset between letters, in pixel
|
||||
float m_lineSpacing; ///< Additional spacing offset between lines, in pixel
|
||||
Uint32 m_style; ///< Text style (see Style enum)
|
||||
Color m_fillColor; ///< Text fill color
|
||||
Color m_outlineColor; ///< Text outline color
|
||||
float m_outlineThickness; ///< Thickness of the text's outline
|
||||
mutable VertexArray m_vertices; ///< Vertex array containing the fill geometry
|
||||
mutable VertexArray m_outlineVertices; ///< Vertex array containing the outline geometry
|
||||
mutable FloatRect m_bounds; ///< Bounding rectangle of the text (in local coordinates)
|
||||
mutable bool m_geometryNeedUpdate; ///< Does the geometry need to be recomputed?
|
||||
mutable Uint64 m_fontTextureId; ///< The font texture id
|
||||
String m_string; ///< String to display
|
||||
const Font* m_font; ///< Font used to display the string
|
||||
unsigned int m_characterSize; ///< Base size of characters, in pixels
|
||||
float m_letterSpacingFactor; ///< Spacing factor between letters
|
||||
float m_lineSpacingFactor; ///< Spacing factor between lines
|
||||
Uint32 m_style; ///< Text style (see Style enum)
|
||||
Color m_fillColor; ///< Text fill color
|
||||
Color m_outlineColor; ///< Text outline color
|
||||
float m_outlineThickness; ///< Thickness of the text's outline
|
||||
mutable VertexArray m_vertices; ///< Vertex array containing the fill geometry
|
||||
mutable VertexArray m_outlineVertices; ///< Vertex array containing the outline geometry
|
||||
mutable FloatRect m_bounds; ///< Bounding rectangle of the text (in local coordinates)
|
||||
mutable bool m_geometryNeedUpdate; ///< Does the geometry need to be recomputed?
|
||||
mutable Uint64 m_fontTextureId; ///< The font texture id
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
@ -74,20 +74,20 @@ namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
Text::Text() :
|
||||
m_string (),
|
||||
m_font (NULL),
|
||||
m_characterSize (30),
|
||||
m_letterSpacing (0.f),
|
||||
m_lineSpacing (0.f),
|
||||
m_style (Regular),
|
||||
m_fillColor (255, 255, 255),
|
||||
m_outlineColor (0, 0, 0),
|
||||
m_outlineThickness (0),
|
||||
m_vertices (Triangles),
|
||||
m_outlineVertices (Triangles),
|
||||
m_bounds (),
|
||||
m_geometryNeedUpdate(false),
|
||||
m_fontTextureId (0)
|
||||
m_string (),
|
||||
m_font (NULL),
|
||||
m_characterSize (30),
|
||||
m_letterSpacingFactor(1.f),
|
||||
m_lineSpacingFactor (1.f),
|
||||
m_style (Regular),
|
||||
m_fillColor (255, 255, 255),
|
||||
m_outlineColor (0, 0, 0),
|
||||
m_outlineThickness (0),
|
||||
m_vertices (Triangles),
|
||||
m_outlineVertices (Triangles),
|
||||
m_bounds (),
|
||||
m_geometryNeedUpdate (false),
|
||||
m_fontTextureId (0)
|
||||
{
|
||||
|
||||
}
|
||||
@ -95,20 +95,20 @@ m_fontTextureId (0)
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Text::Text(const String& string, const Font& font, unsigned int characterSize) :
|
||||
m_string (string),
|
||||
m_font (&font),
|
||||
m_characterSize (characterSize),
|
||||
m_letterSpacing (0.f),
|
||||
m_lineSpacing (0.f),
|
||||
m_style (Regular),
|
||||
m_fillColor (255, 255, 255),
|
||||
m_outlineColor (0, 0, 0),
|
||||
m_outlineThickness (0),
|
||||
m_vertices (Triangles),
|
||||
m_outlineVertices (Triangles),
|
||||
m_bounds (),
|
||||
m_geometryNeedUpdate(true),
|
||||
m_fontTextureId (0)
|
||||
m_string (string),
|
||||
m_font (&font),
|
||||
m_characterSize (characterSize),
|
||||
m_letterSpacingFactor(1.f),
|
||||
m_lineSpacingFactor (1.f),
|
||||
m_style (Regular),
|
||||
m_fillColor (255, 255, 255),
|
||||
m_outlineColor (0, 0, 0),
|
||||
m_outlineThickness (0),
|
||||
m_vertices (Triangles),
|
||||
m_outlineVertices (Triangles),
|
||||
m_bounds (),
|
||||
m_geometryNeedUpdate (true),
|
||||
m_fontTextureId (0)
|
||||
{
|
||||
|
||||
}
|
||||
@ -148,22 +148,22 @@ void Text::setCharacterSize(unsigned int size)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Text::setLetterSpacing(float spacing)
|
||||
void Text::setLetterSpacing(float spacingFactor)
|
||||
{
|
||||
if (m_letterSpacing != spacing)
|
||||
if (m_letterSpacingFactor != spacingFactor)
|
||||
{
|
||||
m_letterSpacing = spacing;
|
||||
m_letterSpacingFactor = spacingFactor;
|
||||
m_geometryNeedUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Text::setLineSpacing(float spacing)
|
||||
void Text::setLineSpacing(float spacingFactor)
|
||||
{
|
||||
if (m_lineSpacing != spacing)
|
||||
if (m_lineSpacingFactor != spacingFactor)
|
||||
{
|
||||
m_lineSpacing = spacing;
|
||||
m_lineSpacingFactor = spacingFactor;
|
||||
m_geometryNeedUpdate = true;
|
||||
}
|
||||
}
|
||||
@ -258,14 +258,14 @@ unsigned int Text::getCharacterSize() const
|
||||
////////////////////////////////////////////////////////////
|
||||
float Text::getLetterSpacing() const
|
||||
{
|
||||
return m_letterSpacing;
|
||||
return m_letterSpacingFactor;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float Text::getLineSpacing() const
|
||||
{
|
||||
return m_lineSpacing;
|
||||
return m_lineSpacingFactor;
|
||||
}
|
||||
|
||||
|
||||
@ -317,8 +317,8 @@ Vector2f Text::findCharacterPos(std::size_t index) const
|
||||
|
||||
// Precompute the variables needed by the algorithm
|
||||
bool isBold = m_style & Bold;
|
||||
float whitespaceWidth = m_font->getGlyph(L' ', m_characterSize, isBold).advance + m_letterSpacing;
|
||||
float lineSpacing = m_font->getLineSpacing(m_characterSize)+ m_lineSpacing;
|
||||
float whitespaceWidth = m_font->getGlyph(L' ', m_characterSize, isBold).advance * m_letterSpacingFactor;
|
||||
float lineSpacing = m_font->getLineSpacing(m_characterSize) * m_lineSpacingFactor;
|
||||
|
||||
// Compute the position
|
||||
Vector2f position;
|
||||
@ -340,7 +340,7 @@ Vector2f Text::findCharacterPos(std::size_t index) const
|
||||
}
|
||||
|
||||
// For regular characters, add the advance offset of the glyph
|
||||
position.x += m_font->getGlyph(curChar, m_characterSize, isBold).advance + m_letterSpacing;
|
||||
position.x += m_font->getGlyph(curChar, m_characterSize, isBold).advance * m_letterSpacingFactor;
|
||||
}
|
||||
|
||||
// Transform the position to global coordinates
|
||||
@ -425,8 +425,8 @@ void Text::ensureGeometryUpdate() const
|
||||
float strikeThroughOffset = xBounds.top + xBounds.height / 2.f;
|
||||
|
||||
// Precompute the variables needed by the algorithm
|
||||
float whitespaceWidth = m_font->getGlyph(L' ', m_characterSize, isBold).advance + m_letterSpacing;
|
||||
float lineSpacing = m_font->getLineSpacing(m_characterSize) + m_lineSpacing;
|
||||
float whitespaceWidth = m_font->getGlyph(L' ', m_characterSize, isBold).advance * m_letterSpacingFactor;
|
||||
float lineSpacing = m_font->getLineSpacing(m_characterSize) * m_lineSpacingFactor;
|
||||
float x = 0.f;
|
||||
float y = static_cast<float>(m_characterSize);
|
||||
|
||||
@ -525,7 +525,7 @@ void Text::ensureGeometryUpdate() const
|
||||
}
|
||||
|
||||
// Advance to the next character
|
||||
x += glyph.advance + m_letterSpacing;
|
||||
x += glyph.advance * m_letterSpacingFactor;
|
||||
}
|
||||
|
||||
// If we're using the underlined style, add the last line
|
||||
|
Loading…
Reference in New Issue
Block a user