2021-08-24 21:03:58 +02:00
|
|
|
#include "cascademenubutton.h"
|
|
|
|
#include "menudrop.h"
|
|
|
|
|
|
|
|
CascadeMenuButton::CascadeMenuButton(const std::string& text) :
|
|
|
|
Button(text)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void CascadeMenuButton::input(const sf::Event& event)
|
|
|
|
{
|
2021-08-26 18:54:30 +02:00
|
|
|
if (!_submenu)
|
|
|
|
return;
|
2021-08-24 21:03:58 +02:00
|
|
|
|
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sf::Event::MouseMoved:
|
|
|
|
if (isUnderMouse(event.mouseButton.x, event.mouseButton.y))
|
|
|
|
{
|
|
|
|
_button_content.setFillColor(sf::Color(84, 158, 253));
|
|
|
|
_submenu->lock();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_button_content.setFillColor(sf::Color::White);
|
|
|
|
_submenu->unlock();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-26 18:54:30 +02:00
|
|
|
void CascadeMenuButton::setRect(const sf::FloatRect& rect)
|
|
|
|
{
|
|
|
|
Button::setRect(rect);
|
|
|
|
resetRect(_submenu);
|
|
|
|
}
|
|
|
|
|
2021-08-24 21:03:58 +02:00
|
|
|
void CascadeMenuButton::setSubmenu(const std::shared_ptr<MenuDrop>& submenu)
|
|
|
|
{
|
|
|
|
_submenu = submenu;
|
2021-08-26 18:54:30 +02:00
|
|
|
resetRect(_submenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::shared_ptr<MenuDrop> CascadeMenuButton::submenu() const
|
|
|
|
{
|
|
|
|
return _submenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CascadeMenuButton::resetRect(const std::shared_ptr<MenuDrop>& submenu)
|
|
|
|
{
|
|
|
|
if (submenu)
|
|
|
|
{
|
|
|
|
submenu->setPosition({_button_content.getPosition().x + _button_content.getSize().x,
|
|
|
|
_button_content.getPosition().y});
|
|
|
|
}
|
2021-08-24 21:03:58 +02:00
|
|
|
}
|