ui: Bug fix: fix the initial window position on multiple monitors

This commit is contained in:
Hajime Hoshi 2018-10-14 16:59:14 +09:00
parent 13174cdb22
commit 0c4ef7ee8e

View File

@ -533,17 +533,20 @@ func Run(width, height int, scale float64, title string, g GraphicsContext, main
// current window will be the active window. Thus, currentMonitor retuls varies before and after // current window will be the active window. Thus, currentMonitor retuls varies before and after
// showing the window. // showing the window.
m := u.currentMonitor() m := u.currentMonitor()
mx, my := m.GetPos()
v := m.GetVideoMode()
// The game is in window mode (not fullscreen mode) at the first state. // The game is in window mode (not fullscreen mode) at the first state.
// Don't refer u.initFullscreen here to avoid some GLFW problems. // Don't refer u.initFullscreen here to avoid some GLFW problems.
u.setScreenSize(width, height, scale, false, u.vsync) u.setScreenSize(width, height, scale, false, u.vsync)
// Get the window size before showing since window.Show might change the current
// monitor which affects glfwSize result.
w, h := u.glfwSize()
u.title = title u.title = title
u.window.SetTitle(title) u.window.SetTitle(title)
u.window.Show() u.window.Show()
mx, my := m.GetPos()
v := m.GetVideoMode()
w, h := u.glfwSize()
x := mx + (v.Width-w)/2 x := mx + (v.Width-w)/2
y := my + (v.Height-h)/3 y := my + (v.Height-h)/3
x, y = adjustWindowPosition(x, y) x, y = adjustWindowPosition(x, y)