diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-11 18:21:03 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-11 18:21:03 +0100 |
commit | 007fe1ecb5e9f76539cdffd6a96afe22c8b2d214 (patch) | |
tree | e3a3fc0984b77e0632a7e869f66553edceebedfc /src/crepe/facade/Font.cpp | |
parent | c585731ab4557e2a03be9630a54295a3700103fc (diff) |
save
Diffstat (limited to 'src/crepe/facade/Font.cpp')
-rw-r--r-- | src/crepe/facade/Font.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/crepe/facade/Font.cpp b/src/crepe/facade/Font.cpp new file mode 100644 index 0000000..2ad176a --- /dev/null +++ b/src/crepe/facade/Font.cpp @@ -0,0 +1,24 @@ +#include "font.h" +#include "../api/Config.h" +using namespace std; +using namespace crepe; + +void Font::load(unique_ptr<Asset> res){ + const char* font_path = res->get_path(); + int font_size = Config::get_instance().font.font_size; + this->font = std::unique_ptr<TTF_Font, decltype(&TTF_CloseFont)>( + TTF_OpenFont(font_path, font_size), &TTF_CloseFont); + + if (!font) { + throw std::runtime_error("Failed to load font: " + std::string(TTF_GetError())); + } +} +Font::Font(const char* src){ + this->load(make_unique<Asset>(src)); +} +Font::Font(std::unique_ptr<Asset> res){ + this->load(std::move(res)); +} +const TTF_Font& Font::get_font() const{ + return this->font; +} |