bn::sprite_text_generator class

Generates sprites containing text from a given sprite_font.

Currently, it supports 4 bits per pixel (16 colors) fixed width AND variable width characters.

Text can be printed in one sprite per character or multiple characters per sprite.

Also, UTF-8 characters are supported.

Public types

enum class alignment_type: uint8_t { LEFT, CENTER, RIGHT }
Available horizontal alignment types.

Constructors, destructors, conversion operators

sprite_text_generator(const sprite_font& font) explicit
Constructor.
sprite_text_generator(const sprite_font& font, const sprite_palette_item& palette_item)
Constructor.

Public functions

auto font() const -> const sprite_font&
Returns the sprite font for drawing text.
auto palette_item() const -> const sprite_palette_item&
Returns the sprite_palette_item that generates the color palette used by the text sprites.
void set_palette_item(const sprite_palette_item& palette_item)
Sets the 16 colors (4 bits per pixel) sprite_palette_item that generates the color palette used by the text sprites.
auto alignment() const -> alignment_type
Returns the horizontal alignment of the output text sprites.
void set_alignment(alignment_type alignment)
Sets the horizontal alignment of the output text sprites.
void set_left_alignment()
Sets the horizontal alignment of the output text sprites to the left.
void set_center_alignment()
Sets the horizontal alignment of the output text sprites to the center.
void set_right_alignment()
Sets the horizontal alignment of the output text sprites to the right.
auto bg_priority() const -> int
Returns the priority of the output sprites priority relative to backgrounds.
void set_bg_priority(int bg_priority)
Sets the priority of the output sprites relative to backgrounds.
auto z_order() const -> int
Returns the priority of the output sprites relative to other sprites.
void set_z_order(int z_order)
Sets the priority of the output sprites relative to other sprites.
auto mosaic_enabled() const -> bool
Indicates if the mosaic effect must be applied to the output sprites or not.
void set_mosaic_enabled(bool mosaic_enabled)
Sets if the mosaic effect must be applied to the output sprites or not.
auto blending_enabled() const -> bool
Indicates if blending must be applied to the output sprites or not.
void set_blending_enabled(bool blending_enabled)
Sets if blending must be applied to the output sprites or not.
auto visible() const -> bool
Indicates if the output sprites must be committed to the GBA or not.
void set_visible(bool visible)
Sets if the output sprites must be committed to the GBA or not.
auto camera() const -> const optional<camera_ptr>&
Returns the camera_ptr to attach to the output sprites (if any).
void set_camera(const camera_ptr& camera)
Sets the camera_ptr to attach to the output sprites.
void set_camera(camera_ptr&& camera)
Sets the camera_ptr to attach to the output sprites.
void set_camera(const optional<camera_ptr>& camera)
Sets or removes the camera_ptr to attach to the output sprites.
void set_camera(optional<camera_ptr>&& camera)
Sets or removes the camera_ptr to attach to the output sprites.
void remove_camera()
Removes the camera_ptr to attach to the output sprites.
auto release_camera() -> optional<camera_ptr>
Releases and returns the camera_ptr to attach to the output sprites (if any).
auto one_sprite_per_character() const -> bool
Indicates if this sprite_text_generator must generate one sprite per character or print multiple characters in each output sprite, generating as less sprites as possible.
void set_one_sprite_per_character(bool one_sprite_per_character)
Sets if this sprite_text_generator must generate one sprite per character or print multiple characters in each output sprite, generating as less sprites as possible.
auto width(const string_view& text) const -> int
Returns the width in pixels of the given text.
template<int MaxSprites>
auto generate(const string_view& text) const -> vector<sprite_ptr, MaxSprites>
Generates text sprites for the given single line of text.
template<int MaxSprites>
auto generate(fixed x, fixed y, const string_view& text) const -> vector<sprite_ptr, MaxSprites>
Generates text sprites for the given single line of text.
template<int MaxSprites>
auto generate(const fixed_point& position, const string_view& text) const -> vector<sprite_ptr, MaxSprites>
Generates text sprites for the given single line of text.
void generate(const string_view& text, ivector<sprite_ptr>& output_sprites) const
Generates text sprites for the given single line of text.
void generate(fixed x, fixed y, const string_view& text, ivector<sprite_ptr>& output_sprites) const
Generates text sprites for the given single line of text.
void generate(const fixed_point& position, const string_view& text, ivector<sprite_ptr>& output_sprites) const
Generates text sprites for the given single line of text.
template<int MaxSprites>
auto generate_top_left(fixed top_left_x, fixed top_left_y, const string_view& text) const -> vector<sprite_ptr, MaxSprites>
Generates text sprites for the given single line of text.
template<int MaxSprites>
auto generate_top_left(const fixed_point& top_left_position, const string_view& text) const -> vector<sprite_ptr, MaxSprites>
Generates text sprites for the given single line of text.
void generate_top_left(fixed top_left_x, fixed top_left_y, const string_view& text, ivector<sprite_ptr>& output_sprites) const
Generates text sprites for the given single line of text.
void generate_top_left(const fixed_point& top_left_position, const string_view& text, ivector<sprite_ptr>& output_sprites) const
Generates text sprites for the given single line of text.
auto generate_optional(const string_view& text, ivector<sprite_ptr>& output_sprites) const -> bool
Generates text sprites for the given single line of text.
auto generate_optional(fixed x, fixed y, const string_view& text, ivector<sprite_ptr>& output_sprites) const -> bool
Generates text sprites for the given single line of text.
auto generate_optional(const fixed_point& position, const string_view& text, ivector<sprite_ptr>& output_sprites) const -> bool
Generates text sprites for the given single line of text.
auto generate_top_left_optional(fixed top_left_x, fixed top_left_y, const string_view& text, ivector<sprite_ptr>& output_sprites) const -> bool
Generates text sprites for the given single line of text.
auto generate_top_left_optional(const fixed_point& top_left_position, const string_view& text, ivector<sprite_ptr>& output_sprites) const -> bool
Generates text sprites for the given single line of text.

Enum documentation

enum class bn::sprite_text_generator::alignment_type: uint8_t

Available horizontal alignment types.

Enumerators
LEFT

Aligns with the left text edge.

CENTER

Aligns with the middle of the text.

RIGHT

Aligns with the right text edge.

Function documentation

bn::sprite_text_generator::sprite_text_generator(const sprite_font& font) explicit

Constructor.

Parameters
font Sprite font for drawing text.

bn::sprite_text_generator::sprite_text_generator(const sprite_font& font, const sprite_palette_item& palette_item)

Constructor.

Parameters
font Sprite font for drawing text.
palette_item 16 colors (4 bits per pixel) sprite_palette_item that generates the color palette used by the text sprites.

int bn::sprite_text_generator::bg_priority() const

Returns the priority of the output sprites priority relative to backgrounds.

Sprites with higher priority are drawn first (and therefore can be covered by later sprites and backgrounds). Sprites cover backgrounds of the same priority.

void bn::sprite_text_generator::set_bg_priority(int bg_priority)

Sets the priority of the output sprites relative to backgrounds.

Parameters
bg_priority Priority relative to backgrounds in the range [0..3].

Sprites with higher priority are drawn first (and therefore can be covered by later sprites and backgrounds). Sprites cover backgrounds of the same priority.

int bn::sprite_text_generator::z_order() const

Returns the priority of the output sprites relative to other sprites.

Sprites with higher z orders are drawn first (and therefore can be covered by later sprites).

void bn::sprite_text_generator::set_z_order(int z_order)

Sets the priority of the output sprites relative to other sprites.

Parameters
z_order Priority relative to other sprites in the range [-32767..32767].

Sprites with higher z orders are drawn first (and therefore can be covered by later sprites).

template<int MaxSprites>
vector<sprite_ptr, MaxSprites> bn::sprite_text_generator::generate(const string_view& text) const

Generates text sprites for the given single line of text.

Template parameters
MaxSprites Maximum size of the returned sprite_ptr vector.
Parameters
text Single line of text to print.
Returns sprite_ptr vector containing the generated text sprites.

template<int MaxSprites>
vector<sprite_ptr, MaxSprites> bn::sprite_text_generator::generate(fixed x, fixed y, const string_view& text) const

Generates text sprites for the given single line of text.

Template parameters
MaxSprites Maximum size of the returned sprite_ptr vector.
Parameters
x Horizontal position of the first generated sprite, considering the current alignment.
y Vertical position of the first generated sprite, considering the current alignment.
text Single line of text to print.
Returns sprite_ptr vector containing the generated text sprites.

template<int MaxSprites>
vector<sprite_ptr, MaxSprites> bn::sprite_text_generator::generate(const fixed_point& position, const string_view& text) const

Generates text sprites for the given single line of text.

Template parameters
MaxSprites Maximum size of the returned sprite_ptr vector.
Parameters
position Position of the first generated sprite, considering the current alignment.
text Single line of text to print.
Returns sprite_ptr vector containing the generated text sprites.

void bn::sprite_text_generator::generate(const string_view& text, ivector<sprite_ptr>& output_sprites) const

Generates text sprites for the given single line of text.

Parameters
text Single line of text to print.
output_sprites Generated text sprites are stored in this vector.

Keep in mind that this vector is not cleared before generating text.

void bn::sprite_text_generator::generate(fixed x, fixed y, const string_view& text, ivector<sprite_ptr>& output_sprites) const

Generates text sprites for the given single line of text.

Parameters
x Horizontal position of the first generated sprite, considering the current alignment.
y Vertical position of the first generated sprite, considering the current alignment.
text Single line of text to print.
output_sprites Generated text sprites are stored in this vector.

Keep in mind that this vector is not cleared before generating text.

void bn::sprite_text_generator::generate(const fixed_point& position, const string_view& text, ivector<sprite_ptr>& output_sprites) const

Generates text sprites for the given single line of text.

Parameters
position Position of the first generated sprite, considering the current alignment.
text Single line of text to print.
output_sprites Generated text sprites are stored in this vector.

Keep in mind that this vector is not cleared before generating text.

template<int MaxSprites>
vector<sprite_ptr, MaxSprites> bn::sprite_text_generator::generate_top_left(fixed top_left_x, fixed top_left_y, const string_view& text) const

Generates text sprites for the given single line of text.

Template parameters
MaxSprites Maximum size of the returned sprite_ptr vector.
Parameters
top_left_x Horizontal top-left position of the first generated sprite, considering the current alignment.
top_left_y Vertical top-left position of the first generated sprite, considering the current alignment.
text Single line of text to print.
Returns sprite_ptr vector containing the generated text sprites.

template<int MaxSprites>
vector<sprite_ptr, MaxSprites> bn::sprite_text_generator::generate_top_left(const fixed_point& top_left_position, const string_view& text) const

Generates text sprites for the given single line of text.

Template parameters
MaxSprites Maximum size of the returned sprite_ptr vector.
Parameters
top_left_position Top-left position of the first generated sprite, considering the current alignment.
text Single line of text to print.
Returns sprite_ptr vector containing the generated text sprites.

void bn::sprite_text_generator::generate_top_left(fixed top_left_x, fixed top_left_y, const string_view& text, ivector<sprite_ptr>& output_sprites) const

Generates text sprites for the given single line of text.

Parameters
top_left_x Horizontal top-left position of the first generated sprite, considering the current alignment.
top_left_y Vertical top-left position of the first generated sprite, considering the current alignment.
text Single line of text to print.
output_sprites Generated text sprites are stored in this vector.

Keep in mind that this vector is not cleared before generating text.

void bn::sprite_text_generator::generate_top_left(const fixed_point& top_left_position, const string_view& text, ivector<sprite_ptr>& output_sprites) const

Generates text sprites for the given single line of text.

Parameters
top_left_position Top-left position of the first generated sprite, considering the current alignment.
text Single line of text to print.
output_sprites Generated text sprites are stored in this vector.

Keep in mind that this vector is not cleared before generating text.

bool bn::sprite_text_generator::generate_optional(const string_view& text, ivector<sprite_ptr>& output_sprites) const

Generates text sprites for the given single line of text.

Parameters
text Single line of text to print.
output_sprites Generated text sprites are stored in this vector.
Returns true if the text generation finished successfully, otherwise false.

Keep in mind that this vector is not cleared before generating text.

bool bn::sprite_text_generator::generate_optional(fixed x, fixed y, const string_view& text, ivector<sprite_ptr>& output_sprites) const

Generates text sprites for the given single line of text.

Parameters
x Horizontal position of the first generated sprite, considering the current alignment.
y Vertical position of the first generated sprite, considering the current alignment.
text Single line of text to print.
output_sprites Generated text sprites are stored in this vector.
Returns true if the text generation finished successfully, otherwise false.

Keep in mind that this vector is not cleared before generating text.

bool bn::sprite_text_generator::generate_optional(const fixed_point& position, const string_view& text, ivector<sprite_ptr>& output_sprites) const

Generates text sprites for the given single line of text.

Parameters
position Position of the first generated sprite, considering the current alignment.
text Single line of text to print.
output_sprites Generated text sprites are stored in this vector.
Returns true if the text generation finished successfully, otherwise false.

Keep in mind that this vector is not cleared before generating text.

bool bn::sprite_text_generator::generate_top_left_optional(fixed top_left_x, fixed top_left_y, const string_view& text, ivector<sprite_ptr>& output_sprites) const

Generates text sprites for the given single line of text.

Parameters
top_left_x Horizontal top-left position of the first generated sprite, considering the current alignment.
top_left_y Vertical top-left position of the first generated sprite, considering the current alignment.
text Single line of text to print.
output_sprites Generated text sprites are stored in this vector.

Keep in mind that this vector is not cleared before generating text.

bool bn::sprite_text_generator::generate_top_left_optional(const fixed_point& top_left_position, const string_view& text, ivector<sprite_ptr>& output_sprites) const

Generates text sprites for the given single line of text.

Parameters
top_left_position Top-left position of the first generated sprite, considering the current alignment.
text Single line of text to print.
output_sprites Generated text sprites are stored in this vector.
Returns true if the text generation finished successfully, otherwise false.

Keep in mind that this vector is not cleared before generating text.