void States::SettingsState::handleEvent(const sf::Event& event)
{
if (event.type == sf::Event::KeyPressed)
{
auto& keyBindingSettings = App::KeyBindingSettings::getInstance();
auto mousePosition = window.mapPixelToCoords({ sf::Mouse::getPosition(window) });
if (moveUpButton->mouseOnWidget(mousePosition))
{
std::cout << "UPP\n";
}
else if (moveDownButton->mouseOnWidget(mousePosition))
{
std::cout << "Down\n";
}
else if (moveRightButton->mouseOnWidget(mousePosition))
{
std::cout << "Right\n";
}
else if (moveLeftButton->mouseOnWidget(mousePosition))
{
std::cout << "Left\n";
}
}
}
@BryanTriana TGUI widgets aren't really supposed to be queried directly. You would normally just pass the sf::Event to TGUI and connect the MouseEntered and MouseLeft signals on the buttons so that you get a callback when the mouse gets on top or leaves the buttons.
The code you showed might fail in 2 cases:
mousePosition - childWindow->getPosition() - childWindow->getChildWidgetsOffset()
to mouseOnWidget.window.mapPixelToCoords({ sf::Mouse::getPosition(window) }, gui.getView())
mousePosition - (button->getAbsolutePosition() - button->getPosition())
to mouseOnWidget. That should work no matter how many layers deep the button is placed.