Example #1
0
func (t *TapRecognizer) OnChange(e *InputEvent) RecognizerState {
	if p, ok := (interface{})(e).(PointerEvent); ok {
		switch p.Type {
		case InputTypeUp:
			result := TapEvent{InputEvent{e.Target, InputTypeDown, e.modifier}, t.e.Position}
			Tap.Fire(result)
			t.down = false
			return RecognizerStateEnd
		case InputTypeMove:
			if math.Distance(p.Position, t.e.Position) > tapTolerance {
				t.down = false
				return RecognizerStateFail
			}
		}
	}
	return RecognizerStateFail
}
Example #2
0
func (r *PanRecognizer) OnPossible(e *InputEvent) RecognizerState {
	if p, ok := (interface{})(e).(PointerEvent); ok {
		if !r.down && p.Type == InputTypeDown {
			r.start = p
			r.last = p.Position
			r.down = true
			return RecognizerStatePossible
		} else if r.down && p.Type == InputTypeMove {
			if math.Distance(p.Position, r.start.Position) > startThreshold {
				r.last = p.Position
				result := PanEvent{InputEvent{e.Target, InputTypeDown, e.modifier},
					p.Position, p.Position.Subtract(r.start.Position)}
				Pan.Fire(result)
				return RecognizerStateActive
			} else {
				return RecognizerStatePossible
			}
		} else {
			r.down = false
			return RecognizerStateFail
		}
	}
	return RecognizerStateFail
}