#include "button.h" #include Button::Button(const std::string &text, const std::shared_ptr& factory, unsigned int font_size) : _core_factory(factory) { _button_text = _core_factory->getText(kku::Font::Id::GUI); _button_text->setString(text); _button_text->setColor(kku::Color{0, 0, 0, 255}); _button_text->setCharacterSize(font_size); } void Button::update(const kku::microsec& dt) { Widget::update(dt); } void Button::display() const { if (_is_visible) { _button_content->display(); _button_text->display(); } Widget::display(); } void Button::setRect(const kku::Area& rect) { _button_content->setRect(rect); _button_text->setPosition(kku::Point{rect.left + 5, rect.top + 5}); } void Button::setPosition(const kku::Point& position) { _button_content->setPosition(position); auto new_point = position; new_point.moveBy(5.f, 5.f); _button_text->setPosition(new_point); } void Button::move(const kku::Vector2& delta) { _button_content->move(delta); _button_text->move(delta); Widget::move(delta); } bool Button::isUnderMouse(const kku::Point& position) const { return _is_visible && _button_content->contains(position); } void Button::setText(const std::string& text) { _button_text->setString(text); } kku::Area Button::getRect() const { return _button_content->getRect(); } kku::Point Button::getPosition() const { return _button_content->getPosition(); }