Beispiel #1
0
        // Touch down event handler.
        /// <summary>
        /// 输入一个点,判定是否为手势,是则不需要在继续判断,手指离开时,将手势标识设置为false
        /// 如果不是则继续判断是否为手势.
        /// </summary>
        /// <param name="drawingCanvas"></param>
        /// <param name="e"></param>
        public void TouchDownHandler(DrawingCanvas drawingCanvas, TouchEventArgs e)
        {
            GestureData.Fingers++;//记录手指数
            GraphicsPolyLine polyLine;
            TouchPoint       touchPoint = e.GetTouchPoint(drawingCanvas);
            Point            p          = touchPoint.Position;

            if (GestureData.Fingers == 1)//记录第一个手指的基本信息,后后续手势判断使用
            {
                if (!GestureData.IsSignFoFingerOne)
                {
                    GestureData.IsTouch               = true;
                    GestureData.FirstDeviceId         = e.TouchDevice.Id;
                    GestureData.FirstFingerBeginPoint = p;
                    GestureData.FirstFingerCurPoint   = p;
                    GestureData.IsSignFoFingerOne     = true;
                }
            }

            HelperFunctions.IsGesture(drawingCanvas, e);//判断是否为手势

            //如果是手势,则将第一个手指画的几何型的Candraw属性置为false,使得后续不在画出来
            if (GestureData.IsGesture && GestureData.Fingers == 2 && _activeStrokes.TryGetValue(GestureData.FirstDeviceId, out polyLine))
            {
                polyLine.CanDraw = false;
            }

            if (_activeStrokes.TryGetValue(e.TouchDevice.Id, out polyLine))
            {
                FinishStroke(polyLine);
                return;
            }

            //当手指的个数大于2时,将第一个手指与第二个手指的canDraw属性置回true
            if (!GestureData.IsGesture && GestureData.Fingers > 2)
            {
                if (_activeStrokes.TryGetValue(GestureData.FirstDeviceId, out polyLine))
                {
                    polyLine.CanDraw = true;
                }
                if (_activeStrokes.TryGetValue(GestureData.SecondDeviceId, out polyLine))
                {
                    polyLine.CanDraw = true;
                }
            }

            // Create new stroke, add point and assign a color to it.
            GraphicsPolyLine newPolyLine = new GraphicsPolyLine(
                new Point[]
            {
                p,
                new Point(p.X + 1, p.Y + 1)
            },
                drawingCanvas.LineWidth,
                drawingCanvas.ObjectColor,
                drawingCanvas.ActualScale);

            newPolyLine.DeviceID = e.TouchDevice.Id;
            //是手势并且是第二个手指,将其画的几何的CanDraw置为false,不用画
            if (GestureData.IsGesture && GestureData.Fingers == 2)
            {
                if (!GestureData.IsSignForFingerTwo)
                {
                    GestureData.SecondDeviceId               = e.TouchDevice.Id;
                    GestureData.SecFingerBeginPoint          = p;
                    GestureData.StartDistInTwoFingers        = HelperFunctions.CalcDistanceSquare(GestureData.FirstFingerBeginPoint, GestureData.SecFingerBeginPoint);
                    GestureData.StartCenterPointInTwoFingers = HelperFunctions.getCenterPoint(GestureData.FirstFingerBeginPoint, GestureData.SecFingerBeginPoint);
                    GestureData.SecFingerCurPoint            = p;
                    newPolyLine.CanDraw            = false;
                    GestureData.IsSignForFingerTwo = true;
                    if (GestureData.FirstFingerBeginPoint.X < GestureData.SecFingerBeginPoint.X)
                    {
                        GestureData.MaxPositionX = true;
                    }
                }
            }
            //防止已经是手势了,但因为用户不小心使得其他手指不小心碰到了触控,需要使得该误碰的手写内容不画出来
            if (GestureData.IsGesture && GestureData.Fingers > 2)
            {
                newPolyLine.CanDraw = false;
            }
            AddNewObject(drawingCanvas, newPolyLine);

            // Add new stroke to the collection of strokes in drawing.
            _activeStrokes[newPolyLine.DeviceID] = newPolyLine;

            System.Diagnostics.Debug.WriteLine("Touchdown:{0}", GestureData.IsGesture);
        }