aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade/Font.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-18 13:26:04 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-18 13:26:04 +0100
commita444da0b35123a9e51cde1f5be9aab0204eb5b66 (patch)
treecb3c02bbd94b2750c57c4579de5f7f8def05f324 /src/crepe/facade/Font.cpp
parentf71769f7d2e9530a49295d0c0c86c2f6add069d8 (diff)
parent81404db80bbf9463c3d535ae389e7fbb753a902c (diff)
merge master
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(); }