mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
parent
180eb483bb
commit
18659ef4ab
@ -208,6 +208,14 @@ func (w *Window) SetSizeLimits(minw, minh, maxw, maxh int) {
|
||||
w.w.SetSizeLimits(minw, minh, maxw, maxh)
|
||||
}
|
||||
|
||||
func (w *Window) SetKeepAspectRatio(keep bool) {
|
||||
n, d := glfw.DontCare, glfw.DontCare
|
||||
if keep {
|
||||
n, d = w.GetSize()
|
||||
}
|
||||
w.w.SetAspectRatio(n, d)
|
||||
}
|
||||
|
||||
func (w *Window) SetIcon(images []image.Image) {
|
||||
w.w.SetIcon(images)
|
||||
}
|
||||
|
@ -261,6 +261,15 @@ func (w *Window) SetSizeLimits(minw, minh, maxw, maxh int) {
|
||||
panicError()
|
||||
}
|
||||
|
||||
func (w *Window) SetKeepAspectRatio(keep bool) {
|
||||
n, d := -1, -1
|
||||
if keep {
|
||||
n, d = w.GetSize()
|
||||
}
|
||||
glfwDLL.call("glfwSetWindowAspectRatio", w.w, uintptr(n), uintptr(d))
|
||||
panicError()
|
||||
}
|
||||
|
||||
func (w *Window) SetIcon(images []image.Image) {
|
||||
gimgs := make([]glfwImage, len(images))
|
||||
defer runtime.KeepAlive(gimgs)
|
||||
|
@ -85,18 +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
|
||||
initScreenTransparent bool
|
||||
initFocused bool
|
||||
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
|
||||
|
||||
fpsModeInited bool
|
||||
|
||||
@ -279,6 +280,19 @@ func (u *UserInterface) setWindowSizeLimitsInDIP(minw, minh, maxw, maxh int) boo
|
||||
return true
|
||||
}
|
||||
|
||||
func (u *UserInterface) isInitWindowKeepAspectRatio() bool {
|
||||
u.m.RLock()
|
||||
v := u.initWindowKeepAspectRatio
|
||||
u.m.RUnlock()
|
||||
return v
|
||||
}
|
||||
|
||||
func (u *UserInterface) setInitWindowKeepAspectRatio(keep bool) {
|
||||
u.m.Lock()
|
||||
u.initWindowKeepAspectRatio = keep
|
||||
u.m.Unlock()
|
||||
}
|
||||
|
||||
func (u *UserInterface) isInitFullscreen() bool {
|
||||
u.m.RLock()
|
||||
v := u.initFullscreen
|
||||
@ -918,6 +932,9 @@ func (u *UserInterface) init() error {
|
||||
u.window.Maximize()
|
||||
}
|
||||
|
||||
keepAspectRatio := u.isInitWindowKeepAspectRatio()
|
||||
u.window.SetKeepAspectRatio(keepAspectRatio)
|
||||
|
||||
u.window.Show()
|
||||
|
||||
if g, ok := Graphics().(interface{ SetWindow(uintptr) }); ok {
|
||||
|
@ -227,6 +227,16 @@ func (w *Window) SetSizeLimits(minw, minh, maxw, maxh int) {
|
||||
w.ui.t.Call(w.ui.updateWindowSizeLimits)
|
||||
}
|
||||
|
||||
func (w *Window) SetKeepAspectRatio(keep bool) {
|
||||
if !w.ui.isRunning() {
|
||||
w.ui.setInitWindowKeepAspectRatio(keep)
|
||||
return
|
||||
}
|
||||
w.ui.t.Call(func() {
|
||||
w.ui.window.SetKeepAspectRatio(keep)
|
||||
})
|
||||
}
|
||||
|
||||
func (w *Window) SetIcon(iconImages []image.Image) {
|
||||
// The icons are actually set at (*UserInterface).loop.
|
||||
w.ui.setIconImages(iconImages)
|
||||
|
@ -79,6 +79,9 @@ func (*Window) IsMinimized() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (*Window) SetKeepAspectRatio(keep bool) {
|
||||
}
|
||||
|
||||
func (*Window) SetIcon(iconImages []image.Image) {
|
||||
}
|
||||
|
||||
|
@ -72,6 +72,13 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
// SetWindowTitle sets the title of the window.
|
||||
//
|
||||
// SetWindowTitle does nothing on browsers or mobiles.
|
||||
|
Loading…
Reference in New Issue
Block a user