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/pushbutton.cpp

41 lines
904 B
C++

#include "pushbutton.h"
PushButton::PushButton(const std::string& text) :
Button(text),
_pressed(false)
{}
void PushButton::input(const sf::Event& event)
{
Button::input(event);
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;
}
}
void PushButton::setCallback(std::function<void(void)> callback)
{
_on_click_callback = callback;
}