internal/uidriver/glfw, internal/devicescale: Add comments

This commit is contained in:
Hajime Hoshi 2021-04-17 15:45:46 +09:00
parent 585f173d1c
commit e89f53774c
2 changed files with 4 additions and 0 deletions

View File

@ -27,6 +27,8 @@ var (
cache = map[pos]float64{} cache = map[pos]float64{}
) )
// GetAt returns the device scale at (x, y).
// x and y are in device-dependent pixels.
func GetAt(x, y int) float64 { func GetAt(x, y int) float64 {
m.Lock() m.Lock()
defer m.Unlock() defer m.Unlock()

View File

@ -25,6 +25,7 @@ import (
// fromGLFWMonitorPixel must be called from the main thread. // fromGLFWMonitorPixel must be called from the main thread.
func fromGLFWMonitorPixel(x float64, deviceScale float64) float64 { func fromGLFWMonitorPixel(x float64, deviceScale float64) float64 {
// deviceScaleFactor is sometimes an unnice value (e.g., 1.502361). Use math.Ceil to clean the vaule.
return math.Ceil(x / deviceScale) return math.Ceil(x / deviceScale)
} }
@ -45,6 +46,7 @@ func (u *UserInterface) toGLFWPixel(x float64) float64 {
// toFramebufferPixel must be called from the main thread. // toFramebufferPixel must be called from the main thread.
func (u *UserInterface) toFramebufferPixel(x float64) float64 { func (u *UserInterface) toFramebufferPixel(x float64) float64 {
s, _ := currentMonitor(u.window).GetContentScale() s, _ := currentMonitor(u.window).GetContentScale()
// deviceScaleFactor is sometimes an unnice value (e.g., 1.502361). Use math.Ceil to clean the vaule.
return math.Ceil(x * float64(s) / u.deviceScaleFactor()) return math.Ceil(x * float64(s) / u.deviceScaleFactor())
} }