/// <summary>
        /// Toda ação de toque vai subir esse manipulador de eventos. 
        /// </summary>
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            int pointsNumber = e.GetTouchPoints(drawCanvas).Count;
            TouchPointCollection pointCollection = e.GetTouchPoints(drawCanvas);

            for (int i = 0; i < pointsNumber; i++)
            {
                if (pointCollection[i].Action == TouchAction.Down)
                {
                    preXArray[i] = pointCollection[i].Position.X;
                    preYArray[i] = pointCollection[i].Position.Y;
                }
                if (pointCollection[i].Action == TouchAction.Move)
                {
                    Line line = new Line();

                    line.X1 = preXArray[i];
                    line.Y1 = preYArray[i];
                    line.X2 = pointCollection[i].Position.X;
                    line.Y2 = pointCollection[i].Position.Y;

                    line.Stroke = new SolidColorBrush(Colors.Black);
                    line.Fill = new SolidColorBrush(Colors.Black);
                    drawCanvas.Children.Add(line);

                    preXArray[i] = pointCollection[i].Position.X;
                    preYArray[i] = pointCollection[i].Position.Y;
                }
            }
        }
Пример #2
0
    private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
    {
        try
        {
            var touchPoints = e.GetTouchPoints(Map);

            SuppressMapGestures = touchPoints.Count == 3;

            if (touchPoints.Count == 3)
            {
                if (!_initialPitchYLocation.HasValue)
                {
                    _initialPitchYLocation = touchPoints[0].Position.Y;
                }

                double delta = touchPoints[0].Position.Y - _initialPitchYLocation.Value;
                double newPitch = Math.Max(0, Math.Min(75, (Map.Pitch + delta * Sensitivity)));
                Map.Pitch = newPitch;
                _initialPitchYLocation = touchPoints[0].Position.Y;
            }
            else
            {
                _initialPitchYLocation = null;
            }
        }
        catch { }
      
    }
Пример #3
0
        //int kol_move = 0;
        void TouchFrameReported(object sender, TouchFrameEventArgs e)
        {
            //kol_move++;
            //if (kol_move==1) MessageBox.Show("");
            var points = e.GetTouchPoints(null);
            if (points != null)
            {
                foreach (var point in points)
                {
                    //textBlock2.Text = point.Position.X.ToString() + point.Position.Y.ToString() + point.Action.ToString();
                    if (point.Action.ToString() == "Down")
                    {
                        downX = point.Position.X;
                        downY = point.Position.Y;
                    }
                    if (point.Action.ToString() == "Up")
                    {
                        double y2 = 0; double x2 = 0;
                        double x = downX - point.Position.X; if (x < 0) x2 = x * -1; else x2 = x;
                        double y = downY - point.Position.Y; if (y < 0) y2 = y * -1; else y2 = y;

                        if (y2 > x2 && y2 > 80) if (y < 0)
                                image22_Tap(null, null); //MessageBox.Show("1");
                            else image24_Tap(null, null); //MessageBox.Show("2");
                    }
                }
            }
        }
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            if (draggingNow == true)
            {
                TouchPoint tp = e.GetPrimaryTouchPoint(map1);

                if (tp.Action == TouchAction.Move)
                {
                    if (draggingArea == true)
                    {
                        if (twoMarker != null)
                        {
                            twoMarker.GeoCoordinate = map1.ConvertViewportPointToGeoCoordinate(tp.Position);
                            areaRadius = (int)twoMarker.GeoCoordinate.GetDistanceTo(oneMarker.GeoCoordinate);
                            DoCreateTheAreaCircle();
                        }
                    }
                    else if (oneMarker != null)
                    {
                        oneMarker.GeoCoordinate = map1.ConvertViewportPointToGeoCoordinate(tp.Position);
                        DoCreateTheAreaCircle();
                        if (twoMarker != null && PolyCircle != null && PolyCircle.Path != null)
                        {
                            twoMarker.GeoCoordinate = PolyCircle.Path[0];
                        }
                    }
                }
                else if (tp.Action == TouchAction.Up)
                {
                    draggingArea = draggingNow = false;
                    map1.IsEnabled = true;
                }
            }
        }
Пример #5
0
 internal static void ReportFrame()
 {
     if (FrameReported != null)
     {
         TouchFrameEventArgs args = new TouchFrameEventArgs(Environment.TickCount);
         FrameReported(null, args);
     }
 }
Пример #6
0
 internal static void ReportFrame()
 { 
     if (FrameReported != null)
     { 
         TouchFrameEventArgs args = new TouchFrameEventArgs(Environment.TickCount); 
         FrameReported(null, args);
     } 
 }
        void TouchFrameReported(object sender, TouchFrameEventArgs e)
        {
            while (TouchPanel.IsGestureAvailable)
            {
                GestureSample gestureSample = TouchPanel.ReadGesture();
                if(gestureSample.GestureType == GestureType.Pinch)
                {
                    if(!_isScaleStarted)
                    {
                        _compositeTransform = new CompositeTransform();
                        Transforms.Children.Add(_compositeTransform);
                        _compositeTransform.CenterX = (gestureSample.Position.X + gestureSample.Position2.X) / 2;
                        _compositeTransform.CenterY = (gestureSample.Position.Y + gestureSample.Position2.Y) / 2;

                        _gestWidth = Math.Abs(gestureSample.Position.X - gestureSample.Position2.X);
                        _gestHeight = Math.Abs(gestureSample.Position.Y - gestureSample.Position2.Y);

                        _isScaleStarted = true;
                    }
                    else
                    {
                        //if (Transforms.Children.OfType<CompositeTransform>().Select(x=>x.ScaleX).Multiplication() >= 1)
                        {
                            _compositeTransform.ScaleX = Math.Abs(gestureSample.Position.X - gestureSample.Position2.X) / _gestWidth;
                        }

                        //if (Transforms.Children.OfType<CompositeTransform>().Select(x => x.ScaleY).Multiplication() >= 1)
                        {
                            _compositeTransform.ScaleY = Math.Abs(gestureSample.Position.Y - gestureSample.Position2.Y) / _gestHeight;
                        }

                    }
                }
                else if(gestureSample.GestureType == GestureType.PinchComplete)
                {
                    _isScaleStarted = false;
                }
                else if (gestureSample.GestureType == GestureType.VerticalDrag || gestureSample.GestureType == GestureType.HorizontalDrag || gestureSample.GestureType == GestureType.FreeDrag)
                {
                    if(!_isDrugStarted)
                    {
                        _compositeTransform = new CompositeTransform();
                        _drugPosition = gestureSample.Position;
                        Transforms.Children.Add(_compositeTransform);
                        _isDrugStarted = true;
                    }
                    else
                    {
                        _compositeTransform.TranslateX = gestureSample.Position.X - _drugPosition.X;
                        _compositeTransform.TranslateY = gestureSample.Position.Y - _drugPosition.Y;
                    }
                }
                else if (gestureSample.GestureType == GestureType.DragComplete)
                {
                    _isDrugStarted = false;
                }
            }
        }
Пример #8
0
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            if (this.mainCanvas != null)
            {
                foreach (TouchPoint _touchPoint in e.GetTouchPoints(this.mainCanvas))
                {

                }
            }
        }
Пример #9
0
 void TouchFrameReported(object sender, TouchFrameEventArgs e)
 {
     TouchPointCollection tpc = e.GetTouchPoints(ContentCanvas);
     tpc.ToList().ForEach(p =>
     {
         // p.Action of type ActionType: Up, Down, Move
         Ellipse el = TouchUtils.CreateEllipse(p.Position);
         ContentCanvas.Children.Add(el);
     });
 }
Пример #10
0
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            try
            {
                int pointsNumber = e.GetTouchPoints(ellipseSense).Count;
                TouchPointCollection pointCollection = e.GetTouchPoints(ellipseSense);


                for (int i = 0; i < pointsNumber; i++)
                {
                    if (pointCollection[i].Position.X > 0 && pointCollection[i].Position.X < ellipseSense.ActualWidth)
                    {
                        if (pointCollection[i].Position.Y > 0 && pointCollection[i].Position.Y < ellipseSense.ActualHeight)
                        {
                            // Update Shpero speed and direction
                            Point p = pointCollection[i].Position;
                            Point center = new Point(ellipseSense.ActualWidth / 2, ellipseSense.ActualHeight / 2);

                            double distance = Math.Sqrt(Math.Pow((p.X - center.X), 2) + Math.Pow((p.Y - center.Y), 2));

                            double distanceRel = distance * 255 / (ellipseSense.ActualWidth / 2);
                            if (distanceRel > 255)
                            {
                                distanceRel = 255;
                            }

                            double angle = Math.Atan2(p.Y - center.Y, p.X - center.X) * 180 / Math.PI;
                            if (angle > 0)
                            {
                                angle += 90;
                            }
                            else
                            {
                                angle = 270 + (180 + angle);
                                if (angle >= 360)
                                {
                                    angle -= 360;
                                }
                            }
                            direction = Convert.ToInt16(angle);
                            speed = Convert.ToInt16(distanceRel);

                            // Set Joystick Pos
                            newX = p.X - (ellipseSense.ActualWidth / 2);
                            newY = p.Y - (ellipseSense.ActualWidth / 2);
                            if (moveJoystick) MoveJoystick(newX, newY);
                        }
                    }
                }
            }
            catch
            {
            }
        }
Пример #11
0
 void Touch_FrameReported(object sender, TouchFrameEventArgs e)
 {
     Debug.WriteLine("Touch_FrameReported");
     var point =  e.GetPrimaryTouchPoint(LayoutRoot);
     Debug.WriteLine(point.Position.X+""+point.Position.Y );
     var points = e.GetTouchPoints(LayoutRoot);
     foreach (var item in points)
     {
         Debug.WriteLine(item.Position.X + "" + item.Position.Y);
     }
 }
Пример #12
0
 void Touch_FrameReported(MainPage mainPage, TouchFrameEventArgs e)
 {
     foreach (TouchPoint touchPoint in e.GetTouchPoints(mainPage))
     {
         this.data = new Newtonsoft.Json.Linq.JObject();
         AddJOValue("xcoord", touchPoint.Position.X);
         AddJOValue("ycoord", touchPoint.Position.Y);
         AddJOValue("action", touchPoint.Action.ToString());
         AddJOValue("timestamp", DeviceTools.GetUnixTime());
         SaveLogToDB(this.data, "/log/touch");
     }
 }
Пример #13
0
        private void Check(object sender, TouchFrameEventArgs e)
        {
            if (!_isHitTestVisible) return;

            var touchCollection = e.GetTouchPoints(null);
            for (var i = 0; i < touchCollection.Count; i++)
            {
                var touch = touchCollection[i];
                for (var j = 0; j < _drums.Drum.Count(); j++)
                {
                    var drum = _drums.Drum[j];
                    if (touch.TouchDevice.DirectlyOver == drum.CurrentPath())
                    {
                        _flags[j] = true;
                        if (touch.Action == TouchAction.Move)
                        {
                            if (!_isHighlighted[j])
                            {
                                drum.CurrentPath().Fill = _translatedBrush;
                                _isHighlighted[j] = false;
                            }
                        }

                        if (touch.Action == TouchAction.Up)
                        {
                            _isHighlighted[j] = false;
                            drum.CurrentPath().Fill = _translatedBrush;
                        }

                        if (touch.Action == TouchAction.Down)
                        {
                            drum.Play();
                            _isHighlighted[j] = true;
                            drum.CurrentPath().Fill = _highlightedBrush;
                        }
                    }
                    else
                    {
                        _flags[j] = false;
                    }
                }
            }

            for (var i = 0; i < _flags.Count(); i++)
            {
                if (!_flags[i]
                    && _isHighlighted[i])
                {
                    _isHighlighted[i] = false;
                    _drums.Drum[i].CurrentPath().Fill = _translatedBrush;
                }
            }
        }
Пример #14
0
    private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
    {
        if(rotate){
            TouchPointCollection touchPoints;
            try
            {
                touchPoints = e.GetTouchPoints(Map);
            }
            catch
            {
                return;
            }

            if (touchPoints.Count == 2)
            {
                // for the initial touch, record the angle between the fingers
                if (!_previousAngle.HasValue)
                {
                    _previousAngle = AngleBetweenPoints(touchPoints[0], touchPoints[1]);
                }

                // should we rotate?
                if (!_isRotating)
                {
                    double angle = AngleBetweenPoints(touchPoints[0], touchPoints[1]);
                    double delta = angle - _previousAngle.Value;
                    if (Math.Abs(delta) > MinimumRotation)
                    {
                        _isRotating = true;
                        SuppressMapGestures = true;
                    }
                }

                // rotate me
                if (_isRotating && rotate)
                {
                    double angle = AngleBetweenPoints(touchPoints[0], touchPoints[1]);
                    double delta = angle - _previousAngle.Value;
                    Map.Heading -= delta;
                    _previousAngle = angle;
                }
            }
            else
            {
                _previousAngle = null;
                _isRotating = false;
                SuppressMapGestures = false;
            }
        }
      
    }
        private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            /* If ui-control-specific gesture detection is enabled,
             * on touch down, update touch ID & Gesture mapping: Which gestures we need to detect for this touch
             *
             * NOTE: While this is useful when application wants ui-control specific gestures but not so good in
             * terms of performance application uses root canvas level gestures
             */

            // Update stroke records of each active touch
            TouchPointCollection slPoints = e.GetTouchPoints(GestureFramework.LayoutRoot);
            List<TouchInfo> touchInfos = slPoints.ToTouchInfo();
            List<TouchPoint2> touchPoints = base.UpdateActiveTouchPoints(touchInfos);

            // Determine touch source for any new touch point
            foreach (var touchPoint in touchPoints)
            {
                if (touchPoint.Action == TouchAction.Down)
                {
                    touchPoint.UpdateSource();
                }
            }

            // Raw data, frame changed
            if (FrameChanged != null)
            {
                FrameInfo fi = new FrameInfo();
                fi.Touches = touchInfos;
                fi.TimeStamp = e.Timestamp;
                fi.WaitTime = (lastTimeStamp == 0 ? 0 : e.Timestamp - lastTimeStamp);
                FrameChanged(this, fi);
            }

            // Creating one callback for each touch point
            if (SingleTouchChanged != null)
            {
                foreach (TouchPoint2 p in touchPoints)
                {
                    SingleTouchChanged(this, new SingleTouchEventArgs(p));
                }
            }

            // Sending all points in one callback
            if (MultiTouchChanged != null)
            {
                MultiTouchChanged(this, new MultiTouchEventArgs(touchPoints));
            }

            lastTimeStamp = e.Timestamp;
        }
Пример #16
0
 private void onTouchFrameReported(object sender, TouchFrameEventArgs e)
 {
     TouchPoint primaryTouchPoint = e.GetPrimaryTouchPoint(null);
     if (primaryTouchPoint != null && primaryTouchPoint.Action == TouchAction.Down)
     {
         if (primaryTouchPoint.TouchDevice.DirectlyOver == txtblk)
         {
             txtblk.Foreground = new SolidColorBrush(Color.FromArgb(255, (byte)rand.Next(256), (byte)rand.Next(256), (byte)rand.Next(256)));
         }
         else if (primaryTouchPoint.TouchDevice.DirectlyOver != KaiSon)
         {
             txtblk.Foreground = originalBrush;
         }
     }
 }
Пример #17
0
        void OnTouchFrameReported(object sender, TouchFrameEventArgs args)
        {
            TouchPoint PritTouch = args.GetPrimaryTouchPoint(null);

            if (PritTouch != null)
            {
                nbMoves = 0;
            }

            if (PritTouch.Action == TouchAction.Move)
            {
                nbMoves++;
            }

            textblock1.Text = String.Format("{0}-{1}", nbMoves.ToString(), PritTouch.Position.ToString());
            ContentPanel.Background = new SolidColorBrush(Color.FromArgb(255, (byte)nbMoves, (byte)PritTouch.Position.X, (byte)PritTouch.Position.Y));
        }
Пример #18
0
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            if (draggingNow == true)
            {
                TouchPoint tp = e.GetPrimaryTouchPoint(map1);

                if (tp.Action == TouchAction.Move && (selectedMarker != null))
                {
                    selectedMarker.GeoCoordinate = map1.ConvertViewportPointToGeoCoordinate(tp.Position);
                    Start_ReverceGeoCoding(selectedMarker);
                }
                else if (tp.Action == TouchAction.Up)
                {
                    selectedMarker = null;
                    draggingNow = false;
                    map1.IsEnabled = true;
                }
            }
        }
Пример #19
0
        private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            // Update stroke records of each active touch
            TouchPointCollection slPoints = e.GetTouchPoints(GestureFramework.LayoutRoot);
            List<TouchInfo> touchInfos = slPoints.ToTouchInfo();
            List<TouchPoint2> touchPoints = base.UpdateActiveTouchPoints(touchInfos);

            // Determine touch source for any new touch point
            foreach (var touchPoint in touchPoints)
            {
                if (touchPoint.Action == TouchAction.Down)
                {
                    touchPoint.UpdateSource();
                }
            }

            // Raw data, frame changed
            if (FrameChanged != null)
            {
                FrameInfo fi = new FrameInfo();
                fi.Touches = touchInfos;
                fi.TimeStamp = e.Timestamp;
                fi.WaitTime = (lastTimeStamp == 0 ? 0 : e.Timestamp - lastTimeStamp);
                FrameChanged(this, fi);
            }

            // Creating one callback for each touch point
            if (SingleTouchChanged != null)
            {
                foreach (TouchPoint2 p in touchPoints)
                {
                    SingleTouchChanged(this, new SingleTouchEventArgs(p));
                }
            }

            // Sending all points in one callback
            if (MultiTouchChanged != null)
            {
                MultiTouchChanged(this, new MultiTouchEventArgs(touchPoints));
            }

            lastTimeStamp = e.Timestamp;
        }
Пример #20
0
        void Touch_FrameReported(object sender, System.Windows.Input.TouchFrameEventArgs e)
        {
            if (draggingNow == true)
            {
                TouchPoint tp = e.GetPrimaryTouchPoint(map1);

                if (tp.Action == TouchAction.Move)
                {
                    if (oneMarker != null)
                    {
                        oneMarker.GeoCoordinate = map1.ConvertViewportPointToGeoCoordinate(tp.Position);
                    }
                }
                else if (tp.Action == TouchAction.Up)
                {
                    draggingNow    = false;
                    map1.IsEnabled = true;
                }
            }
        }
Пример #21
0
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            if (draggingNow == true)
            {
                TouchPoint tp = e.GetPrimaryTouchPoint(map1);

                if (tp.Action == TouchAction.Move)
                {
                    if (oneMarker != null)
                    {
                        SetMarkerLocation(map1.ConvertViewportPointToGeoCoordinate(tp.Position));
                    }
                }
                else if (tp.Action == TouchAction.Up)
                {
                    draggingNow = false;
                    map1.IsEnabled = true;
                }
            }
        }
Пример #22
0
        /// <summary>
        /// 触摸页面报告 用于多点触控缩放
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {

            if (e.GetTouchPoints(this.ShowImageControler).Count > 1)
            {
                if (e.GetTouchPoints(this.ShowImageControler)[0].Action == TouchAction.Down || e.GetTouchPoints(this.ShowImageControler)[1].Action == TouchAction.Down)
                {
                    InitialSize = CalLenth(e.GetTouchPoints(this.ShowImageControler)[0].Position, e.GetTouchPoints(this.ShowImageControler)[1].Position);
                    InitialSizeX = imgScale.ScaleX;
                    InitialSizeY = imgScale.ScaleY;
                }
                if (InitialSize > 0)
                {
                    imgScale.ScaleX = InitialSizeX * CalLenth(e.GetTouchPoints(this.ShowImageControler)[0].Position, e.GetTouchPoints(this.ShowImageControler)[1].Position) / InitialSize;
                    imgScale.ScaleY = InitialSizeY * CalLenth(e.GetTouchPoints(this.ShowImageControler)[0].Position, e.GetTouchPoints(this.ShowImageControler)[1].Position) / InitialSize;

                }

            }
        } 
Пример #23
0
        private static void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            // (When the parent Panorama/Pivot is suspended)
            // Wait for the first touch to end (touchaction up). When it is, restore standard
            // panning behavior, otherwise let the control behave normally (no code for this)
            var lastTouchPoint = InternalPanningControl.GetValue(BlocksPan.LastTouchPointProperty) as TouchPoint;
            var isScrollSuspended = (bool)InternalPanningControl.GetValue(BlocksPan.IsScrollSuspendedProperty);
            var touchPoints = e.GetTouchPoints(InternalPanningControl);

            if (lastTouchPoint != touchPoints.Last() || lastTouchPoint == null)
                lastTouchPoint = touchPoints.Last();

            if (isScrollSuspended)
            {
                // Touch is up, custom behavior is over reset to original values
                if (lastTouchPoint.Action == TouchAction.Up)
                {
                    Touch.FrameReported -= Touch_FrameReported;
                    lastTouchPoint = null;
                    InternalPanningControl.IsHitTestVisible = true;
                    isScrollSuspended = false;
                }
            }
        }
Пример #24
0
 private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
 {
     //SetTiltShiftFocus(e.GetTouchPoints(Viewport));
 }
Пример #25
0
        /// <summary>
        /// Handles TouchFrameReported event and raise TouchDown/Up/Move events.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void TouchFrameReported(object sender, TouchFrameEventArgs e)
        {
            // get the root

            UIElement root = rootNode;
            if (root == null)
            {
                return;
            }

            foreach (TouchPoint touchPoint in e.GetTouchPoints(null))
            {
                int id = touchPoint.TouchDevice.Id;

                // check if the touchDevice is captured or not.
                UIElement captured;
                currentCaptures.TryGetValue(id, out captured);

                switch (touchPoint.Action)
                {
                    // TouchDown
                    case TouchAction.Down:
                        HitTestAndRaiseDownEvent(root, touchPoint);
                        currentTouchPoints[id] = touchPoint;
                        break;

                    // TouchUp
                    case TouchAction.Up:
                        // handle only captured touches
                        if (captured != null)
                        {
                            RaiseUpEvent(captured, touchPoint);

                            // release capture
                            Capture(touchPoint.TouchDevice, null);
                            captured = null;
                        }
                        currentTouchPoints.Remove(id);
                        break;

                    // TouchMove
                    case TouchAction.Move:
                        // just remember the new touchPoint, the event will be raised in bulk later
                        currentTouchPoints[id] = touchPoint;
                        break;
                }
            }

            // raise CapturedReportEvents
            RaiseCapturedReportEvent();
        }
        /// <summary>
        /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed.
        /// <example>
        /// touchframeeventhandler.BeginInvoke(sender, e, callback);
        /// </example>
        /// </summary>
        public static IAsyncResult BeginInvoke(this TouchFrameEventHandler touchframeeventhandler, Object sender, TouchFrameEventArgs e, AsyncCallback callback)
        {
            if(touchframeeventhandler == null) throw new ArgumentNullException("touchframeeventhandler");

            return touchframeeventhandler.BeginInvoke(sender, e, callback, null);
        }
 private void OnFrameReported(object sender, TouchFrameEventArgs e)
 {
     var touchPoints = e.GetTouchPoints(null);
     if (touchPoints != null)
         OnTouch(touchPoints);
 }
Пример #28
0
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            TouchPoint primaryTouchPoint = e.GetPrimaryTouchPoint(null);

            // Inhibit mouse promotion
            if (primaryTouchPoint != null && primaryTouchPoint.Action == TouchAction.Down)
                e.SuspendMousePromotionUntilTouchUp();

            TouchPointCollection touchPoints = e.GetTouchPoints(null);

            foreach (var item in touchPoints)
            {
                if (item.Action == TouchAction.Down)
                {
                    //if (item.TouchDevice.DirectlyOver == image1)
                    //{
                        a = true;
                    //}
                        Image touchIsImage = item.TouchDevice.DirectlyOver as Image;
                        if (touchIsImage != null && touchIsImage.Name != "originalImage")
                        {
                            try
                            {
                                Carrier.Children.Remove(item.TouchDevice.DirectlyOver);//移掉Image控件在Carrier的子节点
                                g.Children.Remove(item.TouchDevice.DirectlyOver);//移掉Image控件在Grid的子节点
                                Carrier.Children.Add(item.TouchDevice.DirectlyOver);//移掉Image控件在Carrier的子节点
                            }
                            catch
                            { }
                            finally
                            {
                            }
                            //try
                            //{
                            //    Carrier.Children.Add(item.TouchDevice.DirectlyOver);//移掉Image控件在Carrier的子节点
                            //}
                            //catch { }

                            downDirectlyOver = item.TouchDevice.DirectlyOver.GetValue(NameProperty).ToString();
                        }
                        originalImage.Visibility = Visibility.Collapsed;
                }

                if (item.Action == TouchAction.Move)
                {
                    moveDirectlyOver = item.TouchDevice.DirectlyOver.GetValue(NameProperty).ToString();
                    if (a == true && moveDirectlyOver == downDirectlyOver)
                    {
                        Canvas.SetLeft(item.TouchDevice.DirectlyOver, item.Position.X - smallSquareWidth / 1.8);
                        Canvas.SetTop(item.TouchDevice.DirectlyOver, item.Position.Y - smallSquareHeight / 1.8);
                        Canvas.SetZIndex(item.TouchDevice.DirectlyOver, 999);//处于最上端
                    }
                }

                if (item.Action == TouchAction.Up)
                {
                    a = false;
                    if (gameClass == "5And5")
                    {
                        #region 第一行
                        if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[0, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[1, 0].y))
                        {
                            //1
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 1].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 0, 0);
                            }
                            //2
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 2].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 1, 1);
                            }
                            //3
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 3].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 2, 2);
                            }
                            //4
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 3].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 4].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 3, 3);
                            }
                            //5
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 4].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 5].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 4, 4);
                            }
                        }
                        #endregion

                        #region 第二行
                        if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[1, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[2, 0].y))
                        {
                            //1
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 1].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 0, 5);
                            }
                            //2
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 2].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 1, 6);
                            }
                            //3
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 3].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 2, 7);
                            }
                            //4
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 3].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 4].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 3, 8);
                            }
                            //5
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 4].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 5].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 4, 9);
                            }
                        }
                        #endregion

                        #region 第三行
                        if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[2, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[3, 0].y))
                        {
                            //1
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 1].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 0, 10);
                            }
                            //2
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 2].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 1, 11);
                            }
                            //3
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 3].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 2, 12);
                            }
                            //4
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 3].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 4].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 3, 13);
                            }
                            //5
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 4].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 5].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 4, 14);
                            }
                        }
                        #endregion

                        #region 第四行
                        if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[3, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[4, 0].y))
                        {
                            //1
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[3, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[3, 1].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 3, 0, 15);
                            }
                            //2
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[3, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[3, 2].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 3, 1, 16);
                            }
                            //3
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[3, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[3, 3].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 3, 2, 17);
                            }
                            //4
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[3, 3].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[3, 4].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 3, 3, 18);
                            }
                            //5
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[3, 4].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[3, 5].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 3, 4, 19);
                            }
                        }
                        #endregion

                        #region 第五行
                        if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[4, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[5, 0].y))
                        {
                            //1
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[4, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[4, 1].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 4, 0, 20);
                            }
                            //2
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[4, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[4, 2].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 4, 1, 21);
                            }
                            //3
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[4, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[4, 3].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 4, 2, 22);
                            }
                            //4
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[4, 3].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[5, 4].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 4, 3, 23);
                            }
                            //5
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[4, 4].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[4, 5].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 4, 4, 24);
                            }
                        }
                        #endregion
                    }

                    if (gameClass == "4And4")
                    {
                        #region 第一行
                        if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[0, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[1, 0].y))
                        {
                            //1
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 1].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 0, 0);
                            }
                            //2
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 2].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 1, 1);
                            }
                            //3
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 3].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 2, 2);
                            }
                            //4
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 3].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 4].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 3, 3);
                            }
                        }
                        #endregion

                        #region 第二行
                        if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[1, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[2, 0].y))
                        {
                            //1
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 1].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 0, 4);
                            }
                            //2
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 2].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 1, 5);
                            }
                            //3
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 3].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 2, 6);
                            }
                            //4
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 3].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 4].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 3, 7);
                            }
                        }
                        #endregion

                        #region 第三行
                        if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[2, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[3, 0].y))
                        {
                            //1
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 1].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 0, 8);
                            }
                            //2
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 2].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 1, 9);
                            }
                            //3
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 3].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 2, 10);
                            }
                            //4
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 3].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 4].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 3, 11);
                            }
                        }
                        #endregion

                        #region 第四行
                        if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[3, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[4, 0].y))
                        {
                            //1
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[3, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[3, 1].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 3, 0, 12);
                            }
                            //2
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[3, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[3, 2].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 3, 1, 13);
                            }
                            //3
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[3, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[3, 3].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 3, 2, 14);
                            }
                            //4
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[3, 3].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[3, 4].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 3, 3, 15);
                            }
                        }
                        #endregion
                    }

                    if (gameClass == "3And3")
                    {
                        #region 第一行
                        if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[0, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[1, 0].y))
                        {
                            //1
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 1].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 0, 0);
                            }
                            //2
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 2].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 1, 1);
                            }
                            //3
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 3].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 2, 2);
                            }
                        }
                        #endregion

                        #region 第二行
                        if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[1, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[2, 0].y))
                        {
                            //1
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 1].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 0, 3);
                            }
                            //2
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 2].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 1, 4);
                            }
                            //3
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 3].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 2, 5);
                            }
                        }
                        #endregion

                        #region 第三行
                        if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[2, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[3, 0].y))
                        {
                            //1
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 1].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 0, 6);
                            }
                            //2
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 2].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 1, 7);
                            }
                            //3
                            if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 3].x)
                            {
                                MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 2, 8);
                            }
                        }
                        #endregion
                    }

                    Canvas.SetZIndex(item.TouchDevice.DirectlyOver, 0);//使拼图返回到原来的层次
                }
            }
        }
Пример #29
0
        private static void TouchFrameReported(object sender, TouchFrameEventArgs e)
        {
            if (_internalPanningControl == null)
                return;

            // (When the parent Panorama/Pivot is suspended)
            // Wait for the first touch to end (touchaction up). When it is, restore standard
            // panning behavior, otherwise let the control behave normally (no code for this)
            var lastTouchPoint = _internalPanningControl.GetValue(LastTouchPointProperty) as TouchPoint;
            var isScrollSuspended = (bool)_internalPanningControl.GetValue(IsScrollSuspendedProperty);

            var touchPoint = e.GetTouchPoints(Application.Current.RootVisual);

            if (lastTouchPoint == null || lastTouchPoint != touchPoint.Last())
                lastTouchPoint = touchPoint.Last();

            if (isScrollSuspended)
            {
                // Touch is up, custom behavior is over reset to original values
                if (lastTouchPoint != null && lastTouchPoint.Action == TouchAction.Up)
                {
                    Touch.FrameReported -= TouchFrameReported;
                    _internalPanningControl.IsHitTestVisible = true;
                    _internalPanningControl.SetValue(IsScrollSuspendedProperty, false);
                }
            }
        }
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            TouchPoint touchPoint = e.GetTouchPoints(this)[0];

            // Slider value can only be modified when the control itself is enabled and the touch point
            // is inside the control (which is elliptic). Also check if the touch position is not in the middle
            // of the control where the textbox is.
            if (this.IsEnabled && PointInsideEllipse(touchPoint.Position.X, controlWidth / 2, touchPoint.Position.Y, controlHeight / 2)
                && !IsPointInsideEllipseShape(InnerEllipse_Dark, touchPoint.Position))
            {
                /*
                * Make sure that the touch point is inside the control, otherwise touch events from any
                * point inside the app are processed. If we don't add this check and there are multiple
                * radial sliders on the form, they will all react to all touch events on the parent page.
                */
                if (Enumerable.Range(0, (int)controlWidth).Contains((int)touchPoint.Position.X) &&
                    Enumerable.Range(0, (int)controlHeight).Contains((int)touchPoint.Position.Y))
                {
                    Thread calcThread = new Thread(new ParameterizedThreadStart(CalculateDraggingPosition));
                    calcThread.Start(touchPoint.Position);
                }
            }
        }
Пример #31
0
        /// <summary>
        /// Handles the FrameReported event of the Touch control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.TouchFrameEventArgs"/> instance containing the event data.</param>
        private void TouchFrameReported(object sender, TouchFrameEventArgs e)
        {
            TouchPoint tp = e.GetPrimaryTouchPoint(null);
            switch (tp.Action)
            {
                case TouchAction.Down:
                    // when the user touches the screen find out if they hit the node, if so start dragging
                    if (Vector2.DistanceSquared(new Vector2((float)tp.Position.X, (float)tp.Position.Y), this.Position) < Global.TouchPointSize * Global.TouchPointSize)
                    {
                        this.isBeingDragged = true;
                        heldAt = new Vector2((float)tp.Position.X, (float)tp.Position.Y);
                    }

                    break;

                case TouchAction.Move:
                    // if dragging move the node to the touch position
                    if (this.isBeingDragged)
                    {
                        var x = tp.Position.X;
                        var y = tp.Position.Y;

                        this.Position = new Vector2((float)x, (float)y);

                        var accentColour = (System.Windows.Media.Color)Application.Current.Resources["PhoneAccentColor"];
                        var tag = new PingTag { AccentColour = accentColour, Ping = false };
                        this.gardener.UpdateSelfNodePosition(x, y, tag.Serialize());
                    }

                    break;

                case TouchAction.Up:
                    // release finger and stop dragging
                    this.isBeingDragged = false;
                    if (heldAt == new Vector2((float)tp.Position.X, (float)tp.Position.Y))
                    {
                        Debug.WriteLine("Ping");
                        var accentColour = (System.Windows.Media.Color)Application.Current.Resources["PhoneAccentColor"];
                        CreateRipple(GetXnaColour(accentColour));
                        var tag = new PingTag { AccentColour = accentColour, Ping = true };
                        gardener.UpdateSelfNodePosition(tp.Position.X, tp.Position.Y, tag.Serialize());
                        gardener.ClearSelfPing();
                    }
                    break;
                default:
                    break;
            }
        }
Пример #32
0
        void HandleTouchFrameReported(object sender, TouchFrameEventArgs e)
        {
            try {
                var pts = e.GetTouchPoints(this);
                var spts = e.GetTouchPoints((UIElement)Parent);

                var began = new List<CanvasTouch>();
                var ended = new List<CanvasTouch>();
                var moved = new List<CanvasTouch>();

                for (var i = 0; i < pts.Count; i++) {

                    var p = pts[i];
                    var handle = new IntPtr(p.TouchDevice.Id + 1);

                    var now = DateTime.UtcNow;

                    if (p.Action == TouchAction.Down) {

                        var pos = p.Position.ToPointF();

                        //
                        // Look for double taps
                        //
                        var tapCount = 1;

                        if (_lastDownTime.ContainsKey(handle) &&
                            _lastBeganPosition.ContainsKey(handle)) {
                            var dt = now - _lastDownTime[handle];

                            if (dt.TotalSeconds < 0.5 && pos.DistanceTo(_lastBeganPosition[handle]) < DoubleClickMinDistance) {
                                tapCount++;
                            }
                        }

                        //
                        // TouchBegan
                        //
                        var t = new CanvasTouch {
                            Handle = handle,
                            TapCount = tapCount,
                            CanvasLocation = pos,
                            CanvasPreviousLocation = pos,
                            SuperCanvasLocation = spts[i].Position.ToPointF(),
                            SuperCanvasPreviousLocation = spts[i].Position.ToPointF(),
                            PreviousTime = now,
                            Time = now,
                        };
                        _activeTouches[t.Handle] = t;
                        _lastDownTime[t.Handle] = now;
                        _lastBeganPosition[t.Handle] = pos;
                        began.Add(t);
                    }
                    else if (_activeTouches.ContainsKey(handle)) {
                        var t = _activeTouches[handle];

                        t.CanvasPreviousLocation = t.CanvasLocation;
                        t.SuperCanvasPreviousLocation = t.SuperCanvasLocation;
                        t.PreviousTime = t.Time;

                        t.CanvasLocation = p.Position.ToPointF();
                        t.SuperCanvasLocation = spts[i].Position.ToPointF();
                        t.Time = now;

                        if (p.Action == TouchAction.Move) {
                            moved.Add(t);
                        }
                        else {
                            ended.Add(t);
                        }
                    }
                }

                var del = Content;
                if (del != null && _touchEnabled) {
                    if (began.Count > 0) {
                        var keys = CanvasKeys.None;
                        //if (Keyboard.IsKeyDown (Key.LeftCtrl) || Keyboard.IsKeyDown (Key.RightCtrl)) {
                        //	keys = keys | CanvasKeys.Command;
                        //}
                        //if (Keyboard.IsKeyDown (Key.LeftShift) || Keyboard.IsKeyDown (Key.RightShift)) {
                        //	keys = keys | CanvasKeys.Shift;
                        //}
                        del.TouchesBegan(began.ToArray(), keys);
                    }
                    if (moved.Count > 0) {
                        del.TouchesMoved(moved.ToArray());
                    }
                    if (ended.Count > 0) {
                        del.TouchesEnded(ended.ToArray());
                    }
                }
            }
            catch (Exception err) {
                System.Diagnostics.Debug.WriteLine(err);
            }
        }
Пример #33
0
        private void Touch_FrameReported(object sender, System.Windows.Input.TouchFrameEventArgs e)
        {
            if (!m_bInThisApp)
            {
                return;
            }

            TouchPoint primaryTouchPoint = e.GetPrimaryTouchPoint(null);

            if (primaryTouchPoint == null)
            {
                return;
            }

            switch (primaryTouchPoint.Action)
            {
            case TouchAction.Down:
                m_ptTouchDown = primaryTouchPoint.Position;
                m_bIsInSwipe  = false;
                break;

            case TouchAction.Move:

                m_bIsInSwipe = IsInSwipe(primaryTouchPoint.Position) != 0;

                if (scrl != null)
                {
                    double dCX = 0;

                    if (ContentPanel.ActualWidth < ContentPanel.ActualHeight)
                    {
                        dCX = primaryTouchPoint.Position.X - m_ptTouchDown.X;
                    }
                    else
                    {
                        dCX = primaryTouchPoint.Position.Y - m_ptTouchDown.Y;
                    }

                    //Smaller movement...
                    dCX = dCX / 5;

                    scrl.Margin = new Thickness(dCX, 0, -dCX, 0);
                }

                break;

            case TouchAction.Up:

                if (scrl != null)
                {
                    scrl.Margin = new Thickness(0);
                }

                int iSwipe = IsInSwipe(primaryTouchPoint.Position);

                if (iSwipe < 0)
                {
                    DoPrev();
                }
                else if (iSwipe > 0)
                {
                    DoNext();
                }

                break;
            }
        }
Пример #34
0
        private void Touch_FrameReported(object sender, System.Windows.Input.TouchFrameEventArgs e)
        {
            if (!m_bInThisApp)
            {
                return;
            }

            TouchPoint primaryTouchPoint = e.GetPrimaryTouchPoint(null);

            if (primaryTouchPoint == null)
            {
                return;
            }

            switch (primaryTouchPoint.Action)
            {
            case TouchAction.Down:
                m_ptTouchDown = primaryTouchPoint.Position;
                break;

            case TouchAction.Move:
                if (scrl != null)
                {
                    double dCX = 0;

                    if (ContentPanel.ActualWidth < ContentPanel.ActualHeight)
                    {
                        dCX = primaryTouchPoint.Position.X - m_ptTouchDown.X;
                    }
                    else
                    {
                        dCX = primaryTouchPoint.Position.Y - m_ptTouchDown.Y;
                    }

                    //Smaller movement...
                    dCX = dCX / 5;

                    scrl.Margin = new Thickness(dCX, 0, -dCX, 0);
                }

                break;

            case TouchAction.Up:

                if (scrl != null)
                {
                    scrl.Margin = new Thickness(0);
                }

                int iDistance      = 0;
                int iDistanceOther = 0;

                if (ContentPanel.ActualWidth < ContentPanel.ActualHeight)
                {
                    iDistance      = (int)(primaryTouchPoint.Position.X - m_ptTouchDown.X);
                    iDistanceOther = (int)(primaryTouchPoint.Position.Y - m_ptTouchDown.Y);
                }
                else
                {
                    iDistance      = (int)(primaryTouchPoint.Position.Y - m_ptTouchDown.Y);
                    iDistanceOther = (int)(primaryTouchPoint.Position.X - m_ptTouchDown.X);
                }
                if (iDistanceOther < 0)
                {
                    iDistanceOther *= -1;
                }

                //SetStatus(iDistanceOther.ToString());

                if (iDistance > 50 && iDistanceOther < 200)
                {
                    //lblStatus.Text = "...to the Right (" + iDistance.ToString() + ")...";
                    DoPrev();
                }
                else if (iDistance < -50 && iDistanceOther < 200)
                {
                    //lblStatus.Text = "...to the Left (" + iDistance.ToString() + ")...";
                    DoNext();
                }
                break;
            }
        }
        private void Touch_FrameReported(object sender, System.Windows.Input.TouchFrameEventArgs e)
        {
            string sLog;

            DateTime dNow = DateTime.Now;

            sLog = RscUtils.pad60(dNow.Minute) + ":" + RscUtils.pad60(dNow.Second) + " - ";

            TouchPoint primaryTouchPoint = e.GetPrimaryTouchPoint(null);

            if (primaryTouchPoint == null)
            {
                sLog += "null";
                lstLog.Items.Insert(0, sLog);
            }
            else
            {
                if (primaryTouchPoint.TouchDevice.DirectlyOver != imgTestArea)
                {
                    return;
                }
                else
                {
                    if (primaryTouchPoint.Action == TouchAction.Down)
                    {
                        ptStart = primaryTouchPoint.Position;
                    }

                    sLog += primaryTouchPoint.Action.ToString();
                    lstLog.Items.Insert(0, sLog);

                    sLog  = "      ";
                    sLog += primaryTouchPoint.Position.ToString();
                    lstLog.Items.Insert(1, sLog);

                    sLog  = "      ";
                    sLog += primaryTouchPoint.Size.ToString();
                    lstLog.Items.Insert(2, sLog);

                    sLog = "      ";
                    if (ptStart.X <= primaryTouchPoint.Position.X)
                    {
                        sLog += "Right";
                    }
                    else
                    {
                        sLog += "Left";
                    }
                    lstLog.Items.Insert(3, sLog);

                    sLog = "      ";
                    if (ptStart.Y <= primaryTouchPoint.Position.Y)
                    {
                        sLog += "Down";
                    }
                    else
                    {
                        sLog += "Top";
                    }
                    lstLog.Items.Insert(4, sLog);

                    /*
                     * sLog = "      ";
                     * sLog += (primaryTouchPoint.Position.X - ptStart.X).ToString();
                     * sLog += ":";
                     * sLog += (primaryTouchPoint.Position.Y - ptStart.Y).ToString();
                     * lstLog.Items.Insert(5, sLog);
                     *
                     * sLog = "      ";
                     * sLog += ptStart.ToString();
                     * lstLog.Items.Insert(6, sLog);
                     */
                }
            }
        }