updated text.cpp

This commit is contained in:
2021-02-19 07:31:50 +01:00
parent 6ab8f39b92
commit 7fc0a86743
2 changed files with 16 additions and 117 deletions

View File

@@ -1,4 +1,3 @@
#include "const.h"
#include "text.h"
// Constructor
@@ -15,15 +14,14 @@ Text::~Text()
}
// Inicializador
void Text::init(LTexture *texture, SDL_Renderer *renderer, Uint8 type, Uint8 size)
void Text::init(LTexture *texture, SDL_Renderer *renderer, Uint8 height)
{
// Inicializa variables
mType = type;
mSize = size;
mHeight = height;
// Inicia los valores del sprite que dibuja las letras
mSprite->setWidth(size);
mSprite->setHeight(size);
mSprite->setWidth(mHeight);
mSprite->setHeight(mHeight);
mSprite->setPosX(0);
mSprite->setPosY(0);
mSprite->setTexture(texture);
@@ -31,7 +29,6 @@ void Text::init(LTexture *texture, SDL_Renderer *renderer, Uint8 type, Uint8 siz
mSprite->setSpriteClip(0, 0, mSprite->getWidth(), mSprite->getHeight());
// Cadena con los caracteres ascii que se van a inicializar
// std::string text = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-/().:#!";
std::string text = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ{\\[]]^_`abcdefghijklmnopqrstuvwxyz";
// Inicializa a cero el vector con las coordenadas
@@ -47,90 +44,8 @@ void Text::init(LTexture *texture, SDL_Renderer *renderer, Uint8 type, Uint8 siz
{
mOffset[int(text[i])].x = ((int(text[i]) - 32) % 15) * mSprite->getWidth();
mOffset[int(text[i])].y = ((int(text[i]) - 32) / 15) * mSprite->getHeight();
if (type == TEXT_FIXED)
{
mOffset[int(text[i])].w = size;
}
}
// Establece el ancho de cada caracter
if (type == TEXT_VARIABLE)
{
mOffset[int(' ')].w = 7;
mOffset[int('-')].w = 6;
mOffset[int('/')].w = 5;
mOffset[int('(')].w = 5;
mOffset[int(')')].w = 5;
mOffset[int('.')].w = 4;
mOffset[int(':')].w = 4;
mOffset[int('#')].w = 7;
mOffset[int('!')].w = 7;
mOffset[int('\'')].w = 3;
mOffset[int('0')].w = 7;
mOffset[int('1')].w = 5;
mOffset[int('2')].w = 7;
mOffset[int('3')].w = 7;
mOffset[int('4')].w = 7;
mOffset[int('5')].w = 7;
mOffset[int('6')].w = 7;
mOffset[int('7')].w = 7;
mOffset[int('8')].w = 7;
mOffset[int('9')].w = 7;
mOffset[int('A')].w = 7;
mOffset[int('B')].w = 7;
mOffset[int('C')].w = 7;
mOffset[int('D')].w = 7;
mOffset[int('E')].w = 7;
mOffset[int('F')].w = 7;
mOffset[int('G')].w = 7;
mOffset[int('H')].w = 7;
mOffset[int('I')].w = 4;
mOffset[int('J')].w = 6;
mOffset[int('K')].w = 8;
mOffset[int('L')].w = 6;
mOffset[int('M')].w = 9;
mOffset[int('N')].w = 8;
mOffset[int('O')].w = 8;
mOffset[int('P')].w = 7;
mOffset[int('Q')].w = 8;
mOffset[int('R')].w = 7;
mOffset[int('S')].w = 6;
mOffset[int('T')].w = 8;
mOffset[int('U')].w = 7;
mOffset[int('V')].w = 8;
mOffset[int('W')].w = 9;
mOffset[int('X')].w = 8;
mOffset[int('Y')].w = 8;
mOffset[int('Z')].w = 7;
mOffset[int('a')].w = 7;
mOffset[int('b')].w = 7;
mOffset[int('c')].w = 6;
mOffset[int('d')].w = 7;
mOffset[int('e')].w = 7;
mOffset[int('f')].w = 5;
mOffset[int('g')].w = 7;
mOffset[int('h')].w = 7;
mOffset[int('i')].w = 4;
mOffset[int('j')].w = 5;
mOffset[int('k')].w = 7;
mOffset[int('l')].w = 4;
mOffset[int('m')].w = 10;
mOffset[int('n')].w = 7;
mOffset[int('o')].w = 7;
mOffset[int('p')].w = 7;
mOffset[int('q')].w = 7;
mOffset[int('r')].w = 6;
mOffset[int('s')].w = 6;
mOffset[int('t')].w = 5;
mOffset[int('u')].w = 7;
mOffset[int('v')].w = 7;
mOffset[int('w')].w = 9;
mOffset[int('x')].w = 7;
mOffset[int('y')].w = 7;
mOffset[int('z')].w = 7;
mOffset[int(text[i])].w = mHeight;
mOffset[int(text[i])].h = mHeight;
}
}
@@ -171,7 +86,7 @@ void Text::write(int x, int y, std::string text, int kerning, Uint8 lenght)
if (text[i] == '*')
{
shift = 0;
y += mSize;
y += mHeight;
}
else
{
@@ -234,11 +149,9 @@ void Text::setType(Uint8 type)
// Obtiene el valor de la variable
Uint8 Text::getSize()
{
return mSize;
}
// Establece el valor de la variable
return mHeight;
}height Establece el valor de la variable
void Text::setSize(Uint8 size)
{
mSize = size;
mHeight = height;
}

View File

@@ -15,7 +15,7 @@ public:
~Text();
// Inicializador
void init(LTexture *texture, SDL_Renderer *renderer, Uint8 type, Uint8 size);
void init(LTexture *texture, SDL_Renderer *renderer, Uint8 height);
// Escribe el texto en pantalla
void write(int x, int y, std::string text);
@@ -36,31 +36,17 @@ public:
// Establece el valor de la variable
void setType(Uint8 type);
// Obtiene el valor de la variable
Uint8 getSize();
// Establece el valor de la variable
void setSize(Uint8 size);
private:
// Objeto con los graficos para el texto
Sprite *mSprite;
// Coordenadas dentro del PNG para cada código ascii y su anchura
struct Offset
{
int x;
int y;
Uint8 w;
};
// Vector con las posiciones y ancho de cada letra
Offset mOffset[255];
// Indica si el texto es de anchura fija o variable
Uint8 mType;
Uint8 mSize;
Sprite *mSprite; // Objeto con los graficos para el texto
SDL_Rect mOffset[255]; // Vector con las posiciones y ancho de cada letra
Uint8 mHeight; // Altura del texto
};
#endif