mirror of
https://github.com/netbirdio/gomobile-tvos-fork.git
synced 2026-05-22 18:43:29 -07:00
event/{mouse,touch}: work in float32 pixels, not geom.Pt.
Higher-level widget or animation libraries should probably work in geom.Pt, but pixels instead of (1/72s of) inches seems a better fit for lower-level event libraries. Needlessly converting from (float32) pixels to (float32) points and back can be lossy and lead to off-by-one errors. Change-Id: I68102e36f2574b07b44c6a1b7281f4f27f9174cf Reviewed-on: https://go-review.googlesource.com/13002 Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
@@ -40,7 +40,6 @@ import (
|
||||
"golang.org/x/mobile/exp/app/debug"
|
||||
"golang.org/x/mobile/exp/f32"
|
||||
"golang.org/x/mobile/exp/gl/glutil"
|
||||
"golang.org/x/mobile/geom"
|
||||
"golang.org/x/mobile/gl"
|
||||
)
|
||||
|
||||
@@ -51,8 +50,9 @@ var (
|
||||
color gl.Uniform
|
||||
buf gl.Buffer
|
||||
|
||||
green float32
|
||||
touchLoc geom.Point
|
||||
green float32
|
||||
touchX float32
|
||||
touchY float32
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -69,12 +69,14 @@ func main() {
|
||||
}
|
||||
case config.Event:
|
||||
c = e
|
||||
touchLoc = geom.Point{c.WidthPt / 2, c.HeightPt / 2}
|
||||
touchX = float32(c.WidthPx / 2)
|
||||
touchY = float32(c.HeightPx / 2)
|
||||
case paint.Event:
|
||||
onPaint(c)
|
||||
a.EndPaint(e)
|
||||
case touch.Event:
|
||||
touchLoc = e.Loc
|
||||
touchX = e.X
|
||||
touchY = e.Y
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -117,7 +119,7 @@ func onPaint(c config.Event) {
|
||||
}
|
||||
gl.Uniform4f(color, 0, green, 0, 1)
|
||||
|
||||
gl.Uniform2f(offset, float32(touchLoc.X/c.WidthPt), float32(touchLoc.Y/c.HeightPt))
|
||||
gl.Uniform2f(offset, touchX/float32(c.WidthPx), touchY/float32(c.HeightPx))
|
||||
|
||||
gl.BindBuffer(gl.ARRAY_BUFFER, buf)
|
||||
gl.EnableVertexAttribArray(position)
|
||||
|
||||
Reference in New Issue
Block a user