Skip to content

Commit

Permalink
Updated the TextHandler class to be properly named Text.
Browse files Browse the repository at this point in the history
  • Loading branch information
bXi committed Mar 21, 2024
1 parent bfa9496 commit 61ab404
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions log/loghandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
10 changes: 6 additions & 4 deletions text/texthandler.cpp
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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 = " ";
};

Expand Down
10 changes: 5 additions & 5 deletions text/texthandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
};
};

0 comments on commit 61ab404

Please sign in to comment.