ebiten: add IsWindowAspectRatioFixed

This also updates examples/windowsize.

Closes #1804
This commit is contained in:
Hajime Hoshi 2022-02-09 20:06:15 +09:00
parent 7482cae978
commit 891ca2a08d
4 changed files with 23 additions and 1 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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) {
}

View File

@ -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.