mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
internal/ui: bug fix: the aspect ratio must be updated whenever the window size is forcibly updated
This also adds a new flag -aspectratiofixed to examples/windowsize Updates #1804
This commit is contained in:
parent
740dfd5aed
commit
7482cae978
@ -38,18 +38,19 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
flagFullscreen = flag.Bool("fullscreen", false, "fullscreen")
|
||||
flagResizable = flag.Bool("resizable", false, "make the window resizable")
|
||||
flagWindowPosition = flag.String("windowposition", "", "window position (e.g., 100,200)")
|
||||
flagTransparent = flag.Bool("transparent", false, "screen transparent")
|
||||
flagAutoAdjusting = flag.Bool("autoadjusting", false, "make the game screen auto-adjusting")
|
||||
flagFloating = flag.Bool("floating", false, "make the window floating")
|
||||
flagMaximize = flag.Bool("maximize", false, "maximize the window")
|
||||
flagVsync = flag.Bool("vsync", true, "enable vsync")
|
||||
flagAutoRestore = flag.Bool("autorestore", false, "restore the window automatically")
|
||||
flagInitFocused = flag.Bool("initfocused", true, "whether the window is focused on start")
|
||||
flagMinWindowSize = flag.String("minwindowsize", "", "minimum window size (e.g., 100x200)")
|
||||
flagMaxWindowSize = flag.String("maxwindowsize", "", "maximium window size (e.g., 1920x1080)")
|
||||
flagFullscreen = flag.Bool("fullscreen", false, "fullscreen")
|
||||
flagResizable = flag.Bool("resizable", false, "make the window resizable")
|
||||
flagWindowPosition = flag.String("windowposition", "", "window position (e.g., 100,200)")
|
||||
flagTransparent = flag.Bool("transparent", false, "screen transparent")
|
||||
flagAutoAdjusting = flag.Bool("autoadjusting", false, "make the game screen auto-adjusting")
|
||||
flagFloating = flag.Bool("floating", false, "make the window floating")
|
||||
flagMaximize = flag.Bool("maximize", false, "maximize the window")
|
||||
flagVsync = flag.Bool("vsync", true, "enable vsync")
|
||||
flagAutoRestore = flag.Bool("autorestore", false, "restore the window automatically")
|
||||
flagInitFocused = flag.Bool("initfocused", true, "whether the window is focused on start")
|
||||
flagAspectRatioFixed = flag.Bool("aspectratiofixed", false, "whether the window's aspect ratio is fixed or not")
|
||||
flagMinWindowSize = flag.String("minwindowsize", "", "minimum window size (e.g., 100x200)")
|
||||
flagMaxWindowSize = flag.String("maxwindowsize", "", "maximium window size (e.g., 1920x1080)")
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -426,6 +427,10 @@ func main() {
|
||||
ebiten.SetRunnableOnUnfocused(true)
|
||||
}
|
||||
|
||||
if *flagAspectRatioFixed {
|
||||
ebiten.SetWindowAspectRatioFixed(true)
|
||||
}
|
||||
|
||||
minw, minh, maxw, maxh := -1, -1, -1, -1
|
||||
reSize := regexp.MustCompile(`^(\d+)x(\d+)$`)
|
||||
if m := reSize.FindStringSubmatch(*flagMinWindowSize); m != nil {
|
||||
|
@ -61,15 +61,16 @@ type UserInterface struct {
|
||||
maxWindowWidthInDIP int
|
||||
maxWindowHeightInDIP int
|
||||
|
||||
running uint32
|
||||
origPosX int
|
||||
origPosY int
|
||||
runnableOnUnfocused bool
|
||||
fpsMode FPSMode
|
||||
iconImages []image.Image
|
||||
cursorShape CursorShape
|
||||
windowClosingHandled bool
|
||||
windowBeingClosed bool
|
||||
running uint32
|
||||
origPosX int
|
||||
origPosY int
|
||||
runnableOnUnfocused bool
|
||||
fpsMode FPSMode
|
||||
iconImages []image.Image
|
||||
cursorShape CursorShape
|
||||
windowClosingHandled bool
|
||||
windowBeingClosed bool
|
||||
windowAspectRatioFixed bool
|
||||
|
||||
// setSizeCallbackEnabled must be accessed from the main thread.
|
||||
setSizeCallbackEnabled bool
|
||||
@ -85,19 +86,18 @@ type UserInterface struct {
|
||||
initFullscreenWidthInDIP int
|
||||
initFullscreenHeightInDIP int
|
||||
|
||||
initFullscreen bool
|
||||
initCursorMode CursorMode
|
||||
initWindowDecorated bool
|
||||
initWindowResizable bool
|
||||
initWindowPositionXInDIP int
|
||||
initWindowPositionYInDIP int
|
||||
initWindowWidthInDIP int
|
||||
initWindowHeightInDIP int
|
||||
initWindowFloating bool
|
||||
initWindowMaximized bool
|
||||
initWindowAspectRatioFixed bool
|
||||
initScreenTransparent bool
|
||||
initFocused bool
|
||||
initFullscreen bool
|
||||
initCursorMode CursorMode
|
||||
initWindowDecorated bool
|
||||
initWindowResizable bool
|
||||
initWindowPositionXInDIP int
|
||||
initWindowPositionYInDIP int
|
||||
initWindowWidthInDIP int
|
||||
initWindowHeightInDIP int
|
||||
initWindowFloating bool
|
||||
initWindowMaximized bool
|
||||
initScreenTransparent bool
|
||||
initFocused bool
|
||||
|
||||
fpsModeInited bool
|
||||
|
||||
@ -280,16 +280,16 @@ func (u *UserInterface) setWindowSizeLimitsInDIP(minw, minh, maxw, maxh int) boo
|
||||
return true
|
||||
}
|
||||
|
||||
func (u *UserInterface) isInitWindowAspectRatioFixed() bool {
|
||||
func (u *UserInterface) isWindowAspectRatioFixed() bool {
|
||||
u.m.RLock()
|
||||
v := u.initWindowAspectRatioFixed
|
||||
v := u.windowAspectRatioFixed
|
||||
u.m.RUnlock()
|
||||
return v
|
||||
}
|
||||
|
||||
func (u *UserInterface) setInitWindowAspectRatioFixed(fixed bool) {
|
||||
func (u *UserInterface) setWindowAspectRatioFixed(fixed bool) {
|
||||
u.m.Lock()
|
||||
u.initWindowAspectRatioFixed = fixed
|
||||
u.windowAspectRatioFixed = fixed
|
||||
u.m.Unlock()
|
||||
}
|
||||
|
||||
@ -932,8 +932,6 @@ func (u *UserInterface) init() error {
|
||||
u.window.Maximize()
|
||||
}
|
||||
|
||||
u.setWindowAspectRatioFixed(u.isInitWindowAspectRatioFixed())
|
||||
|
||||
u.window.Show()
|
||||
|
||||
if g, ok := Graphics().(interface{ SetWindow(uintptr) }); ok {
|
||||
@ -1306,6 +1304,12 @@ func (u *UserInterface) setWindowSizeInDIPImpl(width, height int, fullscreen boo
|
||||
}
|
||||
}
|
||||
|
||||
n, d := glfw.DontCare, glfw.DontCare
|
||||
if !fullscreen && u.isWindowAspectRatioFixed() {
|
||||
n, d = u.window.GetSize()
|
||||
}
|
||||
u.window.SetAspectRatio(n, d)
|
||||
|
||||
return windowRecreated
|
||||
}
|
||||
|
||||
@ -1623,11 +1627,3 @@ func (u *UserInterface) setOrigPos(x, y int) {
|
||||
u.origPosX = x
|
||||
u.origPosY = y
|
||||
}
|
||||
|
||||
func (u *UserInterface) setWindowAspectRatioFixed(fixed bool) {
|
||||
n, d := glfw.DontCare, glfw.DontCare
|
||||
if fixed {
|
||||
n, d = u.window.GetSize()
|
||||
}
|
||||
u.window.SetAspectRatio(n, d)
|
||||
}
|
||||
|
@ -228,13 +228,7 @@ func (w *Window) SetSizeLimits(minw, minh, maxw, maxh int) {
|
||||
}
|
||||
|
||||
func (w *Window) SetAspectRatioFixed(fixed bool) {
|
||||
if !w.ui.isRunning() {
|
||||
w.ui.setInitWindowAspectRatioFixed(fixed)
|
||||
return
|
||||
}
|
||||
w.ui.t.Call(func() {
|
||||
w.ui.setWindowAspectRatioFixed(fixed)
|
||||
})
|
||||
w.ui.setWindowAspectRatioFixed(fixed)
|
||||
}
|
||||
|
||||
func (w *Window) SetIcon(iconImages []image.Image) {
|
||||
|
Loading…
Reference in New Issue
Block a user