From f7a8c7efa642ce755bdb8704d6525214522eef4d Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 5 Jun 2017 00:06:40 +0900 Subject: [PATCH] ui: Avoid recalc the scale factor --- internal/ui/ui_glfw.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 4dc8a13f8..43452c164 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -35,6 +35,7 @@ type userInterface struct { height int scale float64 deviceScale float64 + glfwScale float64 funcs chan func() running bool sizeChanged bool @@ -201,7 +202,10 @@ func Run(width, height int, scale float64, title string, g GraphicsContext) erro } func (u *userInterface) glfwSize() (int, int) { - return int(float64(u.width) * u.scale * glfwScale()), int(float64(u.height) * u.scale * glfwScale()) + if u.glfwScale == 0 { + u.glfwScale = glfwScale() + } + return int(float64(u.width) * u.scale * u.glfwScale), int(float64(u.height) * u.scale * u.glfwScale) } func (u *userInterface) actualScreenScale() float64 { @@ -213,7 +217,10 @@ func (u *userInterface) actualScreenScale() float64 { func (u *userInterface) pollEvents() { glfw.PollEvents() - currentInput.update(u.window, u.scale*glfwScale()) + if u.glfwScale == 0 { + u.glfwScale = glfwScale() + } + currentInput.update(u.window, u.scale*u.glfwScale) } func (u *userInterface) update(g GraphicsContext) error {