hibiscus/renderer/rsdl/resources/font.cpp

33 lines
671 B
C++

#include <iostream>
#include <string>
#include <fmt/format.h>
#include "font.hpp"
namespace hibis::rsdl {
Font::Font(std::string path, uint size) {
this->mSize = size;
this->mPath = path;
loadFont();
}
Font::~Font() {
TTF_CloseFont(mLoadedFont);
}
void Font::loadFont(bool reload) {
// If already loaded, close font
if (mLoadedFont != NULL) {
TTF_CloseFont(mLoadedFont);
mLoadedFont = NULL;
}
mLoadedFont = TTF_OpenFont(mPath.c_str(), mSize);
// Do the message
if (!mDidReload) {
std::cout << fmt::format((reload ? "Reloaded font from" : "Loaded font at") + (std::string)" {}", mPath) << std::endl;
mDidReload = reload;
}
}
}