protected internal override GestureDetectorResponse OnTouchEvent(TouchEventCollection touchEvents)
        {
            GestureDetectorResponse result = base.State;
            TouchEvent primaryTouchEvent   = touchEvents.PrimaryTouchEvent;

            if (base.State != GestureDetectorResponse.None && this.downID != primaryTouchEvent.FingerID)
            {
                return(result);
            }
            switch (primaryTouchEvent.Type)
            {
            case TouchEventType.Up:
                result = GestureDetectorResponse.FailedAndStop;
                break;

            case TouchEventType.Down:
                this.downID   = primaryTouchEvent.FingerID;
                this.downPos  = primaryTouchEvent.WorldPosition;
                this.downTime = primaryTouchEvent.Time;
                result        = GestureDetectorResponse.UndetectedAndContinue;
                break;

            case TouchEventType.Move:
            {
                float num  = primaryTouchEvent.WorldPosition.Distance(this.downPos);
                float num2 = (float)(primaryTouchEvent.Time - this.downTime).TotalMilliseconds;
                if (num <= this.MaxDistance)
                {
                    if (num2 >= this.MinPressDuration)
                    {
                        if (this.LongPressDetected != null)
                        {
                            LongPressEventArgs longPressEventArgs = new LongPressEventArgs(base.TargetWidget, primaryTouchEvent.WorldPosition, primaryTouchEvent.LocalPosition, num2);
                            this.LongPressDetected.Invoke(this, longPressEventArgs);
                        }
                        result = GestureDetectorResponse.DetectedAndContinue;
                    }
                }
                else
                {
                    result = GestureDetectorResponse.FailedAndStop;
                }
                break;
            }
            }
            return(result);
        }
Example #2
0
        protected internal override GestureDetectorResponse OnTouchEvent(TouchEventCollection touchEvents)
        {
            GestureDetectorResponse result = base.State;
            TouchEvent primaryTouchEvent   = touchEvents.PrimaryTouchEvent;

            if (base.State != GestureDetectorResponse.None && this.downID != primaryTouchEvent.FingerID)
            {
                return(result);
            }
            switch (primaryTouchEvent.Type)
            {
            case TouchEventType.Up:
                if (this.DragEndDetected != null)
                {
                    DragEventArgs dragEventArgs = new DragEventArgs(base.TargetWidget, primaryTouchEvent.WorldPosition, primaryTouchEvent.LocalPosition, primaryTouchEvent.WorldPosition - this.previousWorldPosition);
                    this.DragEndDetected.Invoke(this, dragEventArgs);
                }
                this.previousWorldPosition = primaryTouchEvent.WorldPosition;
                result = GestureDetectorResponse.FailedAndStop;
                break;

            case TouchEventType.Down:
                this.downID = primaryTouchEvent.FingerID;
                this.previousWorldPosition = primaryTouchEvent.WorldPosition;
                result = GestureDetectorResponse.UndetectedAndContinue;
                break;

            case TouchEventType.Move:
                if (base.State == GestureDetectorResponse.UndetectedAndContinue)
                {
                    Vector2 worldPosition = primaryTouchEvent.WorldPosition;
                    float   num           = this.previousWorldPosition.Distance(worldPosition);
                    if (num >= this.MaxDistance)
                    {
                        DragEventArgs dragEventArgs2 = new DragEventArgs(base.TargetWidget, primaryTouchEvent.WorldPosition, primaryTouchEvent.LocalPosition, primaryTouchEvent.WorldPosition - this.previousWorldPosition);
                        this.previousWorldPosition = primaryTouchEvent.WorldPosition;
                        if (this.DragStartDetected != null)
                        {
                            this.DragStartDetected.Invoke(this, dragEventArgs2);
                        }
                        if (this.DragDetected != null)
                        {
                            this.DragDetected.Invoke(this, dragEventArgs2);
                        }
                        result = GestureDetectorResponse.DetectedAndContinue;
                    }
                }
                else
                {
                    if (this.DragDetected != null)
                    {
                        DragEventArgs dragEventArgs3 = new DragEventArgs(base.TargetWidget, primaryTouchEvent.WorldPosition, primaryTouchEvent.LocalPosition, primaryTouchEvent.WorldPosition - this.previousWorldPosition);
                        this.DragDetected.Invoke(this, dragEventArgs3);
                    }
                    this.previousWorldPosition = primaryTouchEvent.WorldPosition;
                    result = GestureDetectorResponse.DetectedAndContinue;
                }
                break;
            }
            return(result);
        }
        protected internal override GestureDetectorResponse OnTouchEvent(TouchEventCollection touchEvents)
        {
            GestureDetectorResponse result = base.State;
            TouchEvent primaryTouchEvent   = touchEvents.PrimaryTouchEvent;

            if (base.State != GestureDetectorResponse.None && this.firstDownID != primaryTouchEvent.FingerID)
            {
                return(result);
            }
            Vector2 worldPosition = primaryTouchEvent.WorldPosition;
            float   num           = this.firstDownPos.Distance(worldPosition);
            float   num2          = (float)(primaryTouchEvent.Time - this.previousTime).TotalMilliseconds;

            switch (primaryTouchEvent.Type)
            {
            case TouchEventType.Up:
                if (this.downCount == 2)
                {
                    if (num <= this.MaxDistance && num2 <= this.MaxPressDuration)
                    {
                        if (this.DoubleTapDetected != null)
                        {
                            DoubleTapEventArgs doubleTapEventArgs = new DoubleTapEventArgs(base.TargetWidget, primaryTouchEvent.WorldPosition, primaryTouchEvent.LocalPosition);
                            this.DoubleTapDetected.Invoke(this, doubleTapEventArgs);
                        }
                        result = GestureDetectorResponse.DetectedAndStop;
                    }
                    else
                    {
                        result = GestureDetectorResponse.FailedAndStop;
                    }
                }
                else if (num <= this.MaxDistance && num2 <= this.MaxPressDuration)
                {
                    this.previousTime = primaryTouchEvent.Time;
                    result            = GestureDetectorResponse.UndetectedAndContinue;
                }
                else
                {
                    result = GestureDetectorResponse.FailedAndStop;
                }
                break;

            case TouchEventType.Down:
                if (this.downCount > 0)
                {
                    if (num <= this.MaxDistance && num2 <= this.MaxNextPressDuration)
                    {
                        this.downCount++;
                        this.previousTime = primaryTouchEvent.Time;
                    }
                    else
                    {
                        this.OnResetState();
                    }
                }
                if (this.downCount == 0)
                {
                    this.downCount++;
                    this.firstDownID  = primaryTouchEvent.FingerID;
                    this.firstDownPos = primaryTouchEvent.WorldPosition;
                    this.previousTime = primaryTouchEvent.Time;
                }
                result = GestureDetectorResponse.UndetectedAndContinue;
                break;
            }
            return(result);
        }
        protected internal override GestureDetectorResponse OnTouchEvent(TouchEventCollection touchEvents)
        {
            GestureDetectorResponse result = base.State;
            TouchEventCollection    touchEventCollection = new TouchEventCollection();

            foreach (TouchEvent touchEvent in touchEvents)
            {
                if (touchEvent.Type != TouchEventType.Enter && touchEvent.Type != TouchEventType.Leave && touchEvent.Type != TouchEventType.None)
                {
                    touchEventCollection.Add(touchEvent);
                }
            }
            if (touchEventCollection.Count >= 2)
            {
                bool      flag   = false;
                Vector2[] array  = new Vector2[2];
                Vector2[] array2 = new Vector2[2];
                for (int i = 0; i < 2; i++)
                {
                    TouchEvent touchEvent2 = touchEventCollection[i];
                    array[i]  = touchEvent2.LocalPosition;
                    array2[i] = touchEvent2.WorldPosition;
                    if (touchEvent2.Type == TouchEventType.Up)
                    {
                        flag = true;
                    }
                }
                float num = array[0].Distance(array[1]);
                if (this.firstDistance < 0f)
                {
                    this.firstDistance    = num;
                    this.firstTouchVector = array[1] - array[0];
                }
                if (base.State == GestureDetectorResponse.UndetectedAndContinue || base.State == GestureDetectorResponse.None)
                {
                    if (FMath.Abs(num - this.firstDistance) > this.MinPinchDistance)
                    {
                        Vector2 localCenter = (array[0] + array[1]) / 2f;
                        Vector2 worldCenter = (array2[0] + array2[1]) / 2f;
                        if (this.PinchStartDetected != null)
                        {
                            this.PinchStartDetected.Invoke(this, new PinchEventArgs(base.TargetWidget, num, 1f, 0f, worldCenter, localCenter));
                        }
                        result = GestureDetectorResponse.DetectedAndContinue;
                    }
                    else
                    {
                        result = GestureDetectorResponse.UndetectedAndContinue;
                    }
                }
                else if (base.State == GestureDetectorResponse.DetectedAndContinue)
                {
                    Vector2 vector       = array[1] - array[0];
                    float   scale        = num / this.firstDistance;
                    float   angle        = this.firstTouchVector.Angle(vector);
                    Vector2 localCenter2 = (array[0] + array[1]) / 2f;
                    Vector2 worldCenter2 = (array2[0] + array2[1]) / 2f;
                    if (flag)
                    {
                        if (this.PinchEndDetected != null)
                        {
                            this.PinchEndDetected.Invoke(this, new PinchEventArgs(base.TargetWidget, num, scale, angle, worldCenter2, localCenter2));
                        }
                        result                = GestureDetectorResponse.DetectedAndStop;
                        this.firstDistance    = -1f;
                        this.firstTouchVector = Vector2.Zero;
                    }
                    else
                    {
                        if (this.PinchDetected != null)
                        {
                            this.PinchDetected.Invoke(this, new PinchEventArgs(base.TargetWidget, num, scale, angle, worldCenter2, localCenter2));
                        }
                        result = GestureDetectorResponse.DetectedAndContinue;
                    }
                }
            }
            else if (base.State == GestureDetectorResponse.DetectedAndContinue)
            {
                result = GestureDetectorResponse.FailedAndStop;
            }
            else
            {
                result = GestureDetectorResponse.UndetectedAndContinue;
            }
            return(result);
        }
        protected internal override GestureDetectorResponse OnTouchEvent(TouchEventCollection touchEvents)
        {
            GestureDetectorResponse result = base.State;
            TouchEvent primaryTouchEvent   = touchEvents.PrimaryTouchEvent;

            if (base.State != GestureDetectorResponse.None && this.downID != primaryTouchEvent.FingerID)
            {
                return(result);
            }
            switch (primaryTouchEvent.Type)
            {
            case TouchEventType.Up:
            {
                Vector2 vector = primaryTouchEvent.WorldPosition - this.previousWorldPosition[1];
                float   num    = (float)(primaryTouchEvent.Time - this.previousTime[1]).TotalMilliseconds;
                Vector2 zero   = Vector2.Zero;
                if (this.Direction != FlickDirection.Virtical)
                {
                    zero.X = vector.X / num * 1000f;
                    if (zero.X < -this.MaxSpeed)
                    {
                        zero.X = -this.MaxSpeed;
                    }
                    else if (zero.X > this.MaxSpeed)
                    {
                        zero.X = this.MaxSpeed;
                    }
                    else if (Math.Abs(zero.X) < this.MinSpeed)
                    {
                        zero.X = 0f;
                    }
                }
                if (this.Direction != FlickDirection.Horizontal)
                {
                    zero.Y = vector.Y / num * 1000f;
                    if (zero.Y < -this.MaxSpeed)
                    {
                        zero.Y = -this.MaxSpeed;
                    }
                    else if (this.MaxSpeed < zero.Y)
                    {
                        zero.Y = this.MaxSpeed;
                    }
                    else if (Math.Abs(zero.Y) < this.MinSpeed)
                    {
                        zero.Y = 0f;
                    }
                }
                if (zero.X != 0f || zero.Y != 0f)
                {
                    if (this.FlickDetected != null)
                    {
                        FlickEventArgs flickEventArgs = new FlickEventArgs(base.TargetWidget, primaryTouchEvent.WorldPosition, primaryTouchEvent.LocalPosition, zero);
                        this.FlickDetected.Invoke(this, flickEventArgs);
                    }
                    result = GestureDetectorResponse.DetectedAndStop;
                }
                else
                {
                    result = GestureDetectorResponse.FailedAndStop;
                }
                break;
            }

            case TouchEventType.Down:
                this.downID = primaryTouchEvent.FingerID;
                for (int i = 0; i < 2; i++)
                {
                    this.previousWorldPosition[i] = primaryTouchEvent.WorldPosition;
                    this.previousTime[i]          = primaryTouchEvent.Time;
                }
                result = GestureDetectorResponse.UndetectedAndContinue;
                break;

            case TouchEventType.Move:
                if ((primaryTouchEvent.Time - this.previousTime[0]).TotalMilliseconds > (double)this.pollingMilliseconds)
                {
                    this.previousWorldPosition[1] = this.previousWorldPosition[0];
                    this.previousTime[1]          = this.previousTime[0];
                    this.previousWorldPosition[0] = primaryTouchEvent.WorldPosition;
                    this.previousTime[0]          = primaryTouchEvent.Time;
                    result = GestureDetectorResponse.UndetectedAndContinue;
                }
                break;
            }
            return(result);
        }