46 lines
973 B
C++
46 lines
973 B
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
|
|
{
|
|
if (_is_visible)
|
|
{
|
|
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::setText(const std::string& text)
|
|
{
|
|
_button_text.setString(text);
|
|
}
|