2021-08-21 14:29:58 +02:00
|
|
|
#include "bpmcalculatorwidget.h"
|
2021-08-16 20:54:03 +02:00
|
|
|
|
2021-08-21 14:29:58 +02:00
|
|
|
BPMCalculatorWidget::BPMCalculatorWidget() :
|
2021-08-16 20:54:03 +02:00
|
|
|
_pressed(false)
|
|
|
|
{
|
|
|
|
_button_text.setFillColor(sf::Color::Black);
|
|
|
|
_button_content.setFillColor(sf::Color::White);
|
|
|
|
}
|
|
|
|
|
2021-08-21 14:29:58 +02:00
|
|
|
void BPMCalculatorWidget::input(const sf::Event& event)
|
2021-08-16 20:54:03 +02:00
|
|
|
{
|
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sf::Event::MouseButtonPressed:
|
|
|
|
if (isUnderMouse(event.mouseButton.x, event.mouseButton.y))
|
|
|
|
{
|
|
|
|
_pressed = true;
|
|
|
|
_button_content.setFillColor(sf::Color(155, 155, 155));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sf::Event::MouseButtonReleased:
|
|
|
|
if (_pressed)
|
|
|
|
{
|
|
|
|
_button_content.setFillColor(sf::Color::White);
|
|
|
|
_pressed = false;
|
|
|
|
if (isUnderMouse(event.mouseButton.x, event.mouseButton.y))
|
|
|
|
_on_click_callback();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget::input(event);
|
|
|
|
}
|
|
|
|
|
2021-08-21 14:29:58 +02:00
|
|
|
void BPMCalculatorWidget::update()
|
2021-08-16 20:54:03 +02:00
|
|
|
{
|
|
|
|
Widget::update();
|
|
|
|
}
|
|
|
|
|
2021-08-21 14:29:58 +02:00
|
|
|
void BPMCalculatorWidget::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
2021-08-16 20:54:03 +02:00
|
|
|
{
|
|
|
|
target.draw(_button_content, states);
|
|
|
|
target.draw(_button_text, states);
|
|
|
|
|
|
|
|
Widget::draw(target, states);
|
|
|
|
}
|
|
|
|
|
2021-08-21 14:29:58 +02:00
|
|
|
void BPMCalculatorWidget::setRect(const sf::FloatRect& rect)
|
2021-08-16 20:54:03 +02:00
|
|
|
{
|
|
|
|
_button_content.setPosition(rect.left, rect.top);
|
|
|
|
_button_content.setSize({rect.width, rect.height});
|
|
|
|
}
|
|
|
|
|
2021-08-21 14:29:58 +02:00
|
|
|
void BPMCalculatorWidget::setPosition(const sf::Vector2f &position)
|
2021-08-16 20:54:03 +02:00
|
|
|
{
|
|
|
|
_button_content.setPosition(position);
|
|
|
|
}
|
|
|
|
|
2021-08-21 14:29:58 +02:00
|
|
|
bool BPMCalculatorWidget::isUnderMouse(int mouse_x, int mouse_y) const
|
2021-08-16 20:54:03 +02:00
|
|
|
{
|
|
|
|
return _button_content.getGlobalBounds().contains(mouse_x, mouse_y);
|
|
|
|
}
|