77 lines
No EOL
1.3 KiB
C++
Executable file
77 lines
No EOL
1.3 KiB
C++
Executable file
#include "headers/textobject.hpp"
|
|
|
|
namespace asloengine
|
|
{
|
|
|
|
TextObject::TextObject(std::string _name, sf::String _text, sf::Font& _font, uint _text_size)
|
|
: GameObject(_name)
|
|
{
|
|
|
|
text = std::make_shared<sf::Text>();
|
|
text->setFont(_font);
|
|
text->setCharacterSize(_text_size);
|
|
set_text(_text);
|
|
|
|
}
|
|
|
|
TextObject::~TextObject() {}
|
|
|
|
void TextObject::draw()
|
|
{
|
|
|
|
render_window->draw(*text);
|
|
|
|
}
|
|
|
|
void TextObject::on_main_property_update()
|
|
{
|
|
|
|
sf::FloatRect text_bounds = text->getLocalBounds();
|
|
|
|
text->setOrigin(origin.x * text_bounds.width, origin.y * text_bounds.height * 2);
|
|
text->setScale(scale);
|
|
text->setPosition(position);
|
|
text->setRotation(rotation);
|
|
|
|
}
|
|
|
|
void TextObject::set_text(sf::String _text)
|
|
{
|
|
|
|
text->setString(_text);
|
|
|
|
on_main_property_update();
|
|
|
|
}
|
|
|
|
void TextObject::set_text_size(uint _text_size)
|
|
{
|
|
|
|
text->setCharacterSize(_text_size);
|
|
|
|
on_main_property_update();
|
|
|
|
}
|
|
|
|
sf::String TextObject::get_text() const
|
|
{
|
|
|
|
return text->getString();
|
|
|
|
}
|
|
|
|
uint TextObject::get_text_size() const
|
|
{
|
|
|
|
return text->getCharacterSize();
|
|
|
|
}
|
|
|
|
int TextObject::get_text_length() const
|
|
{
|
|
|
|
return text->getString().getSize();
|
|
|
|
}
|
|
|
|
} |