|
@@ -70,6 +70,10 @@ const OnBeforeRender = "util.application.OnBeforeRender"
|
|
|
// OnAfterRender is the event generated by Application just after rendering the scene/gui
|
|
// OnAfterRender is the event generated by Application just after rendering the scene/gui
|
|
|
const OnAfterRender = "util.application.OnAfterRender"
|
|
const OnAfterRender = "util.application.OnAfterRender"
|
|
|
|
|
|
|
|
|
|
+// OnQuit is the event generated by Application when the user tries to close the window
|
|
|
|
|
+// or the Quit() method is called.
|
|
|
|
|
+const OnQuit = "util.application.OnQuit"
|
|
|
|
|
+
|
|
|
// appInstance contains the pointer to the single Application instance
|
|
// appInstance contains the pointer to the single Application instance
|
|
|
var appInstance *Application
|
|
var appInstance *Application
|
|
|
|
|
|
|
@@ -421,7 +425,19 @@ func (app *Application) Run() error {
|
|
|
app.frameTime = time.Now()
|
|
app.frameTime = time.Now()
|
|
|
|
|
|
|
|
// Render loop
|
|
// Render loop
|
|
|
- for !app.win.ShouldClose() {
|
|
|
|
|
|
|
+ for true {
|
|
|
|
|
+ // If was requested to terminate the application by trying to close the window
|
|
|
|
|
+ // or by calling Quit(), dispatch OnQuit event for subscribers.
|
|
|
|
|
+ // If no subscriber cancelled the event, terminates the application.
|
|
|
|
|
+ if app.win.ShouldClose() {
|
|
|
|
|
+ canceled := app.Dispatch(OnQuit, nil)
|
|
|
|
|
+ if canceled {
|
|
|
|
|
+ app.win.SetShouldClose(false)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Starts measuring this frame
|
|
// Starts measuring this frame
|
|
|
app.frameRater.Start()
|
|
app.frameRater.Start()
|
|
|
|
|
|
|
@@ -521,7 +537,9 @@ func (app *Application) OpenDefaultAudioDevice() error {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Quit ends the application
|
|
|
|
|
|
|
+// Quit requests to terminate the application
|
|
|
|
|
+// Application will dispatch OnQuit events to registered subscriber which
|
|
|
|
|
+// can cancel the process by calling CancelDispatch().
|
|
|
func (app *Application) Quit() {
|
|
func (app *Application) Quit() {
|
|
|
|
|
|
|
|
app.win.SetShouldClose(true)
|
|
app.win.SetShouldClose(true)
|