Exemple #1
0
        protected virtual void OnDragState(ref TouchQueueInfomation info, long time)
        {
            int x = 0;
            int y = 0;

            if (!info.touchQueue.IsActived())
            {
                //release touch in drag state, triggered tap or long-tap event
                info.touchQueue.GetTrackStartingPosition(ref x, ref y);
                if (info.touchQueue.GetCurrentDuration(time) >= mMinTimeForLongTap)
                {
                    mCurrentGestureEvent = new GestureLongTapEvent(x, y, time, 1, info.touchQueue.GetDuration());
                }
                else
                {
                    mCurrentGestureEvent = new GestureTapEvent(x, y, time, 1);
                }
            }
            else
            {
                info.touchQueue.GetAbsMaxMovingDistance(ref x, ref y);
                if ((x > mMaxSteadyMoveDistanceX) || (y > mMaxSteadyMoveDistanceY))
                {
                    // point moved, trigger drag event and change to drag-move state
                    info.touchQueue.GetTrackStartingPosition(ref x, ref y);
                    mCurrentGestureEvent = new GestureDragEvent(x, y, time, 1);
                    info.curState        = TouchState.STATE_DRAG_MOVE;
                    mChangedTouchQueues.AddLast(info);
                    return;
                }
                mChangedTouchQueues.AddLast(info);
            }
        }
Exemple #2
0
        protected virtual void OnDoubleTapState(ref TouchQueueInfomation info, long time)
        {
            int x = 0;
            int y = 0;

            if (!info.touchQueue.IsActived())
            {
                info.touchQueue.GetTrackStartingPosition(ref x, ref y);
                mCurrentGestureEvent = new GestureDoubleClickEvent(x, y, time, 1);
            }
            else
            {
                info.touchQueue.GetAbsMaxMovingDistance(ref x, ref y);
                if ((x > mMaxSteadyMoveDistanceX) || (y > mMaxSteadyMoveDistanceY))
                {
                    // point moved, change to swipe state
                    info.curState = TouchState.STATE_SWIPE;
                    mChangedTouchQueues.AddLast(info);
                    return;
                }
                if (info.touchQueue.GetCurrentDuration(time) > mMinSteadyTimeForDrag)
                {
                    info.curState = TouchState.STATE_DRAG;
                    mChangedTouchQueues.AddLast(info);
                    return;
                }
                mChangedTouchQueues.AddLast(info);
            }
        }
Exemple #3
0
        protected virtual void OnSwipeState(ref TouchQueueInfomation info, long time)
        {
            int x = 0;
            int y = 0;

            info.touchQueue.GetTrackStartingPosition(ref x, ref y);
            if (!info.touchQueue.IsActived() || (info.touchQueue.GetCurrentDuration(time) >= mMaxSwipeDuration))
            {
                TouchArcShape  arcType   = TouchArcShape.ARC_NONE;
                TouchDirection direction = TouchDirection.DIR_NONE;
                bool           isArc     = info.touchQueue.IsArcTrack(mMinXDistanceForArc, mMinYChangePersentForArc, ref arcType, ref direction);
                if (isArc)
                {
                    mCurrentGestureEvent = new GestureArcEvent(x, y, time, 1, arcType, direction);
                }
                else
                {
                    mCurrentGestureEvent = new GestureSwipeEvent(x, y, time, 1, direction);
                }

                //force deactive the touch queue when it expired
                if (info.touchQueue.IsActived())
                {
                    info.touchQueue.ForceReleaseTouch();
                }
            }
            else
            {
                mChangedTouchQueues.AddLast(info);
            }
        }
Exemple #4
0
        protected virtual void OnMultiTouch(long time)
        {
            LinkedList <TouchQueue> temp = new LinkedList <TouchQueue>();
            int count = mChangedTouchQueues.Count;

            for (int i = 0; i < count; ++i)
            {
                if (mChangedTouchQueues.ElementAt(i).touchQueue.IsActived())
                {
                    temp.AddLast(mChangedTouchQueues.ElementAt(i).touchQueue);
                    mChangedTouchQueues.ElementAt(i).curState = TouchState.STATE_MULTI;
                }
            }
            count = temp.Count;
            if (count == 2) // rotate pinch
            {
                int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
                temp.ElementAt(0).GetTrackStartingPosition(ref x0, ref y0);
                Vector3 p0 = new Vector3(x0, y0, 0.0f);
                temp.ElementAt(0).GetTrackEndingPosition(ref x1, ref y1);
                Vector3 p1 = new Vector3(x1, y1, 0.0f);
                Vector3 v0 = new Vector3(x1 - x0, y1 - y0, 0.0f);
                temp.ElementAt(1).GetTrackStartingPosition(ref x0, ref y0);
                Vector3 p2 = new Vector3(x0, y0, 0.0f);
                temp.ElementAt(1).GetTrackEndingPosition(ref x1, ref y1);
                Vector3 p3   = new Vector3(x1, y1, 0.0f);
                Vector3 v1   = new Vector3(x1 - x0, y1 - y0, 0.0f);
                float   len1 = v0.magnitude;
                float   len2 = v1.magnitude;
                if ((len1 < _MAX_DISTANCE_RATIO_FOR_STEADY) && (len2 < _MAX_DISTANCE_RATIO_FOR_STEADY))
                {
                    //hold stady, exit anyway
                    return;
                }
                if ((len1 < _MAX_DISTANCE_RATIO_FOR_STEADY) || (len2 < _MAX_DISTANCE_RATIO_FOR_STEADY))
                {
                    // todo, buggy here
                    mCurrentGestureEvent = new GestureRotateEvent((int)p1.x, (int)p1.y, time, 2, 1.0f);
                }
                else
                {
                    float dot = Vector3.Dot(v0, v1);
                    if (dot > 0.0f)
                    {
                        //two tracks in the same direction, move
                        p0 = (p1 + p3) * 0.5f;
                        mCurrentGestureEvent = new GestureMoveEvent((int)p0.x, (int)p0.y, time, 2);
                        _inMultiTouchMove    = true;
                        _lastMultiTouchMoveX = (int)p0.x;
                        _lastMultiTouchMoveY = (int)p0.y;
                    }
                    else
                    {
                        //pinch
                        mCurrentGestureEvent = new GesturePinchEvent((int)p3.x, (int)p3.y, time, 2, (p1 - p3).sqrMagnitude / (p0 - p2).sqrMagnitude);
                    }
                }
            }
        }
Exemple #5
0
        protected virtual void OnLongTapState(ref TouchQueueInfomation info, long time)
        {
            int x = 0;
            int y = 0;

            info.touchQueue.GetTrackStartingPosition(ref x, ref y);
            if (!info.touchQueue.IsActived())
            {
                mCurrentGestureEvent = new GestureLongTapEvent(x, y, time, 1, info.touchQueue.GetDuration());
            }
            else
            {
                mChangedTouchQueues.AddLast(info);
            }
        }
Exemple #6
0
        protected virtual void OnDragMoveState(ref TouchQueueInfomation info, long time)
        {
            int x = 0;
            int y = 0;

            info.touchQueue.GetTrackEndingPosition(ref x, ref y);
            if (!info.touchQueue.IsActived())
            {
                mCurrentGestureEvent = new GestureDropEvent(x, y, time, 1);
            }
            else
            {
                mCurrentGestureEvent = new GestureDragMoveEvent(x, y, time, 1);
                mChangedTouchQueues.AddLast(info);
            }
        }
Exemple #7
0
        public virtual void Update()
        {
            if (!mTimer.IsRunning)
            {
                return;
            }
            mGestureRecognizer.Update(mTimer.ElapsedMilliseconds);
            BaseGestureEvent gestureEvent = mGestureRecognizer.GetCurrentGestureEvent();

            if (gestureEvent == null)
            {
                return;
            }
            for (int i = 0; i < mGestureListeners.Count; i++)
            {
                mGestureListeners[i].GestureEvent(gestureEvent);
            }
            mGestureRecognizer.ResetCurrentGesture();
        }
Exemple #8
0
        public virtual void Update(long currentTime)
        {
            int count = mChangedTouchQueues.Count;

            if (GetActiveTouchQueueCount() > 1)
            {
                OnMultiTouch(currentTime);
            }
            else
            {
                if (_inMultiTouchMove)
                {
                    mCurrentGestureEvent = new GestureEndMoveEvent(_lastMultiTouchMoveX, _lastMultiTouchMoveY, currentTime, 2);
                    _lastMultiTouchMoveX = _lastMultiTouchMoveY = 0;
                    _inMultiTouchMove    = false;
                }
                int idx = 0;
                while (mChangedTouchQueues.Count > 0 && (idx < count))
                {
                    TouchQueueInfomation info = mChangedTouchQueues.First.Value;
                    mChangedTouchQueues.RemoveFirst();
                    idx++;
                    int x = 0;
                    int y = 0;
                    info.touchQueue.GetTrackStartingPosition(ref x, ref y);
                    switch (info.curState)
                    {
                    case TouchState.STATE_TAP:
                        OnTapState(ref info, currentTime);
                        break;

                    case TouchState.STATE_SWIPE:
                        OnSwipeState(ref info, currentTime);
                        break;

                    case TouchState.STATE_MOVE:
                        OnMoveState(ref info, currentTime);
                        break;

                    case TouchState.STATE_LONG_TAP:
                        OnLongTapState(ref info, currentTime);
                        break;

                    case TouchState.STATE_DOUBLE_TAP:
                        OnDoubleTapState(ref info, currentTime);
                        break;

                    case TouchState.STATE_DRAG:
                        OnDragState(ref info, currentTime);
                        break;

                    case TouchState.STATE_DRAG_MOVE:
                        OnDragMoveState(ref info, currentTime);
                        break;

                    case TouchState.STATE_MULTI:
                        info.touchQueue.ForceReleaseTouch();
                        break;

                    case TouchState.STATE_NONE:
                        info.touchQueue.ForceReleaseTouch();
                        break;

                    default:
                        info.touchQueue.ForceReleaseTouch();
                        break;
                    }
                }
            }
        }
Exemple #9
0
 public virtual void ResetCurrentGesture()
 {
     mCurrentGestureEvent = new BaseGestureEvent();
 }
Exemple #10
0
        protected virtual void OnTapState(ref TouchQueueInfomation info, long time)
        {
            int x = 0;
            int y = 0;

            if (!info.touchQueue.IsActived())
            {
                // touch release
                if (info.repeatTimes <= 1)
                {
                    info.touchQueue.GetTrackStartingPosition(ref x, ref y);
                    if (info.releaseTime + mMaxIntervalOfDoubleClick < time)
                    {
                        // tap event
                        // ResetCurrentGesture();
                        mCurrentGestureEvent = new GestureTapEvent(x, y, time, 1);
                    }
                    else
                    {
                        mChangedTouchQueues.AddLast(info);
                    }
                    return;
                }
                else
                {
                    // double click
                    info.curState = TouchState.STATE_DOUBLE_TAP;
                    mChangedTouchQueues.AddLast(info);
                    return;
                }
            }
            else
            {
                info.touchQueue.GetAbsMaxMovingDistance(ref x, ref y);
                if ((x > mMaxSteadyMoveDistanceX) || (y > mMaxSteadyMoveDistanceY))
                {
                    // point moved, change to swipe or move state
                    float maxSpeed = 0;
                    float avgSpeed = 0;
                    bool  gotSpeed = info.touchQueue.GetMovingSpeeds(ref maxSpeed, ref avgSpeed);
                    if (gotSpeed && (maxSpeed < mMinSpeedForSwipe))
                    {
                        info.curState = TouchState.STATE_MOVE;
                    }
                    else
                    {
                        info.curState = TouchState.STATE_SWIPE;
                    }
                    mChangedTouchQueues.AddLast(info);
                    return;
                }
                info.touchQueue.GetTrackStartingPosition(ref x, ref y);
                if (info.touchQueue.GetCurrentDuration(time) > mMinSteadyTimeForDrag)
                {
                    info.curState = TouchState.STATE_DRAG;

                    /*
                     * ResetCurrentGesture();
                     * new (mCurrentGestureEvent) GestureDragEvent(x, y, time, 1);
                     */
                    mChangedTouchQueues.AddLast(info);
                    return;
                }
                mChangedTouchQueues.AddLast(info);
            }
        }
Exemple #11
0
        public void GestureEvent(BaseGestureEvent gestureEvent)
        {
            GestureType = gestureEvent.GetEventType();
            switch (gestureEvent.GetEventType())
            {
            case GestureEventType.GESTURE_TAP:
                Debug.Log("GESTURE_TAP");
                break;

            case GestureEventType.GESTURE_DOUBLE_CLICK:
                Debug.Log("GESTURE_DOUBLE_CLICK");
                break;

            case GestureEventType.GESTURE_LONG_TAP:
                Debug.Log("GESTURE_LONG_TAP");
                break;

            case GestureEventType.GESTURE_BEGIN_MOVE:
                Debug.Log("GESTURE_BEGIN_MOVE");
                break;

            case GestureEventType.GESTURE_MOVE:
                Debug.Log("GESTURE_MOVE");
                break;

            case GestureEventType.GESTURE_END_MOVE:
                Debug.Log("GESTURE_END_MOVE");
                break;

            case GestureEventType.GESTURE_DRAG:
                Debug.Log("GESTURE_DRAG");
                break;

            case GestureEventType.GESTURE_DRAG_MOVE:
                Debug.Log("GESTURE_DRAG_MOVE");
                break;

            case GestureEventType.GESTURE_DROP:
                Debug.Log("GESTURE_DROP");
                break;

            case GestureEventType.GESTURE_ARC:
                Debug.Log("GESTURE_ARC");
                break;

            case GestureEventType.GESTURE_PINCH:
                Debug.Log("GESTURE_PINCH");
                break;

            case GestureEventType.GESTURE_SWIPE:
                Debug.Log("GESTURE_SWIPE");
                break;

            case GestureEventType.GESTURE_ROTATE:
                Debug.Log("GESTURE_ROTATE");
                break;

            case GestureEventType.GESTURE_UNKNOWN:
                Debug.Log("GESTURE_UNKNOWN");
                break;

            default:
                Debug.Log("wrong GESTURE");
                break;
            }
        }