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 ( const (
initScreenWidth = 480 initScreenWidth = 480
initScreenHeight = 360 initScreenHeight = 480
initScreenScale = 1 initScreenScale = 1
) )
@ -291,6 +291,10 @@ func (g *game) Update() error {
ebiten.SetWindowIcon([]image.Image{createRandomIconImage()}) ebiten.SetWindowIcon([]image.Image{createRandomIconImage()})
} }
if inpututil.IsKeyJustPressed(ebiten.KeyA) {
ebiten.SetWindowAspectRatioFixed(!ebiten.IsWindowAspectRatioFixed())
}
g.count++ g.count++
return nil return nil
} }
@ -344,6 +348,7 @@ func (g *game) Draw(screen *ebiten.Image) {
[D] Switch the window decoration (only for desktops) [D] Switch the window decoration (only for desktops)
[L] Switch the window floating state (only for desktops) [L] Switch the window floating state (only for desktops)
[W] Switch whether to skip clearing the screen [W] Switch whether to skip clearing the screen
[A] Switch whether to fix window aspect ratio (only for desktops)
%s %s
IsFocused?: %s IsFocused?: %s
Window Position: (%d, %d) Window Position: (%d, %d)

View File

@ -231,6 +231,10 @@ func (w *Window) SetAspectRatioFixed(fixed bool) {
w.ui.setWindowAspectRatioFixed(fixed) w.ui.setWindowAspectRatioFixed(fixed)
} }
func (w *Window) IsAspectRatioFixed() bool {
return w.ui.isWindowAspectRatioFixed()
}
func (w *Window) SetIcon(iconImages []image.Image) { func (w *Window) SetIcon(iconImages []image.Image) {
// The icons are actually set at (*UserInterface).loop. // The icons are actually set at (*UserInterface).loop.
w.ui.setIconImages(iconImages) w.ui.setIconImages(iconImages)

View File

@ -82,6 +82,10 @@ func (*Window) IsMinimized() bool {
func (*Window) SetAspectRatioFixed(fixed bool) { func (*Window) SetAspectRatioFixed(fixed bool) {
} }
func (*Window) IsAspectRatioFixed() bool {
return false
}
func (*Window) SetIcon(iconImages []image.Image) { 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 sets whether the window should keep its aspect ratio while resizing.
//
// SetWindowAspectRatioFixed is concurrent-safe.
func SetWindowAspectRatioFixed(fixed bool) { func SetWindowAspectRatioFixed(fixed bool) {
ui.Get().Window().SetAspectRatioFixed(fixed) 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 sets the title of the window.
// //
// SetWindowTitle does nothing on browsers or mobiles. // SetWindowTitle does nothing on browsers or mobiles.