100 lines
2.1 KiB
C++
100 lines
2.1 KiB
C++
#include "core/rendering/writer.h"
|
|
|
|
#include "core/rendering/text.h" // for Text
|
|
|
|
// Constructor
|
|
Writer::Writer(Text *text)
|
|
: text_(text) {
|
|
}
|
|
|
|
// Actualiza el objeto
|
|
void Writer::update() {
|
|
if (enabled_) {
|
|
if (!completed_) { // No completado
|
|
if (writing_counter_ > 0) {
|
|
writing_counter_--;
|
|
}
|
|
|
|
else if (writing_counter_ == 0) {
|
|
index_++;
|
|
writing_counter_ = speed_;
|
|
}
|
|
|
|
if (index_ == length_) {
|
|
completed_ = true;
|
|
}
|
|
}
|
|
|
|
if (completed_) { // Completado
|
|
if (enabled_counter_ > 0) {
|
|
enabled_counter_--;
|
|
} else if (enabled_counter_ == 0) {
|
|
finished_ = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Dibuja el objeto en pantalla
|
|
void Writer::render() {
|
|
if (enabled_) {
|
|
text_->write(pos_x_, pos_y_, caption_, kerning_, index_);
|
|
}
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Writer::setPosX(int value) {
|
|
pos_x_ = value;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Writer::setPosY(int value) {
|
|
pos_y_ = 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;
|
|
length_ = text.length();
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Writer::setSpeed(int value) {
|
|
speed_ = value;
|
|
writing_counter_ = value;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Writer::setEnabled(bool value) {
|
|
enabled_ = value;
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
auto Writer::isEnabled() const -> bool {
|
|
return enabled_;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Writer::setEnabledCounter(int time) {
|
|
enabled_counter_ = time;
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
auto Writer::getEnabledCounter() const -> int {
|
|
return enabled_counter_;
|
|
}
|
|
|
|
// 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
|
|
auto Writer::hasFinished() const -> bool {
|
|
return finished_;
|
|
} |