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;
                }
            }
        }
Example #2
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);
     }
 }
Example #3
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;
         }
     }
 }
Example #4
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));
        }
        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;
                }
            }
        }
        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;
                }
            }
        }
        /// <summary>
        ///     Control Multi-Touch inputs using this method.
        ///     Currently provides page switch on swipe with a single finger.
        /// </summary>
        private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            if (_isGlobeOpen)
            {
                TouchPointCollection touchPoints = e.GetTouchPoints(ViewportGlobe);
                if (touchPoints.Count >= 2 && touchPoints[0].Action == TouchAction.Up)
                {
                    TouchLine.X1 = touchPoints[0].Position.X;
                    TouchLine.X2 = touchPoints[1].Position.X;
                    TouchLine.Y1 = touchPoints[0].Position.Y;
                    TouchLine.Y2 = touchPoints[1].Position.Y;
                }
            }
            else
            {
                if (Viewbox != null)
                {
                    // Reset screensaver timer on touch interation as it previously only resetted on mouse interaction.
                    _timer.Interval = new TimeSpan(0, 0, Constants.ScreenSaverWaitTime);

                    // Interact with each of the finger touches.
                    foreach (TouchPoint touchPoint in e.GetTouchPoints(Viewbox))
                    {
                        TouchPoint primaryTouchPoint = e.GetPrimaryTouchPoint(Viewbox);
                            // First touch point on the ViewBox
                        if (touchPoint.Action == TouchAction.Down)
                        {
                            Debug.WriteLine("Home Button Touched. " + Home_BtnRec.AreAnyTouchesCaptured);

                            // Make sure the touches are captured from the viewbox.
                            // Might need to adjust depending on components that might affected by swipe gestures. - ASA
                            touchPoint.TouchDevice.Capture(Viewbox);
                            _initialTouchPoint.X = touchPoint.Position.X;
                        }
                            // Compare id of this touch with the original. If the id's are different then this touch belongs to another finger.
                        else if (touchPoint.Action == TouchAction.Move && e.GetPrimaryTouchPoint(Viewbox) != null)
                        {
                            // First finger touch.
                            TouchPoint point = e.GetPrimaryTouchPoint(Viewbox);
                            if (primaryTouchPoint != null &&
                                touchPoint.TouchDevice.Id == primaryTouchPoint.TouchDevice.Id)
                            {
                                if (_currentPage == Pages.Home)
                                {
                                    ReleaseAllTouchCaptures();
                                    touchPoint.TouchDevice.Capture(ImageGrid);
                                    if (!_alreadySwipedCarousel)
                                    {
                                        // Swipe Left with 50px threshold.
                                        if (touchPoint.Position.X <
                                            (_initialTouchPoint.X - Constants.CarouselImageSwipeThreshold))
                                        {
                                            NextImage_MouseDown(null, null); // Transition to the next carousel image.
                                            _alreadySwipedCarousel = true;
                                        }
                                        // Swipe Right with 50px threshold.
                                        if (touchPoint.Position.X >
                                            (_initialTouchPoint.X + Constants.CarouselImageSwipeThreshold))
                                        {
                                            PreviousImage_MouseDown(null, null);
                                                // Transition to the previous carousel image.
                                            _alreadySwipedCarousel = true;
                                        }
                                    }
                                }
                                else if (_currentPage == Pages.AboutUs || _currentPage == Pages.Help ||
                                         _currentPage == Pages.Support)
                                {
                                    ReleaseAllTouchCaptures();

                                    PageDataScrollViewer.ScrollToHorizontalOffset(_scrollViewerOffset +
                                                                                  _initialTouchPoint.X -
                                                                                  touchPoint.Position.X);
                                    InformationPage2PageDataScrollViewer.ScrollToHorizontalOffset(
                                        _scrollViewerOffset + _initialTouchPoint.X - touchPoint.Position.X);
                                    InformationPage1PageDataScrollViewer.ScrollToHorizontalOffset(
                                        _scrollViewerOffset + _initialTouchPoint.X - touchPoint.Position.X);
                                }
                            }
                                // Perform second finger touch point.
                            else
                            {
                                if (point != null && touchPoint.TouchDevice.Id != point.TouchDevice.Id)
                                {
                                    // _touchPoint is now the object of the second finger.
                                    if (!_alreadySwiped)
                                    {
                                        // Swipe Left with 50px threshold.
                                        if (touchPoint.Position.X > (_initialTouchPoint.X + 50))
                                        {
                                            SwitchPage(true); // Switch Pages
                                            _alreadySwiped = true;
                                        }

                                        // Swipe Right with 50px threshold.
                                        if (touchPoint.Position.X < (_initialTouchPoint.X - 50))
                                        {
                                            SwitchPage(false); // Switch pages.
                                            _alreadySwiped = true;
                                        }
                                    }
                                }
                            }
                        }
                        else if (touchPoint.Action == TouchAction.Up)
                        {
                            _alreadySwiped = false;
                            _alreadySwipedCarousel = false;
                            // Release viewbox touch capture.
                            if (Equals(touchPoint.TouchDevice.Captured, Viewbox))
                            {
                                Viewbox.ReleaseTouchCapture(touchPoint.TouchDevice);
                            }
                                // Release ImageGrid (Carousel) touch capture.
                            else if ((Equals(touchPoint.TouchDevice.Captured, ImageGrid)))
                            {
                                ImageGrid.ReleaseTouchCapture(touchPoint.TouchDevice);
                            }
                            else if ((Equals(touchPoint.TouchDevice.Captured, PageDataScrollViewer)))
                            {
                                PageDataScrollViewer.ReleaseTouchCapture(touchPoint.TouchDevice);
                            }
                            else if ((Equals(touchPoint.TouchDevice.Captured, InformationPage1PageDataScrollViewer)))
                            {
                                InformationPage1PageDataScrollViewer.ReleaseTouchCapture(touchPoint.TouchDevice);
                            }
                            else if ((Equals(touchPoint.TouchDevice.Captured, InformationPage2PageDataScrollViewer)))
                            {
                                InformationPage2PageDataScrollViewer.ReleaseTouchCapture(touchPoint.TouchDevice);
                            }
                            // Update current position of scrollviewer
                            PageDataScrollViewer.UpdateLayout(); //in case we didn't get the current position
                            _scrollViewerOffset = PageDataScrollViewer.HorizontalOffset;

                            InformationPage1PageDataScrollViewer.UpdateLayout();
                                //in case we didn't get the current position
                            _scrollViewerOffset = InformationPage1PageDataScrollViewer.HorizontalOffset;

                            InformationPage2PageDataScrollViewer.UpdateLayout();
                                //in case we didn't get the current position
                            _scrollViewerOffset = InformationPage2PageDataScrollViewer.HorizontalOffset;
                        }
                    }
                }
            }
        }
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            if (!(ListBoxComponent.ActualHeight > 0))
            {
                return;
            }

            foreach (TouchPoint _touchPoint in e.GetTouchPoints(ListBoxComponent))
            {
                if (_touchPoint.Action == TouchAction.Down)
                {
                    if (scrollViewer == null)
                    {
                        if (ListBoxComponent != null)
                            scrollViewer = FindScrollViewer(this);

                        if (scrollViewer == null)
                            return;
                    }

                }
                else if (_touchPoint.Action == TouchAction.Move && e.GetPrimaryTouchPoint(ListBoxComponent) != null)
                {
                    if (!moveStarted && scrollViewer != null)
                    {
                        var offset = scrollViewer.VerticalOffset;

                        if (offset < 0.0001)
                        {
                            if(goBackAnimation != null)
                                goBackAnimation.SkipToFill();

                            moveStarted = true;
                            startY = _touchPoint.Position.Y;
                        }
                    }

                    if (moveStarted)
                    {
                        double visibleHeight = (_touchPoint.Position.Y - startY) * touchSensebility;

                        if (HeaderComponnet != null)
                        {
                            double newHeight = HeaderComponnet.Height + visibleHeight;

                            if (newHeight < 0) {
                                newHeight = 0;
                            }

                            bool inFullHeight = false;

                            if (newHeight >= HeaderComponnet.ActualHeight) {
                                newHeight = HeaderComponnet.ActualHeight;

                                inFullHeight = true;

                                if (!isActivated)
                                {
                                    isActivated = true;
                                }
                            }

                            if (!inFullHeight && isActivated)
                            {
                                isActivated = false;
                            }

                            HeaderComponnet.Height = newHeight;
                        }

                        startY = _touchPoint.Position.Y;
                    }
                } else if (_touchPoint.Action == TouchAction.Up) {
                    moveStarted = false;
                    startY = 0.0f;

                    if (isActivated)
                    {
                        if (OnActivatedDrop != null)
                            OnActivatedDrop(this, null);

                        isActivated = false;
                    }

                    if (HeaderComponnet.Height > 0)
                    {
                        goBackAnimation = CreateGoBackAnimation();
                        goBackAnimation.Begin();
                    }

                }
            }
        }
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            TouchPoint primaryTouchPoint = e.GetPrimaryTouchPoint(null);
            if (primaryTouchPoint != null && primaryTouchPoint.Action == TouchAction.Down) {
                e.SuspendMousePromotionUntilTouchUp();
            }
            TouchPoint touchPoint = (e.GetTouchPoints(inkPresenter))[0];
            Point pt = touchPoint.Position;
            int id = touchPoint.TouchDevice.Id;
            switch (touchPoint.Action) {
                case TouchAction.Down:
                    Stroke stroke = new Stroke();
                    stroke.DrawingAttributes.Color = Colors.DarkGray;
                    stroke.DrawingAttributes.Height = 4;
                    stroke.DrawingAttributes.Width = 4;
                    stroke.StylusPoints.Add(new StylusPoint(pt.X, pt.Y));

                    inkPresenter.Strokes.Add(stroke);
                    activeStokes.Add(id, stroke);

                    break;
                case TouchAction.Move:
                    activeStokes[id].StylusPoints.Add(new StylusPoint(pt.X, pt.Y));
                    break;
                case TouchAction.Up:
                    activeStokes[id].StylusPoints.Add(new StylusPoint(pt.X, pt.Y));
                    activeStokes.Remove(id);
                    DoneNumber += 1;
                    break;
            }
        }
        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;
                }
            }
        }
Example #11
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;
            }
        }
        void TouchFrameReported(object sender, TouchFrameEventArgs e)
        {
            if (!AssociatedObject.DesiredSize.Equals(new Size(0, 0))) //Code Fix by Devix: enables Multi-Page support
            {
                _processor.Process(e.GetTouchPoints(AssociatedObject));

            #if DEBUG
                HandleDebugInfoAndFingers(
                    e.GetTouchPoints(RootVisual),
                    e.GetPrimaryTouchPoint(RootVisual));

            #endif
            }
        }
        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)
            {
                while (TouchPanel.IsGestureAvailable)
                {
                    Image touchIsImage = item.TouchDevice.DirectlyOver as Image;
                    GestureSample gs = TouchPanel.ReadGesture();

                    switch (gs.GestureType)
                    {
                        case GestureType.Tap:
                            InfoControl.Visibility = Visibility.Collapsed;//隐藏用户控件CancelControl
                            if (lastTouchImage != null)
                            {
                                lastTouchImage.Width = 200;
                                lastTouchImage.Height = 200;
                            }
                            if (touchIsImage != null)
                            {
                                //触摸图片变小
                                touchIsImage.Width = 190;
                                touchIsImage.Height = 190;
                                NavigationService.Navigate(new Uri("/MainPage.xaml?gameClass=" + gameClass + "&imgUri=" + touchIsImage.Name, UriKind.Relative));
                                Touch.FrameReported -= Touch_FrameReported;
                            }
                            break;

                        case GestureType.DoubleTap:
                            break;

                        case GestureType.Hold:
                            if (touchIsImage != null)
                            {
                                //触摸图片变小
                                lastTouchImage = touchIsImage;
                                touchIsImage.Width = 150;
                                touchIsImage.Height = 150;
                                deleteImg = touchIsImage.Name;
                                InfoControl.Visibility = Visibility.Visible;
                                InfoControl.Margin = new Thickness(0, item.Position.Y, 0, 0);
                            }
                            break;

                        case GestureType.FreeDrag:
                            break;

                        case GestureType.HorizontalDrag:
                            break;

                        case GestureType.VerticalDrag:
                            break;

                        case GestureType.Flick:
                            break;
                    }
                }
            }
        }
        void Touch_FrameReported(object sender, TouchFrameEventArgs args)
        {
            TouchPointCollection col = args.GetTouchPoints(cl);
            TouchAction act = args.GetPrimaryTouchPoint(cl).Action;
            if (col.Count == 1)
            {
                if (instance.currentlyEditing != null)
                {
                    com.codename1.ui.Form f = (com.codename1.ui.Form)instance.currentlyEditing.getComponentForm();
                    if (f.getComponentAt((int)col[0].Position.X, (int)col[0].Position.Y) == instance.currentlyEditing) {
                        return;
                    }
                }
                if (act == TouchAction.Down)
                {
                    pointerPressed((int)col[0].Position.X, (int)col[0].Position.Y);
                    return;
                }
                if (act == TouchAction.Up)
                {
                    if (instance.currentlyEditing != null)
                    {
                        com.codename1.ui.Form f = (com.codename1.ui.Form)instance.currentlyEditing.getComponentForm();
                        if (f.getComponentAt((int)col[0].Position.X, (int)col[0].Position.Y) != instance.currentlyEditing)
                        {
                            commitEditing();
                        }
                    }

                    pointerReleased((int)col[0].Position.X, (int)col[0].Position.Y);
                    return;
                }
                if (act == TouchAction.Move)
                {
                    pointerDragged((int)col[0].Position.X, (int)col[0].Position.Y);
                    return;
                }
                return;
            }

            int[] x = new int[col.Count];
            int[] y = new int[x.Length];
            for(int iter = 0 ; iter < col.Count ; iter++) {
                x[iter] = (int)col[iter].Position.X;
                x[iter] = (int)col[iter].Position.Y;
            }
            _nArrayAdapter<int> xarr = new _nArrayAdapter<int>(x);
            _nArrayAdapter<int> yarr = new _nArrayAdapter<int>(y);
            if (act == TouchAction.Down)
            {
                pointerPressed(xarr, yarr);
                return;
            }
            if (act == TouchAction.Up)
            {
                pointerReleased(xarr, yarr);
                return;
            }
            if (act == TouchAction.Move)
            {
                pointerDragged(xarr, yarr);
                return;
            }
        }
Example #15
0
        // Win 7 / Silverlight 3 standard WM_TOUCH messages MultiTouch device input
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            TouchPointCollection touchcollection = e.GetTouchPoints(_targetelement);
            TouchPoint primarytouch = e.GetPrimaryTouchPoint(_targetelement);
            if (_tpids.Count == 0 && primarytouch != null && primarytouch.Action == TouchAction.Down)
            {
                try
                {
                    IEnumerable<UIElement> hits = VisualTreeHelper.FindElementsInHostCoordinates(_targetelement.TransformToVisual(Application.Current.RootVisual).Transform(primarytouch.Position), Application.Current.RootVisual);
                    foreach (UIElement uiel in hits)
                    {
                        if (typeof(Touchable).IsAssignableFrom(uiel.GetType()) || _hastouchableparent(uiel))
                        {
                            e.SuspendMousePromotionUntilTouchUp();
                            break;
                        }
                        else if (typeof(Control).IsAssignableFrom(uiel.GetType()))
                        {
                            return;
                        }
                    }
                }
                catch (Exception ex) { }
            }

            lock (this)
            {
                List<int> removed = new List<int>();
                for (int i = 0; i < touchcollection.Count; i++)
                {
                    if (i + 1 > _tpids.Count)
                    {
                        int max = 1;
                        for (int c = 0; c < _tpids.Count; c++)
                            max = Math.Max(max, int.Parse(_tpids[c]) + 1000);
                        _tpids.Add((max).ToString());
                        _cursoradd("WM_TOUCH:" + (max).ToString());
                    }

                    TouchPoint tp = touchcollection[i];
                    if (tp.Action == TouchAction.Up)
                    {
                        _cursordel("WM_TOUCH:" + _tpids[i]);
                        removed.Add(i);
                    }
                    else
                    {
                        _cursorupd("WM_TOUCH:" + _tpids[i], touchcollection[i].Position);
                    }
                }
                removed.Reverse();
                foreach (int r in removed)
                    _tpids.RemoveAt(r);
            }
        }
Example #16
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;
            }
        }
Example #17
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)
            {
                Rectangle touchIsRectangle = item.TouchDevice.DirectlyOver as Rectangle;
                while (TouchPanel.IsGestureAvailable)
                {
                    GestureSample gs = TouchPanel.ReadGesture();
                    switch (gs.GestureType)
                    {
                        case GestureType.Pinch:
                            //    Vector2 a = gs.Position;                      //取得第一個觸碰點
                            //Vector2 aOld = gs.Position - gs.Delta;//取得第一個觸碰點的起始位置
                            //Vector2 b = gs.Position2;                 //取得第二個觸碰點
                            //Vector2 bOld = gs.Position2 - gs.Delta2;//取得第二個觸碰點的起始位置
                            //float d = Vector2.Distance(a, b);           //計算兩個觸碰點之間的距離
                            //float dOld = Vector2.Distance(aOld, bOld);//計算兩個原始座標之間的距離
                            //float scaleChange = (d - dOld) * .01f;            //計算距離的變化量
                            //Scale += scaleChange;           //將距離變化量的 1/10 當做縮放的比例
                            if (touchIsRectangle != null)
                            {
                                double d1 = Math.Sqrt(Math.Abs(gs.Position.X - gs.Position2.X) * Math.Abs(gs.Position.X - gs.Position2.X) + Math.Abs(gs.Position.Y - gs.Position2.Y) * Math.Abs(gs.Position.Y - gs.Position2.Y));
                                double d2 = Math.Sqrt(Math.Abs((gs.Position.X - gs.Delta.X) - (gs.Position2.X - gs.Delta2.X)) * Math.Abs((gs.Position.X - gs.Delta.X) - (gs.Position2.X - gs.Delta2.X)) + Math.Abs((gs.Position.Y - gs.Delta.Y) - (gs.Position2.Y - gs.Delta2.Y)) * Math.Abs((gs.Position.Y - gs.Delta.Y) - (gs.Position2.Y - gs.Delta2.Y)));
                                double distance = (d1 - d2) * 0.5;
                                _cutImgRect.Width += distance;
                                _cutImgRect.Height += distance;
                            }
                            break;
                    }
                }

                if (item.Action == TouchAction.Down)
                {
                    if (touchIsRectangle != null)
                    {
                        lastRectPositionX = item.Position.X - Canvas.GetLeft(_cutImgRect);
                        lastRectPositionY = item.Position.Y - Canvas.GetTop(_cutImgRect);
                    }
                }

                if (item.Action == TouchAction.Move)
                {
                    if (touchIsRectangle != null)
                    {
                        Canvas.SetLeft(item.TouchDevice.DirectlyOver, item.Position.X - lastRectPositionX);
                        Canvas.SetTop(item.TouchDevice.DirectlyOver, item.Position.Y - lastRectPositionY);
                        Canvas.SetZIndex(item.TouchDevice.DirectlyOver, 999);//处于最上端
                    }
                }
            }
        }
Example #18
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);//使拼图返回到原来的层次
                }
            }
        }
Example #19
0
        /// <summary>
        /// Touches the frame reported.
        /// </summary>
        /// <param name="sender">The sender.</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((UIElement)sender);
            double prevY = this.Y;
            switch (tp.Action)
            {
                case TouchAction.Down:
                    this.isBeingDragged = true;
                    this.X = tp.Position.X;
                    this.Y = tp.Position.Y;

                    this.CurrentX = this.X;
                    this.CurrentY = this.Y;
                    break;

                case TouchAction.Move:
                    if (this.isBeingDragged)
                    {

                        this.X = tp.Position.X;
                        this.Y = tp.Position.Y;

                        this.CurrentX = this.X;
                        this.CurrentY = this.Y;

                        this.gardener.UpdateSelfNodePosition(this.X, this.Y);
                    }

                    break;

                case TouchAction.Up:
                    this.isBeingDragged = false;
                    break;
                default:
                    break;
            }
        }
Example #20
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);
                     */
                }
            }
        }