You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
project-kyoku/src/gui/widgets/button.cpp

48 lines
1.0 KiB
C++

#include "button.h"
Button::Button(const std::string &text)
{
setText(text);
_button_text.setFillColor(sf::Color::Black);
_button_content.setFillColor(sf::Color::White);
}
void Button::update()
{
Widget::update();
}
void Button::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
target.draw(_button_content, states);
target.draw(_button_text, states);
Widget::draw(target, states);
}
void Button::setRect(const sf::FloatRect& rect)
{
_button_content.setPosition(rect.left, rect.top);
_button_content.setSize({rect.width, rect.height});
}
void Button::setPosition(const sf::Vector2f &position)
{
_button_content.setPosition(position);
}
bool Button::isUnderMouse(int mouse_x, int mouse_y) const
{
return _is_visible && _button_content.getGlobalBounds().contains(mouse_x, mouse_y);
}
void Button::setFillColor(sf::Color&& color)
{
_button_content.setFillColor(std::move(color));
}
void Button::setText(const std::string& text)
{
_button_text.setString(text);
}