I'm new to GTK3. I'm trying to design a multi-player game. I have a button to start a new game on my main window defined so:
Gtk::Button new_game;
And it's linked to its on_clicked function :
new_game.signal_clicked().connect(sigc::mem_fun(*this, &Window::onNewGameClicked));
And the function does the following:
void Window::onNewGameClicked(){
startGame();
}
startGame() keeps running till the game ends. Right now, once it's pressed, the new_game button remains pressed and I can't click any other button on the window. I need the new_game button to be released after it's pressed and the game starts. I do understand that the reason the button isn't released is because the function in it is running. But I really hope there's some way I can manually release the button, because the user should be able to press it again, while the game is in action.
Thanks.
GTK+ is an event-driven toolkit. It reacts to events, and sometimes let you react to those events (when you connect to signals). As you have one single thread, all the parts of your program, including its dependencies like GTK+, shares the CPU time.
Think of 2 workers trying to dig holes with only one shovel. GTK+ has the shovel and can dig. If you connected to a signal, GTK+ will call your callback, and give you the shovel so you can do your work. The problem is that you never exit the callback, so you never give back the shovel to GTK+, so the entire user interface is frozen.
startGame
can't be a blocking function. You need to split the game in steps that make sense, and when one of your callback is called, realize that you must return from it as soon as possible.