Primer commit. Clon del repo de CC
This commit is contained in:
137
source/common/writer.cpp
Normal file
137
source/common/writer.cpp
Normal file
@@ -0,0 +1,137 @@
|
||||
#include "writer.h"
|
||||
|
||||
// Constructor
|
||||
Writer::Writer(Text *text)
|
||||
{
|
||||
// Copia los punteros
|
||||
this->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;
|
||||
}
|
||||
}
|
||||
|
||||
if (completed)
|
||||
{ // 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()
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Writer::setEnabledCounter(int time)
|
||||
{
|
||||
enabledCounter = time;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Writer::getEnabledCounter()
|
||||
{
|
||||
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()
|
||||
{
|
||||
return finished;
|
||||
}
|
||||
Reference in New Issue
Block a user