From 007fe1ecb5e9f76539cdffd6a96afe22c8b2d214 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Wed, 11 Dec 2024 18:21:03 +0100 Subject: save --- src/crepe/facade/Font.cpp | 24 ++++++++++++++++++++++++ src/crepe/facade/Font.h | 33 +++++++++++++++++++++++++++++++++ src/crepe/facade/font.cpp | 21 --------------------- src/crepe/facade/font.h | 31 ------------------------------- 4 files changed, 57 insertions(+), 52 deletions(-) create mode 100644 src/crepe/facade/Font.cpp create mode 100644 src/crepe/facade/Font.h delete mode 100644 src/crepe/facade/font.cpp delete mode 100644 src/crepe/facade/font.h 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 res){ + const char* font_path = res->get_path(); + int font_size = Config::get_instance().font.font_size; + this->font = std::unique_ptr( + 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(src)); +} +Font::Font(std::unique_ptr res){ + this->load(std::move(res)); +} +const TTF_Font& Font::get_font() const{ + return this->font; +} diff --git a/src/crepe/facade/Font.h b/src/crepe/facade/Font.h new file mode 100644 index 0000000..e34ac63 --- /dev/null +++ b/src/crepe/facade/Font.h @@ -0,0 +1,33 @@ +#pragma once + +#include +#include + +#include "../api/Asset.h" +#include "../api/Config.h" + +namespace crepe { + +/** + * \brief Font resource facade + * + * This class is a wrapper around an SDL_ttf font instance, encapsulating font loading and usage. + */ +class Font : public Resource{ +public: + /**. + * \param src Asset with texture data to load. + * \param mediator use the SDLContext reference to load the image + */ + Font(const Asset & src, Mediator & mediator); + + + ~Font() = default + const TTF_Font& get_font() const; +private: + //! The SDL_ttf font object with custom deleter. + std::unique_ptr font; + int default_font_size = Config::get_instance().font.font_size; +}; + +} // namespace crepe diff --git a/src/crepe/facade/font.cpp b/src/crepe/facade/font.cpp deleted file mode 100644 index 259a6cd..0000000 --- a/src/crepe/facade/font.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "font.h" -#include "../api/Config.h" -using namespace std; -using namespace crepe; - -void Font::load(unique_ptr res){ - const char* font_path = res->get_path(); - int font_size = Config::get_instance().font.font_size; - this->font = std::unique_ptr( - 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(src)); -} -Font::Font(std::unique_ptr res){ - this->load(std::move(res)); -} diff --git a/src/crepe/facade/font.h b/src/crepe/facade/font.h deleted file mode 100644 index a8d8040..0000000 --- a/src/crepe/facade/font.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include -#include - -#include "../api/Asset.h" - -namespace crepe { - -/** - * \brief Font resource facade - * - * This class is a wrapper around an SDL_ttf font instance, encapsulating font loading and usage. - */ -class Font : public Resource{ -public: - /** - * \param res A unique pointer to an Asset holding the font resource. - */ - Font(const Asset & src, Mediator & mediator); - - /** - * \brief Destructor to clean up font resources. - */ - ~Font() = default; -private: - //! The SDL_ttf font object with custom deleter. - std::unique_ptr font; -}; - -} // namespace crepe -- cgit v1.2.3