ui: Forbid RestoreWindow when the window is not maximized nor minimized

Fixes #1124
This commit is contained in:
Hajime Hoshi 2020-03-31 02:48:19 +09:00
parent b470dace1a
commit 161d8aae8f
2 changed files with 14 additions and 1 deletions

View File

@ -231,7 +231,10 @@ func (g *game) Update(screen *ebiten.Image) error {
}
maximize := inpututil.IsKeyJustPressed(ebiten.KeyM)
minimize := inpututil.IsKeyJustPressed(ebiten.KeyN)
restore := inpututil.IsKeyJustPressed(ebiten.KeyE)
restore := false
if ebiten.IsWindowMaximized() || ebiten.IsWindowMinimized() {
restore = inpututil.IsKeyJustPressed(ebiten.KeyE)
}
if toUpdateWindowSize {
if *flagLegacy {

View File

@ -278,10 +278,15 @@ func MaximizeWindow() {
// IsWindowMaximized reports whether the window is maximized or not.
//
// IsWindowMaximized returns false when the window is not resizable.
//
// IsWindowMaximized always returns false on browsers and mobiles.
//
// IsWindowMaximized is concurrent-safe.
func IsWindowMaximized() bool {
if !IsWindowResizable() {
return false
}
if w := uiDriver().Window(); w != nil {
return w.IsMaximized()
}
@ -315,8 +320,13 @@ func IsWindowMinimized() bool {
// RestoreWindow restores the window from its maximized or minimized state.
//
// RestoreWindow panics when the window is not maximized nor minimized.
//
// RestoreWindow is concurrent-safe.
func RestoreWindow() {
if !IsWindowMaximized() && !IsWindowMinimized() {
panic("ebiten: RestoreWindow must be called on a maximized or a minimized window")
}
if w := uiDriver().Window(); w != nil {
w.Restore()
}