示例#1
0
 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);
     }
 }
示例#2
0
        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;
        }
示例#3
0
 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;
 }
示例#4
0
        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);
        }
示例#5
0
 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();
 }
示例#6
0
 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);
     }
 }
示例#7
0
 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);
     }
 }
示例#8
0
        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();
        }
示例#9
0
 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);
     }
 }
示例#10
0
        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;
        }
示例#11
0
 public void Update(TouchEvent touchEvent)
 {
     this.state.Update(touchEvent);
 }
示例#12
0
 private void TranstionToMultiDownState(TouchEvent touchEvent)
 {
     this.machine.ChangeState(new MultiDownState(this.machine, this.manager), touchEvent);
 }
示例#13
0
 internal override void Exit(TouchEvent touchEvent)
 {
     this.longTapTimer.Stop();
     this.tapWatch.Stop();
 }
示例#14
0
 internal override void Exit(TouchEvent touchEvent)
 {
 }
示例#15
0
 internal override void Enter(TouchEvent touchEvent)
 {
     this.prevPointer = touchEvent.Touches[0];
 }
示例#16
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);
            }
        }
示例#17
0
 internal override void Enter(TouchEvent touchEvent)
 {
     this.prevEvent = touchEvent;
 }
示例#18
0
 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);
 }
示例#19
0
 internal abstract void Exit(TouchEvent touchEvent);
示例#20
0
 internal abstract void Update(TouchEvent touchEvent);
示例#21
0
 private void TransitionToTapState(TouchEvent touchEvent)
 {
     this.manager.OnTap();
     this.machine.ChangeState(new JustTappedState(this.machine, this.manager), touchEvent);
 }
示例#22
0
 private void TransitionToNullState(TouchEvent touchEvent)
 {
     this.machine.ChangeState(new NullState(this.machine, this.manager), touchEvent);
 }
示例#23
0
 internal override void Enter(TouchEvent touchEvent)
 {
 }
示例#24
0
 internal override void Update(TouchEvent touchEvent)
 {
     this.manager.OnDown();
     this.machine.ChangeState(new MarkingState(this.machine, this.manager), touchEvent);
 }
示例#25
0
 internal override void Exit(TouchEvent touchEvent)
 {
     nextTapTimer.Stop();
 }
示例#26
0
 public void ProcessEvent(TouchEvent touchEvent)
 {
     this.machine.Update(touchEvent);
 }
示例#27
0
 internal abstract void Enter(TouchEvent touchEvent);