I want to know if any widgets in a Gui have focus. If not, I allow my game engine to handle events. I currently do this by looping through all the widgets in the Gui. I was disappointed to see how Gui::hasFocus worked.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu#include <TGUI/TGUI.hpp>
#define THEME_CONFIG_FILE "widgets/Black.conf"
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI window");
tgui::Gui gui(window);
if (gui.setGlobalFont("fonts/DejaVuSans.ttf") == false)
return 1;
tgui::ChatBox::Ptr chatbox(gui);
chatbox->load(THEME_CONFIG_FILE);
chatbox->setSize(200, 100);
chatbox->setTextSize(20);
chatbox->setPosition(400, 25);
chatbox->addLine("Line 1", sf::Color::Red);
chatbox->addLine("Line 2", sf::Color::Blue);
chatbox->addLine("Line 3", sf::Color::Green);
chatbox->addLine("Line 4", sf::Color::Yellow);
chatbox->addLine("Line 5", sf::Color::Cyan);
chatbox->addLine("Line 6", sf::Color::Magenta);
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
gui.handleEvent(event);
}
window.clear();
gui.draw();
window.display();
}
return 0;
}
// Check for mouse wheel scrolling
else if (event.type == sf::Event::MouseWheelMoved)
{
// Find the widget under the mouse
Widget::Ptr widget = mouseOnWidget(static_cast<float>(event.mouseWheel.x), static_cast<float>(event.mouseWheel.y));
if (widget != nullptr)
{
// Send the event to the widget
widget->mouseWheelMoved(event.mouseWheel.delta, event.mouseWheel.x, event.mouseWheel.y);
return true;
}
return false;
}