would it be possible to add a new callback method to handle the case where the user leaves the gosu window ? Something that allows us to control to leave or not the program on some conditions ?
It could look like this :
if #(conditions are met)
false # in this case, the window would still live
We need this because we're doing some applications using Gosu, and we don't want the user to accidentally close the window (for example without saving the work at first).
This has been on my internal To Do list already, I've promoted it to a GitHub issue: https://github.com/gosu/gosu/issues/287
I don't think a boolean callback works here because you might want to show an in-game dialog box, and delay the decision by many frames.
Yes, you're right. But was about to handle it as a button_down(id) ? In fact, in SDL, it's kinda the case because you handle a SDL_QUIT event.
The callback would only be used to check whether closing should be allowed. It could set appropriate flags - so that the "Really quit?" dialog could be shown - then cancel the close. Other logic could then call "Window#close" when the decision to close has been made. Even if "Window#close" also triggers the callback (and I'm not sure it should), you could just set whatever flag the code in the callback checks so that it allows the window to close as normal. That's my take on it, anyway...
BTW, I think the callback should simply be called "closed".
I've thought about it some more. I think it would be more Ruby-ish to call it
Perhaps Gosu could even pass an argument indicating the reason for closing (e.g. the "X" button was clicked, the computer wants to shut down, Window#close was called, etc.).
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill