Cambiados los nombres de variables en text.h
This commit is contained in:
@@ -13,7 +13,7 @@ Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer)
|
||||
mSprite = new Sprite(rect, texture, renderer);
|
||||
mSprite->setTexture(texture);
|
||||
mSprite->setRenderer(renderer);
|
||||
mFile = textFile;
|
||||
file = textFile;
|
||||
|
||||
init();
|
||||
}
|
||||
@@ -35,17 +35,17 @@ void Text::init()
|
||||
// Inicializa a cero el vector con las coordenadas
|
||||
for (int i = 0; i < 128; i++)
|
||||
{
|
||||
mOffset[i].x = 0;
|
||||
mOffset[i].y = 0;
|
||||
mOffset[i].w = 0;
|
||||
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
|
||||
mSprite->setWidth(mBoxWidth);
|
||||
mSprite->setHeight(mBoxHeight);
|
||||
mSprite->setWidth(boxWidth);
|
||||
mSprite->setHeight(boxHeight);
|
||||
mSprite->setPosX(0);
|
||||
mSprite->setPosY(0);
|
||||
mSprite->setSpriteClip(0, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||
@@ -53,12 +53,12 @@ void Text::init()
|
||||
// Establece las coordenadas para cada caracter ascii de la cadena y su ancho
|
||||
for (int i = 32; i < 128; i++)
|
||||
{
|
||||
mOffset[i].x = ((i - 32) % 15) * mBoxWidth;
|
||||
mOffset[i].y = ((i - 32) / 15) * mBoxHeight;
|
||||
offset[i].x = ((i - 32) % 15) * boxWidth;
|
||||
offset[i].y = ((i - 32) / 15) * boxHeight;
|
||||
}
|
||||
|
||||
printf("Cargando %s\n", mFile.c_str());
|
||||
const std::string texto = "w = "+ std::to_string(mBoxWidth) + ", h = " + std::to_string(mBoxHeight);
|
||||
printf("Cargando %s\n", file.c_str());
|
||||
const std::string texto = "w = "+ std::to_string(boxWidth) + ", h = " + std::to_string(boxHeight);
|
||||
printf("%s\n",texto.c_str());
|
||||
}
|
||||
|
||||
@@ -72,11 +72,11 @@ void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
||||
|
||||
for (int i = 0; i < lenght; ++i)
|
||||
{
|
||||
mSprite->setSpriteClip(mOffset[int(text[i])].x, mOffset[int(text[i])].y, mSprite->getWidth(), mSprite->getHeight());
|
||||
mSprite->setSpriteClip(offset[int(text[i])].x, offset[int(text[i])].y, mSprite->getWidth(), mSprite->getHeight());
|
||||
mSprite->setPosX(x + shift);
|
||||
mSprite->setPosY(y);
|
||||
mSprite->render();
|
||||
shift += (mOffset[int(text[i])].w + kerning);
|
||||
shift += (offset[int(text[i])].w + kerning);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ int Text::lenght(std::string text, int kerning)
|
||||
int shift = 0;
|
||||
|
||||
for (int i = 0; i < (int)text.length(); i++)
|
||||
shift += (mOffset[int(text[i])].w + kerning);
|
||||
shift += (offset[int(text[i])].w + kerning);
|
||||
|
||||
// Descuenta el kerning del último caracter
|
||||
return shift - kerning;
|
||||
@@ -152,7 +152,7 @@ int Text::lenght(std::string text, int kerning)
|
||||
// Inicializa el vector de offsets desde un fichero
|
||||
void Text::initOffsetFromFile()
|
||||
{
|
||||
std::ifstream rfile(mFile);
|
||||
std::ifstream rfile(file);
|
||||
if (rfile.is_open() && rfile.good())
|
||||
{
|
||||
std::string buffer;
|
||||
@@ -160,11 +160,11 @@ void Text::initOffsetFromFile()
|
||||
// Lee los dos primeros valores del fichero
|
||||
std::getline(rfile, buffer);
|
||||
std::getline(rfile, buffer);
|
||||
mBoxWidth = std::stoi(buffer);
|
||||
boxWidth = std::stoi(buffer);
|
||||
|
||||
std::getline(rfile, buffer);
|
||||
std::getline(rfile, buffer);
|
||||
mBoxHeight = std::stoi(buffer);
|
||||
boxHeight = std::stoi(buffer);
|
||||
|
||||
// lee el resto de datos del fichero
|
||||
int index = 32;
|
||||
@@ -173,7 +173,7 @@ void Text::initOffsetFromFile()
|
||||
{
|
||||
// Almacena solo las lineas impares
|
||||
if (line_read % 2 == 1)
|
||||
mOffset[index++].w = std::stoi(buffer);
|
||||
offset[index++].w = std::stoi(buffer);
|
||||
|
||||
// Limpia el buffer
|
||||
buffer.clear();
|
||||
@@ -185,5 +185,5 @@ void Text::initOffsetFromFile()
|
||||
// Devuelve el valor de la variable
|
||||
int Text::getCharacterWidth()
|
||||
{
|
||||
return mBoxWidth;
|
||||
return boxWidth;
|
||||
}
|
||||
@@ -23,11 +23,11 @@ private:
|
||||
int y;
|
||||
int w;
|
||||
};
|
||||
Offset mOffset[128]; // Vector con las posiciones y ancho de cada letra
|
||||
Offset offset[128]; // Vector con las posiciones y ancho de cada letra
|
||||
|
||||
int mBoxWidth; // Anchura de la caja de cada caracter en el png
|
||||
int mBoxHeight; // Altura de la caja de cada caracter en el png
|
||||
std::string mFile; // Fichero con los descriptores de la fuente
|
||||
int boxWidth; // Anchura de la caja de cada caracter en el png
|
||||
int boxHeight; // Altura de la caja de cada caracter en el png
|
||||
std::string file; // Fichero con los descriptores de la fuente
|
||||
LTexture *texture; // Textura con los bitmaps del texto
|
||||
|
||||
// Inicializador
|
||||
|
||||
Reference in New Issue
Block a user