ui: Adjust window size in case when glfwGetVideoMode fails (#328)

This commit is contained in:
Hajime Hoshi 2017-04-19 00:51:15 +09:00
parent 71f427ecbc
commit fb612a4b87
4 changed files with 27 additions and 0 deletions

View File

@ -194,6 +194,7 @@ func Run(width, height int, scale float64, title string, g GraphicsContext) erro
w, h := u.glfwSize() w, h := u.glfwSize()
x := (v.Width - w) / 2 x := (v.Width - w) / 2
y := (v.Height - h) / 3 y := (v.Height - h) / 3
x, y = adjustWindowPosition(x, y)
u.window.SetPos(x, y) u.window.SetPos(x, y)
return nil return nil
}); err != nil { }); err != nil {

View File

@ -25,3 +25,7 @@ func deviceScale() float64 {
func glfwScale() float64 { func glfwScale() float64 {
return deviceScale() return deviceScale()
} }
func adjustWindowPosition(x, y int) (int, int) {
return x, y
}

View File

@ -36,3 +36,7 @@ func deviceScale() float64 {
func glfwScale() float64 { func glfwScale() float64 {
return 1 return 1
} }
func adjustWindowPosition(x, y int) (int, int) {
return x, y
}

View File

@ -30,6 +30,11 @@ package ui
// } // }
// return ""; // return "";
// } // }
//
// static int getCaptionHeight() {
// return GetSystemMetrics(SM_CYCAPTION);
// }
//
import "C" import "C"
func deviceScale() float64 { func deviceScale() float64 {
@ -43,3 +48,16 @@ func deviceScale() float64 {
func glfwScale() float64 { func glfwScale() float64 {
return deviceScale() return deviceScale()
} }
func adjustWindowPosition(x, y int) (int, int) {
// As the video width/height might be wrong,
// adjust x/y at least to enable to handle the window (#328)
if x < 0 {
x = 0
}
t := int(C.getCaptionHeight())
if y < t {
y = t
}
return x, y
}