diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-12 21:16:19 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-12 21:16:19 +0100 |
commit | 054b1ebea645bb8916f87e0d8f0f85d59e998eaf (patch) | |
tree | 8d49a3e516010dfe8faf8e0f457df58cba8344a9 /src/crepe | |
parent | 3ed4e51e23b5093a44a166b2f11ff66164e5cff1 (diff) |
font facade added to SDLContext
Diffstat (limited to 'src/crepe')
-rw-r--r-- | src/crepe/api/Text.h | 6 | ||||
-rw-r--r-- | src/crepe/facade/Font.h | 31 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.h | 5 |
3 files changed, 26 insertions, 16 deletions
diff --git a/src/crepe/api/Text.h b/src/crepe/api/Text.h index 51bab98..8436611 100644 --- a/src/crepe/api/Text.h +++ b/src/crepe/api/Text.h @@ -20,8 +20,6 @@ public: Text(game_object_id_t id,const vec2 & dimensions, const vec2 & offset,std::string text,std::string font_family); //! Text data that does not have to be set in the constructor struct Data { - //! Label text color. - Color text_color = Color::BLACK; /** * \brief fontsize for text rendering * @@ -32,11 +30,15 @@ public: * Instead this value is used to upscale the font texture which can cause blurring or distorted text when upscaling or downscaling too much. */ unsigned int font_size = 16; + //! Layer sorting level of the text const int sorting_in_layer = 0; //! Order within the sorting text const int order_in_layer = 0; + + //! Label text color. + Color text_color = Color::BLACK; }; public: //! font family name such as (Arial,Helvetica,Inter) diff --git a/src/crepe/facade/Font.h b/src/crepe/facade/Font.h index a27676b..fbc1b8f 100644 --- a/src/crepe/facade/Font.h +++ b/src/crepe/facade/Font.h @@ -1,35 +1,40 @@ #pragma once - -#include <memory> #include <SDL2/SDL_ttf.h> +#include <memory> #include "../api/Asset.h" #include "../api/Config.h" #include "../Resource.h" + namespace crepe { /** * \brief Resource for managing font creation and destruction * * This class is a wrapper around an SDL_ttf font instance, encapsulating font loading and usage. + * It loads a font from an Asset and manages its lifecycle. The font is automatically unloaded + * when this object is destroyed. */ class Font : public Resource{ public: /** - * \param src Asset with font data to load. - * \param mediator use the SDLContext reference to get_font() - */ + * \param src The Asset containing the font file path and metadata to load the font. + * \param mediator The Mediator object used for managing the SDL context or related systems. + */ Font(const Asset & src, Mediator & mediator); - /** - * \brief getter for TTF_Font - * - * \param src Asset with font data to load. - * \param mediator use the SDLContext reference to get_font() - */ - TTF_Font* get_font() const; + /** + * \brief Gets the underlying TTF_Font resource. + * + * This function returns the raw pointer to the SDL_ttf TTF_Font object that represents + * the loaded font. This can be used with SDL_ttf functions to render text. + * + * \return The raw TTF_Font object wrapped in a unique pointer. + */ + TTF_Font* get_font() const; + private: - //! The SDL_ttf font object with custom deleter. + //! The SDL_ttf font object with custom deleter. std::unique_ptr<TTF_Font, decltype(&TTF_CloseFont)> font; }; diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 6b725e3..bbbb542 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -16,9 +16,10 @@ #include "api/KeyCodes.h" #include "api/Sprite.h" #include "api/Transform.h" - #include "types.h" +#include "SDLFontContext.h" + namespace crepe { class Texture; @@ -226,6 +227,7 @@ public: void set_color_texture(const Texture & texture, const Color & color); private: + //! sdl Window std::unique_ptr<SDL_Window, std::function<void(SDL_Window *)>> game_window; @@ -234,6 +236,7 @@ private: //! black bars rectangle to draw SDL_FRect black_bars[2] = {}; + SDLFontContext font_facade{}; }; } // namespace crepe |