lxgui
Loading...
Searching...
No Matches
gui_sdl_font.hpp
1#ifndef LXGUI_GUI_SDL_FONT_HPP
2#define LXGUI_GUI_SDL_FONT_HPP
3
4#include "lxgui/gui_font.hpp"
5#include "lxgui/impl/gui_sdl_material.hpp"
6#include "lxgui/utils.hpp"
7
8#include <vector>
9
10struct SDL_Renderer;
11
12namespace lxgui::gui::sdl {
13
19class font final : public gui::font {
20public:
33 SDL_Renderer* rdr,
34 const std::string& font_file,
35 std::size_t size,
36 std::size_t outline,
37 const std::vector<code_point_range>& code_points,
38 char32_t default_code_point,
39 bool pre_multiplied_alpha_supported);
40
45 std::size_t get_size() const override;
46
54 bounds2f get_character_uvs(char32_t c) const override;
55
61 bounds2f get_character_bounds(char32_t c) const override;
62
68 float get_character_width(char32_t c) const override;
69
75 float get_character_height(char32_t c) const override;
76
87 float get_character_kerning(char32_t c1, char32_t c2) const override;
88
93 std::weak_ptr<gui::material> get_texture() const override;
94
99 void update_texture(std::shared_ptr<gui::material> mat) override;
100
101private:
102 struct character_info {
103 char32_t code_point = 0;
104 bounds2f uvs;
105 bounds2f rect;
106 float advance = 0.0f;
107 };
108
109 struct range_info {
110 code_point_range range;
111 std::vector<character_info> data;
112 };
113
114 const character_info* get_character_(char32_t c) const;
115
116 std::size_t size_ = 0u;
117 char32_t default_code_point_ = 0u;
118
119 std::shared_ptr<sdl::material> texture_;
120 std::vector<range_info> range_list_;
121};
122
123} // namespace lxgui::gui::sdl
124
125#endif
A texture containing characters.
Definition gui_font.hpp:22
A texture containing characters This is the SDL implementation of the gui::font. It uses SDL_ttf to r...
font(SDL_Renderer *rdr, const std::string &font_file, std::size_t size, std::size_t outline, const std::vector< code_point_range > &code_points, char32_t default_code_point, bool pre_multiplied_alpha_supported)
Constructor.
void update_texture(std::shared_ptr< gui::material > mat) override
Update the material to use for rendering.
std::weak_ptr< gui::material > get_texture() const override
Returns the underlying material to use for rendering.
float get_character_height(char32_t c) const override
Returns the height of a character in pixels.
float get_character_kerning(char32_t c1, char32_t c2) const override
Return the kerning amount between two characters.
float get_character_width(char32_t c) const override
Returns the width of a character in pixels.
bounds2f get_character_uvs(char32_t c) const override
Returns the uv coordinates of a character on the texture.
bounds2f get_character_bounds(char32_t c) const override
Returns the rect coordinates of a character as it should be drawn relative to the baseline.
std::size_t get_size() const override
Get the size of the font in pixels.
Represents a contiguous range of unicode code points.