137 lines
2.0 KiB
C++
137 lines
2.0 KiB
C++
#include "writer.h"
|
|
#include "text.h" // for Text
|
|
|
|
// Constructor
|
|
Writer::Writer(Text *text) : text(text)
|
|
{
|
|
// Inicializa variables
|
|
posX = 0;
|
|
posY = 0;
|
|
kerning = 0;
|
|
caption = "";
|
|
speed = 0;
|
|
writingCounter = 0;
|
|
index = 0;
|
|
lenght = 0;
|
|
completed = false;
|
|
enabled = false;
|
|
enabledCounter = 0;
|
|
finished = false;
|
|
}
|
|
|
|
// Actualiza el objeto
|
|
void Writer::update()
|
|
{
|
|
if (enabled)
|
|
{
|
|
if (!completed)
|
|
{
|
|
// No completado
|
|
if (writingCounter > 0)
|
|
{
|
|
writingCounter--;
|
|
}
|
|
|
|
else if (writingCounter == 0)
|
|
{
|
|
index++;
|
|
writingCounter = speed;
|
|
}
|
|
|
|
if (index == lenght)
|
|
{
|
|
completed = true;
|
|
}
|
|
}
|
|
|
|
else
|
|
{
|
|
// Completado
|
|
if (enabledCounter > 0)
|
|
{
|
|
enabledCounter--;
|
|
}
|
|
else if (enabledCounter == 0)
|
|
{
|
|
finished = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Dibuja el objeto en pantalla
|
|
void Writer::render()
|
|
{
|
|
if (enabled)
|
|
{
|
|
text->write(posX, posY, caption, kerning, index);
|
|
}
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Writer::setPosX(int value)
|
|
{
|
|
posX = value;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Writer::setPosY(int value)
|
|
{
|
|
posY = value;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Writer::setKerning(int value)
|
|
{
|
|
kerning = value;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Writer::setCaption(std::string text)
|
|
{
|
|
caption = text;
|
|
lenght = text.length();
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Writer::setSpeed(int value)
|
|
{
|
|
speed = value;
|
|
writingCounter = value;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Writer::setEnabled(bool value)
|
|
{
|
|
enabled = value;
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
bool Writer::IsEnabled() const
|
|
{
|
|
return enabled;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Writer::setEnabledCounter(int time)
|
|
{
|
|
enabledCounter = time;
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
int Writer::getEnabledCounter() const
|
|
{
|
|
return enabledCounter;
|
|
}
|
|
|
|
// Centra la cadena de texto a un punto X
|
|
void Writer::center(int x)
|
|
{
|
|
setPosX(x - (text->lenght(caption, kerning) / 2));
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
bool Writer::hasFinished() const
|
|
{
|
|
return finished;
|
|
} |