示例#1
0
        /// <summary>
        /// [内部メソッド]
        /// 「ピンチ」イベントを実行する
        /// </summary>
        /// <param name="touchPoint1">接触点1</param>
        /// <param name="touchPoint2">接触点2</param>
        private void executePinchEvent(TouchPoint touchPoint1, TouchPoint touchPoint2)
        {
            // 接触点1と接触点2の距離から「ピンチ」イベントハンドラを実行するか
            int distance = Calculator.CalcurateDistance(touchPoint1.X, touchPoint1.Y, touchPoint2.X, touchPoint2.Y);

            if (Math.Abs(this.baseTwoTouchDistanceCentiPixel - distance) < pinchIntervalCentiPixel)
            {
                return;
            }

            // 接触点1と接触点2の角度を計算する
            int angle = Calculator.CalculateAngle(touchPoint1.X, touchPoint1.Y, touchPoint2.X, touchPoint2.Y);

            // 基準となる距離と接触点1,2の距離からピンチ区分を決定する
            PinchType type = Calculator.DistanceToPinchType(this.baseTwoTouchDistanceCentiPixel, distance);

            // 「ピンチ」イベントハンドラを実行する
            var pinchData = new PinchData(touchPoint1, touchPoint2, angle, this.baseTwoTouchDistanceCentiPixel, distance, type);
            var peArgs    = new PinchEventArgs(pinchData);

            OnPinch(peArgs);
            this.baseTwoTouchDistanceCentiPixel = distance;
        }
 /// <summary>
 /// [コンストラクタ]
 /// </summary>
 /// <param name="pinchData">ピンチ操作データ</param>
 public PinchEventArgs(PinchData pinchData)
 {
     this.pinchData = pinchData;
 }
示例#3
0
        /// <summary>
        /// [内部メソッド]
        /// 排他的イベントを割り当てる
        /// </summary>
        private void allocateExclusiveEvent(Win32ApiWrapper.TouchEventData[] eventData)
        {
            Win32ApiWrapper.TouchEventFlags eventFlags = eventData[0].dwEventFlags;

            // 接触点の座標情報を設定する
            TouchPoint touchPoint1 = new TouchPoint(eventData[0].x, eventData[0].y);
            TouchPoint touchPoint2 = null;

            if (eventData.Length > 1)
            {
                touchPoint2 = new TouchPoint(eventData[1].x, eventData[1].y);
            }

            // 各イベントを割り当てる
            if (eventData.Length > 1 && (eventData[1].dwEventFlags & Win32ApiWrapper.TouchEventFlags.DOWN) == Win32ApiWrapper.TouchEventFlags.DOWN)
            {
                // ピンチ操作の開始を検知する
                _baseTwoTouchDistance = Calculator.CalcurateDistance(touchPoint1.X, touchPoint1.Y, touchPoint2.X, touchPoint2.Y);
            }
            else if (eventData.Length > 1 && (eventData[1].dwEventFlags & Win32ApiWrapper.TouchEventFlags.MOVE) == Win32ApiWrapper.TouchEventFlags.MOVE)
            {
                // 「ピンチ」イベントハンドラを実行するか
                int distance = Calculator.CalcurateDistance(touchPoint1.X, touchPoint1.Y, touchPoint2.X, touchPoint2.Y);
                if (Math.Abs(_baseTwoTouchDistance - distance) > PinchInterval)
                {
                    // 「ピンチ」イベントハンドラを実行する
                    int       angle     = Calculator.CalculateAngle(touchPoint1.X, touchPoint1.Y, touchPoint2.X, touchPoint2.Y);
                    PinchType type      = Calculator.DistanceToPinchType(_baseTwoTouchDistance, distance);
                    var       pinchData = new PinchData(touchPoint1, touchPoint2, angle, _baseTwoTouchDistance, distance, type);
                    var       peArgs    = new PinchEventArgs(pinchData);
                    OnPinch(peArgs);
                    _baseTwoTouchDistance = distance;
                }
            }
            else if ((eventFlags & Win32ApiWrapper.TouchEventFlags.UP) == Win32ApiWrapper.TouchEventFlags.UP)
            {
                int      distance  = Calculator.CalcurateDistance(_baseTouchPoint.X, _baseTouchPoint.Y, touchPoint1.X, touchPoint1.Y);
                TimeSpan touchSpan = DateTime.Now - _touchDownTime;
                TimeSpan tapSpan   = DateTime.Now - _previousTapTime;

                if (shouldExecSwipeEvent(touchPoint1, distance))
                {
                    // 「スワイプ」イベントハンドラを実行する
                    int            angle     = Calculator.CalculateAngle(_baseTouchPoint.X, _baseTouchPoint.Y, touchPoint1.X, touchPoint1.Y);
                    SwipeDirection direction = Calculator.AngleToDirection(angle);
                    var            swipeData = new SwipeData(_baseTouchPoint, touchPoint1, angle, distance, direction);
                    var            seArgs    = new SwipeEventArgs(swipeData, _orbit);
                    OnSwipe(touchPoint1, seArgs);
                    resetFields();
                }
                else if (touchSpan.TotalMilliseconds < _tapInterval && tapSpan.TotalMilliseconds < _doubleTapInterval)
                {
                    // 「ダブルタップ」イベントハンドラを実行する
                    var teArgs = new TouchEventArgs(touchPoint1, _orbit);
                    OnDoubleTap(teArgs);
                }
                else if (touchSpan.TotalMilliseconds < _tapInterval)
                {
                    // 「タップ」イベントハンドラを実行する
                    _previousTapTime = DateTime.Now;
                    var teArgs = new TouchEventArgs(touchPoint1, _orbit);
                    OnTap(teArgs);
                }
            }
        }