diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-12-17 09:09:32 +0100 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-12-17 09:09:32 +0100 |
commit | bfc07676707eae2c0161c6b86ccdd1583d96f71b (patch) | |
tree | b18bd17b0d07b3b51b2461462e3380d36905e61f /src/crepe/facade | |
parent | 2f8d36a33854715828d412792663f355b9e393ae (diff) | |
parent | d63eb7302d05fbe9b4c044ece3444e8ac4e56e02 (diff) |
Merge branch 'wouter/text-component' into niels/UI
Diffstat (limited to 'src/crepe/facade')
-rw-r--r-- | src/crepe/facade/Font.cpp | 16 | ||||
-rw-r--r-- | src/crepe/facade/Font.h | 4 | ||||
-rw-r--r-- | src/crepe/facade/FontFacade.cpp | 3 |
3 files changed, 10 insertions, 13 deletions
diff --git a/src/crepe/facade/Font.cpp b/src/crepe/facade/Font.cpp index a9f1633..8c16563 100644 --- a/src/crepe/facade/Font.cpp +++ b/src/crepe/facade/Font.cpp @@ -1,3 +1,4 @@ +#include "../api/Asset.h" #include "../api/Config.h" #include "util/Log.h" #include <iostream> @@ -11,17 +12,12 @@ Font::Font(const Asset & src, Mediator & mediator) : Resource(src, mediator) { dbg_trace(); Config & config = Config::get_instance(); - const std::string & FONT_PATH = src.get_path(); - cout << FONT_PATH.c_str() << endl; - TTF_Font * font = TTF_OpenFont(FONT_PATH.c_str(), config.font.size); - if (font == NULL) + 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 = {font, [](TTF_Font * font) { TTF_CloseFont(font); }}; -} - -Font::~Font(){ - dbg_trace(); - this->font.reset(); + } + this->font = {loaded_font, [](TTF_Font * font) { TTF_CloseFont(font); }}; } TTF_Font * Font::get_font() const { return this->font.get(); } diff --git a/src/crepe/facade/Font.h b/src/crepe/facade/Font.h index e9f5fa1..91c59c0 100644 --- a/src/crepe/facade/Font.h +++ b/src/crepe/facade/Font.h @@ -1,13 +1,14 @@ #pragma once + #include <SDL2/SDL_ttf.h> #include <memory> #include "../Resource.h" -#include "../api/Asset.h" #include "../api/Config.h" namespace crepe { +class Asset; /** * \brief Resource for managing font creation and destruction * @@ -16,6 +17,7 @@ namespace crepe { * when this object is destroyed. */ class Font : public Resource { + public: /** * \param src The Asset containing the font file path and metadata to load the font. diff --git a/src/crepe/facade/FontFacade.cpp b/src/crepe/facade/FontFacade.cpp index 708b2ff..aa9d00c 100644 --- a/src/crepe/facade/FontFacade.cpp +++ b/src/crepe/facade/FontFacade.cpp @@ -1,4 +1,3 @@ -#include <SDL2/SDL_ttf.h> #include <fontconfig/fontconfig.h> #include <stdexcept> @@ -43,7 +42,7 @@ Asset FontFacade::get_font_asset(const string font_family) { } // Convert the file path to a string - string font_file_path(reinterpret_cast<const char *>(file_path)); + string font_file_path = reinterpret_cast<const char *>(file_path); FcPatternDestroy(matched_pattern); FcFini(); return Asset(font_file_path); |