mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
ui: Stop the game when the window is deactivated (#230)
This commit is contained in:
parent
ff30f01c1b
commit
3ebc5cc15a
@ -30,6 +30,7 @@ type userInterface struct {
|
|||||||
deviceScale float64
|
deviceScale float64
|
||||||
sizeChanged bool
|
sizeChanged bool
|
||||||
contextRestored chan struct{}
|
contextRestored chan struct{}
|
||||||
|
windowFocus chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentUI = &userInterface{
|
var currentUI = &userInterface{
|
||||||
@ -81,6 +82,9 @@ func (u *userInterface) ActualScreenScale() float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterface) Update() (interface{}, error) {
|
func (u *userInterface) Update() (interface{}, error) {
|
||||||
|
if u.windowFocus != nil {
|
||||||
|
<-u.windowFocus
|
||||||
|
}
|
||||||
if u.contextRestored != nil {
|
if u.contextRestored != nil {
|
||||||
<-u.contextRestored
|
<-u.contextRestored
|
||||||
}
|
}
|
||||||
@ -151,6 +155,16 @@ func initialize() (*opengl.Context, error) {
|
|||||||
})
|
})
|
||||||
<-ch
|
<-ch
|
||||||
}
|
}
|
||||||
|
window.Call("addEventListener", "focus", func() {
|
||||||
|
if currentUI.windowFocus == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
close(currentUI.windowFocus)
|
||||||
|
currentUI.windowFocus = nil
|
||||||
|
})
|
||||||
|
window.Call("addEventListener", "blur", func() {
|
||||||
|
currentUI.windowFocus = make(chan struct{})
|
||||||
|
})
|
||||||
|
|
||||||
canvas = doc.Call("createElement", "canvas")
|
canvas = doc.Call("createElement", "canvas")
|
||||||
canvas.Set("width", 16)
|
canvas.Set("width", 16)
|
||||||
|
Loading…
Reference in New Issue
Block a user