Files
coffee_crisis_opendingux_dev/source/text2.cpp

159 lines
2.4 KiB
C++

#include "const.h"
#include "text2.h"
// Constructor
Text2::Text2()
{
init(nullptr, nullptr, 0, 0);
}
// Destructor
Text2::~Text2()
{
init(nullptr, nullptr, 0, 0);
}
// Inicializador
void Text2::init(LTexture *texture, SDL_Renderer *renderer, Uint8 type, Uint8 size)
{
Text::init(texture, renderer, type, size);
mPosX = 0;
mPosY = 0;
mKerning = 0;
mCaption = "";
mWrittingSpeed = 0;
mWrittingTimer = 0;
mIndex = 0;
mLenght = 0;
mWrittingCompleted = false;
mEnabled = false;
mEnabledTimer = 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)
{
mWrittingSpeed = value;
mWrittingTimer = 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)
{
mEnabledTimer = value;
}
// Obtiene el valor de la variable
Uint16 Text2::getEnabledTimer()
{
return mEnabledTimer;
}
// Actualiza el objeto
void Text2::update()
{
if (mEnabled)
{
if (mWrittingCompleted == false)
{
if (mWrittingTimer > 0)
{
--mWrittingTimer;
}
if (mWrittingTimer == 0)
{
++mIndex;
mWrittingTimer = mWrittingSpeed;
}
if (mIndex == mLenght)
{
mWrittingCompleted = true;
}
}
if (mWrittingCompleted)
{
if (mEnabledTimer > 0)
{
--mEnabledTimer;
}
else if (mEnabledTimer == 0)
{
if (mId < 0)
{
mEnabled = false;
}
else
{
mIntroEvents[mId] = EVENT_COMPLETED;
}
}
}
}
}
// Dibuja el objeto en pantalla
void Text2::render()
{
if (mEnabled)
{
Text::write(mPosX, mPosY, mCaption, mKerning, mIndex);
}
}
// 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;
}