Trabajando en el TITULO
This commit is contained in:
@@ -6,13 +6,12 @@
|
||||
// Constructor
|
||||
Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer)
|
||||
{
|
||||
texture = new LTexture(renderer, bitmapFile);
|
||||
sprite = new Sprite({0, 0, 0, 0}, texture, renderer);
|
||||
sprite->setTexture(texture);
|
||||
sprite->setRenderer(renderer);
|
||||
file = textFile;
|
||||
// Carga los offsets desde el fichero
|
||||
initOffsetFromFile(textFile);
|
||||
|
||||
init();
|
||||
// Crea los objetos
|
||||
texture = new LTexture(renderer, bitmapFile);
|
||||
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -22,35 +21,6 @@ Text::~Text()
|
||||
delete sprite;
|
||||
}
|
||||
|
||||
// Inicializador
|
||||
void Text::init()
|
||||
{
|
||||
// Inicializa a cero el vector con las coordenadas
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
offset[i].x = 0;
|
||||
offset[i].y = 0;
|
||||
offset[i].w = 0;
|
||||
}
|
||||
|
||||
// Carga los offsets desde el fichero
|
||||
initOffsetFromFile();
|
||||
|
||||
// Inicia los valores del sprite que dibuja las letras
|
||||
sprite->setWidth(boxWidth);
|
||||
sprite->setHeight(boxHeight);
|
||||
sprite->setPosX(0);
|
||||
sprite->setPosY(0);
|
||||
sprite->setSpriteClip(0, 0, sprite->getWidth(), sprite->getHeight());
|
||||
|
||||
// Establece las coordenadas para cada caracter ascii de la cadena y su ancho
|
||||
for (int i = 32; i < 128; ++i)
|
||||
{
|
||||
offset[i].x = ((i - 32) % 15) * boxWidth;
|
||||
offset[i].y = ((i - 32) / 15) * boxHeight;
|
||||
}
|
||||
}
|
||||
|
||||
// Escribe texto en pantalla
|
||||
void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
||||
{
|
||||
@@ -139,10 +109,19 @@ int Text::lenght(std::string text, int kerning)
|
||||
}
|
||||
|
||||
// Inicializa el vector de offsets desde un fichero
|
||||
void Text::initOffsetFromFile()
|
||||
void Text::initOffsetFromFile(std::string file)
|
||||
{
|
||||
// Inicializa a cero el vector con las coordenadas
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
offset[i].x = 0;
|
||||
offset[i].y = 0;
|
||||
offset[i].w = 0;
|
||||
}
|
||||
|
||||
// Abre el fichero para leer los valores
|
||||
const std::string filename = file.substr(file.find_last_of("\\/") + 1).c_str();
|
||||
std::ifstream rfile(file);
|
||||
printf("Reading file %s\n", file.c_str());
|
||||
|
||||
if (rfile.is_open() && rfile.good())
|
||||
{
|
||||
@@ -172,14 +151,21 @@ void Text::initOffsetFromFile()
|
||||
};
|
||||
|
||||
// Cierra el fichero
|
||||
printf("Closing file %s\n\n", file.c_str());
|
||||
printf("Text loaded: %s\n\n", filename.c_str());
|
||||
rfile.close();
|
||||
}
|
||||
|
||||
// El fichero no se puede abrir
|
||||
else
|
||||
{
|
||||
printf("Warning: Unable to open %s file\n", file.c_str());
|
||||
printf("Warning: Unable to open %s file\n", filename.c_str());
|
||||
}
|
||||
|
||||
// Establece las coordenadas para cada caracter ascii de la cadena y su ancho
|
||||
for (int i = 32; i < 128; ++i)
|
||||
{
|
||||
offset[i].x = ((i - 32) % 15) * boxWidth;
|
||||
offset[i].y = ((i - 32) / 15) * boxHeight;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user