update text.cpp
This commit is contained in:
@@ -1,19 +1,16 @@
|
|||||||
#include "text.h"
|
#include "text.h"
|
||||||
|
|
||||||
// Constructor
|
|
||||||
Text::Text()
|
Text::Text()
|
||||||
{
|
{
|
||||||
mSprite = new Sprite();
|
mSprite = new Sprite();
|
||||||
init(nullptr, nullptr, 0, 0);
|
init(nullptr, nullptr, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
|
||||||
Text::~Text()
|
Text::~Text()
|
||||||
{
|
{
|
||||||
delete mSprite;
|
delete mSprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializador
|
|
||||||
void Text::init(LTexture *texture, SDL_Renderer *renderer, Uint8 height)
|
void Text::init(LTexture *texture, SDL_Renderer *renderer, Uint8 height)
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
@@ -49,43 +46,26 @@ void Text::init(LTexture *texture, SDL_Renderer *renderer, Uint8 height)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribe el texto en pantalla con kerning
|
|
||||||
void Text::write(int x, int y, std::string text, int kerning)
|
|
||||||
{
|
|
||||||
Uint16 shift = 0;
|
|
||||||
for (Uint8 i = 0; i < text.length(); ++i)
|
|
||||||
{
|
|
||||||
mSprite->setSpriteClip(mOffset[int(text[i])].x, mOffset[int(text[i])].y, mSprite->getWidth(), mSprite->getHeight());
|
|
||||||
mSprite->setPosX(x + shift);
|
|
||||||
mSprite->setPosY(y);
|
|
||||||
mSprite->render();
|
|
||||||
shift += (mOffset[int(text[i])].w + kerning);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Escribe una cantidad determinada de caracteres del texto en pantalla
|
|
||||||
void Text::write(int x, int y, std::string text, Sint8 kerning, Uint8 lenght)
|
void Text::write(int x, int y, std::string text, Sint8 kerning, Uint8 lenght)
|
||||||
{
|
{
|
||||||
Uint16 shift = 0;
|
Uint16 shift = 0;
|
||||||
for (Uint8 i = 0; i < lenght; ++i)
|
std::string text2;
|
||||||
{
|
|
||||||
if (text[i] == '*')
|
if (lenght > 0)
|
||||||
{
|
text2 = text.substr(0, lenght);
|
||||||
shift = 0;
|
|
||||||
y += mHeight;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
|
text2 = text;
|
||||||
|
|
||||||
|
for (Uint8 i = 0; i < text2.length(); ++i)
|
||||||
{
|
{
|
||||||
mSprite->setSpriteClip(mOffset[int(text[i])].x, mOffset[int(text[i])].y, mSprite->getWidth(), mSprite->getHeight());
|
mSprite->setSpriteClip(mOffset[int(text2[i])].x, mOffset[int(text2[i])].y, mSprite->getWidth(), mSprite->getHeight());
|
||||||
mSprite->setPosX(x + shift);
|
mSprite->setPosX(x + shift);
|
||||||
mSprite->setPosY(y);
|
mSprite->setPosY(y);
|
||||||
mSprite->render();
|
mSprite->render();
|
||||||
shift += (mOffset[int(text[i])].w + kerning);
|
shift += (mOffset[int(text2[i])].w + kerning);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribe el texto con colores
|
|
||||||
void Text::writeColored(int x, int y, std::string text, Uint8 R, Uint8 G, Uint8 B)
|
void Text::writeColored(int x, int y, std::string text, Uint8 R, Uint8 G, Uint8 B)
|
||||||
{
|
{
|
||||||
mSprite->getTexture()->setColor(R, G, B);
|
mSprite->getTexture()->setColor(R, G, B);
|
||||||
@@ -93,7 +73,6 @@ void Text::writeColored(int x, int y, std::string text, Uint8 R, Uint8 G, Uint8
|
|||||||
mSprite->getTexture()->setColor(255, 255, 255);
|
mSprite->getTexture()->setColor(255, 255, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribe el texto centrado en un punto x y con kerning
|
|
||||||
void Text::writeCentered(int x, int y, std::string text, int kerning)
|
void Text::writeCentered(int x, int y, std::string text, int kerning)
|
||||||
{
|
{
|
||||||
// Uint16 lenght = Text::lenght(text, kerning);
|
// Uint16 lenght = Text::lenght(text, kerning);
|
||||||
@@ -109,7 +88,6 @@ void Text::writeCentered(int x, int y, std::string text, int kerning)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene la longitud en pixels de una cadena
|
|
||||||
Uint16 Text::lenght(std::string text, int kerning)
|
Uint16 Text::lenght(std::string text, int kerning)
|
||||||
{
|
{
|
||||||
Uint16 shift = 0;
|
Uint16 shift = 0;
|
||||||
@@ -120,24 +98,12 @@ Uint16 Text::lenght(std::string text, int kerning)
|
|||||||
return shift;
|
return shift;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
Uint8 Text::getHeight()
|
||||||
Uint8 Text::getType()
|
|
||||||
{
|
|
||||||
return mType;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void Text::setType(Uint8 type)
|
|
||||||
{
|
|
||||||
mType = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
Uint8 Text::getSize()
|
|
||||||
{
|
{
|
||||||
return mHeight;
|
return mHeight;
|
||||||
}height Establece el valor de la variable
|
}
|
||||||
void Text::setSize(Uint8 size)
|
|
||||||
{
|
void Text::setHeight(Uint8 size)
|
||||||
mHeight = height;
|
{
|
||||||
|
mHeight = size;
|
||||||
}
|
}
|
||||||
@@ -44,10 +44,10 @@ public:
|
|||||||
void setType(Uint8 type);
|
void setType(Uint8 type);
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
Uint8 getSize();
|
Uint8 getHeight();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setSize(Uint8 size);
|
void setHeight(Uint8 size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Sprite *mSprite; // Objeto con los graficos para el texto
|
Sprite *mSprite; // Objeto con los graficos para el texto
|
||||||
|
|||||||
Reference in New Issue
Block a user