diff --git a/internal/ui/input.go b/internal/ui/input.go index 93bc71a44..7675b26ac 100644 --- a/internal/ui/input.go +++ b/internal/ui/input.go @@ -28,7 +28,7 @@ func CurrentInput() *Input { func (i *Input) CursorPosition() (x, y int) { i.m.RLock() defer i.m.RUnlock() - return i.cursorX, i.cursorY + return adjustCursorPosition(i.cursorX, i.cursorY) } func (i *Input) GamepadAxisNum(id int) int { diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 866e4e595..dab2049f7 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -214,6 +214,20 @@ func ScreenOffset() (float64, float64) { return ox, oy } +func adjustCursorPosition(x, y int) (int, int) { + u := currentUI + if !u.isRunning() { + return x, y + } + ox, oy := ScreenOffset() + s := 0.0 + _ = currentUI.runOnMainThread(func() error { + s = currentUI.actualScreenScale() + return nil + }) + return x - int(ox/s), y - int(oy/s) +} + func SetCursorVisibility(visible bool) { // This can be called before Run: change the state asyncly. go func() { diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index 65ec31f8a..f16b5e50d 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -70,6 +70,10 @@ func ScreenOffset() (float64, float64) { return 0, 0 } +func adjustCursorPosition(x, y int) (int, int) { + return x, y +} + func SetCursorVisibility(visibility bool) { if visibility { canvas.Get("style").Set("cursor", "auto") diff --git a/internal/ui/ui_mobile.go b/internal/ui/ui_mobile.go index ac0044d21..454e939ea 100644 --- a/internal/ui/ui_mobile.go +++ b/internal/ui/ui_mobile.go @@ -110,6 +110,10 @@ func ScreenOffset() (float64, float64) { return 0, 0 } +func adjustCursorPosition(x, y int) (int, int) { + return x, y +} + func SetCursorVisibility(visibility bool) { // Do nothing }