ge211
Text_sprite::Builder Class Reference

Detailed Description

Builder-style API for configuring and constructing Text_sprites.

The idea is that a Text_sprite::Builder allows configuring a Text_sprite in detail before actually constructing it. For example:

Font sans("sans.ttf", 24);
Text_sprite sprite =
Text_sprite::Builder(sans)
.message("Hello, world!")
.build();

Definition at line 238 of file ge211_sprites.h.

Public Member Functions

Constructor and builder
 Builder (Font const &)
 Constructs a new Text_sprite::Builder with the given Font.
 
Text_sprite build () const
 Builds the configured Text_sprite.
 
Builder-style setters
template<class T >
Builderadd_message (T const &value)
 Adds to the builder's message. More...
 
template<class T >
Builderoperator<< (T const &value)
 Adds to the builder's message. More...
 
Buildermessage (std::string const &)
 Replaces the configured message with the given message. More...
 
Builderfont (Font const &)
 Sets font to use. More...
 
Buildercolor (Color)
 Sets the color to use. More...
 
Builderantialias (bool)
 Sets whether to use anti-aliasing. More...
 
Builderword_wrap (int)
 Sets the pixel width for wrapping the text. More...
 
Getters
std::string message () const
 Gets the configured message.
 
Font const & font () const
 Gets the font that will be used.
 
Color color () const
 Gets the color that will be used.
 
bool antialias () const
 Gets whether anti-aliasing will be used.
 
int word_wrap () const
 Gets the wrapping width that will be used.
 

Member Function Documentation

◆ add_message()

Builder& add_message ( T const &  value)
inline

Adds to the builder's message.

This takes any printable type and prints it à la operator<<. Returns the builder, for call chaining.

Definition at line 259 of file ge211_sprites.h.

◆ antialias()

Text_sprite::Builder & antialias ( bool  antialias)

Sets whether to use anti-aliasing.

Anti-aliasing, on by default, makes text smoother but can make it take longer to render. Returns a reference to the Builder for call chaining.

Definition at line 271 of file ge211_sprites.cpp.

◆ color()

Text_sprite::Builder & color ( Color  color)

Sets the color to use.

Returns a reference to the Builder for call chaining.

Definition at line 265 of file ge211_sprites.cpp.

◆ font()

Text_sprite::Builder & font ( Font const &  font)

Sets font to use.

Returns a reference to the Builder for call chaining.

Definition at line 259 of file ge211_sprites.cpp.

◆ message()

Text_sprite::Builder & message ( std::string const &  message)

Replaces the configured message with the given message.

Returns a reference to the Builder for call chaining.

Definition at line 253 of file ge211_sprites.cpp.

◆ operator<<()

Builder& operator<< ( T const &  value)
inline

Adds to the builder's message.

This is an alias for add_message(const T&).

For example:

Text_sprite position_sprite(Position position)
{
Builder builder(font);
builder << "(" << position.x << ", " << position.y << ")";
return builder.build();
}

Definition at line 279 of file ge211_sprites.h.

◆ word_wrap()

Text_sprite::Builder & word_wrap ( int  word_wrap)

Sets the pixel width for wrapping the text.

If set to 0, the text does not wrap at all. Newlines in the text will produces newlines in the output only if wrapping is on (non-zero). Returns a reference to the Builder for call chaining.

Definition at line 277 of file ge211_sprites.cpp.


The documentation for this class was generated from the following files: