internal/uidriver/glfw: Refactoring

This commit is contained in:
Hajime Hoshi 2021-11-12 22:19:32 +09:00
parent b6cf95f5bb
commit c4df397d87
2 changed files with 6 additions and 7 deletions

View File

@ -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) {

View File

@ -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
}