From 56358fd0c445c55ea7ff0fcac56a480bc7b35c22 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 21 Mar 2020 00:08:40 +0900 Subject: [PATCH] ui: Rename IsForeground -> IsFocused Updates #1102 --- examples/windowsize/main.go | 4 ++-- internal/driver/ui.go | 2 +- internal/uidriver/glfw/ui.go | 8 ++++---- internal/uidriver/js/ui.go | 8 ++++---- internal/uidriver/mobile/ui.go | 4 ++-- run.go | 10 +++++----- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/windowsize/main.go b/examples/windowsize/main.go index 0bb062c3d..010129dd1 100644 --- a/examples/windowsize/main.go +++ b/examples/windowsize/main.go @@ -287,7 +287,7 @@ func (g *game) Update(screen *ebiten.Image) error { msgR = "Press R key to switch the window resizable state (only for desktops)\n" } fg := "Yes" - if !ebiten.IsForeground() { + if !ebiten.IsFocused() { fg = "No" } @@ -302,7 +302,7 @@ Press T key to switch TPS (ticks per second) Press D key to switch the window decoration (only for desktops) Press L key to switch the window floating state (only for desktops) %s -IsForeground?: %s +IsFocused?: %s Windows Position: (%d, %d) Cursor: (%d, %d) TPS: Current: %0.2f / Max: %s diff --git a/internal/driver/ui.go b/internal/driver/ui.go index 054cb06bf..305a04f99 100644 --- a/internal/driver/ui.go +++ b/internal/driver/ui.go @@ -37,7 +37,7 @@ type UI interface { DeviceScaleFactor() float64 CursorMode() CursorMode IsFullscreen() bool - IsForeground() bool + IsFocused() bool IsRunnableInBackground() bool IsVsyncEnabled() bool ScreenSizeInFullscreen() (int, int) diff --git a/internal/uidriver/glfw/ui.go b/internal/uidriver/glfw/ui.go index 181dd3f5f..0b7187c3f 100644 --- a/internal/uidriver/glfw/ui.go +++ b/internal/uidriver/glfw/ui.go @@ -416,17 +416,17 @@ func (u *UserInterface) SetFullscreen(fullscreen bool) { u.setWindowSize(w, h, fullscreen, u.vsync) } -func (u *UserInterface) IsForeground() bool { +func (u *UserInterface) IsFocused() bool { if !u.isRunning() { return false } - var foreground bool + var focused bool _ = u.t.Call(func() error { - foreground = u.window.GetAttrib(glfw.Focused) == glfw.True + focused = u.window.GetAttrib(glfw.Focused) == glfw.True return nil }) - return foreground + return focused } func (u *UserInterface) SetRunnableInBackground(runnableInBackground bool) { diff --git a/internal/uidriver/js/ui.go b/internal/uidriver/js/ui.go index d2c717e24..74576ef43 100644 --- a/internal/uidriver/js/ui.go +++ b/internal/uidriver/js/ui.go @@ -76,8 +76,8 @@ func (u *UserInterface) IsFullscreen() bool { return false } -func (u *UserInterface) IsForeground() bool { - return u.isForeground() +func (u *UserInterface) IsFocused() bool { + return u.isFocused() } func (u *UserInterface) SetRunnableInBackground(runnableInBackground bool) { @@ -145,10 +145,10 @@ func (u *UserInterface) suspended() bool { if u.runnableInBackground { return false } - return !u.isForeground() + return !u.isFocused() } -func (u *UserInterface) isForeground() bool { +func (u *UserInterface) isFocused() bool { if !document.Call("hasFocus").Bool() { return false } diff --git a/internal/uidriver/mobile/ui.go b/internal/uidriver/mobile/ui.go index ebeb3a345..f15cc7214 100644 --- a/internal/uidriver/mobile/ui.go +++ b/internal/uidriver/mobile/ui.go @@ -74,7 +74,7 @@ func (u *UserInterface) Update() error { default: } - if !u.IsForeground() { + if !u.IsFocused() { return nil } @@ -398,7 +398,7 @@ func (u *UserInterface) SetFullscreen(fullscreen bool) { // Do nothing } -func (u *UserInterface) IsForeground() bool { +func (u *UserInterface) IsFocused() bool { u.m.Lock() fg := u.foreground u.m.Unlock() diff --git a/run.go b/run.go index 7c13f20af..7bc994c74 100644 --- a/run.go +++ b/run.go @@ -359,14 +359,14 @@ func SetFullscreen(fullscreen bool) { uiDriver().SetFullscreen(fullscreen) } -// IsForeground returns a boolean value indicating whether +// IsFocused returns a boolean value indicating whether // the game is in focus or in the foreground. // -// IsForeground will only return true if IsRunnableInBackground is false. +// IsFocused will only return true if IsRunnableInBackground is false. // -// IsForeground is concurrent-safe. -func IsForeground() bool { - return uiDriver().IsForeground() +// IsFocused is concurrent-safe. +func IsFocused() bool { + return uiDriver().IsFocused() } // IsRunnableInBackground returns a boolean value indicating whether