From 5b6fa2d384a1e7ffc8233b3380dc9611d319508b Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 30 Jun 2017 01:39:15 +0900 Subject: [PATCH] ui: Adjust cursor position on fullscreen (#267) --- internal/ui/ui_glfw.go | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 73c42e42a..cf419bfa6 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -240,25 +240,29 @@ func (u *userInterface) glfwSize() (int, int) { return int(float64(u.width) * u.scale * u.glfwScale), int(float64(u.height) * u.scale * u.glfwScale) } +func (u *userInterface) getScale() float64 { + if !u.fullscreen { + return u.scale + } + if u.fullscreenScale == 0 { + m := glfw.GetPrimaryMonitor() + v := m.GetVideoMode() + sw := float64(v.Width) / float64(u.width) + sh := float64(v.Height) / float64(u.height) + s := sw + if s > sh { + s = sh + } + u.fullscreenScale = s + } + return u.fullscreenScale +} + func (u *userInterface) actualScreenScale() float64 { if u.deviceScale == 0 { u.deviceScale = deviceScale() } - if u.fullscreen { - if u.fullscreenScale == 0 { - m := glfw.GetPrimaryMonitor() - v := m.GetVideoMode() - sw := float64(v.Width) / float64(u.width) - sh := float64(v.Height) / float64(u.height) - s := sw - if s > sh { - s = sh - } - u.fullscreenScale = s - } - return u.fullscreenScale * u.deviceScale - } - return u.scale * u.deviceScale + return u.getScale() * u.deviceScale } func (u *userInterface) pollEvents() { @@ -266,7 +270,7 @@ func (u *userInterface) pollEvents() { if u.glfwScale == 0 { u.glfwScale = glfwScale() } - currentInput.update(u.window, u.scale*u.glfwScale) + currentInput.update(u.window, u.getScale()*u.glfwScale) } func (u *userInterface) update(g GraphicsContext) error {