|
Aegis2D
Modular C++26 2D game engine for networked games
|
Monospaced font whose glyphs are cells of a texture, drawn as sprites. More...
#include <aegis2d/render/bitmap_font.hpp>
Public Member Functions | |
| BitmapFont (TextureId atlas, const GlyphGrid &grid) | |
Uses an atlas texture laid out as grid. | |
| TextureId | texture () const noexcept |
| Texture of the atlas. | |
| const GlyphGrid & | grid () const noexcept |
| Layout of the atlas. | |
| float | line_height (float scale=1.0F) const noexcept |
| Distance between two lines. | |
| Vec2 | measure (std::string_view text, float scale=1.0F) const noexcept |
| Size a text takes on screen. | |
| std::string | wrap (std::string_view text, float width, float scale=1.0F) const |
| Breaks a text into lines that fit a width. | |
| void | draw (IRenderer &renderer, std::string_view text, Vec2 position, const TextStyle &style={}) const |
| Draws a text, one sprite per visible character. | |
Static Public Member Functions | |
| static BitmapFont | builtin (TextureManager &textures) |
| The engine's built-in font: printable ASCII, 5 x 8 pixel glyphs (descenders included), 6 pixels apart, lines 10 pixels apart. | |
| static Image | builtin_image () |
| Atlas image of the built-in font. | |
| static GlyphGrid | builtin_grid () noexcept |
| Layout of the built-in font's atlas. | |
Monospaced font whose glyphs are cells of a texture, drawn as sprites.
Each character is one sprite of the atlas texture, so a whole text, and every text of the same font and layer, is drawn in one call by the batcher. \n starts a new line; characters the font does not have, including each non-ASCII UTF-8 character, are drawn as GlyphGrid::fallback; other control characters are skipped.
Uses an atlas texture laid out as grid.
| atlas | Texture of the atlas. |
| grid | Layout of the atlas. |
| std::invalid_argument | if a size of grid is not positive, a glyph is larger than its cell, the cells do not fit the atlas, or fallback is not in the font. |
|
static |
The engine's built-in font: printable ASCII, 5 x 8 pixel glyphs (descenders included), 6 pixels apart, lines 10 pixels apart.
The atlas is added to textures as "aegis2d.font" the first time, and reused afterwards.
| textures | Textures of the game. |
|
staticnoexcept |
Layout of the built-in font's atlas.
|
static |
Atlas image of the built-in font.
| void aegis2d::render::BitmapFont::draw | ( | IRenderer & | renderer, |
| std::string_view | text, | ||
| Vec2 | position, | ||
| const TextStyle & | style = {} |
||
| ) | const |
Draws a text, one sprite per visible character.
| renderer | Renderer in a frame. |
| text | UTF-8 text, lines separated by \n. |
| position | Top-left corner of the first character, in logical pixels. |
| style | Scale, color and layer of the text. |
| std::logic_error | outside a frame (as IRenderer::draw()). |
|
noexcept |
Layout of the atlas.
|
noexcept |
Distance between two lines.
| scale | Scale of the text (TextStyle::scale). |
line_height * scale, in logical pixels.
|
noexcept |
Size a text takes on screen.
| text | UTF-8 text, lines separated by \n. |
| scale | Scale of the text (TextStyle::scale). |
|
noexcept |
Texture of the atlas.
| std::string aegis2d::render::BitmapFont::wrap | ( | std::string_view | text, |
| float | width, | ||
| float | scale = 1.0F |
||
| ) | const |
Breaks a text into lines that fit a width.
Lines break at spaces; a word longer than a line is cut. Existing line breaks are kept, and the spaces where a line breaks are dropped.
| text | UTF-8 text. |
| width | Largest width of a line, in logical pixels. |
| scale | Scale of the text (TextStyle::scale). |
text with line breaks, so that measure() of each line is at most width (at least one character per line, even if it is wider).