/// <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;
                }
            }
        }
        //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");
                    }
                }
            }
        }
Example #3
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 { }
      
    }
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            if (this.mainCanvas != null)
            {
                foreach (TouchPoint _touchPoint in e.GetTouchPoints(this.mainCanvas))
                {

                }
            }
        }
 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);
     });
 }
Example #6
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);
     }
 }
 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");
     }
 }
Example #8
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;
                }
            }
        }
Example #9
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;
        }
Example #11
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;

                }

            }
        } 
        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;
        }
Example #13
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;
                }
            }
        }
Example #14
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();
        }
 private void OnFrameReported(object sender, TouchFrameEventArgs e)
 {
     var touchPoints = e.GetTouchPoints(null);
     if (touchPoints != null)
         OnTouch(touchPoints);
 }
 void Touch_FrameReported(object sender, TouchFrameEventArgs e)
 {
     var points = e.GetTouchPoints();
     var first = points.First();
 }
        private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            if (!IsEnabled)
                return;

            if (IsActive)
            {
                var touchPoints = e.GetTouchPoints(_todoList);

                // if we still have two touch points continue the pinch gesture
                if (touchPoints.Count == 2)
                {
                    double currentDelta = GetDelta(touchPoints[0], touchPoints[1]);

                    double itemsOffset = 0;

                    // is the delta bigger than the initial?
                    if (currentDelta > _initialDelta)
                    {
                        double delta = currentDelta - _initialDelta;
                        itemsOffset = delta / 2;

                        // play a sound effect if the users has pinched far enough to add a new item
                        if (delta > ToDoItemHeight && !_effectPlayed)
                        {
                            _effectPlayed = true;
                            _popSound.Play();
                        }

                        _addNewThresholdReached = delta > ToDoItemHeight;

                        // stretch and fade in the new item
                        var cappedDelta = Math.Min(ToDoItemHeight, delta);
                        ((ScaleTransform)_pullDownItem.RenderTransform).ScaleY = cappedDelta / ToDoItemHeight;
                        _pullDownItem.Opacity = cappedDelta / ToDoItemHeight;

                        // set the text
                        _pullDownItem.Text = cappedDelta < ToDoItemHeight ? "Pull to create new item" : "Release to add new item";
                    }

                    // offset all the items in the list so that they 'part'
                    for (int i = 0; i < _todoItems.Count; i++)
                    {
                        var container = _todoList.ItemContainerGenerator.ContainerFromIndex(i) as FrameworkElement;
                        var translateTransform = (TranslateTransform)container.RenderTransform;
                        translateTransform.Y = i <= _itemOneIndex ? -itemsOffset : itemsOffset;
                    }
                }
                else
                {
                    // if we no longer have two touch points, end the interactions
                    IsActive = false;

                    RefreshView();

                    // hide the pull-down item
                    _pullDownItem.VerticalOffset = -ToDoItemHeight;

                    if (_addNewThresholdReached)
                    {
                        var newItem = new ToDoItemViewModel("");
                        var todoModel = newItem.ToModel();
                        _todoManager.Save(todoModel);
                        newItem.Update(todoModel);

                        _todoItems.Insert(_itemOneIndex, newItem);

                        // when the new item has been rendered, use the edit interaction to place the UI
                        // into edit mode
                        _todoList.InvokeOnNextLayoutUpdated(() => _editInteraction.EditItem(newItem));
                    }
                }
            }
            else
            {
                var touchPoints = e.GetTouchPoints(_todoList);
                if (touchPoints.Count == 2)
                {
                    _addNewThresholdReached = false;
                    _effectPlayed = false;

                    // find the items that were touched ...
                    var itemOne = GetToDoItemAtLocation(touchPoints[0].Position);
                    var itemTwo = GetToDoItemAtLocation(touchPoints[1].Position);

                    if (itemOne != null && itemTwo != null)
                    {
                        // find their indices
                        _itemOneIndex = _todoItems.IndexOf(itemOne);
                        _itemTwoIndex = _todoItems.IndexOf(itemTwo);

                        // are the two items next to each other?
                        if (Math.Abs(_itemOneIndex - _itemTwoIndex) == 1)
                        {
                            if (_itemOneIndex > _itemTwoIndex)
                            {
                                // We need to swap the two
                                int tempIndex = _itemOneIndex;
                                _itemOneIndex = _itemTwoIndex;
                                _itemTwoIndex = tempIndex;

                                var tempItem = itemOne;
                                itemOne = itemTwo;
                                itemTwo = tempItem;
                            }
                            IsActive = true;

                            // determine where to locate the new item placeholder
                            var itemOneContainer = _todoList.ItemContainerGenerator.ContainerFromItem(itemOne) as FrameworkElement;
                            var itemOneContainerPos = itemOneContainer.GetRelativePosition(_todoList);
                            _newItemLocation = itemOneContainerPos.Y + ToDoItemHeight - (ToDoItemHeight / 2);

                            // position the placeholder and add a scale transform
                            _pullDownItem.VerticalOffset = _newItemLocation;
                            _pullDownItem.Opacity = 0;
                            _pullDownItem.RenderTransform = new ScaleTransform()
                            {
                                ScaleY = 1,
                                CenterY = ToDoItemHeight / 2
                            };

                            // record the initial distance between touch point
                            _initialDelta = GetDelta(touchPoints[0], touchPoints[1]);

                            AddTranslateTransfromToElements();

                            _pullDownItem.Opacity = 1;
                        }
                    }
                }
            }
        }
 void Touch_FrameReported(object sender, TouchFrameEventArgs e)
 {
     foreach (TouchPoint tp in e.GetTouchPoints(Application.Current.RootVisual))
         if (tp.Action != TouchAction.Up)
             return;
     Touch.FrameReported -= Touch_FrameReported;
     disableScrollViewers(false);
     mouseIsDownOnNuance = false;
     mouseIsDownOnSpectrum = false;
 }
        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
            {
            }
        }
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            //TouchPoint primaryTouchPoint = e.GetPrimaryTouchPoint(null);

            TouchPointCollection touchPoints = e.GetTouchPoints(null);

            foreach (TouchPoint tp in touchPoints)
            {
                if (tp.Action == TouchAction.Down)
                {
                    foreach (var touchPoint in touchPointsCollection)
                    {
                        if (touchPoint.Key.Contains(tp.Position))
                        {
                            PlaySound(touchPoint.Value);
                        }
                    }
                }

            }
        }
Example #21
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);
            }
        }
Example #22
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 #23
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);//处于最上端
                    }
                }
            }
        }
        ////private void dt_tick(object sender, eventargs e)
        //{
        //detikcanting++;
        //    waktubasahkuastext.text = (waktubasahkuas - detikcanting).tostring();
        //    if (detikcanting == waktubasahkuas)
        //    {
        //        detikcanting = 0;
        //        kuasbasah = false;
        //        dt.stop();
        //    }
        //}
        private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            if (kuasBasah)
            {
                int pointsNumber = e.GetTouchPoints(canvasGambarBatik).Count;
                TouchPointCollection pointCollection = e.GetTouchPoints(canvasGambarBatik);
                var imagePen = (CompositeTransform) penBatik.RenderTransform;

                for (int i = 0; i < pointsNumber; i++)
                {
                    scoreNyorek++;
                    if (pointCollection[i].Action == TouchAction.Down)
                    {
                        if ((pointCollection[i].Position.X > 29) && (pointCollection[i].Position.X < 555))
                        {
                            preXArray[i] = pointCollection[i].Position.X - 30;
                            preYArray[i] = pointCollection[i].Position.Y - 55;
                            imagePen.TranslateX = pointCollection[i].Position.X + 100;
                            imagePen.TranslateY = pointCollection[i].Position.Y - 290;
                        }
                    }
                    if (pointCollection[i].Action == TouchAction.Move)
                    {
                        if ((pointCollection[i].Position.X > 29) && (pointCollection[i].Position.X < 555))
                        {
                            Line line = new Line();

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

                            imagePen.TranslateX = pointCollection[i].Position.X + 100;
                            imagePen.TranslateY = pointCollection[i].Position.Y - 290;

                            line.Stroke = selectedColor;
                            line.Fill = selectedColor;
                            line.StrokeThickness = 4.0;
                            canvasGambarBatik.Children.Add(line);

                            preXArray[i] = pointCollection[i].Position.X - 30;
                            preYArray[i] = pointCollection[i].Position.Y - 55;
                        }
                    }
                }
            }
             scoreNgelowongText.Text = scoreNyorek.ToString();
        }
Example #25
0
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            if (Visibility == System.Windows.Visibility.Collapsed)
                return;

            TouchPointCollection points = e.GetTouchPoints(this);
            
            System.Windows.Point center = new System.Windows.Point(joystick.ActualWidth / 2, joystick.ActualHeight / 2);
            for (int i = 0; i < points.Count; i++)
            {
                TouchPoint point = points[i];

                // If Pointer enter on the main stick
                if (IsEnabled && point.Action == TouchAction.Down && XamlHelper.IsControlChildOf(point.TouchDevice.DirectlyOver, mainStickContainer) && idPointer == -1)
                {
                    #region Pointer enter on MainStick
 
                    // Lock stick type
                    calibrationStickMoving = false;
                    mainStickMoving = true;

                    // Store TouchDeviceId
                    idPointer = point.TouchDevice.Id;

                    // Updating sticks data
                    Refresh(point.Position, center);

                    // Update mainStick position
                    MoveJoystick(newX, newY);

                    // Prepare event args
                    JoystickMoveEventArgs args = new JoystickMoveEventArgs
                    {
                        Angle = (int)angle,
                        Speed = (float)normalizedDistance
                    };

                    // Fire event
                    if (Moving != null)
                        Moving(this, args);

                    #endregion
                }
                // Else if pointer enter on calibrationstick
                else if (IsEnabled && point.Action == TouchAction.Down && (XamlHelper.IsControlChildOf(point.TouchDevice.DirectlyOver, CalibrationPath) || XamlHelper.IsControlChildOf(point.TouchDevice.DirectlyOver, CalibrationTxt)) && idPointer == -1)
                {
                    // Lock stick type
                    calibrationStickMoving = true;
                    mainStickMoving = false;

                    // Store TouchDeviceId
                    idPointer = point.TouchDevice.Id;

                    // Updating sticks data
                    Refresh(point.Position, center);
                }
                // Else if the pointer moving
                else if (point.TouchDevice.Id == idPointer && point.Action == TouchAction.Move)
                {
                    // Updating sticks data
                    Refresh(point.Position, center);

                    // If calibrating
                    if (calibrationStickMoving)
                    {
                        // Update angle
                        rotationTransform.Rotation = basicAngle;

                        // Fire event
                        if (Calibrating != null)
                        {
                            JoystickCalibrationEventArgs args = new JoystickCalibrationEventArgs { Angle = (int)basicAngle };
                            Calibrating(this, args);
                        }

                    }
                    else if (mainStickMoving)
                    {
                        // Update main stick position
                        MoveJoystick(newX, newY);

                        // Fire event
                        if (Moving != null)
                        {
                            JoystickMoveEventArgs args = new JoystickMoveEventArgs
                            {
                                Angle = (int)angle,
                                Speed = (float)normalizedDistance
                            };

                            Moving(this, args);
                        }
                    }
                }
                // On pointer released
                else if (point.TouchDevice.Id == idPointer && point.Action == TouchAction.Up)
                {
                    // release the pointer Id
                    idPointer = -1;

                    
                    if (mainStickMoving)
                    {
                        // Fire event
                        if (Released != null)
                        {
                            JoystickMoveEventArgs args = new JoystickMoveEventArgs
                            {
                                Angle = (int)angle,
                                Speed = (float)normalizedDistance
                            };

                            Released(this, args);
                        }
                    }

                    if(calibrationStickMoving)
                    {
                        // Fire event
                        if (CalibrationReleased != null)
                        {
                            JoystickCalibrationEventArgs args = new JoystickCalibrationEventArgs { Angle = (int)basicAngle };
                            CalibrationReleased(this, args);
                        }
                    }

                    // Reinit data
                    newX = 0;
                    newY = 0;
                    angle = 0;
                    normalizedDistance = 0;

                    // Update main stick position
                    MoveJoystick(newX, newY);
                    
                    // Reinit calibration rotation
                    rotationTransform.Rotation = 135;

                    // Reinit flags
                    calibrationStickMoving = false;
                    mainStickMoving = false;
                }
            }
        }
        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 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);
                }
            }
        }
        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();
                    }

                }
            }
        }
        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);
                }
            }
        }
        /// <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;
                        }
                    }
                }
            }
        }