From 623c050537f19e1d726bf414673be02ed6420875 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 9 Feb 2022 19:29:51 +0900 Subject: [PATCH] ebiten: rename SetKeepWindowAspectRatio -> SetWindowAspectRatioFixed Updates #1804 --- internal/glfw/glfw_notwindows.go | 4 ++-- internal/glfw/glfw_windows.go | 4 ++-- internal/ui/ui_glfw.go | 37 ++++++++++++++++---------------- internal/ui/window_glfw.go | 6 +++--- internal/ui/window_null.go | 2 +- window.go | 8 +++---- 6 files changed, 29 insertions(+), 32 deletions(-) diff --git a/internal/glfw/glfw_notwindows.go b/internal/glfw/glfw_notwindows.go index 58d85aa4e..b3070a118 100644 --- a/internal/glfw/glfw_notwindows.go +++ b/internal/glfw/glfw_notwindows.go @@ -208,9 +208,9 @@ func (w *Window) SetSizeLimits(minw, minh, maxw, maxh int) { w.w.SetSizeLimits(minw, minh, maxw, maxh) } -func (w *Window) SetKeepAspectRatio(keep bool) { +func (w *Window) SetAspectRatioFixed(fixed bool) { n, d := glfw.DontCare, glfw.DontCare - if keep { + if fixed { n, d = w.GetSize() } w.w.SetAspectRatio(n, d) diff --git a/internal/glfw/glfw_windows.go b/internal/glfw/glfw_windows.go index afcc8f853..380765ce5 100644 --- a/internal/glfw/glfw_windows.go +++ b/internal/glfw/glfw_windows.go @@ -261,9 +261,9 @@ func (w *Window) SetSizeLimits(minw, minh, maxw, maxh int) { panicError() } -func (w *Window) SetKeepAspectRatio(keep bool) { +func (w *Window) SetAspectRatioFixed(fixed bool) { n, d := -1, -1 - if keep { + if fixed { n, d = w.GetSize() } glfwDLL.call("glfwSetWindowAspectRatio", w.w, uintptr(n), uintptr(d)) diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index a6dd7db89..d7bd7bd82 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -85,19 +85,19 @@ 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 - initWindowKeepAspectRatio 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 + initWindowAspectRatioFixed 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) isInitWindowKeepAspectRatio() bool { +func (u *UserInterface) isInitWindowAspectRatioFixed() bool { u.m.RLock() - v := u.initWindowKeepAspectRatio + v := u.initWindowAspectRatioFixed u.m.RUnlock() return v } -func (u *UserInterface) setInitWindowKeepAspectRatio(keep bool) { +func (u *UserInterface) setInitWindowAspectRatioFixed(fixed bool) { u.m.Lock() - u.initWindowKeepAspectRatio = keep + u.initWindowAspectRatioFixed = fixed u.m.Unlock() } @@ -932,8 +932,7 @@ func (u *UserInterface) init() error { u.window.Maximize() } - keepAspectRatio := u.isInitWindowKeepAspectRatio() - u.window.SetKeepAspectRatio(keepAspectRatio) + u.window.SetAspectRatioFixed(u.isInitWindowAspectRatioFixed()) u.window.Show() diff --git a/internal/ui/window_glfw.go b/internal/ui/window_glfw.go index c0c234167..7ccb4cdb6 100644 --- a/internal/ui/window_glfw.go +++ b/internal/ui/window_glfw.go @@ -227,13 +227,13 @@ func (w *Window) SetSizeLimits(minw, minh, maxw, maxh int) { w.ui.t.Call(w.ui.updateWindowSizeLimits) } -func (w *Window) SetKeepAspectRatio(keep bool) { +func (w *Window) SetAspectRatioFixed(fixed bool) { if !w.ui.isRunning() { - w.ui.setInitWindowKeepAspectRatio(keep) + w.ui.setInitWindowAspectRatioFixed(fixed) return } w.ui.t.Call(func() { - w.ui.window.SetKeepAspectRatio(keep) + w.ui.window.SetAspectRatioFixed(fixed) }) } diff --git a/internal/ui/window_null.go b/internal/ui/window_null.go index b3d1ce543..ab95f7fc2 100644 --- a/internal/ui/window_null.go +++ b/internal/ui/window_null.go @@ -79,7 +79,7 @@ func (*Window) IsMinimized() bool { return false } -func (*Window) SetKeepAspectRatio(keep bool) { +func (*Window) SetAspectRatioFixed(fixed bool) { } func (*Window) SetIcon(iconImages []image.Image) { diff --git a/window.go b/window.go index 88fb9d1f6..42868bf36 100644 --- a/window.go +++ b/window.go @@ -72,11 +72,9 @@ func SetWindowResizable(resizable bool) { ui.Get().Window().SetResizable(resizable) } -// SetWindowKeepAspectRatio sets whether the window should keep its aspect ratio while resizing. -func SetWindowKeepAspectRatio(keep bool) { - if w := ui.Get().Window(); w != nil { - w.SetKeepAspectRatio(keep) - } +// SetWindowAspectRatioFixed sets whether the window should keep its aspect ratio while resizing. +func SetWindowAspectRatioFixed(fixed bool) { + ui.Get().Window().SetAspectRatioFixed(fixed) } // SetWindowTitle sets the title of the window.