From c4df397d876ed09028c732b624a8f2f1c662f552 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 12 Nov 2021 22:19:32 +0900 Subject: [PATCH] internal/uidriver/glfw: Refactoring --- internal/uidriver/glfw/input.go | 3 +-- internal/uidriver/glfw/ui.go | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/uidriver/glfw/input.go b/internal/uidriver/glfw/input.go index 5317cbcd3..fa6a82d1f 100644 --- a/internal/uidriver/glfw/input.go +++ b/internal/uidriver/glfw/input.go @@ -304,10 +304,9 @@ func (i *Input) update(window *glfw.Window, context driver.UIContext) { cx, cy := window.GetCursorPos() // TODO: This is tricky. Rename the function? m := i.ui.currentMonitor() - s := i.ui.deviceScaleFactor(m) cx = i.ui.dipFromGLFWPixel(cx, m) cy = i.ui.dipFromGLFWPixel(cy, m) - cx, cy = context.AdjustPosition(cx, cy, s) + cx, cy = context.AdjustPosition(cx, cy, i.ui.deviceScaleFactor()) // AdjustPosition can return NaN at the initialization. if !math.IsNaN(cx) && !math.IsNaN(cy) { diff --git a/internal/uidriver/glfw/ui.go b/internal/uidriver/glfw/ui.go index 977754155..8702aa591 100644 --- a/internal/uidriver/glfw/ui.go +++ b/internal/uidriver/glfw/ui.go @@ -684,20 +684,20 @@ func (u *UserInterface) SetCursorShape(shape driver.CursorShape) { func (u *UserInterface) DeviceScaleFactor() float64 { if !u.isRunning() { // TODO: Use the initWindowPosition. This requires to convert the units correctly (#1575). - return u.deviceScaleFactor(u.currentMonitor()) + return u.deviceScaleFactor() } f := 0.0 _ = u.t.Call(func() error { - f = u.deviceScaleFactor(u.currentMonitor()) + f = u.deviceScaleFactor() return nil }) return f } // deviceScaleFactor must be called from the main thread. -func (u *UserInterface) deviceScaleFactor(monitor *glfw.Monitor) float64 { - mx, my := monitor.GetPos() +func (u *UserInterface) deviceScaleFactor() float64 { + mx, my := u.currentMonitor().GetPos() return devicescale.GetAt(mx, my) } @@ -1213,7 +1213,7 @@ func (u *UserInterface) setWindowSizeInDIP(width, height int, fullscreen bool) { u.Graphics().SetFullscreen(fullscreen) - scale := u.deviceScaleFactor(u.currentMonitor()) + scale := u.deviceScaleFactor() if u.windowWidthInDIP == width && u.windowHeightInDIP == height && u.isFullscreen() == fullscreen && u.lastDeviceScaleFactor == scale { return }