Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
font_atlas.h
1#ifndef OE_GUI_FONT_ATLAS_H
2#define OE_GUI_FONT_ATLAS_H
3
4#include <string>
5#include <vector>
6#include <memory>
7#include <glm/vec2.hpp>
8
9namespace oe::render
10{
11 class Texture;
12}
13
14struct nk_font;
15struct nk_font_atlas;
16struct nk_draw_null_texture;
17
18namespace oe::gui
19{
28 {
29 public:
30 FontAtlas();
31
32 ~FontAtlas();
33
40 void generate();
41
51 FontAtlas* addFile(const std::string& font_name, const std::string& font_file, const float& size);
52
56 bool isValid() const
57 {
58 return _tex != nullptr;
59 }
60
67 size_t getIdFromName(const std::string& font_id) const;
68
72 nk_font* getHandle(const size_t& font_id) const
73 {
74 return std::get<2>(_font_conf.at(font_id).second);
75 }
76
80 nk_font* getHandle(const std::string& font_id) const;
81
82 nk_font* getDefaultFont()
83 {
84 return _default_font;
85 }
86
87 const std::unique_ptr<oe::render::Texture>& getTexture()
88 {
89 return _tex;
90 }
91
95 glm::vec2 white_pixel_uv = glm::vec2(0.f);
96
97 private:
98 std::vector<std::pair<std::string, std::tuple<std::string, float, nk_font*>>> _font_conf;
99
100 std::unique_ptr<oe::render::Texture> _tex;
101 std::unique_ptr<nk_font_atlas> _atlas;
102
103 nk_font* _default_font = nullptr;
104 };
105}
106#endif
Handle and bake font atlas for using in the GUI.
Definition font_atlas.h:28
FontAtlas * addFile(const std::string &font_name, const std::string &font_file, const float &size)
Add a font from a file.
glm::vec2 white_pixel_uv
uv coordinates of a white pixel in the texture
Definition font_atlas.h:95
bool isValid() const
Check if the font atlas is ready to use.
Definition font_atlas.h:56
size_t getIdFromName(const std::string &font_id) const
Get a font name from the list when you know its id.
nk_font * getHandle(const size_t &font_id) const
Get a font handle when you know its id.
Definition font_atlas.h:72
nk_font * getHandle(const std::string &font_id) const
Get a font handle from the custom font name.
void generate()
Generate the atlas.
Graphical user interface (panels, buttons, text input, ...)
Definition component.h:13
Render related abstractions (Shader, Framebuffer, Cubemaps, Textures)
Definition opengl.h:10