Small RAII wrapper for an SDL_ttf font handle.
More...
#include <mxvk/include/mxvk/mxvk_text.hpp>
Small RAII wrapper for an SDL_ttf font handle.
This is optional convenience for APIs that accept a font object. Existing code can continue using VK_Text::setFont() and printText() unchanged.
Definition at line 46 of file mxvk_text.hpp.
◆ Font() [1/4]
◆ Font() [2/4]
| mxvk::Font::Font |
( |
const std::string & | fontPath, |
|
|
int | fontSize ) |
◆ ~Font()
◆ Font() [3/4]
| mxvk::Font::Font |
( |
const Font & | | ) |
|
|
delete |
◆ Font() [4/4]
| mxvk::Font::Font |
( |
Font && | other | ) |
|
|
noexcept |
Definition at line 14 of file mxvk_text.cpp.
14: font(std::exchange(other.font, nullptr)), font_path(std::move(other.font_path)), font_size(std::exchange(other.font_size, 0)), ownsTtfInit(std::exchange(other.ownsTtfInit, false)) {}
◆ get()
| TTF_Font * mxvk::Font::get |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
◆ operator bool()
| mxvk::Font::operator bool |
( |
| ) |
const |
|
inlineexplicitnodiscardnoexcept |
◆ operator=() [1/2]
| Font & mxvk::Font::operator= |
( |
const Font & | | ) |
|
|
delete |
◆ operator=() [2/2]
| Font & mxvk::Font::operator= |
( |
Font && | other | ) |
|
|
noexcept |
Definition at line 16 of file mxvk_text.cpp.
16 {
17 if (this != &other) {
19 font = std::exchange(other.font, nullptr);
20 font_path = std::move(other.font_path);
21 font_size = std::exchange(other.font_size, 0);
22 ownsTtfInit = std::exchange(other.ownsTtfInit, false);
23 }
24 return *this;
25 }
◆ path()
| const std::string & mxvk::Font::path |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
◆ reset() [1/2]
| void mxvk::Font::reset |
( |
| ) |
|
Definition at line 27 of file mxvk_text.cpp.
27 {
28 if (font != nullptr) {
29 TTF_CloseFont(font);
30 font = nullptr;
31 }
32 font_path.clear();
33 font_size = 0;
34 if (ownsTtfInit) {
35 TTF_Quit();
36 ownsTtfInit = false;
37 }
38 }
◆ reset() [2/2]
| void mxvk::Font::reset |
( |
const std::string & | fontPath, |
|
|
int | fontSize ) |
Definition at line 40 of file mxvk_text.cpp.
40 {
41 if (fontPath.empty() || fontSize <= 0) {
42 throw mxvk::Exception("Font requires a non-empty path and positive font size");
43 }
44
46
47 if (!TTF_Init()) {
48 throw mxvk::Exception("Failed to initialize SDL_ttf: " + std::string(SDL_GetError()));
49 }
50
51 TTF_Font *newFont = TTF_OpenFont(fontPath.c_str(), fontSize);
52 if (newFont == nullptr) {
53 TTF_Quit();
54 throw mxvk::Exception("Failed to load font: " + std::string(SDL_GetError()));
55 }
56
57 font = newFont;
58 font_path = fontPath;
59 font_size = fontSize;
60 ownsTtfInit = true;
61 }
◆ size()
| int mxvk::Font::size |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
The documentation for this class was generated from the following files: