diff --git a/source/text.cpp b/source/text.cpp index 5116707..1db1aa9 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -1,19 +1,16 @@ #include "text.h" -// Constructor Text::Text() { mSprite = new Sprite(); init(nullptr, nullptr, 0, 0); } -// Destructor Text::~Text() { delete mSprite; } -// Inicializador void Text::init(LTexture *texture, SDL_Renderer *renderer, Uint8 height) { // 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) { Uint16 shift = 0; - for (Uint8 i = 0; i < lenght; ++i) + std::string text2; + + if (lenght > 0) + text2 = text.substr(0, lenght); + else + text2 = text; + + for (Uint8 i = 0; i < text2.length(); ++i) { - if (text[i] == '*') - { - shift = 0; - y += mHeight; - } - else - { - 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); - } + mSprite->setSpriteClip(mOffset[int(text2[i])].x, mOffset[int(text2[i])].y, mSprite->getWidth(), mSprite->getHeight()); + mSprite->setPosX(x + shift); + mSprite->setPosY(y); + mSprite->render(); + 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) { 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); } -// Escribe el texto centrado en un punto x y con kerning void Text::writeCentered(int x, int y, std::string text, int 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 shift = 0; @@ -120,24 +98,12 @@ Uint16 Text::lenght(std::string text, int kerning) return shift; } -// Obtiene el valor de la variable -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() +Uint8 Text::getHeight() { return mHeight; -}height Establece el valor de la variable -void Text::setSize(Uint8 size) +} + +void Text::setHeight(Uint8 size) { - mHeight = height; + mHeight = size; } \ No newline at end of file diff --git a/source/text.h b/source/text.h index 88a74d6..6d45402 100644 --- a/source/text.h +++ b/source/text.h @@ -44,10 +44,10 @@ public: void setType(Uint8 type); // Obtiene el valor de la variable - Uint8 getSize(); + Uint8 getHeight(); // Establece el valor de la variable - void setSize(Uint8 size); + void setHeight(Uint8 size); private: Sprite *mSprite; // Objeto con los graficos para el texto