mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
internal/ui: give up SetWindowAspectRatioFixed
Unfortunately, it is almost impossible to provide a consistent behavior to keep the aspect ratio of the window on Windows. Instead of having an incomplete API, let's remove this. Closes #1988
This commit is contained in:
parent
2773d2456d
commit
35b9dd0846
@ -48,7 +48,6 @@ 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)")
|
||||
)
|
||||
@ -291,10 +290,6 @@ func (g *game) Update() error {
|
||||
ebiten.SetWindowIcon([]image.Image{createRandomIconImage()})
|
||||
}
|
||||
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyA) {
|
||||
ebiten.SetWindowAspectRatioFixed(!ebiten.IsWindowAspectRatioFixed())
|
||||
}
|
||||
|
||||
g.count++
|
||||
return nil
|
||||
}
|
||||
@ -348,7 +343,6 @@ 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)
|
||||
@ -432,10 +426,6 @@ 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,7 +70,6 @@ type UserInterface struct {
|
||||
cursorShape CursorShape
|
||||
windowClosingHandled bool
|
||||
windowBeingClosed bool
|
||||
windowAspectRatioFixed bool
|
||||
|
||||
// setSizeCallbackEnabled must be accessed from the main thread.
|
||||
setSizeCallbackEnabled bool
|
||||
@ -280,19 +279,6 @@ func (u *UserInterface) setWindowSizeLimitsInDIP(minw, minh, maxw, maxh int) boo
|
||||
return true
|
||||
}
|
||||
|
||||
func (u *UserInterface) isWindowAspectRatioFixed() bool {
|
||||
u.m.RLock()
|
||||
v := u.windowAspectRatioFixed
|
||||
u.m.RUnlock()
|
||||
return v
|
||||
}
|
||||
|
||||
func (u *UserInterface) setWindowAspectRatioFixed(fixed bool) {
|
||||
u.m.Lock()
|
||||
u.windowAspectRatioFixed = fixed
|
||||
u.m.Unlock()
|
||||
}
|
||||
|
||||
func (u *UserInterface) isInitFullscreen() bool {
|
||||
u.m.RLock()
|
||||
v := u.initFullscreen
|
||||
@ -1138,12 +1124,6 @@ func (u *UserInterface) swapBuffers() {
|
||||
|
||||
// updateWindowSizeLimits must be called from the main thread.
|
||||
func (u *UserInterface) updateWindowSizeLimits() {
|
||||
aspectRatio := 0.0
|
||||
if !u.isFullscreen() && u.isWindowAspectRatioFixed() {
|
||||
w, h := u.window.GetSize()
|
||||
aspectRatio = float64(h) / float64(w)
|
||||
}
|
||||
|
||||
m := u.currentMonitor()
|
||||
minw, minh, maxw, maxh := u.getWindowSizeLimitsInDIP()
|
||||
|
||||
@ -1154,11 +1134,7 @@ func (u *UserInterface) updateWindowSizeLimits() {
|
||||
minw = int(u.dipToGLFWPixel(float64(minw), m))
|
||||
}
|
||||
if minh < 0 {
|
||||
if aspectRatio > 0 {
|
||||
minh = int(float64(minw) * aspectRatio)
|
||||
} else {
|
||||
minh = glfw.DontCare
|
||||
}
|
||||
} else {
|
||||
minh = int(u.dipToGLFWPixel(float64(minh), m))
|
||||
}
|
||||
@ -1231,14 +1207,6 @@ func (u *UserInterface) setWindowSizeInDIP(width, height int, fullscreen bool) {
|
||||
|
||||
u.setWindowSizeInDIPImpl(width, height, fullscreen)
|
||||
|
||||
// TODO: This must be called just after the window is created.
|
||||
// This relies on the initial value of lastDeviceScaleFactor is 0 so this is called, but the condition is fragile.
|
||||
// Refactor this.
|
||||
n, d := glfw.DontCare, glfw.DontCare
|
||||
if !fullscreen && u.isWindowAspectRatioFixed() {
|
||||
n, d = width, height
|
||||
}
|
||||
u.window.SetAspectRatio(n, d)
|
||||
u.updateWindowSizeLimits()
|
||||
|
||||
u.adjustViewSize()
|
||||
|
@ -227,14 +227,6 @@ func (w *Window) SetSizeLimits(minw, minh, maxw, maxh int) {
|
||||
w.ui.t.Call(w.ui.updateWindowSizeLimits)
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -79,13 +79,6 @@ func (*Window) IsMinimized() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (*Window) SetAspectRatioFixed(fixed bool) {
|
||||
}
|
||||
|
||||
func (*Window) IsAspectRatioFixed() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (*Window) SetIcon(iconImages []image.Image) {
|
||||
}
|
||||
|
||||
|
14
window.go
14
window.go
@ -72,20 +72,6 @@ func SetWindowResizable(resizable bool) {
|
||||
ui.Get().Window().SetResizable(resizable)
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
Loading…
Reference in New Issue
Block a user