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

53 lines
1.1 KiB
C++

#include "menubar.h"
#include "iostream"
MenuBar::MenuBar()
{
}
void MenuBar::input(const sf::Event &event)
{
Widget::input(event);
for (const auto& bar_button : _bar_buttons)
bar_button->input(event);
}
void MenuBar::update()
{
Widget::update();
}
void MenuBar::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
Widget::draw(target, states);
target.draw(_bar_rect, states);
for (const auto& bar_button : _bar_buttons)
target.draw(*bar_button, states);
}
void MenuBar::setRect(const sf::FloatRect& rect)
{
_bar_rect.setPosition(rect.left, rect.top);
_bar_rect.setSize({rect.width, rect.height});
int x = 0;
int button_width = 100;
for (const auto& bar_button : _bar_buttons)
{
bar_button->setRect(sf::FloatRect(x, 0, button_width, _bar_rect.getSize().y));
x += button_width;
}
}
void MenuBar::setPosition(const sf::Vector2f& position)
{
_bar_rect.setPosition(position);
}
bool MenuBar::isUnderMouse(int mouse_x, int mouse_y) const
{
return _bar_rect.getGlobalBounds().contains(mouse_x, mouse_y);
}