This commit is contained in:
2026-04-17 22:20:37 +02:00
parent 513eacf356
commit 20b9a95619
38 changed files with 310 additions and 622 deletions

View File

@@ -39,8 +39,10 @@ static void computeTextFileOffsets(textFile_t &tf) {
}
// Llena una estructuta textFile_t desde un fichero
textFile_t LoadTextFile(std::string file, bool verbose) {
textFile_t LoadTextFile(const std::string &file, bool verbose) {
textFile_t tf;
tf.boxWidth = 0;
tf.boxHeight = 0;
for (int i = 0; i < 128; ++i) {
tf.offset[i].x = 0;
tf.offset[i].y = 0;
@@ -65,6 +67,8 @@ textFile_t LoadTextFile(std::string file, bool verbose) {
// Llena una estructura textFile_t desde bytes en memoria
textFile_t LoadTextFileFromMemory(const std::vector<uint8_t> &bytes, bool verbose) {
textFile_t tf;
tf.boxWidth = 0;
tf.boxHeight = 0;
for (int i = 0; i < 128; ++i) {
tf.offset[i].x = 0;
tf.offset[i].y = 0;
@@ -83,7 +87,7 @@ textFile_t LoadTextFileFromMemory(const std::vector<uint8_t> &bytes, bool verbos
}
// Constructor
Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer) {
Text::Text(const std::string &bitmapFile, const std::string &textFile, SDL_Renderer *renderer) {
// Carga los offsets desde el fichero
textFile_t tf = LoadTextFile(textFile);
@@ -105,7 +109,7 @@ Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer)
}
// Constructor
Text::Text(std::string textFile, Texture *texture, SDL_Renderer *renderer) {
Text::Text(const std::string &textFile, Texture *texture, SDL_Renderer *renderer) {
// Carga los offsets desde el fichero
textFile_t tf = LoadTextFile(textFile);
@@ -172,7 +176,7 @@ Text::~Text() {
}
// Escribe texto en pantalla
void Text::write(int x, int y, std::string text, int kerning, int lenght) {
void Text::write(int x, int y, const std::string &text, int kerning, int lenght) {
int shift = 0;
if (lenght == -1) {
@@ -192,14 +196,14 @@ void Text::write(int x, int y, std::string text, int kerning, int lenght) {
}
// Escribe el texto con colores
void Text::writeColored(int x, int y, std::string text, color_t color, int kerning, int lenght) {
void Text::writeColored(int x, int y, const std::string &text, color_t color, int kerning, int lenght) {
sprite->getTexture()->setColor(color.r, color.g, color.b);
write(x, y, text, kerning, lenght);
sprite->getTexture()->setColor(255, 255, 255);
}
// Escribe el texto con sombra
void Text::writeShadowed(int x, int y, std::string text, color_t color, Uint8 shadowDistance, int kerning, int lenght) {
void Text::writeShadowed(int x, int y, const std::string &text, color_t color, Uint8 shadowDistance, int kerning, int lenght) {
sprite->getTexture()->setColor(color.r, color.g, color.b);
write(x + shadowDistance, y + shadowDistance, text, kerning, lenght);
sprite->getTexture()->setColor(255, 255, 255);
@@ -207,13 +211,13 @@ void Text::writeShadowed(int x, int y, std::string text, color_t color, Uint8 sh
}
// Escribe el texto centrado en un punto x
void Text::writeCentered(int x, int y, std::string text, int kerning, int lenght) {
void Text::writeCentered(int x, int y, const std::string &text, int kerning, int lenght) {
x -= (Text::lenght(text, kerning) / 2);
write(x, y, text, kerning, lenght);
}
// Escribe texto con extras
void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, color_t textColor, Uint8 shadowDistance, color_t shadowColor, int lenght) {
void Text::writeDX(Uint8 flags, int x, int y, const std::string &text, int kerning, color_t textColor, Uint8 shadowDistance, color_t shadowColor, int lenght) {
const bool centered = ((flags & TXT_CENTER) == TXT_CENTER);
const bool shadowed = ((flags & TXT_SHADOW) == TXT_SHADOW);
const bool colored = ((flags & TXT_COLOR) == TXT_COLOR);
@@ -245,7 +249,7 @@ void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, col
}
// Obtiene la longitud en pixels de una cadena
int Text::lenght(std::string text, int kerning) {
int Text::lenght(const std::string &text, int kerning) {
int shift = 0;
for (int i = 0; i < (int)text.length(); ++i)