event: delete TouchType in favor of Change.
Change-Id: I8772c8d2690fbe6b636f1dcafe1393f6810d6716 Reviewed-on: https://go-review.googlesource.com/11822 Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
parent
f464c65ce4
commit
15dc27054b
|
@ -82,10 +82,10 @@ var touchEvents struct {
|
|||
pending []event.Touch
|
||||
}
|
||||
|
||||
func sendTouch(ty event.TouchType, x, y float32) {
|
||||
func sendTouch(c event.Change, x, y float32) {
|
||||
eventsIn <- event.Touch{
|
||||
ID: 0,
|
||||
Type: ty,
|
||||
Change: c,
|
||||
Loc: geom.Point{
|
||||
X: geom.Pt(x / pixelsPerPt),
|
||||
Y: windowHeight - geom.Pt(y/pixelsPerPt),
|
||||
|
@ -94,13 +94,13 @@ func sendTouch(ty event.TouchType, x, y float32) {
|
|||
}
|
||||
|
||||
//export eventMouseDown
|
||||
func eventMouseDown(x, y float32) { sendTouch(event.TouchStart, x, y) }
|
||||
func eventMouseDown(x, y float32) { sendTouch(event.ChangeOn, x, y) }
|
||||
|
||||
//export eventMouseDragged
|
||||
func eventMouseDragged(x, y float32) { sendTouch(event.TouchMove, x, y) }
|
||||
func eventMouseDragged(x, y float32) { sendTouch(event.ChangeNone, x, y) }
|
||||
|
||||
//export eventMouseEnd
|
||||
func eventMouseEnd(x, y float32) { sendTouch(event.TouchEnd, x, y) }
|
||||
func eventMouseEnd(x, y float32) { sendTouch(event.ChangeOff, x, y) }
|
||||
|
||||
var startedgl = false
|
||||
|
||||
|
|
|
@ -117,7 +117,7 @@ var touchEvents struct {
|
|||
}
|
||||
|
||||
//export sendTouch
|
||||
func sendTouch(touch uintptr, touchType int, x, y float32) {
|
||||
func sendTouch(touch, change uintptr, x, y float32) {
|
||||
id := -1
|
||||
for i, val := range touchIDs {
|
||||
if val == touch {
|
||||
|
@ -138,14 +138,14 @@ func sendTouch(touch uintptr, touchType int, x, y float32) {
|
|||
}
|
||||
}
|
||||
|
||||
ty := event.TouchType(touchType)
|
||||
if ty == event.TouchEnd {
|
||||
c := event.Change(change)
|
||||
if c == event.ChangeOff {
|
||||
touchIDs[id] = 0
|
||||
}
|
||||
|
||||
eventsIn <- event.Touch{
|
||||
ID: event.TouchSequenceID(id),
|
||||
Type: ty,
|
||||
Change: c,
|
||||
Loc: geom.Point{
|
||||
X: geom.Pt(x / pixelsPerPt),
|
||||
Y: geom.Pt(y / pixelsPerPt),
|
||||
|
|
|
@ -65,28 +65,28 @@ struct utsname sysInfo;
|
|||
drawgl((GoUintptr)self.context);
|
||||
}
|
||||
|
||||
#define TOUCH_START 0 // event.TouchStart
|
||||
#define TOUCH_MOVE 1 // event.TouchMove
|
||||
#define TOUCH_END 2 // event.TouchEnd
|
||||
#define CHANGE_NONE 0 // event.ChangeNone
|
||||
#define CHANGE_ON 1 // event.ChangeOn
|
||||
#define CHANGE_OFF 2 // event.ChangeOff
|
||||
|
||||
static void sendTouches(int ty, NSSet* touches) {
|
||||
static void sendTouches(int change, NSSet* touches) {
|
||||
CGFloat scale = [UIScreen mainScreen].scale;
|
||||
for (UITouch* touch in touches) {
|
||||
CGPoint p = [touch locationInView:touch.view];
|
||||
sendTouch((GoUintptr)touch, ty, p.x*scale, p.y*scale);
|
||||
sendTouch((GoUintptr)touch, (GoUintptr)change, p.x*scale, p.y*scale);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
|
||||
sendTouches(TOUCH_START, touches);
|
||||
sendTouches(CHANGE_ON, touches);
|
||||
}
|
||||
|
||||
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
|
||||
sendTouches(TOUCH_MOVE, touches);
|
||||
sendTouches(CHANGE_NONE, touches);
|
||||
}
|
||||
|
||||
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
|
||||
sendTouches(TOUCH_END, touches);
|
||||
sendTouches(CHANGE_OFF, touches);
|
||||
}
|
||||
@end
|
||||
|
||||
|
|
|
@ -171,24 +171,24 @@ func processEvent(e *C.AInputEvent) {
|
|||
case C.AINPUT_EVENT_TYPE_KEY:
|
||||
log.Printf("TODO input event: key")
|
||||
case C.AINPUT_EVENT_TYPE_MOTION:
|
||||
// At most one of the events in this batch is an up or down event; get its index and type.
|
||||
// At most one of the events in this batch is an up or down event; get its index and change.
|
||||
upDownIndex := C.size_t(C.AMotionEvent_getAction(e)&C.AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> C.AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT
|
||||
upDownTyp := event.TouchMove
|
||||
upDownChange := event.ChangeNone
|
||||
switch C.AMotionEvent_getAction(e) & C.AMOTION_EVENT_ACTION_MASK {
|
||||
case C.AMOTION_EVENT_ACTION_DOWN, C.AMOTION_EVENT_ACTION_POINTER_DOWN:
|
||||
upDownTyp = event.TouchStart
|
||||
upDownChange = event.ChangeOn
|
||||
case C.AMOTION_EVENT_ACTION_UP, C.AMOTION_EVENT_ACTION_POINTER_UP:
|
||||
upDownTyp = event.TouchEnd
|
||||
upDownChange = event.ChangeOff
|
||||
}
|
||||
|
||||
for i, n := C.size_t(0), C.AMotionEvent_getPointerCount(e); i < n; i++ {
|
||||
typ := event.TouchMove
|
||||
change := event.ChangeNone
|
||||
if i == upDownIndex {
|
||||
typ = upDownTyp
|
||||
change = upDownChange
|
||||
}
|
||||
eventsIn <- event.Touch{
|
||||
ID: event.TouchSequenceID(C.AMotionEvent_getPointerId(e, i)),
|
||||
Type: typ,
|
||||
Change: change,
|
||||
Loc: geom.Point{
|
||||
X: geom.Pt(float32(C.AMotionEvent_getX(e, i)) / pixelsPerPt),
|
||||
Y: geom.Pt(float32(C.AMotionEvent_getY(e, i)) / pixelsPerPt),
|
||||
|
|
10
app/x11.go
10
app/x11.go
|
@ -98,10 +98,10 @@ func onResize(w, h int) {
|
|||
}
|
||||
}
|
||||
|
||||
func sendTouch(ty event.TouchType, x, y float32) {
|
||||
func sendTouch(c event.Change, x, y float32) {
|
||||
eventsIn <- event.Touch{
|
||||
ID: 0, // TODO: button??
|
||||
Type: ty,
|
||||
Change: c,
|
||||
Loc: geom.Point{
|
||||
X: geom.Pt(x / pixelsPerPt),
|
||||
Y: geom.Pt(y / pixelsPerPt),
|
||||
|
@ -110,13 +110,13 @@ func sendTouch(ty event.TouchType, x, y float32) {
|
|||
}
|
||||
|
||||
//export onTouchStart
|
||||
func onTouchStart(x, y float32) { sendTouch(event.TouchStart, x, y) }
|
||||
func onTouchStart(x, y float32) { sendTouch(event.ChangeOn, x, y) }
|
||||
|
||||
//export onTouchMove
|
||||
func onTouchMove(x, y float32) { sendTouch(event.TouchMove, x, y) }
|
||||
func onTouchMove(x, y float32) { sendTouch(event.ChangeNone, x, y) }
|
||||
|
||||
//export onTouchEnd
|
||||
func onTouchEnd(x, y float32) { sendTouch(event.TouchEnd, x, y) }
|
||||
func onTouchEnd(x, y float32) { sendTouch(event.ChangeOff, x, y) }
|
||||
|
||||
var stopped bool
|
||||
|
||||
|
|
|
@ -36,8 +36,6 @@ package event // import "golang.org/x/mobile/event"
|
|||
// TODO: keyboard events.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/mobile/geom"
|
||||
)
|
||||
|
||||
|
@ -181,60 +179,27 @@ func (l LifecycleStage) String() string {
|
|||
}
|
||||
}
|
||||
|
||||
// On Android, Touch is an AInputEvent with AINPUT_EVENT_TYPE_MOTION:
|
||||
// - ChangeOn is an AMOTION_EVENT_ACTION_DOWN.
|
||||
// - ChangeNone is an AMOTION_EVENT_ACTION_MOVE.
|
||||
// - ChangeOff is an AMOTION_EVENT_ACTION_UP.
|
||||
//
|
||||
// On iOS, Touch is the UIEvent delivered to a UIView:
|
||||
// - ChangeOn is a call to touchesBegan.
|
||||
// - ChangeNone is a call to touchesMoved.
|
||||
// - ChangeOff is a call to touchesEnded.
|
||||
|
||||
// Touch is a user touch event.
|
||||
//
|
||||
// The same ID is shared by all events in a sequence. A sequence starts with a
|
||||
// single TouchStart, is followed by zero or more TouchMoves, and ends with a
|
||||
// single TouchEnd. An ID distinguishes concurrent sequences but is
|
||||
// subsequently reused.
|
||||
//
|
||||
// On Android, Touch is an AInputEvent with AINPUT_EVENT_TYPE_MOTION.
|
||||
// On iOS, Touch is the UIEvent delivered to a UIView.
|
||||
// single ChangeOn (a touch start), is followed by zero or more ChangeNones
|
||||
// (touch moves), and ends with a single ChangeOff (a touch end). An ID
|
||||
// distinguishes concurrent sequences but is subsequently reused.
|
||||
type Touch struct {
|
||||
ID TouchSequenceID
|
||||
Type TouchType
|
||||
Change Change
|
||||
Loc geom.Point
|
||||
}
|
||||
|
||||
func (t Touch) String() string {
|
||||
var ty string
|
||||
switch t.Type {
|
||||
case TouchStart:
|
||||
ty = "start"
|
||||
case TouchMove:
|
||||
ty = "move "
|
||||
case TouchEnd:
|
||||
ty = "end "
|
||||
}
|
||||
return fmt.Sprintf("Touch{ %s, %s }", ty, t.Loc)
|
||||
}
|
||||
|
||||
// TouchSequenceID identifies a sequence of Touch events.
|
||||
type TouchSequenceID int64
|
||||
|
||||
// TODO: change TouchType to Change.
|
||||
|
||||
// TouchType describes the type of a touch event.
|
||||
type TouchType byte
|
||||
|
||||
const (
|
||||
// TouchStart is a user first touching the device.
|
||||
//
|
||||
// On Android, this is a AMOTION_EVENT_ACTION_DOWN.
|
||||
// On iOS, this is a call to touchesBegan.
|
||||
TouchStart TouchType = iota
|
||||
|
||||
// TouchMove is a user dragging across the device.
|
||||
//
|
||||
// A TouchMove is delivered between a TouchStart and TouchEnd.
|
||||
//
|
||||
// On Android, this is a AMOTION_EVENT_ACTION_MOVE.
|
||||
// On iOS, this is a call to touchesMoved.
|
||||
TouchMove
|
||||
|
||||
// TouchEnd is a user no longer touching the device.
|
||||
//
|
||||
// On Android, this is a AMOTION_EVENT_ACTION_UP.
|
||||
// On iOS, this is a call to touchesEnded.
|
||||
TouchEnd
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue