ui: Adjust cursor positoin on fullscreen mode (#374)

This commit is contained in:
Hajime Hoshi 2017-07-01 04:27:38 +09:00
parent c694851765
commit ba204c6d3b
4 changed files with 23 additions and 1 deletions

View File

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

View File

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

View File

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

View File

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