diff --git a/examples/windowsize/main.go b/examples/windowsize/main.go index 488fd6f77..9344f8b5b 100644 --- a/examples/windowsize/main.go +++ b/examples/windowsize/main.go @@ -60,7 +60,7 @@ func init() { const ( initScreenWidth = 480 - initScreenHeight = 360 + initScreenHeight = 480 initScreenScale = 1 ) @@ -291,6 +291,10 @@ func (g *game) Update() error { ebiten.SetWindowIcon([]image.Image{createRandomIconImage()}) } + if inpututil.IsKeyJustPressed(ebiten.KeyA) { + ebiten.SetWindowAspectRatioFixed(!ebiten.IsWindowAspectRatioFixed()) + } + g.count++ return nil } @@ -344,6 +348,7 @@ func (g *game) Draw(screen *ebiten.Image) { [D] Switch the window decoration (only for desktops) [L] Switch the window floating state (only for desktops) [W] Switch whether to skip clearing the screen +[A] Switch whether to fix window aspect ratio (only for desktops) %s IsFocused?: %s Window Position: (%d, %d) diff --git a/internal/ui/window_glfw.go b/internal/ui/window_glfw.go index ddfbfb282..47e865078 100644 --- a/internal/ui/window_glfw.go +++ b/internal/ui/window_glfw.go @@ -231,6 +231,10 @@ func (w *Window) SetAspectRatioFixed(fixed bool) { w.ui.setWindowAspectRatioFixed(fixed) } +func (w *Window) IsAspectRatioFixed() bool { + return w.ui.isWindowAspectRatioFixed() +} + func (w *Window) SetIcon(iconImages []image.Image) { // The icons are actually set at (*UserInterface).loop. w.ui.setIconImages(iconImages) diff --git a/internal/ui/window_null.go b/internal/ui/window_null.go index ab95f7fc2..f8c05c158 100644 --- a/internal/ui/window_null.go +++ b/internal/ui/window_null.go @@ -82,6 +82,10 @@ func (*Window) IsMinimized() bool { func (*Window) SetAspectRatioFixed(fixed bool) { } +func (*Window) IsAspectRatioFixed() bool { + return false +} + func (*Window) SetIcon(iconImages []image.Image) { } diff --git a/window.go b/window.go index 42868bf36..00bb80584 100644 --- a/window.go +++ b/window.go @@ -73,10 +73,19 @@ func SetWindowResizable(resizable bool) { } // SetWindowAspectRatioFixed sets whether the window should keep its aspect ratio while resizing. +// +// SetWindowAspectRatioFixed is concurrent-safe. func SetWindowAspectRatioFixed(fixed bool) { ui.Get().Window().SetAspectRatioFixed(fixed) } +// IsWindowAspectRatioFixed reports whether the window should keep its aspect ratio while resizing. +// +// IsWindowAspectRatioFixed is concurrent-safe. +func IsWindowAspectRatioFixed() bool { + return ui.Get().Window().IsAspectRatioFixed() +} + // SetWindowTitle sets the title of the window. // // SetWindowTitle does nothing on browsers or mobiles.