internal override void Update(TouchEvent touchEvent) { if (touchEvent.Touches.Count == 0) { if (this.tapWatch.Elapsed <= tapTime) { TransitionToTapState(touchEvent); } else { TransitionToNullState(touchEvent); } } else if (touchEvent.Touches.Count == 1) { Touch pointer = touchEvent.Touches[0]; if (Moved(pointer.Location)) { TransitionToMoveState(touchEvent, pointer); } } else { TranstionToMultiDownState(touchEvent); } }
internal override void Update(TouchEvent touchEvent) { if (touchEvent.Touches.Count == 1) { this.machine.ChangeState(new MoveState(this.machine, this.manager), touchEvent); } else if (touchEvent.Touches.Count == 2) { int delta; if (IsPinch(touchEvent, out delta)) { this.manager.OnPinch(delta); } else { Move(touchEvent); } } else if (touchEvent.Touches.Count > 0) { Move(touchEvent); } else { this.machine.ChangeState(new NullState(machine, manager), null); } this.prevEvent = touchEvent; }
private void Move(TouchEvent touchEvent) { Touch currPointer = touchEvent.Touches[0]; this.manager.OnMove((int)(this.prevPointer.Location.X - currPointer.Location.X), (int)(this.prevPointer.Location.Y - currPointer.Location.Y)); this.prevPointer = currPointer; }
internal void ChangeState(TouchState newState, TouchEvent te) { Console.WriteLine("{0} to {1}", state, newState); if (this.state != null) this.state.Exit(te); this.state = newState; this.state.Enter(te); }
internal override void Enter(TouchEvent touchEvent) { nextTapTimer = new Timer(doubleTapTimeIntervall); nextTapTimer.AutoReset = false; nextTapTimer.Elapsed += (s, e) => { this.machine.ChangeState(new NullState(this.machine, this.manager), null); }; nextTapTimer.Start(); }
internal override void Update(TouchEvent touchEvent) { if (touchEvent.Touches.Count == 1) { this.machine.ChangeState(new DownState(this.machine, this.manager), touchEvent); } else { this.machine.ChangeState(new MultiDownState(this.machine, this.manager), touchEvent); } }
internal override void Update(TouchEvent touchEvent) { if (touchEvent.Touches.Count > 0) { Move(touchEvent); } else { this.manager.OnUp(); this.machine.ChangeState(new NullState(this.machine, this.manager), touchEvent); } }
internal override void Enter(TouchEvent touchEvent) { this.startPointer = touchEvent.Touches[0]; this.longTapTimer.AutoReset = false; longTapTimer.Elapsed += (s, e) => { this.manager.OnLongTap(); this.manager.OnDown(); this.machine.ChangeState(new MarkingState(this.machine, this.manager), new TouchEvent(this.startPointer)); }; longTapTimer.Start(); this.tapWatch.Start(); }
internal override void Update(TouchEvent touchEvent) { if (touchEvent.Touches.Count == 1) { Touch currPointer = touchEvent.Touches[0]; this.manager.OnMove((int)(this.prevPointer.Location.X - currPointer.Location.X), (int)(this.prevPointer.Location.Y - currPointer.Location.Y)); this.prevPointer = currPointer; } else if (touchEvent.Touches.Count == 0) { this.machine.ChangeState(new NullState(machine, manager), null); } else { this.machine.ChangeState(new MultiMoveState(this.machine, this.manager), touchEvent); } }
private bool IsPinch(TouchEvent touchEvent, out int delta) { Vector2 prevA = this.prevEvent.Touches[0].Location; Vector2 prevB = this.prevEvent.Touches[1].Location; Vector2 currA = touchEvent.Touches[0].Location; Vector2 currB = touchEvent.Touches[1].Location; float doted0 = Vector2.Dot(prevA - currA, prevB - currB); float doted1 = Vector2.Dot(prevA - prevB, prevA - currA); if(doted1 + 0.1 > 0 && doted1 - 0.1 < 0 || doted1 + 0.1 > Math.PI && doted1 - 0.1 < Math.PI) { float dist0 = Vector2.Distance(prevA, prevB); float dist1 = Vector2.Distance(currA, currB); delta = (int)(dist1 - dist0); return true; } delta = 0; return false; }
public void Update(TouchEvent touchEvent) { this.state.Update(touchEvent); }
private void TranstionToMultiDownState(TouchEvent touchEvent) { this.machine.ChangeState(new MultiDownState(this.machine, this.manager), touchEvent); }
internal override void Exit(TouchEvent touchEvent) { this.longTapTimer.Stop(); this.tapWatch.Stop(); }
internal override void Exit(TouchEvent touchEvent) { }
internal override void Enter(TouchEvent touchEvent) { this.prevPointer = touchEvent.Touches[0]; }
private void Move(TouchEvent touchEvent) { int count = Math.Min(this.prevEvent.Touches.Count, touchEvent.Touches.Count); int x = 0, y = 0; for (int i = 0; i < count; i++) { Vector2 prev = this.prevEvent.Touches[i].Location; Vector2 curr = touchEvent.Touches[i].Location; x = (int)(prev.X - curr.X); y = (int)(prev.Y - curr.Y); this.manager.OnMultiMove(count, x, y); } }
internal override void Enter(TouchEvent touchEvent) { this.prevEvent = touchEvent; }
private void TransitionToMoveState(TouchEvent touchEvent, Touch pointer) { this.manager.OnMove((int)(this.startPointer.Location.X - pointer.Location.X), (int)(this.startPointer.Location.Y - pointer.Location.Y)); this.machine.ChangeState(new MoveState(this.machine, this.manager), touchEvent); }
internal abstract void Exit(TouchEvent touchEvent);
internal abstract void Update(TouchEvent touchEvent);
private void TransitionToTapState(TouchEvent touchEvent) { this.manager.OnTap(); this.machine.ChangeState(new JustTappedState(this.machine, this.manager), touchEvent); }
private void TransitionToNullState(TouchEvent touchEvent) { this.machine.ChangeState(new NullState(this.machine, this.manager), touchEvent); }
internal override void Enter(TouchEvent touchEvent) { }
internal override void Update(TouchEvent touchEvent) { this.manager.OnDown(); this.machine.ChangeState(new MarkingState(this.machine, this.manager), touchEvent); }
internal override void Exit(TouchEvent touchEvent) { nextTapTimer.Stop(); }
public void ProcessEvent(TouchEvent touchEvent) { this.machine.Update(touchEvent); }
internal abstract void Enter(TouchEvent touchEvent);