Skip to content

Commit

Permalink
Added support for outlined text
Browse files Browse the repository at this point in the history
  • Loading branch information
zsbzsb authored and eXpl0it3r committed Dec 31, 2015
1 parent 7ff9478 commit 957cabb
Show file tree
Hide file tree
Showing 6 changed files with 352 additions and 111 deletions.
2 changes: 1 addition & 1 deletion examples/pong/Pong.cpp
Expand Up @@ -71,7 +71,7 @@ int main()
pauseMessage.setFont(font);
pauseMessage.setCharacterSize(40);
pauseMessage.setPosition(170.f, 150.f);
pauseMessage.setColor(sf::Color::White);
pauseMessage.setFillColor(sf::Color::White);
pauseMessage.setString("Welcome to SFML pong!\nPress space to start the game");

// Define the paddles properties
Expand Down
4 changes: 2 additions & 2 deletions examples/shader/Shader.cpp
Expand Up @@ -300,12 +300,12 @@ int main()
// Create the description text
sf::Text description("Current effect: " + effects[current]->getName(), font, 20);
description.setPosition(10, 530);
description.setColor(sf::Color(80, 80, 80));
description.setFillColor(sf::Color(80, 80, 80));

// Create the instructions text
sf::Text instructions("Press left and right arrows to change the current shader", font, 20);
instructions.setPosition(280, 555);
instructions.setColor(sf::Color(80, 80, 80));
instructions.setFillColor(sf::Color(80, 80, 80));

// Start the game loop
sf::Clock clock;
Expand Down
24 changes: 15 additions & 9 deletions include/SFML/Graphics/Font.hpp
Expand Up @@ -166,14 +166,18 @@ class SFML_GRAPHICS_API Font
/// might be available. If the glyph is not available at the
/// requested size, an empty glyph is returned.
///
/// \param codePoint Unicode code point of the character to get
/// \param characterSize Reference character size
/// \param bold Retrieve the bold version or the regular one?
/// Be aware that using a negative value for the outline
/// thickness will cause distorted rendering.
///
/// \param codePoint Unicode code point of the character to get
/// \param characterSize Reference character size
/// \param bold Retrieve the bold version or the regular one?
/// \param outlineThickness Thickness of outline (when != 0 the glyph will not be filled)
///
/// \return The glyph corresponding to \a codePoint and \a characterSize
///
////////////////////////////////////////////////////////////
const Glyph& getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const;
const Glyph& getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, float outlineThickness = 0) const;

////////////////////////////////////////////////////////////
/// \brief Get the kerning offset of two glyphs
Expand Down Expand Up @@ -277,7 +281,7 @@ class SFML_GRAPHICS_API Font
////////////////////////////////////////////////////////////
// Types
////////////////////////////////////////////////////////////
typedef std::map<Uint32, Glyph> GlyphTable; ///< Table mapping a codepoint to its glyph
typedef std::map<Uint64, Glyph> GlyphTable; ///< Table mapping a codepoint to its glyph

////////////////////////////////////////////////////////////
/// \brief Structure defining a page of glyphs
Expand All @@ -302,14 +306,15 @@ class SFML_GRAPHICS_API Font
////////////////////////////////////////////////////////////
/// \brief Load a new glyph and store it in the cache
///
/// \param codePoint Unicode code point of the character to load
/// \param characterSize Reference character size
/// \param bold Retrieve the bold version or the regular one?
/// \param codePoint Unicode code point of the character to load
/// \param characterSize Reference character size
/// \param bold Retrieve the bold version or the regular one?
/// \param outlineThickness Thickness of outline (when != 0 the glyph will not be filled)
///
/// \return The glyph corresponding to \a codePoint and \a characterSize
///
////////////////////////////////////////////////////////////
Glyph loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const;
Glyph loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, float outlineThickness) const;

////////////////////////////////////////////////////////////
/// \brief Find a suitable rectangle within the texture for a glyph
Expand Down Expand Up @@ -344,6 +349,7 @@ class SFML_GRAPHICS_API Font
void* m_library; ///< Pointer to the internal library interface (it is typeless to avoid exposing implementation details)
void* m_face; ///< Pointer to the internal font face (it is typeless to avoid exposing implementation details)
void* m_streamRec; ///< Pointer to the stream rec instance (it is typeless to avoid exposing implementation details)
void* m_stroker; ///< Pointer to the stroker (it is typeless to avoid exposing implementation details)
int* m_refCount; ///< Reference counter used by implicit sharing
Info m_info; ///< Information about the font
mutable PageTable m_pages; ///< Table containing the glyphs pages by character size
Expand Down
106 changes: 95 additions & 11 deletions include/SFML/Graphics/Text.hpp
Expand Up @@ -159,16 +159,63 @@ class SFML_GRAPHICS_API Text : public Drawable, public Transformable
void setStyle(Uint32 style);

////////////////////////////////////////////////////////////
/// \brief Set the global color of the text
/// \brief Set the fill color of the text
///
/// By default, the text's color is opaque white.
/// By default, the text's fill color is opaque white.
/// Setting the fill color to a transparent color with an outline
/// will cause the outline to be displayed in the fill area of the text.
///
/// \param color New color of the text
/// \param color New fill color of the text
///
/// \see getColor
/// \see getFillColor
///
/// \deprecated There is now fill and outline colors instead
/// of a single global color.
/// Use setFillColor() or setOutlineColor() instead.
///
////////////////////////////////////////////////////////////
SFML_DEPRECATED void setColor(const Color& color);

////////////////////////////////////////////////////////////
/// \brief Set the fill color of the text
///
/// By default, the text's fill color is opaque white.
/// Setting the fill color to a transparent color with an outline
/// will cause the outline to be displayed in the fill area of the text.
///
/// \param color New fill color of the text
///
/// \see getFillColor
///
////////////////////////////////////////////////////////////
void setFillColor(const Color& color);

////////////////////////////////////////////////////////////
/// \brief Set the outline color of the text
///
/// By default, the text's outline color is opaque black.
///
/// \param color New outline color of the text
///
/// \see getOutlineColor
///
////////////////////////////////////////////////////////////
void setOutlineColor(const Color& color);

////////////////////////////////////////////////////////////
/// \brief Set the thickness of the text's outline
///
/// By default, the outline thickness is 0.
///
/// Be aware that using a negative value for the outline
/// thickness will cause distorted rendering.
///
/// \param thickness New outline thickness, in pixels
///
/// \see getOutlineThickness
///
////////////////////////////////////////////////////////////
void setColor(const Color& color);
void setOutlineThickness(float thickness);

////////////////////////////////////////////////////////////
/// \brief Get the text's string
Expand Down Expand Up @@ -224,14 +271,48 @@ class SFML_GRAPHICS_API Text : public Drawable, public Transformable
Uint32 getStyle() const;

////////////////////////////////////////////////////////////
/// \brief Get the global color of the text
/// \brief Get the fill color of the text
///
/// \return Fill color of the text
///
/// \see setFillColor
///
/// \deprecated There is now fill and outline colors instead
/// of a single global color.
/// Use getFillColor() or getOutlineColor() instead.
///
////////////////////////////////////////////////////////////
SFML_DEPRECATED const Color& getColor() const;

////////////////////////////////////////////////////////////
/// \brief Get the fill color of the text
///
/// \return Fill color of the text
///
/// \see setFillColor
///
////////////////////////////////////////////////////////////
const Color& getFillColor() const;

////////////////////////////////////////////////////////////
/// \brief Get the outline color of the text
///
/// \return Outline color of the text
///
/// \see setOutlineColor
///
////////////////////////////////////////////////////////////
const Color& getOutlineColor() const;

////////////////////////////////////////////////////////////
/// \brief Get the outline thickness of the text
///
/// \return Global color of the text
/// \return Outline thickness of the text, in pixels
///
/// \see setColor
/// \see setOutlineThickness
///
////////////////////////////////////////////////////////////
const Color& getColor() const;
float getOutlineThickness() const;

////////////////////////////////////////////////////////////
/// \brief Return the position of the \a index-th character
Expand Down Expand Up @@ -305,8 +386,11 @@ class SFML_GRAPHICS_API Text : public Drawable, public Transformable
const Font* m_font; ///< Font used to display the string
unsigned int m_characterSize; ///< Base size of characters, in pixels
Uint32 m_style; ///< Text style (see Style enum)
Color m_color; ///< Text color
mutable VertexArray m_vertices; ///< Vertex array containing the text's geometry
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?
};
Expand Down

0 comments on commit 957cabb

Please sign in to comment.