aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade/Font.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-12 21:09:55 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-12 21:09:55 +0100
commit3ed4e51e23b5093a44a166b2f11ff66164e5cff1 (patch)
tree75a8eaadc2e21759936d2c716594cb9c4d23714c /src/crepe/facade/Font.cpp
parent431d7cceb25db86f31a8c89440f3cdd2c7bf061f (diff)
font working
Diffstat (limited to 'src/crepe/facade/Font.cpp')
-rw-r--r--src/crepe/facade/Font.cpp31
1 files changed, 14 insertions, 17 deletions
diff --git a/src/crepe/facade/Font.cpp b/src/crepe/facade/Font.cpp
index 66835ee..37dee3a 100644
--- a/src/crepe/facade/Font.cpp
+++ b/src/crepe/facade/Font.cpp
@@ -1,28 +1,25 @@
#include "../api/Config.h"
-#include "font.h"
+#include "Font.h"
using namespace std;
using namespace crepe;
-void Font::load(unique_ptr<Asset> res){
- const char* font_path = res->get_path();
- this->font = std::unique_ptr<TTF_Font, decltype(&TTF_CloseFont)>(
- TTF_OpenFont(font_path, this->default_font_size), &TTF_CloseFont);
+Font::Font(const Asset& src, Mediator& mediator)
+ : Resource(src, mediator), font(nullptr, TTF_CloseFont) {
+ // Get the font file path from the Asset
+ const std::string font_path = src.get_path();
- if (!font) {
- throw std::runtime_error("Failed to load font: " + std::string(TTF_GetError()));
- }
-}
+ // Attempt to load the font
+ this->font.reset(TTF_OpenFont(font_path.c_str(), Config::get_instance().font.size));
-Font::Font(const char* src){
- this->load(make_unique<Asset>(src));
-}
-
-Font::Font(std::unique_ptr<Asset> res){
- this->load(std::move(res));
+ // Check if font loading failed
+ if (!this->font) {
+ throw runtime_error(format("Failed to load font from path: {}"
+ ". SDL_ttf error: {}",font_path, TTF_GetError()));
+ }
}
-TTF_Font* Font::get_font() const{
- return this->font.get();
+TTF_Font* Font::get_font() const {
+ return this->font.get();
}