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 18 of file mxvk_text.cpp.
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)) {}
◆ 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 24 of file mxvk_text.cpp.
24 {
25 if (this != &other) {
27 font = std::exchange(other.font, nullptr);
28 font_path = std::move(other.font_path);
29 font_size = std::exchange(other.font_size, 0);
30 ownsTtfInit = std::exchange(other.ownsTtfInit, false);
31 }
32 return *this;
33 }
◆ path()
| const std::string & mxvk::Font::path |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
◆ reset() [1/2]
| void mxvk::Font::reset |
( |
| ) |
|
Definition at line 35 of file mxvk_text.cpp.
35 {
36 if (font != nullptr) {
37 TTF_CloseFont(font);
38 font = nullptr;
39 }
40 font_path.clear();
41 font_size = 0;
42 if (ownsTtfInit) {
43 TTF_Quit();
44 ownsTtfInit = false;
45 }
46 }
◆ reset() [2/2]
| void mxvk::Font::reset |
( |
const std::string & | fontPath, |
|
|
int | fontSize ) |
Definition at line 48 of file mxvk_text.cpp.
48 {
49 if (fontPath.empty() || fontSize <= 0) {
50 throw mxvk::Exception("Font requires a non-empty path and positive font size");
51 }
52
54
55 if (!TTF_Init()) {
56 throw mxvk::Exception("Failed to initialize SDL_ttf: " + std::string(SDL_GetError()));
57 }
58
59 TTF_Font *newFont = TTF_OpenFont(fontPath.c_str(), fontSize);
60 if (newFont == nullptr) {
61 TTF_Quit();
62 throw mxvk::Exception("Failed to load font: " + std::string(SDL_GetError()));
63 }
64
65 font = newFont;
66 font_path = fontPath;
67 font_size = fontSize;
68 ownsTtfInit = true;
69 }
◆ size()
| int mxvk::Font::size |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
The documentation for this class was generated from the following files: