mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-12 22:17:26 +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
@ -48,6 +48,7 @@ var (
|
||||
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)")
|
||||
)
|
||||
@ -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 {
|
||||
|
@ -70,6 +70,7 @@ type UserInterface struct {
|
||||
cursorShape CursorShape
|
||||
windowClosingHandled bool
|
||||
windowBeingClosed bool
|
||||
windowAspectRatioFixed bool
|
||||
|
||||
// setSizeCallbackEnabled must be accessed from the main thread.
|
||||
setSizeCallbackEnabled bool
|
||||
@ -95,7 +96,6 @@ type UserInterface struct {
|
||||
initWindowHeightInDIP int
|
||||
initWindowFloating bool
|
||||
initWindowMaximized bool
|
||||
initWindowAspectRatioFixed bool
|
||||
initScreenTransparent bool
|
||||
initFocused 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)
|
||||
})
|
||||
}
|
||||
|
||||
func (w *Window) SetIcon(iconImages []image.Image) {
|
||||
|
Loading…
Reference in New Issue
Block a user