diff --git a/app/darwin_amd64.go b/app/darwin_amd64.go index f13f804..48df495 100644 --- a/app/darwin_amd64.go +++ b/app/darwin_amd64.go @@ -111,17 +111,17 @@ func startloop(ctx C.GLintptr) { go loop(ctx) } -var windowHeightPt geom.Pt +var windowHeightPx float32 //export setGeom func setGeom(ppp float32, widthPx, heightPx int) { pixelsPerPt = ppp - windowHeightPt = geom.Pt(float32(heightPx) / pixelsPerPt) + windowHeightPx = float32(heightPx) eventsIn <- config.Event{ WidthPx: widthPx, HeightPx: heightPx, WidthPt: geom.Pt(float32(widthPx) / pixelsPerPt), - HeightPt: windowHeightPt, + HeightPt: geom.Pt(float32(heightPx) / pixelsPerPt), PixelsPerPt: pixelsPerPt, } } @@ -133,12 +133,10 @@ var touchEvents struct { func sendTouch(t touch.Type, x, y float32) { eventsIn <- touch.Event{ + X: x, + Y: windowHeightPx - y, Sequence: 0, Type: t, - Loc: geom.Point{ - X: geom.Pt(x / pixelsPerPt), - Y: windowHeightPt - geom.Pt(y/pixelsPerPt), - }, } } diff --git a/app/darwin_armx.go b/app/darwin_armx.go index 69205f0..3639c7d 100644 --- a/app/darwin_armx.go +++ b/app/darwin_armx.go @@ -151,12 +151,10 @@ func sendTouch(cTouch, cTouchType uintptr, x, y float32) { } eventsIn <- touch.Event{ + X: x, + Y: y, Sequence: touch.Sequence(id), Type: t, - Loc: geom.Point{ - X: geom.Pt(x / pixelsPerPt), - Y: geom.Pt(y / pixelsPerPt), - }, } } diff --git a/app/internal/testapp/testapp.go b/app/internal/testapp/testapp.go index 4904d72..561a379 100644 --- a/app/internal/testapp/testapp.go +++ b/app/internal/testapp/testapp.go @@ -61,7 +61,7 @@ func main() { } a.EndPaint(e) case touch.Event: - comm.Send("touch", e.Type, e.Loc.X.Px(c.PixelsPerPt), e.Loc.Y.Px(c.PixelsPerPt)) + comm.Send("touch", e.Type, e.X, e.Y) } } }) diff --git a/app/loop_android.go b/app/loop_android.go index cda023b..5d6c3ca 100644 --- a/app/loop_android.go +++ b/app/loop_android.go @@ -218,12 +218,10 @@ func processEvent(e *C.AInputEvent) { t = upDownType } eventsIn <- touch.Event{ + X: float32(C.AMotionEvent_getX(e, i)), + Y: float32(C.AMotionEvent_getY(e, i)), Sequence: touch.Sequence(C.AMotionEvent_getPointerId(e, i)), Type: t, - Loc: geom.Point{ - X: geom.Pt(float32(C.AMotionEvent_getX(e, i)) / pixelsPerPt), - Y: geom.Pt(float32(C.AMotionEvent_getY(e, i)) / pixelsPerPt), - }, } } default: diff --git a/app/x11.go b/app/x11.go index 6a6173b..cb03439 100644 --- a/app/x11.go +++ b/app/x11.go @@ -90,12 +90,10 @@ func onResize(w, h int) { func sendTouch(t touch.Type, x, y float32) { eventsIn <- touch.Event{ + X: x, + Y: y, Sequence: 0, // TODO: button?? Type: t, - Loc: geom.Point{ - X: geom.Pt(x / pixelsPerPt), - Y: geom.Pt(y / pixelsPerPt), - }, } } diff --git a/event/mouse/mouse.go b/event/mouse/mouse.go index e5c5c3f..4e9ab58 100644 --- a/event/mouse/mouse.go +++ b/event/mouse/mouse.go @@ -11,18 +11,17 @@ import ( "fmt" "golang.org/x/mobile/event/key" - "golang.org/x/mobile/geom" ) // Event is a mouse event. type Event struct { + // X and Y are the mouse location, in pixels. + X, Y float32 + // Button is the mouse button being pressed or released. Its value may be // zero, for a mouse move or drag without any button change. Button Button - // Loc is the mouse location. - Loc geom.Point - // TODO: have a field to hold what other buttons are down, for detecting // drags or button-chords. diff --git a/event/touch/touch.go b/event/touch/touch.go index d95a86a..c91967b 100644 --- a/event/touch/touch.go +++ b/event/touch/touch.go @@ -14,20 +14,21 @@ package touch // import "golang.org/x/mobile/event/touch" import ( "fmt" - - "golang.org/x/mobile/geom" ) // Event is a touch event. -// -// The same Sequence is shared by all events in a sequence. A sequence begins -// with a single TypeBegin, is followed by zero or more TypeMoves, and ends -// with a single TypeEnd. A Sequence distinguishes concurrent sequences but its -// value is subsequently reused. type Event struct { + // X and Y are the touch location, in pixels. + X, Y float32 + + // Sequence is the sequence number. The same number is shared by all events + // in a sequence. A sequence begins with a single TypeBegin, is followed by + // zero or more TypeMoves, and ends with a single TypeEnd. A Sequence + // distinguishes concurrent sequences but its value is subsequently reused. Sequence Sequence - Type Type - Loc geom.Point + + // Type is the touch type. + Type Type } // Sequence identifies a sequence of touch events. diff --git a/example/basic/main.go b/example/basic/main.go index 666800d..8e39842 100644 --- a/example/basic/main.go +++ b/example/basic/main.go @@ -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)