AsloEngine/asloengine/builtin/button.cpp
2019-08-29 18:42:28 +02:00

49 lines
No EOL
1.3 KiB
C++
Executable file

#include "headers/button.hpp"
namespace asloengine
{
Button::Button(sf::String _name, sf::String _text, sf::Font& _font, sf::Texture& _texture, uint _text_size)
: text_vertical_offset(3.5), TextOnlyButton(_name, _text, _font, _text_size), SpriteObject(_name, _texture), GameObject(_name) {}
Button::~Button() {}
void Button::draw()
{
SpriteObject::draw();
TextOnlyButton::draw();
}
void Button::on_main_property_update()
{
SpriteObject::on_main_property_update();
sf::FloatRect sprite_bounds = sprite.getLocalBounds();
sf::FloatRect text_bounds = text->getLocalBounds();
sf::Vector2f offset(0, -text_bounds.height / text_vertical_offset);
sf::Vector2f position_correction = calculate_child_position_centered(
sprite_bounds, text_bounds, offset, scale, rotation
);
text->setPosition(position.x + position_correction.x, position.y + position_correction.y);
text->setScale(scale);
text->setOrigin(origin);
text->setRotation(rotation);
sprite_bounds = sprite.getGlobalBounds();
update_clickable(sprite_bounds);
}
void Button::on_start()
{
set_clickable(sprite.getGlobalBounds(), render_window);
}
}