diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-18 13:26:04 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-18 13:26:04 +0100 |
commit | a444da0b35123a9e51cde1f5be9aab0204eb5b66 (patch) | |
tree | cb3c02bbd94b2750c57c4579de5f7f8def05f324 /src/crepe/api | |
parent | f71769f7d2e9530a49295d0c0c86c2f6add069d8 (diff) | |
parent | 81404db80bbf9463c3d535ae389e7fbb753a902c (diff) |
merge master
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/crepe/api/Config.h | 11 | ||||
-rw-r--r-- | src/crepe/api/Engine.h | 15 | ||||
-rw-r--r-- | src/crepe/api/Text.cpp | 12 | ||||
-rw-r--r-- | src/crepe/api/Text.h | 66 |
5 files changed, 100 insertions, 6 deletions
diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index 18d6942..2bee3fb 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -20,6 +20,7 @@ target_sources(crepe PUBLIC Button.cpp UIObject.cpp AI.cpp + Text.cpp Scene.cpp ) @@ -52,4 +53,5 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES Button.h UIObject.h AI.h + Text.h ) diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h index ed1cf38..6b9e3ca 100644 --- a/src/crepe/api/Config.h +++ b/src/crepe/api/Config.h @@ -76,6 +76,17 @@ struct Config final { */ std::string root_pattern = ".crepe-root"; } asset; + //! Default font options + struct { + /** + * \brief Default font size + * + * Using the SDL_ttf library the font size needs to be set when loading the font. + * This config option is the font size at which all fonts will be loaded initially. + * + */ + unsigned int size = 16; + } font; //! Configuration for click tolerance. struct { //! The maximum number of pixels the mouse can move between MouseDown and MouseUp events to be considered a click. diff --git a/src/crepe/api/Engine.h b/src/crepe/api/Engine.h index 3145723..700a0cd 100644 --- a/src/crepe/api/Engine.h +++ b/src/crepe/api/Engine.h @@ -53,6 +53,15 @@ private: //! Global context Mediator mediator; + //! SystemManager + SystemManager system_manager{mediator}; + + //! SDLContext instance + SDLContext sdl_context{mediator}; + + //! Resource manager instance + ResourceManager resource_manager{mediator}; + //! Component manager instance ComponentManager component_manager{mediator}; //! Scene manager instance @@ -61,16 +70,10 @@ private: LoopTimerManager loop_timer{mediator}; //! EventManager instance EventManager event_manager{mediator}; - //! Resource manager instance - ResourceManager resource_manager{mediator}; //! Save manager instance SaveManager save_manager{mediator}; - //! SDLContext instance - SDLContext sdl_context{mediator}; //! ReplayManager instance ReplayManager replay_manager{mediator}; - //! SystemManager - SystemManager system_manager{mediator}; }; } // namespace crepe diff --git a/src/crepe/api/Text.cpp b/src/crepe/api/Text.cpp new file mode 100644 index 0000000..54a4370 --- /dev/null +++ b/src/crepe/api/Text.cpp @@ -0,0 +1,12 @@ +#include "../facade/FontFacade.h" + +#include "Text.h" + +using namespace crepe; + +Text::Text(game_object_id_t id, const vec2 & dimensions, const vec2 & offset, + const std::string & font_family, const Data & data, const std::string & text) + : UIObject(id, dimensions, offset), + text(text), + data(data), + font_family(font_family) {} diff --git a/src/crepe/api/Text.h b/src/crepe/api/Text.h new file mode 100644 index 0000000..c30dc80 --- /dev/null +++ b/src/crepe/api/Text.h @@ -0,0 +1,66 @@ +#pragma once + +#include <optional> +#include <string> + +#include "../Component.h" + +#include "Asset.h" +#include "Color.h" +#include "UIObject.h" + +namespace crepe { +/** + * \brief Text UIObject component for displaying text + * + * This class can be used to display text on screen. By setting the font_family to a font already stored on the current device it will automatically be loaded in. + */ +class Text : public UIObject { +public: + //! Text data that does not have to be set in the constructor + struct Data { + /** + * \brief fontsize for text rendering + * + * \note this is not the actual font size that is loaded in. + * + * Since SDL_TTF requires the font size when loading in the font it is not possible to switch the font size. + * The default font size that is loaded is set in the Config. + * 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: + /** + * + * \param dimensions Width and height of the UIObject. + * \param offset Offset of the UIObject relative to its transform + * \param text The text to be displayed. + * \param font_family The font style name to be displayed. + * \param data Data struct containing extra text parameters. + * \param font Optional font asset that can be passed or left empty. + */ + Text(game_object_id_t id, const vec2 & dimensions, const vec2 & offset, + const std::string & font_family, const Data & data, const std::string & text = ""); + + //! Label text. + std::string text = ""; + //! font family name + std::string font_family = ""; + //! Font asset variable if this is not set, it will use the font_family to create an asset. + std::optional<Asset> font; + //! Data instance + Data data; +}; + +} // namespace crepe |