aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade/Font.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-17 19:16:25 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-17 19:16:25 +0100
commitb421eec1073c1fb4b99d46cc36c5c9cbd8d3c4a7 (patch)
tree461e290e0c2c3adf588f02d24031edc7f8114390 /src/crepe/facade/Font.cpp
parentc4c896c2995f2b74fca322736aa944b28b14a1f6 (diff)
parenta8ccf7fe8662086bb223aa4eafd0f85e717d16cf (diff)
Merge branch 'master' of https://github.com/lonkaars/crepe into wouter/button-improvement
Diffstat (limited to 'src/crepe/facade/Font.cpp')
-rw-r--r--src/crepe/facade/Font.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/crepe/facade/Font.cpp b/src/crepe/facade/Font.cpp
new file mode 100644
index 0000000..771002f
--- /dev/null
+++ b/src/crepe/facade/Font.cpp
@@ -0,0 +1,21 @@
+#include <SDL2/SDL_ttf.h>
+
+#include "../api/Asset.h"
+#include "../api/Config.h"
+
+#include "Font.h"
+
+using namespace std;
+using namespace crepe;
+
+Font::Font(const Asset & src, Mediator & mediator) : Resource(src, mediator) {
+ const Config & config = Config::get_instance();
+ const std::string FONT_PATH = src.get_path();
+ TTF_Font * loaded_font = TTF_OpenFont(FONT_PATH.c_str(), config.font.size);
+ if (loaded_font == NULL) {
+ throw runtime_error(format("Font: {} (path: {})", TTF_GetError(), FONT_PATH));
+ }
+ this->font = {loaded_font, [](TTF_Font * close_font) { TTF_CloseFont(close_font); }};
+}
+
+TTF_Font * Font::get_font() const { return this->font.get(); }