示例#1
0
 private void OnManipulationDelta(object Sender, ManipulationDeltaEventArgs DeltaRoutedEventArgs)
 {
     if (DeltaRoutedEventArgs.CumulativeManipulation.Translation.X < -30)
     {
         _gameGrid.HandleMove(MoveDirection.Left);
         DeltaRoutedEventArgs.Complete();
         DeltaRoutedEventArgs.Handled = true;
     }
     else if (DeltaRoutedEventArgs.CumulativeManipulation.Translation.X > 30)
     {
         _gameGrid.HandleMove(MoveDirection.Right);
         DeltaRoutedEventArgs.Complete();
         DeltaRoutedEventArgs.Handled = true;
     }
     else if (DeltaRoutedEventArgs.CumulativeManipulation.Translation.Y < -30)
     {
         _gameGrid.HandleMove(MoveDirection.Up);
         DeltaRoutedEventArgs.Complete();
         DeltaRoutedEventArgs.Handled = true;
     }
     else if (DeltaRoutedEventArgs.CumulativeManipulation.Translation.Y > 30)
     {
         _gameGrid.HandleMove(MoveDirection.Down);
         DeltaRoutedEventArgs.Complete();
         DeltaRoutedEventArgs.Handled = true;
     }
 }
        protected override void OnManipulationDelta(ManipulationDeltaEventArgs args)
        {
            if (!manipulationDeltaInProgress)
            {
                IsActive = true;

                if (!tapInertiaInProgess)
                    SelectedIndex = -1;
            }

            manipulationDeltaInProgress = true;

            // This is the fake inertia from a tap
            if (tapInertiaInProgess)
            {
                VerticalOffset -= args.DeltaManipulation.Translation.Y;
            }

            // All other direct manipulation and inertia
            else
            {
                // For non-wrappable panel, check for end of the line
                if (!isWrappableStackPanel)
                {
                    double newVerticalOffset = VerticalOffset - inertiaDirection * args.DeltaManipulation.Translation.Y;

                    if (FractionalCenteredIndexFromVerticalOffset(newVerticalOffset, false) < 0)
                    {
                        double verticalOffsetIncrement = VerticalOffset - VerticalOffsetFromCenteredIndex(0);
                        double verticalOffsetExcess = args.DeltaManipulation.Translation.Y - verticalOffsetIncrement;
                        VerticalOffset -= verticalOffsetIncrement;
                        SelectedIndex = 0;
                        args.ReportBoundaryFeedback(new ManipulationDelta(new Vector(0, verticalOffsetExcess), 0, new Vector(), new Vector()));
                        args.Complete();
                    }
                    else if (FractionalCenteredIndexFromVerticalOffset(newVerticalOffset, false) > Items.Count - 1)
                    {
                        double verticalOffsetIncrement = VerticalOffsetFromCenteredIndex(Items.Count - 1) - VerticalOffset;
                        double verticalOffsetExcess = args.DeltaManipulation.Translation.Y - verticalOffsetIncrement;
                        VerticalOffset += verticalOffsetIncrement;
                        SelectedIndex = Items.Count - 1;
                        args.ReportBoundaryFeedback(new ManipulationDelta(new Vector(0, verticalOffsetExcess), 0, new Vector(), new Vector()));
                        args.Complete();
                    }
                }

                // Here's where scrolling might reverse itself
                if (args.IsInertial && inertiaToUnknownIndex && !reverseInertiaChecked)
                    CheckForBackupManeuver(VerticalOffset, args.DeltaManipulation.Translation.Y, args.Velocities.LinearVelocity.Y);

                // This is the normal direct manipulation and inertia
                VerticalOffset -= inertiaDirection * args.DeltaManipulation.Translation.Y;
            }

            base.OnManipulationDelta(args);
        }
示例#3
0
        protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
        {
            if (_panningInfo != null)
            {
                if (e.IsInertial && CompleteScrollManipulation)
                {
                    e.Complete();
                }
                else
                {
                    bool cancelManipulation = false;
                    if (_panningInfo.IsPanning)
                    {
                        // Do the scrolling if we already started it.
                        ManipulateScroll(e);
                    }
                    else if (CanStartScrollManipulation(e.CumulativeManipulation.Translation, out cancelManipulation))
                    {
                        // Check if we can start the scrolling and do accordingly
                        _panningInfo.IsPanning = true;
                        ManipulateScroll(e);
                    }
                    else if (cancelManipulation)
                    {
                        e.Cancel();
                        _panningInfo = null;
                    }
                }

                e.Handled = true;
            }
        }
 private void Border_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
 {
     //Debug.WriteLine("Border_ManipulationDelta");
     // optionally suppress zoom
     if ((ScrollDisabled || !userScalable) && (e.DeltaManipulation.Scale.X != 0.0 || e.DeltaManipulation.Scale.Y != 0.0))
     {
         e.Handled = true;
         e.Complete();
     }
     // optionally suppress scrolling
     if (ScrollDisabled && (e.DeltaManipulation.Translation.X != 0.0 || e.DeltaManipulation.Translation.Y != 0.0))
     {
         e.Handled = true;
         e.Complete();
     }
 }
        private void player_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            // Get the Rectangle and its RenderTransform matrix.

            //Canvas rectToMove = e.OriginalSource as Canvas;
            FieldPlayer rectToMove = (FieldPlayer)sender;

            rectToMove.NormalizeTransformGroup();

            if (isFieldRotated == false)
            {
                rectToMove.OffsetTo((rectToMove.RenderTransform.Value.OffsetX + (e.DeltaManipulation.Translation.X / field.RenderTransform.Value.M22)), (rectToMove.RenderTransform.Value.OffsetY + (e.DeltaManipulation.Translation.Y / field.RenderTransform.Value.M22)));
            }
            else
            {
                rectToMove.OffsetTo((rectToMove.RenderTransform.Value.OffsetX + (e.DeltaManipulation.Translation.Y / field.RenderTransform.Value.M22)), (rectToMove.RenderTransform.Value.OffsetY + (-e.DeltaManipulation.Translation.X / field.RenderTransform.Value.M22)));
            }

            //Debugger.Break();

            double a = lastPlayerPointDot.X - (rectToMove.RenderTransform.Value.OffsetX + (e.DeltaManipulation.Translation.X / field.RenderTransform.Value.M22));
            double b = lastPlayerPointDot.Y - (rectToMove.RenderTransform.Value.OffsetY + (e.DeltaManipulation.Translation.Y / field.RenderTransform.Value.M22));
            double distance = Math.Sqrt(a * a + b * b);
            //lastPlayerPointDot = new Point(rectToMove.RenderTransform.Value.OffsetX, rectToMove.RenderTransform.Value.OffsetY);

            if (distance > (45 / field.RenderTransform.Value.M22))
            {
                lastPlayerPointDot = new Point(rectToMove.RenderTransform.Value.OffsetX, rectToMove.RenderTransform.Value.OffsetY);

                FieldPlayer tempFieldPlayer = (FieldPlayer)sender;

                Point locationFromWindow = tempFieldPlayer.TranslatePoint(new Point(0, 0), this);
                locationFromWindow.X = locationFromWindow.X / tempFieldPlayer.RenderTransform.Value.M22;

                Point locationFromScreen = tempFieldPlayer.PointToScreen(locationFromWindow);
                tempFieldPlayer.number.Text = (84 - (0.5 * ((1 / field.RenderTransform.Value.M22) - 1) * 168)).ToString();
                tempFieldPlayer.name.Text = (e.ManipulationOrigin.X - locationFromWindow.X).ToString();
                //if (e.ManipulationOrigin.X - locationFromWindow.X < 84 - (0.25 * ((1 / field.RenderTransform.Value.M22) - 1) * 168))
                if (tempFieldPlayer.playerTrailEnabled == true)
                {

                    Ellipse tempEllipse = new Ellipse();
                    tempEllipse.Height = 15 / field.RenderTransform.Value.M22;
                    tempEllipse.Width = 15 / field.RenderTransform.Value.M22;

                    tempEllipse.Fill = tempFieldPlayer.swatchBackground.Fill;
                    //tempEllipse.Fill = new SolidColorBrush(Colors.Red);

                    ScaleTransform ellipseScaleTransform = new ScaleTransform();
                    ellipseScaleTransform.ScaleY = 1;// / field.RenderTransform.Value.M22;
                    ellipseScaleTransform.ScaleX = 1;// / field.RenderTransform.Value.M22;
                    ellipseScaleTransform.CenterX = .5;
                    ellipseScaleTransform.CenterY = .5;

                    RotateTransform ellipseRotateTransform = new RotateTransform();
                    ellipseRotateTransform.Angle = 0;

                    TranslateTransform ellipseTranslate = new TranslateTransform();
                    ellipseTranslate.X = lastPlayerPointDot.X + rectToMove.Width / 2;// / field.RenderTransform.Value.M22;
                    ellipseTranslate.Y = lastPlayerPointDot.Y + rectToMove.Height / 2;// / field.RenderTransform.Value.M22;

                    SkewTransform ellipseSkew = new SkewTransform();
                    ellipseSkew.AngleX = 0;
                    ellipseSkew.AngleY = 0;

                    // Create a TransformGroup to contain the transforms
                    // and add the transforms to it.
                    TransformGroup ellipseTransformGroup = new TransformGroup();
                    ellipseTransformGroup.Children.Add(ellipseScaleTransform);
                    ellipseTransformGroup.Children.Add(ellipseRotateTransform);
                    ellipseTransformGroup.Children.Add(ellipseTranslate);
                    ellipseTransformGroup.Children.Add(ellipseSkew);

                    tempEllipse.RenderTransform = ellipseTransformGroup;

                    playerDots.Children.Add(tempEllipse);
                }
                //MessageBox.Show(playerDots.Children.Count.ToString());

            }
            //Matrix rectsMatrix = ((MatrixTransform)rectToMove.RenderTransform).Matrix;

            //// Move the Rectangle.
            //rectsMatrix.Translate(e.DeltaManipulation.Translation.X / field.RenderTransform.Value.M22,
            //                      e.DeltaManipulation.Translation.Y / field.RenderTransform.Value.M22);

            //// Apply the changes to the Rectangle.
            //rectToMove.RenderTransform = new MatrixTransform(rectsMatrix);

            Rect containingRect =
                new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize);

            Rect shapeBounds =
                rectToMove.RenderTransform.TransformBounds(
                    new Rect(rectToMove.RenderSize));

            // Check if the rectangle is completely in the window.
            // If it is not and intertia is occuring, stop the manipulation.
            if (e.IsInertial && !containingRect.Contains(shapeBounds))
            {
                e.Complete();
            }

            e.Handled = true;
        }
        private void DrawingCanvas_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            TouchableImage image = e.OriginalSource as TouchableImage;
            if (image != null)
            {
                Rect containingRect = new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize);
                Rect shapeBounds = image.transformGroup.TransformBounds(new Rect(image.RenderSize));

                if (e.IsInertial && !containingRect.Contains(shapeBounds))
                {
                    e.Complete();
                }

                Point center = new Point(image.RenderSize.Width / 2.0, image.RenderSize.Height / 2.0);

                //rotation
                image.rotate.CenterX = center.X;
                image.rotate.CenterY = center.Y;
                image.rotate.Angle += e.DeltaManipulation.Rotation;

                //scale
                image.scale.CenterX = center.X;
                image.scale.CenterY = center.Y;
                image.scale.ScaleX *= e.DeltaManipulation.Scale.X;
                image.scale.ScaleY *= e.DeltaManipulation.Scale.Y;

                //trans
                image.traslation.X += e.DeltaManipulation.Translation.X;
                image.traslation.Y += e.DeltaManipulation.Translation.Y;
            }
        }
        private void OnManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            if (_isPaused)
                return;

            e.Handled = true;

            if (e.CumulativeManipulation.Translation.X > 0 && IsFirstPage ||
                e.CumulativeManipulation.Translation.X < 0 && IsLastPage)
            {
               CancelNextEvent();
                e.Complete();
            }
            else
            {
                if ((_mode & FlippingMode.Slide) == FlippingMode.Slide)
                    ManipulationDelta(sender, e);
            }
        }
示例#8
0
        /// <summary>
        /// Event fired when the user wiggles their finger after the initial press
        /// </summary>
        /// <param name="sender">Source of the event.</param>
        /// <param name="e">Event arguments.</param>
        private void OnOwnerManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            // If the context menu is open already, then complete this gesture
            // good to do for owner of type ListBox, Pivot, Panorama
            if (IsOpen == true)
            {
                e.Complete();
                e.Handled = true;
            }

            // If there is a non-negative drag or multi-finger, then cancel the timer
            if (Math.Abs(e.DeltaManipulation.Translation.X) != ContextMenuCancelMovement
                || Math.Abs(e.DeltaManipulation.Translation.Y) != ContextMenuCancelMovement
                || Math.Abs(e.DeltaManipulation.Scale.X) != 0
                || Math.Abs(e.DeltaManipulation.Scale.Y) != 0)
            {
                tapAndHoldTimer.Stop();
            }
        }
示例#9
0
        protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
        {
            // manipulation canceled
            if (_tracker.Canceled) return;

            if (_tracker.TrackManipulation(e.CumulativeManipulation.Translation))
            {
                // mark as handled to stop
                // underlying control's manipulations
                e.Handled = true;

                // cancel capture from current object to disable click behavior,
                // if we've started scrolling. Not sure what the best technique is.
                // let's just hook/override OnManipulationCompleted
                // and force e.Handled on it for now...
                _hook.HookCompletedHandler(OnManipulationCompleted);

                // move to position
                double position = _tracker.Start.X - e.CumulativeManipulation.Translation.X;
                if (_trackHeader)
                {
                    // tracking Headers : Items move twice as fast
                    ScrollView.HeaderPosition = _tracker.Start.X - _tracker.Delta.X;
                    ScrollView.Position = _tracker.Start.Y - (_tracker.Delta.X * 2);
                }
                else
                {
                    // tracking Items : Headers move twice as slow
                    ScrollView.HeaderPosition = _tracker.Start.Y - (_tracker.Delta.X / 2);
                    ScrollView.Position = _tracker.Start.X - _tracker.Delta.X;
                }
            }

            // complete manipulation
            if (_tracker.Completed) e.Complete();
        }
        void image_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            var element = e.Source as FrameworkElement;
            if (element != null)
            {
                var deltaManipulation = e.DeltaManipulation;
                var matrix = ((MatrixTransform)element.RenderTransform).Matrix;
                System.Windows.Point center = new System.Windows.Point(element.ActualWidth / 2, element.ActualHeight / 2);
                center = matrix.Transform(center);
                matrix.ScaleAt(deltaManipulation.Scale.X, deltaManipulation.Scale.Y, center.X, center.Y);
                matrix.RotateAt(e.DeltaManipulation.Rotation, center.X, center.Y);
                matrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);

                ((MatrixTransform)element.RenderTransform).Matrix = matrix;
                e.Handled = true;

                if (e.IsInertial)
                {
                    Rect containingRect = new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize);
                    Rect shapeBounds = element.RenderTransform.TransformBounds(new Rect(element.RenderSize));
                    if (e.IsInertial && !containingRect.Contains(shapeBounds))
                    {
                        e.ReportBoundaryFeedback(e.DeltaManipulation);
                        e.Complete();
                    }
                }
            }
        }
示例#11
0
        protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
        {
            // manipulation canceled
            if (_tracker.Canceled) return;

            if (_tracker.TrackManipulation(e.CumulativeManipulation.Translation))
            {
                // handle this one
                e.Handled = true;

                // cancel capture from current object to disable behaviors
                // for example, a button will not trigger the Click event
                // after we've done scrolling
                UIElement ui = e.ManipulationContainer as UIElement;
                ui.ReleaseMouseCapture();

                // the above code doesn't seem to work for unknown reasons
                // let's just hook/override it for now...
                _hack.Set(e.ManipulationContainer, OnManipulationCompleted);

                // move to position
                double position = _tracker.Start.X - e.CumulativeManipulation.Translation.X;
                if (_trackHeader)
                {
                    // tracking Headers : Items move twice as fast
                    ScrollView.HeaderPosition = _tracker.Start.X - _tracker.Delta.X;
                    ScrollView.Position = _tracker.Start.Y - (_tracker.Delta.X * 2);
                }
                else
                {
                    // tracking Items : Headers move twice as slow
                    ScrollView.HeaderPosition = _tracker.Start.Y - (_tracker.Delta.X / 2);
                    ScrollView.Position = _tracker.Start.X - _tracker.Delta.X;
                }
            }

            // complete manipulation
            if (_tracker.Completed) e.Complete();
        }
        private void Canvas_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            Matrix rectsMatrix = ((MatrixTransform)this.RenderTransform).Matrix;

            //get the current center point of the object
            // 1. relative to itself
            // 2. translated to the global window object --> point is then relative to the screen size
            Point centerRelative = new Point(this.ActualWidth / 2, this.ActualHeight / 2);
            Point centerTranslatedToWindow = this.TranslatePoint(centerRelative, App.Window);

            //count how many fingers are currently manipulating the object
            int numberOfFingers = e.Manipulators.Count();

            //One or Two Finger Rotation
            if (this.ProtoDefinition.RotateManipulation.IsEnabled)
            {
                //standard 2+ Finger-Rotation center point
                Point rotationCenter = new Point(e.ManipulationOrigin.X, e.ManipulationOrigin.Y);

                //special rotation if the object is fixed in one axis (or both)
                //either CanMove is false, or the translation modifier is reduced to 0 in its X or Y component
                if (!this.ProtoDefinition.MoveManipulation.IsEnabled || this.ProtoDefinition.MoveManipulation.XModifier == 0 || this.ProtoDefinition.MoveManipulation.YModifier == 0)
                {
                    //the object needs to be rotate around its own center for a stabilized rotation
                    rotationCenter.X = centerTranslatedToWindow.X;
                    rotationCenter.Y = centerTranslatedToWindow.Y;
                }

                //rotation by a discrete amount, no smooth analogue movement!
                if (this.ProtoDefinition.RotateManipulation.DiscreteRotationAngle != 0)
                {
                    //if the (absolute) sum of the rotation deltas is bigger than the fixed rotation angle --> rotate
                    if (Math.Abs(this.DiscreteRotationAngleCounter) >= this.ProtoDefinition.RotateManipulation.DiscreteRotationAngle)
                    {
                        rectsMatrix.RotateAt(Math.Sign(e.DeltaManipulation.Rotation) * this.ProtoDefinition.RotateManipulation.DiscreteRotationAngle, rotationCenter.X, rotationCenter.Y);
                        this.DiscreteRotationAngleCounter = 0;
                    }
                    else if (e.DeltaManipulation.Rotation != 0)
                    {
                        //sum up all rotation deltas
                        this.DiscreteRotationAngleCounter += e.DeltaManipulation.Rotation;
                    }

                }
                else
                {
                    //standard smooth analogue rotation
                    rectsMatrix.RotateAt(e.DeltaManipulation.Rotation * this.ProtoDefinition.RotateManipulation.Modifier, rotationCenter.X, rotationCenter.Y);
                }

            }

            //scaling with 2 fingers
            if (this.ProtoDefinition.ScaleManipulation.IsEnabled) // && e.DeltaManipulation.Scale.X != 1)
            {
                double xScale = 1 + (e.DeltaManipulation.Scale.X - 1) * this.ProtoDefinition.ScaleManipulation.XModifier;
                double yScale = 1 + (e.DeltaManipulation.Scale.Y - 1) * this.ProtoDefinition.ScaleManipulation.YModifier;

                //discrete X Scaling
                if (this.ProtoDefinition.ScaleManipulation.DiscreteScalingX != 0)
                {
                    if (Math.Abs(this.DiscreteScalingCounter_X) >= 0.75)
                    {
                        xScale = 1 - (Math.Sign(1 - e.DeltaManipulation.Scale.X) * this.ProtoDefinition.ScaleManipulation.DiscreteScalingX);
                        this.DiscreteScalingCounter_X = 0;
                    }
                    else if(e.DeltaManipulation.Scale.X != 1.0)
                    {
                        this.DiscreteScalingCounter_X += ((1 - e.DeltaManipulation.Scale.X) * 10);
                        xScale = 1;
                    }
                }

                if (this.ProtoDefinition.ScaleManipulation.DiscreteScalingY != 0)
                {
                    if (Math.Abs(this.DiscreteScalingCounter_Y) >= 0.75)
                    {
                        yScale = 1 - (Math.Sign(1 - e.DeltaManipulation.Scale.Y) * this.ProtoDefinition.ScaleManipulation.DiscreteScalingY);
                        this.DiscreteScalingCounter_Y = 0;
                    }
                    else if (e.DeltaManipulation.Scale.Y != 1.0)
                    {
                        this.DiscreteScalingCounter_Y += ((1 - e.DeltaManipulation.Scale.Y) * 10);
                        yScale = 1;
                    }
                }

                rectsMatrix.ScaleAt(xScale, yScale, e.ManipulationOrigin.X, e.ManipulationOrigin.Y);

            }

            //translation with multiple fingers
            if (this.ProtoDefinition.MoveManipulation.IsEnabled)
            {
                //discrete movement, like on a chess board for example

                // standard movement formula
                double xDif = e.DeltaManipulation.Translation.X * this.ProtoDefinition.MoveManipulation.XModifier;
                double yDif = e.DeltaManipulation.Translation.Y * this.ProtoDefinition.MoveManipulation.YModifier;

                // overriding the standard movement if the ProtoDefinition contains a "discrete X movement distance"
                if (this.ProtoDefinition.MoveManipulation.DiscreteMovementDistanceX != 0)
                {
                    if (Math.Abs(this.DiscreteMovementCounter_X) >= this.ProtoDefinition.MoveManipulation.DiscreteMovementDistanceX)
                    {
                        xDif = Math.Sign(e.DeltaManipulation.Translation.X) * this.ProtoDefinition.MoveManipulation.DiscreteMovementDistanceX * this.ProtoDefinition.MoveManipulation.XModifier;
                        this.DiscreteMovementCounter_X = 0;
                    }
                    else if(e.DeltaManipulation.Translation.X != 0)
                    {
                        this.DiscreteMovementCounter_X += e.DeltaManipulation.Translation.X;
                        xDif = 0;
                    }
                }

                // overriding the standard movement if the ProtoDefinition contains a "discrete Y movement distance"
                if(this.ProtoDefinition.MoveManipulation.DiscreteMovementDistanceY != 0)
                {
                    if (Math.Abs(this.DiscreteMovementCounter_Y) >= this.ProtoDefinition.MoveManipulation.DiscreteMovementDistanceY)
                    {
                        yDif = Math.Sign(e.DeltaManipulation.Translation.Y) * this.ProtoDefinition.MoveManipulation.DiscreteMovementDistanceY * this.ProtoDefinition.MoveManipulation.YModifier;
                        this.DiscreteMovementCounter_Y = 0;
                    }
                    else if (e.DeltaManipulation.Translation.Y != 0)
                    {
                        this.DiscreteMovementCounter_Y += e.DeltaManipulation.Translation.Y;
                        yDif = 0;
                    }
                }

                //apply the translation values, either analogue or discrete, or a mixture with one axis analogue and the other discrete
                rectsMatrix.Translate(xDif, yDif);

            }

            //apply the matrix transformation to the render transform of the object
            this.RenderTransform = new MatrixTransform(rectsMatrix);

            //check if the object should be kept inside the given boundaries after inertia behaviour has started
            if (this.ProtoDefinition.KeepInsideBoundaries)
            {
                //window boundaries
                Rect boundaries = new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize);
                //the objects bounds
                Rect thisBounds = this.RenderTransform.TransformBounds(new Rect(this.RenderSize));

                //stop movement inside boundaries
                if (e.IsInertial && !boundaries.Contains(thisBounds))
                {
                    e.Complete();
                }
            }
            e.Handled = true;

            //Console.WriteLine("Selfmade SVI, rendertransform: " + rectsMatrix.M11);
        }
示例#13
0
        private void cnvTable_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            Piece element = e.OriginalSource as Piece;

            // find the old center; arguaby this could be cached
            Point center = new Point(element.ActualWidth / 2, element.ActualHeight / 2);

            //element.RotatePiece(e.DeltaManipulation.Rotation,
            //                    e.ManipulationOrigin.X,
            //                    e.ManipulationOrigin.Y);

            //element.RotatePiece(e.DeltaManipulation.Rotation,
            //                    center.X,
            //                    center.Y);

            element.Rotate(e.DeltaManipulation.Rotation);

            element.MoveDeltaPiece(e.DeltaManipulation.Translation.X,
                             e.DeltaManipulation.Translation.Y);

            e.Handled = true;

            // checking boundaries during inertia
            if (e.IsInertial)
            {
                Rect containingRect = new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize);

                Rect shapeBounds = element.RenderTransform.TransformBounds(new Rect(element.RenderSize));

                // Check if the element is completely in the window.
                // If it is not and intertia is occuring, stop the manipulation.
                if (e.IsInertial && !containingRect.Contains(shapeBounds))
                {
                    //Report that we have gone over our boundary
                    e.ReportBoundaryFeedback(e.DeltaManipulation);
                    e.Complete();
                }
            }

            UnionValidation();
            VerticalUnionValidation();
        }
        private void OnManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            Matrix m = _ImageTransform.Matrix;

            // If element beyond edge, report back to WPF
            Vector pastEdgeVector;
            if (ElementPastBoundary(_ImageControl, out pastEdgeVector))
            {
                m.Translate(-1.0 * pastEdgeVector.X, -1.0 * pastEdgeVector.Y);
                _ImageTransform.Matrix = m;

                e.Complete();
                e.Handled = true;
                return;
            }

            // Find center of element and then transform to get current location of center
            FrameworkElement fe = _ImageControl;
            if (fe == null)
                return;
            Point center = new Point(fe.ActualWidth / 2, fe.ActualHeight / 2);
            center = m.Transform(center);

            // Update matrix to reflect translation and rotation
            ManipulationDelta md = e.DeltaManipulation;
            m.Translate(md.Translation.X, md.Translation.Y);
            m.ScaleAt(md.Scale.X, md.Scale.Y, center.X, center.Y);

            _ImageTransform.Matrix = m;
            RaisePropertyChanged("ImageTransform");

            e.Handled = true;
        }
示例#15
0
        private void ManipulateScroll(ManipulationDeltaEventArgs e)
        {
            Debug.Assert(_panningInfo != null);
            PanningMode panningMode = _panningInfo.PanningMode;
            if (panningMode != PanningMode.VerticalOnly)
            {
                // Scroll horizontally unless the mode is VerticalOnly
                ManipulateScroll(e.DeltaManipulation.Translation.X, e.CumulativeManipulation.Translation.X, true);
            }

            if (panningMode != PanningMode.HorizontalOnly)
            {
                // Scroll vertically unless the mode is HorizontalOnly
                ManipulateScroll(e.DeltaManipulation.Translation.Y, e.CumulativeManipulation.Translation.Y, false);
            }

            if (e.IsInertial && IsPastInertialLimit())
            {
                e.Complete();
            }
            else
            {
                double unusedX = _panningInfo.UnusedTranslation.X;
                if (!_panningInfo.InHorizontalFeedback &&
                    DoubleUtil.LessThan(Math.Abs(unusedX), PanningInfo.PreFeedbackTranslationX))
                {
                    unusedX = 0;
                }
                _panningInfo.InHorizontalFeedback = (!DoubleUtil.AreClose(unusedX, 0));

                double unusedY = _panningInfo.UnusedTranslation.Y;
                if (!_panningInfo.InVerticalFeedback &&
                    DoubleUtil.LessThan(Math.Abs(unusedY), PanningInfo.PreFeedbackTranslationY))
                {
                    unusedY = 0;
                }
                _panningInfo.InVerticalFeedback = (!DoubleUtil.AreClose(unusedY, 0));

                if (_panningInfo.InHorizontalFeedback || _panningInfo.InVerticalFeedback)
                {
                    // Report boundary feedback if needed
                    e.ReportBoundaryFeedback(new ManipulationDelta(new Vector(unusedX, unusedY), 0.0, new Vector(1.0, 1.0), new Vector()));

                    if (e.IsInertial && _panningInfo.InertiaBoundaryBeginTimestamp == 0)
                    {
                        _panningInfo.InertiaBoundaryBeginTimestamp = Environment.TickCount;
                    }
                }
            }
        }
示例#16
0
        private void initManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            FrameworkElement element = e.Source as FrameworkElement;

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(recordingFilename);
            XmlNode root = xmlDoc.DocumentElement;

            XmlNode eventsNode = xmlDoc.GetElementsByTagName("Events").Item(0);
            XmlElement scaleNode = xmlDoc.CreateElement("Scale");
            XmlElement rotateNode = xmlDoc.CreateElement("Rotate");
            XmlElement translateNode = xmlDoc.CreateElement("Translate");

            if (element != null)
            {                
                ManipulationDelta deltaManipulation = e.DeltaManipulation;

                Matrix matrix = ((MatrixTransform)element.RenderTransform).Matrix;

                Point center = new Point(element.ActualWidth / 2, element.ActualHeight / 2);

                center = matrix.Transform(center);

                //Zoom
                if (!noScale)
                {
                    if (deltaManipulation.Scale.X != 1 && deltaManipulation.Scale.Y != 1)
                    {
                        eventsNode.AppendChild(scaleNode);
                        scaleNode.SetAttribute("Element", element.Name);
                        scaleNode.SetAttribute("X", deltaManipulation.Scale.X.ToString());
                        scaleNode.SetAttribute("Y", deltaManipulation.Scale.Y.ToString());
                        scaleNode.SetAttribute("CenterX", center.X.ToString());
                        scaleNode.SetAttribute("CenterY", center.Y.ToString());
                    }

                    matrix.ScaleAt(deltaManipulation.Scale.X, deltaManipulation.Scale.Y, center.X, center.Y);
                }

                // Rotate
                if (!noRotate)
                {
                    if (deltaManipulation.Rotation != 0)
                    {
                        eventsNode.AppendChild(rotateNode);
                        rotateNode.SetAttribute("Element", element.Name);
                        rotateNode.SetAttribute("Rotation", deltaManipulation.Rotation.ToString());
                        rotateNode.SetAttribute("CenterX", center.X.ToString());
                        rotateNode.SetAttribute("CenterY", center.Y.ToString());
                    }

                    matrix.RotateAt(deltaManipulation.Rotation, center.X, center.Y);
                }

                //Pan
                if (!noTranslate)
                {
                    if (deltaManipulation.Translation.X != 0 && deltaManipulation.Translation.Y != 0)
                    {
                        eventsNode.AppendChild(translateNode);
                        translateNode.SetAttribute("Element", element.Name);
                        translateNode.SetAttribute("X", deltaManipulation.Translation.X.ToString());
                        translateNode.SetAttribute("Y", deltaManipulation.Translation.Y.ToString());
                    }
                    
                    matrix.Translate(deltaManipulation.Translation.X, deltaManipulation.Translation.Y);
                }

                xmlDoc.Save(recordingFilename);

                //((MatrixTransform)element.RenderTransform).Matrix = matrix;
                element.RenderTransform = new MatrixTransform(matrix);

                if (e.IsInertial)
                {
                    Rect containingRect = new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize);
                    Rect shapeBounds = element.RenderTransform.TransformBounds(new Rect(element.RenderSize));

                    if (!containingRect.Contains(shapeBounds))
                    {
                        //let us know if we go outside the boundaries
                        e.ReportBoundaryFeedback(e.DeltaManipulation);

                        e.Complete();
                    }
                }

                e.Handled = true;
            }
        }
        /// <summary>
        /// Called when the ManipulationDelta event occurs.
        /// </summary>
        /// <param name="e">Event data for the event.</param>
        protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
        {
            if (null == e)
            {
                throw new ArgumentNullException("e");
            }

            base.OnManipulationDelta(e);

            if (ListPickerMode == ListPickerMode.Normal)
            {
                if (!IsEnabled)
                {
                    e.Complete();
                    return;
                }

                Point p = e.ManipulationOrigin;

                if (e.OriginalSource != e.ManipulationContainer)
                {
                    p = e.ManipulationContainer.TransformToVisual((UIElement)e.OriginalSource).Transform(p);
                }

                if (!IsValidManipulation(e.OriginalSource, p))
                {
                    IsHighlighted = false;
                    e.Complete();
                }
            }
        }
示例#18
0
        //domove
        private void cTimeLine_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            if (!Timeline.CanChangeTimeInterval) return;
            if (stopInertia && e.IsInertial)
            {
                stopInertia = false;
                e.Complete();
                return;
            }

            foreach (IManipulator tm in e.Manipulators.ToList())
                if (cTimeLine.TouchesCaptured.All(k => k.Id != tm.Id))
                {
                    Manipulation.RemoveManipulator(cTimeLine, tm);
                    //cTimeLine.ReleaseTouchCapture(tm);
                }

            span = span / e.DeltaManipulation.Scale.X; //.Delta.ScaleX;//.ScaleDelta;
            TimeSpan dif = Timeline.End - Timeline.Start;
            delta = (dif.TotalHours / cTimeLine.ActualWidth) * e.DeltaManipulation.Translation.X / 1.0;

            CalculateStartEnd(delta, e.DeltaManipulation.Scale.X,
                new Point(e.ManipulationOrigin.X, e.ManipulationOrigin.Y));

            Timeline.ForceTimeChanged();
            if (fixHold)
            {
                Timeline.TimelinePlayer.FixFocus = true;
            }

            stopInertia = false;
        }
示例#19
0
        void Window_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            //Debug.WriteLine("Window_ManipulationDelta");

            // Get the Rectangle and its RenderTransform matrix.
            Rectangle rectToMove = e.OriginalSource as Rectangle;
            Matrix rectsMatrix = ((MatrixTransform)rectToMove.RenderTransform).Matrix;

            // Rotate the Rectangle.
            rectsMatrix.RotateAt(e.DeltaManipulation.Rotation,
                                 e.ManipulationOrigin.X,
                                 e.ManipulationOrigin.Y);

            // Resize the Rectangle.  Keep it square
            // so use only the X value of Scale.
            rectsMatrix.ScaleAt(e.DeltaManipulation.Scale.X,
                                e.DeltaManipulation.Scale.X,
                                e.ManipulationOrigin.X,
                                e.ManipulationOrigin.Y);

            // Move the Rectangle.
            rectsMatrix.Translate(e.DeltaManipulation.Translation.X,
                                  e.DeltaManipulation.Translation.Y);

            // Apply the changes to the Rectangle.
            rectToMove.RenderTransform = new MatrixTransform(rectsMatrix);

            Rect containingRect =
                new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize);

            Rect shapeBounds =
                rectToMove.RenderTransform.TransformBounds(
                    new Rect(rectToMove.RenderSize));

            // Check if the rectangle is completely in the window.
            // If it is not and intertia is occuring, stop the manipulation.
            if (e.IsInertial && !containingRect.Contains(shapeBounds))
            {
                e.Complete();
            }

            e.Handled = true;
        }
示例#20
0
        private void OnManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            // Get the UI element and its RenderTransform matrix.
            var uiElement = e.OriginalSource as UIElement;
            if (uiElement != null)
            {
                var matrixTransform = (MatrixTransform) uiElement.RenderTransform;
                var matrix = matrixTransform.Matrix;

                // Rotate the item.
                matrix.RotateAt(e.DeltaManipulation.Rotation,
                                e.ManipulationOrigin.X,
                                e.ManipulationOrigin.Y);

                // Resize the item.  Keep it square
                // so use only the X value of Scale.
                matrix.ScaleAt(e.DeltaManipulation.Scale.X,
                               e.DeltaManipulation.Scale.X,
                               e.ManipulationOrigin.X,
                               e.ManipulationOrigin.Y);

                // Move the item.
                matrix.Translate(e.DeltaManipulation.Translation.X,
                                 e.DeltaManipulation.Translation.Y);

                // Apply the changes to the item.
                matrixTransform.Matrix = matrix;

                // Update adorner
                UpdateAdorner(uiElement, matrix);

                var manipulationContainer = (FrameworkElement)e.ManipulationContainer;
                var containingRect = new Rect(manipulationContainer.RenderSize);
                var elementBounds = uiElement.RenderTransform.TransformBounds(new Rect(uiElement.RenderSize));

                // Check if the ScatterViewItem is completely in the ScatterView.
                // If it is not and intertia is occuring, stop the manipulation.
                if (e.IsInertial && !containingRect.Contains(elementBounds))
                {
                    //e.ReportBoundaryFeedback(e.DeltaManipulation);
                    e.Complete();
                }
            }

            e.Handled = true;
        }
 private void Border_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
 {
     // optionally suppress zoom
     if (ZoomDisabled && (e.DeltaManipulation.Scale.X != 0.0 || e.DeltaManipulation.Scale.Y != 0.0) )
     {
         e.Handled = true;
         e.Complete();
     }
     // optionally suppress scrolling
     if (ScrollDisabled && (e.DeltaManipulation.Translation.X != 0.0 || e.DeltaManipulation.Translation.Y != 0.0) )
     {
         e.Handled = true;
         e.Complete();
     }
 }
        private void field_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            // Get the Rectangle and its RenderTransform matrix.

            //Canvas rectToMove = e.OriginalSource as Canvas;
            Canvas rectToMove = (Canvas)field;

            Matrix rectsMatrix = ((MatrixTransform)rectToMove.RenderTransform).Matrix;

            // Rotate the Rectangle.
            //rectsMatrix.RotateAt(e.DeltaManipulation.Rotation,
            //                     e.ManipulationOrigin.X + 4000 - (System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width / 2),
            //                     e.ManipulationOrigin.Y + 5520 - (System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height / 2));

            // Resize the Rectangle.  Keep it square
            // so use only the X value of Scale.
            rectsMatrix.ScaleAt(e.DeltaManipulation.Scale.X,
                                e.DeltaManipulation.Scale.X,
                                e.ManipulationOrigin.X + 4000 - (System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width / 2),
                                 e.ManipulationOrigin.Y + 5520 - (System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height / 2));

            myCanvas.ControlScale = (1 / field.RenderTransform.Value.M22);

            for (int i = 0; i < field.Children.Count; i++)
            {
                if (field.Children[i] is FieldPlayer)
                {
                    FieldPlayer tempFieldPlayer = (FieldPlayer)field.Children[i];

                    //tempFieldPlayer.NormalizeTransformGroup();
                    //tempFieldPlayer.ScaleTo(1 / field.RenderTransform.Value.M22, 1 / field.RenderTransform.Value.M22);

                    ScaleTransform myScaleTransform = new ScaleTransform();
                    myScaleTransform.ScaleY = 1 / field.RenderTransform.Value.M22;
                    myScaleTransform.ScaleX = 1 / field.RenderTransform.Value.M22;

                    RotateTransform myRotateTransform = new RotateTransform();
                    myRotateTransform.Angle = 0;

                    //TranslateTransform myTranslate = new TranslateTransform();
                    //myTranslate.X = (tempFieldPlayer.RenderTransform.Value.OffsetX * field.RenderTransform.Value.M22);// -tempFieldPlayer.RenderTransform.Value.OffsetX;
                    //myTranslate.Y = (tempFieldPlayer.RenderTransform.Value.OffsetY * field.RenderTransform.Value.M22);// -tempFieldPlayer.RenderTransform.Value.OffsetY;

                    SkewTransform mySkew = new SkewTransform();
                    mySkew.AngleX = 0;
                    mySkew.AngleY = 0;

                    // Create a TransformGroup to contain the transforms
                    // and add the transforms to it.
                    TransformGroup myTransformGroup = new TransformGroup();
                    myTransformGroup.Children.Add(myScaleTransform);
                    myTransformGroup.Children.Add(myRotateTransform);
                   // myTransformGroup.Children.Add(myTranslate);
                    myTransformGroup.Children.Add(mySkew);

                    // Associate the transforms to the object
                    tempFieldPlayer.playerCanvas.RenderTransform = myTransformGroup;

                }
            }

            // Move the Rectangle.
            if (isFieldRotated == false)
            {
                rectsMatrix.Translate(e.DeltaManipulation.Translation.X,
                                      e.DeltaManipulation.Translation.Y);
            }
            else
            {
                rectsMatrix.Translate(e.DeltaManipulation.Translation.Y,
                                      -e.DeltaManipulation.Translation.X);
            }
            // Apply the changes to the Rectangle.
            rectToMove.RenderTransform = new MatrixTransform(rectsMatrix);

            Rect containingRect =
                new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize);

            Rect shapeBounds =
                rectToMove.RenderTransform.TransformBounds(
                    new Rect(rectToMove.RenderSize));

            // Check if the rectangle is completely in the window.
            // If it is not and intertia is occuring, stop the manipulation.
            if (e.IsInertial && !containingRect.Contains(shapeBounds))
            {
                e.Complete();
            }

            e.Handled = true;
        }
        /// <summary>
        /// Called when the ManipulationDelta event occurs.
        /// </summary>
        /// <param name="e">Event data for the event.</param>
        protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
        {
            if (null == e)
            {
                throw new ArgumentNullException("e");
            }

            base.OnManipulationDelta(e);

            if (!IsEnabled)
            {
                e.Complete();
                return;
            }

            if (!IsValidManipulation(e.OriginalSource, e.ManipulationOrigin.X, e.ManipulationOrigin.Y))
            {
                IsHighlighted = false;
                e.Complete();
            }
        }
示例#24
0
        //Behandeln der Manipulationsdaten, die während der des Ziehens des Stackpanels auftreten
        void PhoneApplicationPage_ManupualtionDelta(object sender, ManipulationDeltaEventArgs e)
        {
            e.Handled = true;

            //aktuelle Koordinaten des Stackpanels aktualisieren
            _currentX += e.DeltaManipulation.Translation.X;
            _currentY += e.DeltaManipulation.Translation.Y;


            //ermitteln wo sich die Ränder des bewegten Stackpanels befinden
            double rightCorner = _currentX + stackForDrag.ActualWidth;
            double leftCorner = _currentX;
            double bottomCorner = _currentY + stackForDrag.ActualHeight;
            double upperCorner = _currentY;

            //prüfen, ob Stackpanels außerhalb seines Containers gezogen wurde
            if (rightCorner <= _containerWidth && bottomCorner <= _containerHeight &&
                leftCorner >= 0 && upperCorner >= 0)
            {
                //stackpanel in X-Richtung bewegen
                _translation.X += e.DeltaManipulation.Translation.X;
                _translation.Y += e.DeltaManipulation.Translation.Y;
            }
            else
            {
                //Stackpanel auf den Startpunkt zurücksetzen
                _translation.X = stackForDrag.RenderTransformOrigin.X;
                _translation.Y = stackForDrag.RenderTransformOrigin.Y;

                //aktuelle Position zurücksetzen
                _currentX = 0;
                _currentY = 0;
                
                //setzen des Status, dass Stackpanel außerhalb seines Containers gezogen wurde
                e.Complete();
            }

            //Ausgabe der aktuellen Koordinaten des Stackpanels
            txt_mouseX.Text = _currentX.ToString();
            txt_mouseY.Text = _currentY.ToString();
        }