commit de acabar la jornada laboral

This commit is contained in:
2024-10-17 13:57:41 +02:00
parent db884cb422
commit 59de566c5b
24 changed files with 78 additions and 274 deletions

View File

@@ -1,10 +1,10 @@
#include "text.h"
#include <SDL2/SDL_rect.h> // for SDL_Rect
#include <fstream> // for basic_ostream, basic_ifstream, basic_istream
#include <iostream> // for cout
#include "sprite.h" // for Sprite
#include "texture.h" // for Texture
#include "utils.h" // for Color
#include <SDL2/SDL_rect.h> // for SDL_Rect
#include <fstream> // for basic_ostream, basic_ifstream, basic_istream
#include <iostream> // for cout
#include "sprite.h" // for Sprite
#include "texture.h" // for Texture
#include "utils.h" // for Color
// Llena una estructuta TextFile desde un fichero
TextFile LoadTextFile(std::string file_path)
@@ -22,9 +22,7 @@ TextFile LoadTextFile(std::string file_path)
}
// Abre el fichero para leer los valores
#ifdef VERBOSE
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1).c_str();
#endif
std::ifstream file(file_path);
if (file.is_open() && file.good())
@@ -56,19 +54,15 @@ TextFile LoadTextFile(std::string file_path)
line_read++;
};
// Cierra el fichero
#ifdef VERBOSE
// Cierra el fichero
std::cout << "Text loaded: " << file_name << std::endl;
#endif
file.close();
}
// El fichero no se puede abrir
else
{
#ifdef VERBOSE
std::cout << "Warning: Unable to open " << file_name << " file" << std::endl;
#endif
}
// Establece las coordenadas para cada caracter ascii de la cadena y su ancho
@@ -158,14 +152,14 @@ void Text::write(int x, int y, const std::string &text, int kerning, int lenght)
lenght = text.length();
}
sprite_->setPosY(y);
sprite_->setY(y);
const auto width = sprite_->getWidth();
const auto height = sprite_->getHeight();
for (int i = 0; i < lenght; ++i)
{
const auto index = static_cast<int>(text[i]);
sprite_->setSpriteClip(offset_[index].x, offset_[index].y, width, height);
sprite_->setPosX(x + shift);
sprite_->setX(x + shift);
sprite_->render();
shift += fixed_width_ ? box_width_ : (offset_[int(text[i])].w + kerning);
}