/// <summary> /// [内部メソッド] /// UP イベントデータを実行する /// </summary> /// <param name="eventData">イベントデータ</param> private void executeUpEvent(Win32ApiWrapper.TouchEventData eventData) { // 接触点を軌道に追加する var touchPoint = new TouchPoint(eventData.x, eventData.y); this.orbit.Add(touchPoint); // 「タッチアップ」イベントハンドラを実行する var teArgs = new TouchEventArgs(touchPoint, this.orbit); OnTouchUp(teArgs); }
/// <summary> /// [内部メソッド] /// 「スワイプ」イベントを実行する /// </summary> /// <param name="touchPoint">接触点</param> private void executeSwipeEvent(TouchPoint touchPoint) { // 基準点と接触点の距離を取得する int distance = touchPoint.GetDistanceFrom(this.baseTouchPoint); // 基準点と接触点の角度を計算する int angle = Calculator.CalculateAngle(this.baseTouchPoint.X, this.baseTouchPoint.Y, touchPoint.X, touchPoint.Y); // 角度からスワイプの方向を決定する SwipeDirection direction = Calculator.AngleToDirection(angle); // 「スワイプ」イベントハンドラを実行する var swipeData = new SwipeData(this.baseTouchPoint, touchPoint, angle, distance, direction); var seArgs = new SwipeEventArgs(swipeData, this.orbit); OnSwipe(touchPoint, seArgs); }
/// <summary> /// [内部メソッド] /// DOWN ベントを実行する /// </summary> /// <param name="eventData">イベントデータ</param> private void executeDownEvent(Win32ApiWrapper.TouchEventData eventData) { // タッチ操作のデータを初期化する resetFields(); // タッチの基準点を保持しておく this.touchDownTime = DateTime.Now; this.baseTouchPoint = new TouchPoint(eventData.x, eventData.y); // 接触点を軌道に追加する this.orbit.Add(this.baseTouchPoint); // 「タッチダウン」イベントハンドラを実行する var teArgs = new TouchEventArgs(this.baseTouchPoint, this.orbit); OnTouchDown(teArgs); }
/// <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.IsDown()) { // 「ピンチ」操作の開始を検知する this.baseTwoTouchDistanceCentiPixel = Calculator.CalcurateDistance(touchPoint1.X, touchPoint1.Y, touchPoint2.X, touchPoint2.Y); } else if (eventData.Length > 1 && eventData[1].dwEventFlags.IsMove()) { // 「ピンチ」イベントを実行する executePinchEvent(touchPoint1, touchPoint2); } else if (eventFlags.IsUp()) { if (isSwipe(touchPoint1)) { // 「スワイプ」イベントを実行する executeSwipeEvent(touchPoint1); } else if (isDoubleTap()) { // 「ダブルタップ」イベントを実行する executeDoubleTapEvent(touchPoint1); } else if (isTap()) { // 「タップ」イベントを実行する executeTapEvent(touchPoint1); } } }
/// <summary> /// [内部メソッド] /// スワイプイベントを実行するか /// </summary> /// <returns>実行するか</returns> private bool shouldExecSwipeEvent(TouchPoint lastTouchPoint, int distance) { if (_baseTouchPoint.X < 0 || _baseTouchPoint.Y < 0) { return(false); } if (lastTouchPoint.X < 0 || lastTouchPoint.Y < 0) { return(false); } if (_hasPinched) { return(false); } return(distance > SwipeInterval); }
/// <summary> /// [内部メソッド] /// 「スワイプ」操作か /// </summary> /// <returns>「スワイプ」操作か</returns> private bool isSwipe(TouchPoint lastTouchPoint) { if (this.baseTouchPoint.X < 0 || this.baseTouchPoint.Y < 0) { return(false); } if (lastTouchPoint.X < 0 || lastTouchPoint.Y < 0) { return(false); } if (this.hasPinched) { return(false); } int distance = lastTouchPoint.GetDistanceFrom(this.baseTouchPoint); return(distance > swipeIntervalCentiPixel); }
/// <summary> /// [内部メソッド] /// MOVE イベントを実行する /// </summary> /// <param name="eventData">イベントデータ</param> private void executeMoveEvent(Win32ApiWrapper.TouchEventData eventData) { // 移動距離が規定の間隔に満たない場合は処理しない TouchPoint lastTouchPoint = this.orbit.Last(); int distance = Calculator.CalcurateDistance(lastTouchPoint.X, lastTouchPoint.Y, eventData.x, eventData.y); if (distance < this.moveIntervalCentiPixel) { return; } //接触点を軌道に追加する var touchPoint = new TouchPoint(eventData.x, eventData.y); this.orbit.Add(touchPoint); // 「タッチムーブ」イベントハンドラを実行する var teArgs = new TouchEventArgs(touchPoint, this.orbit); OnTouchMove(teArgs); }
/// <summary> /// [内部メソッド] /// 基本イベントを割り当てる /// </summary> /// <param name="eventData">イベントデータ</param> private void allocateBasicEvent(Win32ApiWrapper.TouchEventData eventData) { Win32ApiWrapper.TouchEventFlags eventFlags = eventData.dwEventFlags; if ((eventFlags & Win32ApiWrapper.TouchEventFlags.DOWN) == Win32ApiWrapper.TouchEventFlags.DOWN) { // 「タッチダウン」イベントハンドラを実行する resetFields(); _touchDownTime = DateTime.Now; _baseTouchPoint = new TouchPoint(eventData.x, eventData.y); var teArgs = new TouchEventArgs(_baseTouchPoint, _orbit); _orbit.Add(_baseTouchPoint); OnTouchDown(teArgs); } else if ((eventFlags & Win32ApiWrapper.TouchEventFlags.MOVE) == Win32ApiWrapper.TouchEventFlags.MOVE) { // 移動距離が規定の間隔に満たない場合は処理しない TouchPoint lastTouchPoint = _orbit.Last(); int distance = Calculator.CalcurateDistance(lastTouchPoint.X, lastTouchPoint.Y, eventData.x, eventData.y); if (distance < _moveInterval) { return; } // 「タッチムーブ」イベントハンドラを実行する var touchPoint = new TouchPoint(eventData.x, eventData.y); var teArgs = new TouchEventArgs(touchPoint, _orbit); _orbit.Add(touchPoint); OnTouchMove(teArgs); } else if ((eventFlags & Win32ApiWrapper.TouchEventFlags.UP) == Win32ApiWrapper.TouchEventFlags.UP) { // 「タッチアップ」イベントハンドラを実行する var touchPoint = new TouchPoint(eventData.x, eventData.y); var teArgs = new TouchEventArgs(touchPoint, _orbit); _orbit.Add(touchPoint); OnTouchUp(teArgs); } }
/// <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> /// [内部メソッド] /// 距離を取得する( 1 / 100 ピクセル ) /// </summary> /// <param name="touchPoint">基準となる接触点</param> /// <returns> 基準点との距離 </returns> public int GetDistanceFrom(TouchPoint baseTouchPoint) { return(Calculator.CalcurateDistance(baseTouchPoint.X, baseTouchPoint.Y, this.X, this.Y)); }
/// <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); } } }