2021-08-24 21:03:58 +02:00
|
|
|
#include "cascademenubutton.h"
|
|
|
|
#include "menudrop.h"
|
|
|
|
|
2021-08-26 19:41:16 +02:00
|
|
|
CascadeMenuButton::CascadeMenuButton(const std::string& text, const std::shared_ptr<sf::Font> &font, unsigned int font_size) :
|
|
|
|
Button(text, font, font_size)
|
2021-08-26 20:36:09 +02:00
|
|
|
{
|
|
|
|
_color_idle = sf::Color(230, 230, 230);
|
|
|
|
_color_hover = sf::Color(84, 158, 253);
|
|
|
|
_button_content.setFillColor(_color_idle);
|
|
|
|
}
|
2021-08-24 21:03:58 +02:00
|
|
|
|
|
|
|
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:
|
2021-08-26 20:22:19 +02:00
|
|
|
if (isUnderMouse(event.mouseMove.x, event.mouseMove.y))
|
2021-08-24 21:03:58 +02:00
|
|
|
{
|
2021-08-26 20:36:09 +02:00
|
|
|
_button_content.setFillColor(_color_hover);
|
2021-08-24 21:03:58 +02:00
|
|
|
_submenu->lock();
|
2021-08-26 20:22:19 +02:00
|
|
|
_submenu->setVisibility(true);
|
2021-08-24 21:03:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_submenu->unlock();
|
2021-08-26 20:36:09 +02:00
|
|
|
if (!_submenu->isVisible())
|
|
|
|
{
|
|
|
|
_button_content.setFillColor(sf::Color(_color_idle));
|
|
|
|
}
|
2021-08-24 21:03:58 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2021-08-26 20:36:09 +02:00
|
|
|
|
|
|
|
void CascadeMenuButton::setFillColors(sf::Color&& idle_color, sf::Color&& hover_color)
|
|
|
|
{
|
|
|
|
_color_idle = idle_color;
|
|
|
|
_color_hover = hover_color;
|
|
|
|
}
|