From 46164976b6b7aff6e64d2c19506ce32afb14ba15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Fri, 19 Feb 2021 17:33:29 +0100 Subject: [PATCH] update text2.cpp --- source/text2.cpp | 77 +++++++++++++++++------------------------------- source/text2.h | 67 +++++++++++++---------------------------- 2 files changed, 47 insertions(+), 97 deletions(-) diff --git a/source/text2.cpp b/source/text2.cpp index 6b9586c..77f735a 100644 --- a/source/text2.cpp +++ b/source/text2.cpp @@ -1,121 +1,107 @@ #include "const.h" #include "text2.h" -// Constructor Text2::Text2() { - init(nullptr, nullptr, 0, 0); + init(nullptr, nullptr, 0); } -// Destructor Text2::~Text2() { - init(nullptr, nullptr, 0, 0); + init(nullptr, nullptr, 0); } -// Inicializador -void Text2::init(LTexture *texture, SDL_Renderer *renderer, Uint8 type, Uint8 size) +void Text2::init(LTexture *texture, SDL_Renderer *renderer, Uint8 height) { - Text::init(texture, renderer, type, size); + Text::init(texture, renderer, height); mPosX = 0; mPosY = 0; mKerning = 0; mCaption = ""; - mWrittingSpeed = 0; - mWrittingTimer = 0; + mSpeed = 0; + mCounter = 0; mIndex = 0; mLenght = 0; - mWrittingCompleted = false; + mCompleted = false; mEnabled = false; - mEnabledTimer = 0; + mEnabledCounter = 0; mId = -1; - mIntroEvents = nullptr; } -// Establece el valor de la variable void Text2::setPosX(int value) { mPosX = value; } -// Establece el valor de la variable void Text2::setPosY(int value) { mPosY = value; } -// Establece el valor de la variable void Text2::setKerning(int value) { mKerning = value; } -// Establece el valor de la variable void Text2::setCaption(std::string text) { mCaption = text; mLenght = text.length(); } -// Establece el valor de la variable -void Text2::setWrittingSpeed(Uint16 value) +void Text2::setSpeed(Uint16 value) { - mWrittingSpeed = value; - mWrittingTimer = value; + mSpeed = value; + mCounter = value; } -// Establece el valor de la variable void Text2::setEnabled(bool value) { mEnabled = value; } -// Obtiene el valor de la variable bool Text2::IsEnabled() { return mEnabled; } -// Establece el valor de la variable -void Text2::setEnabledTimer(Uint16 value) +void Text2::setEnabledCounter(Uint16 value) { - mEnabledTimer = value; + mEnabledCounter = value; } -// Obtiene el valor de la variable -Uint16 Text2::getEnabledTimer() +Uint16 Text2::getEnabledCounter() { - return mEnabledTimer; + return mEnabledCounter; } -// Actualiza el objeto void Text2::update() { if (mEnabled) { - if (mWrittingCompleted == false) + if (mCompleted == false) { - if (mWrittingTimer > 0) + if (mCounter > 0) { - --mWrittingTimer; + --mCounter; } - if (mWrittingTimer == 0) + if (mCounter == 0) { ++mIndex; - mWrittingTimer = mWrittingSpeed; + mCounter = mSpeed; } if (mIndex == mLenght) { - mWrittingCompleted = true; + mCompleted = true; } } - if (mWrittingCompleted) + if (mCompleted) { - if (mEnabledTimer > 0) + if (mEnabledCounter > 0) { - --mEnabledTimer; + --mEnabledCounter; } - else if (mEnabledTimer == 0) + else if (mEnabledCounter == 0) { if (mId < 0) { @@ -123,14 +109,13 @@ void Text2::update() } else { - mIntroEvents[mId] = EVENT_COMPLETED; + //mIntroEvents[mId] = EVENT_COMPLETED; } } } } } -// Dibuja el objeto en pantalla void Text2::render() { if (mEnabled) @@ -139,20 +124,12 @@ void Text2::render() } } -// Centra la cadena de texto a un punto X void Text2::center(int x) { setPosX(x - (lenght(mCaption, mKerning) / 2)); } -// Establece el valor de la variable void Text2::setId(int id) { mId = id; -} - -// Establece el valor de la variable -void Text2::setIntroEvents(Uint8 *value) -{ - mIntroEvents = value; -} +} \ No newline at end of file diff --git a/source/text2.h b/source/text2.h index 9366d61..fc70fd5 100644 --- a/source/text2.h +++ b/source/text2.h @@ -16,7 +16,7 @@ public: ~Text2(); // Inicializador - void init(LTexture *texture, SDL_Renderer *renderer, Uint8 type, Uint8 size); + void init(LTexture *texture, SDL_Renderer *renderer, Uint8 height); // Establece el valor de la variable void setPosX(int value); @@ -31,72 +31,45 @@ public: void setCaption(std::string text); // Establece el valor de la variable - void setWrittingSpeed(Uint16 value); + void setSpeed(Uint16 value); // Establece el valor de la variable void setEnabled(bool value); // Obtiene el valor de la variable bool IsEnabled(); - + // Establece el valor de la variable - void setEnabledTimer(Uint16 value); + void setEnabledCounter(Uint16 value); // Obtiene el valor de la variable - Uint16 getEnabledTimer(); + Uint16 getEnabledCounter(); - // Actualiza el objeto + // Actualiza todas las variables del objeto void update(); // Dibuja el objeto en pantalla void render(); - // Centra la cadena de texto a un punto X + // Centra la cadena de texto respecto a un punto X void center(int x); - // Establece el valor de la variable + // Establece el valor de la variable mId void setId(int id); - // Establece el valor de la variable - void setIntroEvents(Uint8 *value); - private: - // Posicion X/Y donde empezar a escribir el texto - int mPosX; - int mPosY; - - // Kerning del texto - int mKerning; - - // Texto para escribir - std::string mCaption; - - // Velocidad de escritura - Uint16 mWrittingSpeed; - - // Temporizador de escritura para cada caracter - Uint16 mWrittingTimer; - - // Posición del texto que se está escribiendo - Uint16 mIndex; - - // Longitud de la cadena a escribir - Uint16 mLenght; - - // Indica si se ha escrito todo el texto - bool mWrittingCompleted; - - // Indica si el objeto está habilitado - bool mEnabled; - - // Temporizador para deshabilitar el objeto - Uint16 mEnabledTimer; - - // Identificador - int mId; - - // Dirección del array de eventos donde notificar el estado - Uint8 *mIntroEvents; + bool mCompleted; // Indica si se ha escrito todo el texto + bool mEnabled; // Indica si el objeto está habilitado + int mId; // Identificador + int mKerning; // Espacio entre caracteres + int mPosX; // Posicion en el eje X donde empezar a escribir el texto + int mPosY; // Posicion en el eje Y donde empezar a escribir el texto + std::string mCaption; // Texto para escribir + Uint16 mCounter; // Temporizador de escritura para cada caracter + Uint16 mEnabledCounter; // Contador para deshabilitar el objeto + Uint16 mIndex; // Indice a la posición dentro de la cadena de texto que se está escribiendo + Uint16 mLenght; // Longitud de la cadena a escribir + Uint16 mSpeed; // Velocidad de escritura }; #endif