ui: Add IsForeground API to glfw driver (#1058)

Updates #1037
This commit is contained in:
Zachary Burkett 2020-01-15 20:47:23 -05:00 committed by Hajime Hoshi
parent 6eb05a0203
commit 6686044452
5 changed files with 34 additions and 0 deletions

View File

@ -37,6 +37,7 @@ type UI interface {
DeviceScaleFactor() float64
CursorMode() CursorMode
IsFullscreen() bool
IsForeground() bool
IsRunnableInBackground() bool
IsVsyncEnabled() bool
ScreenSizeInFullscreen() (int, int)

View File

@ -402,6 +402,19 @@ func (u *UserInterface) SetFullscreen(fullscreen bool) {
u.setWindowSize(w, h, fullscreen, u.vsync)
}
func (u *UserInterface) IsForeground() bool {
if !u.isRunning() {
return false
}
var foreground bool
_ = u.t.Call(func() error {
foreground = u.window.GetAttrib(glfw.Focused) == glfw.True
return nil
})
return foreground
}
func (u *UserInterface) SetRunnableInBackground(runnableInBackground bool) {
u.setRunnableInBackground(runnableInBackground)
}

View File

@ -76,6 +76,11 @@ func (u *UserInterface) IsFullscreen() bool {
return false
}
func (u *UserInterface) IsForeground() bool {
// TODO: implement this
return true
}
func (u *UserInterface) SetRunnableInBackground(runnableInBackground bool) {
u.runnableInBackground = runnableInBackground
}

View File

@ -369,6 +369,11 @@ func (u *UserInterface) SetFullscreen(fullscreen bool) {
// Do nothing
}
func (u *UserInterface) IsForeground() {
// TODO: implement this
return true
}
func (u *UserInterface) IsRunnableInBackground() bool {
return false
}

10
run.go
View File

@ -346,6 +346,16 @@ func SetFullscreen(fullscreen bool) {
uiDriver().SetFullscreen(fullscreen)
}
// IsForeground returns a boolean value indicating whether
// the game is in focus or in the foreground.
//
// IsForeground will only return true if IsRunnableInBackground is false.
//
// IsForeground is concurrent-safe.
func IsForeground() bool {
return uiDriver().IsForeground()
}
// IsRunnableInBackground returns a boolean value indicating whether
// the game runs even in background.
//