Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / a Callback method when the user exits ?
- - By bestguigui Date 2015-07-31 07:18
Hi,

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 :

def allows_exit?
  if #(conditions are met)
    true
  else
    false # in this case, the window would still live
  end
end

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).
Parent - By RunnerPack Date 2015-08-01 00:40
+1
Parent - - By jlnr (dev) Date 2015-08-01 14:28
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.
Parent - By bestguigui Date 2015-08-01 17:39
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.
Parent - By RunnerPack Date 2015-12-11 02:12 Edited 2017-01-22 13:14
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".

EDIT:

I've thought about it some more. I think it would be more Ruby-ish to call it Window#close?.
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.).
Up Topic Gosu / Gosu Exchange / a Callback method when the user exits ?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill