From 61ab4049962d24e142601e5e127ba5ea6135f539 Mon Sep 17 00:00:00 2001 From: Dennis Meinen Date: Thu, 21 Mar 2024 12:21:50 +0100 Subject: [PATCH] Updated the TextHandler class to be properly named Text. --- log/loghandler.cpp | 6 +++--- text/texthandler.cpp | 10 ++++++---- text/texthandler.h | 10 +++++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/log/loghandler.cpp b/log/loghandler.cpp index cb6126c..eb303d6 100644 --- a/log/loghandler.cpp +++ b/log/loghandler.cpp @@ -3,11 +3,11 @@ #include "text/texthandler.h" void Log::_addLine(const char *line1, const char *line2) { - auto font = Fonts::GetFont("assets/fonts/APL386.ttf", 20); + auto font = Text::GetFont("assets/fonts/APL386.ttf", 20); - headerWidth = std::max(Fonts::MeasureText(font, line1), headerWidth); + headerWidth = std::max(Text::MeasureText(font, line1), headerWidth); - longestLineWidth = std::max(Fonts::MeasureText(font, line2), longestLineWidth); + longestLineWidth = std::max(Text::MeasureText(font, line2), longestLineWidth); lines.emplace_back(line1, line2); } diff --git a/text/texthandler.cpp b/text/texthandler.cpp index 2ccd819..0d09ea9 100644 --- a/text/texthandler.cpp +++ b/text/texthandler.cpp @@ -1,7 +1,7 @@ #include "texthandler.h" -Font Fonts::_getFont(const char *fileName, const int fontSize) { +Font Text::_getFont(const char *fileName, const int fontSize) { std::string index = std::string(Helpers::TextFormat("%s%d", fileName, fontSize)); auto it = _fonts.find(index); @@ -27,7 +27,7 @@ Font Fonts::_getFont(const char *fileName, const int fontSize) { } } -void Fonts::_drawText(Font font, vf2d pos, std::string textToDraw, Color color) { +void Text::_drawText(Font font, vf2d pos, std::string textToDraw, Color color) { if (textToDraw.empty()) return; @@ -46,7 +46,7 @@ void Fonts::_drawText(Font font, vf2d pos, std::string textToDraw, Color color) } -int Fonts::_measureText(Font font, std::string textToDraw) { +int Text::_measureText(Font font, std::string textToDraw) { if (textToDraw.empty()) return 0; @@ -60,8 +60,10 @@ int Fonts::_measureText(Font font, std::string textToDraw) { return width; } -Texture Fonts::_drawTextToTexture(Font font, std::string textToDraw, Color color) { +Texture Text::_drawTextToTexture(Font font, std::string textToDraw, Color color) { if (textToDraw.empty()) { + // In this case we return space so we still render something for when the user uses + // the height of the returned texture to position multiple lines of text. textToDraw = " "; }; diff --git a/text/texthandler.h b/text/texthandler.h index b4a86ce..7d214c5 100644 --- a/text/texthandler.h +++ b/text/texthandler.h @@ -13,7 +13,7 @@ /** * @brief Provides functionality for managing fonts and rendering text. */ -class Fonts { +class Text { public: /** * @brief Retrieves a font asset with the specified filename and font size. @@ -73,15 +73,15 @@ class Fonts { Texture _drawTextToTexture(Font font, std::string textToDraw, Color color); public: - Fonts(const Fonts &) = delete; + Text(const Text &) = delete; - static Fonts &get() { - static Fonts instance; + static Text &get() { + static Text instance; return instance; } private: - Fonts() { + Text() { TTF_Init(); }; }; \ No newline at end of file