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);
        }
Пример #2
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;
                    }
                }
            }
        }
Пример #3
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;
            }
        }
        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();
                    }
                }
            }
        }
Пример #5
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();
        }