112 lines
2.3 KiB
C++
112 lines
2.3 KiB
C++
#include "core/rendering/writer.h"
|
|
|
|
#include "core/rendering/text.h" // for Text
|
|
|
|
// Constructor
|
|
Writer::Writer(Text *text)
|
|
: text(text),
|
|
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(const 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;
|
|
} |