/// <summary>
 /// Here when manipulation gives a delta.
 /// </summary>
 private void OnManipulationDelta(object sender, Manipulation2DDeltaEventArgs e)
 {
     Move(new Point(e.OriginX, e.OriginY),
          new Vector(e.Delta.TranslationX, e.Delta.TranslationY),
          e.Delta.Rotation,
          e.Delta.ScaleX);
 }
Esempio n. 2
0
        // </Snippet_GamePiece_OnManipulationStarted>

        // <Snippet_GamePiece_OnManipulationDelta>
        #region OnManipulationDelta
        private void OnManipulationDelta(object sender, Manipulation2DDeltaEventArgs e)
        {
            //// Adjust the position and rotation of the game piece.
            float deltaX = e.Delta.TranslationX;
            float deltaY = e.Delta.TranslationY;

            if (dragPoint.X != double.NaN || dragPoint.Y != double.NaN)
            {
                // Single-manipulator-drag-rotate mode. Adjust for drag / rotation
                System.Windows.Point  center   = new System.Windows.Point(position.X, position.Y);
                System.Windows.Vector toCenter = center - dragPoint;
                double sin = Math.Sin(e.Delta.Rotation);
                double cos = Math.Cos(e.Delta.Rotation);
                System.Windows.Vector rotatedToCenter =
                    new System.Windows.Vector(
                        toCenter.X * cos - toCenter.Y * sin,
                        toCenter.X * sin + toCenter.Y * cos);
                System.Windows.Vector shift = rotatedToCenter - toCenter;
                deltaX += (float)shift.X;
                deltaY += (float)shift.Y;
            }

            X        += deltaX;
            Y        += deltaY;
            rotation += e.Delta.Rotation;
        }
 /// <summary>
 /// Here when manipulation gives a delta.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnManipulationDelta(object sender, Manipulation2DDeltaEventArgs e)
 {
     ScreenMessage(String.Format("Delta: Rotation: {0}", e.Delta.Rotation));
     Move(
         e.Delta.TranslationX,
         e.Delta.TranslationY,
         e.Delta.Rotation,
         e.Delta.ScaleX);
 }
        private void OnManipulationDelta(object sender, Manipulation2DDeltaEventArgs e)
        {            
            
            if (pickedObject != null){    
                //Rotations================================================
                float toRotate = MathHelper.ToDegrees(e.Delta.Rotation);                
                Quaternion q = pickedObject.Orientation;

                double yaw = Math.Atan2(2.0 * (q.Y * q.Z + q.W * q.X), q.W * q.W - q.X * q.X - q.Y * q.Y + q.Z * q.Z);
                double pitch = Math.Asin(-2.0 * (q.X * q.Z - q.W * q.Y));
                double roll = Math.Atan2(2.0 * (q.X * q.Y + q.W * q.Z), q.W * q.W + q.X * q.X - q.Y * q.Y - q.Z * q.Z);

                float currentRotation = MathHelper.ToDegrees((float)roll);
                float finalRotation = currentRotation - toRotate;
                if (finalRotation < 0)
                {
                    finalRotation = 360 + finalRotation;
                }
                if (finalRotation > 360)
                {
                    finalRotation = 360 - finalRotation;
                }

                float totalRotation = MathHelper.ToRadians(finalRotation);
                Quaternion finalOrientation = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1.0f), totalRotation);                
                this.orientation = finalOrientation;

                //Zooms==================================================                
                Vector3 direction = viewManager.Position - pickedObject.Position;                
                Vector3 newPosition = pickedObject.Position;

                direction.Normalize();
                float scaleConstant = 1.5f;
                float scaleFactor = e.Cumulative.ScaleX;

                
                scaleFactor = scaleFactor < 1 ? -(1 / scaleFactor) : scaleFactor;
                

                newPosition = Vector3.Add(Vector3.Multiply(direction, (scaleConstant * scaleFactor)), this.beginPos);

                Segment s;
                s.P1 = game.GraphicsDevice.Viewport.Unproject(new Vector3(touchPosition.X, touchPosition.Y, 0f),
                    viewManager.Projection, viewManager.View, Matrix.Identity);
                s.P2 = game.GraphicsDevice.Viewport.Unproject(new Vector3(touchPosition.X, touchPosition.Y, 1f),
                    viewManager.Projection, viewManager.View, Matrix.Identity);
                float scalar;
                Vector3 point;
                var c = physics.BroadPhase.Intersect(ref s, out scalar, out point);
                pickedDistance = scalar;

               //Put together=============================================
               pickedObject.SetWorld(newPosition, finalOrientation);
            }
        }
 /// <summary>
 /// Handles the Delta event of the ScatterManipulationProcessor control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.Windows.Input.Manipulations.Manipulation2DDeltaEventArgs"/> instance containing the event data.</param>
 private void ScatterManipulationProcessor_Delta(object sender, Manipulation2DDeltaEventArgs e)
 {
     if (!_overridingScatterViewItem && e.Delta.ScaleX >= 1 &&
         GetMaxScale() > 1 &&
         (Math.Abs(ScatterViewItem.ActualWidth - ScatterViewItem.MaxWidth) <= .1 || Math.Abs(ScatterViewItem.ActualHeight - ScatterViewItem.MaxHeight) <= .1))
     {
         // If the SVI is scalled up to its maximum, steal its contacts and begin scaling the content.
         _overridingScatterViewItem = true;
         ScatterViewItem.TouchesCaptured.ToList().ForEach(c => c.Capture(this));
     }
 }
        /// <summary>
        /// Here when manipulation gives a delta.
        /// </summary>
        private void OnManipulationDelta(object sender, Manipulation2DDeltaEventArgs e)
        {
            if (!this.AreManipulationsEnabled)
            {
                return;
            }

            Move(new Point(e.OriginX, e.OriginY),
                 new Vector(e.Delta.TranslationX, e.Delta.TranslationY),
                 e.Delta.Rotation,
                 e.Delta.ScaleX);
        }
Esempio n. 7
0
        // </Snippet_GamePiece_OnManipulationCompleted>

        // <Snippet_GamePiece_OnInertiaDelta>
        #region OnInertiaDelta
        private void OnInertiaDelta(object sender, Manipulation2DDeltaEventArgs e)
        {
            // Adjust the position of the game piece.
            X        += e.Delta.TranslationX;
            Y        += e.Delta.TranslationY;
            rotation += e.Delta.Rotation;

            // Check to see if the piece has hit the edge of the view port.
            bool reverseX = false;
            bool reverseY = false;

            if (X > viewport.Width)
            {
                reverseX = true;
                X        = viewport.Width;
            }

            else if (X < viewport.X)
            {
                reverseX = true;
                X        = viewport.X;
            }

            if (Y > viewport.Height)
            {
                reverseY = true;
                Y        = viewport.Height;
            }

            else if (Y < viewport.Y)
            {
                reverseY = true;
                Y        = viewport.Y;
            }

            if (reverseX || reverseY)
            {
                // Get the current velocities, reversing as needed.
                // If reversing, apply sponge factor to slow the piece slightly.
                float velocityX = e.Velocities.LinearVelocityX * ((reverseX) ? -spongeFactor : 1.0f);
                float velocityY = e.Velocities.LinearVelocityY * ((reverseY) ? -spongeFactor : 1.0f);
                // Must stop inertia processing before changing parameters.
                if (inertiaProcessor.IsRunning)
                {
                    inertiaProcessor.Complete(Timestamp);
                }
                // Assign the new velocities.
                inertiaProcessor.TranslationBehavior.InitialVelocityX = velocityX;
                inertiaProcessor.TranslationBehavior.InitialVelocityY = velocityY;
                // Set flag so that inertia processing will continue.
                processInertia = true;
            }
        }
Esempio n. 8
0
        private void OnManipulationDelta(object sender, Manipulation2DDeltaEventArgs e) 
        {
            var deltaArguments = new ManipulationDeltaEventArgs( 
                _manipulationDevice, 
                LastTimestamp,
                _currentContainer, 
                new Point(e.OriginX, e.OriginY),
                ConvertDelta(e.Delta, null),
                ConvertDelta(e.Cumulative, _lastManipulationBeforeInertia),
                ConvertVelocities(e.Velocities), 
                IsInertiaActive);
 
            PushEvent(deltaArguments); 
        }
Esempio n. 9
0
        private void OnManipulationDelta(object sender, Manipulation2DDeltaEventArgs e)
        {
            var deltaArguments = new ManipulationDeltaEventArgs(
                _manipulationDevice,
                LastTimestamp,
                _currentContainer,
                new Point(e.OriginX, e.OriginY),
                ConvertDelta(e.Delta, null),
                ConvertDelta(e.Cumulative, _lastManipulationBeforeInertia),
                ConvertVelocities(e.Velocities),
                IsInertiaActive);

            PushEvent(deltaArguments);
        }
Esempio n. 10
0
        private void unsolved_ManipulationDelta(object sender, Manipulation2DDeltaEventArgs e)
        {
            Canvas element = scene;

            var matrix = GetUnsolvedTransform();

            //if (e.Delta.ScaleX < 1)
            //    if (matrix.M11 <= 1.0 || matrix.M22 <= 1.0)
            //        return;

            //matrix.ScaleAt(e.DeltaManipulation.Scale.X,
            //               e.DeltaManipulation.Scale.Y,
            //               e.ManipulationOrigin.X - this.ActualWidth / 2,
            //               e.ManipulationOrigin.Y - this.ActualHeight / 2);

            var xScale = (e.Delta.ScaleX + 2) / 3;

            var finalFact = matrix.M11 * xScale;

            if (finalFact > MAX_ZOOM || finalFact < MIN_ZOOM)
            {
                return;
            }

            matrix.ScaleAt(xScale,
                           xScale,
                           e.OriginX - this.ActualWidth / 2,
                           e.OriginY - this.ActualHeight / 2);

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

            matrix.Translate(e.Delta.TranslationX,
                             e.Delta.TranslationY);

            updateZoomFactor(matrix.M11);

            SetWorkingAreaTransform(matrix, e.Delta.TranslationX < 0,
                                    e.Delta.TranslationY < 0,
                                    e.Delta.ScaleX > 1,
                                    e.Delta.ScaleX < 1);
        }
Esempio n. 11
0
        /// <summary>
        /// Extract the Manipulation Data and write it into our Dictionary
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnAffine2DDelta(object sender, Manipulation2DDeltaEventArgs e)
        {
            ReadOnlyTouchPointCollection currentContacts = contactTarget.GetState();

            foreach (TouchPoint c in currentContacts)
            {
                if (c.X == e.OriginX && c.Y == e.OriginY)
                {
                    // BugFix
                    // Apparently this event handling is not thread-safe
                    // Once the surface is reporting a bunch of touches (~30 in testing)
                    // It will try to add a moving touch multiple times to this dictionary.
                    //
                    // I've fixed this by only taking the last touch
                    // and just skip all the inbetween touches.
                    _contactManipulationData[c.Id] = e;
                }
            }
        }
Esempio n. 12
0
        //private void Window_ManipulationStarting(object sender, Manipulation2DStartedEventArgs e)
        //{
        //    //e.Handled = true;
        //    //e.ManipulationContainer = this;
        //}

        private void Window_ManipulationDelta(object sender, Manipulation2DDeltaEventArgs e)
        {
            //e.Handled = true;
            unsolved_ManipulationDelta(sender, e);
        }
Esempio n. 13
0
        //==========================================================//
        /// <summary>
        /// Event handler for the manipulation and inertia processor's delta events. 
        /// Occurs whenever the manipulation or inertia processors processes or extrapolate 
        /// manipulator data.
        /// </summary>
        /// <param name="sender">The manipulation or inertia processor that raised the event.</param>
        /// <param name="e">The event args for the event.</param>
        private void OnAffine2DDelta(object sender, Manipulation2DDeltaEventArgs e)
        {
            Debug.Assert(manipulating && sender is ManipulationProcessor2D ||
                extrapolating && sender is InertiaProcessor2D);

            Vector2 manipulationOrigin = new Vector2(e.OriginX, e.OriginY);
            Vector2 manipulationDelta = new Vector2(e.Delta.TranslationX, e.Delta.TranslationY);
            Vector2 previousOrigin = new Vector2(manipulationOrigin.X - manipulationDelta.X, manipulationOrigin.Y - manipulationDelta.Y);
            float restrictedOrientation = RestrictOrientation(e.Delta.Rotation);
            float restrictedScale = RestrictScale(e.Delta.ScaleX);

            // Adjust the position of the item based on change in rotation
            if (restrictedOrientation != 0.0f)
            {
                Vector2 manipulationOffset = transformedCenter - previousOrigin;
                Vector2 rotatedOffset = GeometryHelper.RotatePointVector(manipulationOffset, restrictedOrientation);
                Vector2 compensation = rotatedOffset - manipulationOffset;
                transformedCenter += compensation;
            }

            // Adjust the position of the item based on change in scale
            if (restrictedScale != 1.0f)
            {
                Vector2 manipulationOffset = manipulationOrigin - transformedCenter;
                Vector2 scaledOffset = manipulationOffset * restrictedScale;
                Vector2 compensation = manipulationOffset - scaledOffset;
                transformedCenter += compensation;
            }

            // Rotate the item if it is allowed
            if (canRotate || canRotateFlick)
            {
                orientation += restrictedOrientation;
            }

            // Scale the item if it is allowed
            if (canScale || canScaleFlick)
            {
                scaleFactor *= restrictedScale;
            }

            // Translate the item if it is allowed
            if (canTranslate || canTranslateFlick)
            {
                transformedCenter += new Vector2(e.Delta.TranslationX, e.Delta.TranslationY);
            }

            RestrictCenter();

            if (canRotate || canRotateFlick)
            {
                manipulationProcessor.Pivot = new ManipulationPivot2D
                {
                    X = transformedCenter.X,
                    Y = transformedCenter.Y,
                    Radius = Math.Max(Width, Height) / 2.0f
                };
            }
        }
        private void OnManipulationDelta(object sender, Manipulation2DDeltaEventArgs e)
        {
            if (!rotateOrZoom)
            {
                float newHeightAngle = MathHelper.ToRadians((MathHelper.ToDegrees(_viewManager.HeightAngle)
                    + (JengaConstants.HEIGHT_REVERSED * e.Delta.TranslationY / JengaConstants.PAN_SPEED_DIVISOR)));
                float newRotationAngle = MathHelper.ToRadians((MathHelper.ToDegrees(_viewManager.RotationAngle)
                    + (JengaConstants.ROTATE_REVERSED * e.Delta.TranslationX / JengaConstants.PAN_SPEED_DIVISOR)));

                _viewManager.updateCameraPosition(newRotationAngle, newHeightAngle, _viewManager.CameraDistance);
            }else{              
                //Rotations================================================
                float toRotate = MathHelper.ToDegrees(e.Delta.Rotation);
                Quaternion q = selectedBrick.Item1.Orientation;

                double yaw = Math.Atan2(2.0 * (q.Y * q.Z + q.W * q.X), q.W * q.W - q.X * q.X - q.Y * q.Y + q.Z * q.Z);
                double pitch = Math.Asin(-2.0 * (q.X * q.Z - q.W * q.Y));
                double roll = Math.Atan2(2.0 * (q.X * q.Y + q.W * q.Z), q.W * q.W + q.X * q.X - q.Y * q.Y - q.Z * q.Z);

                float currentRotation = MathHelper.ToDegrees((float)roll);
                float finalRotation = currentRotation - toRotate;
                if (finalRotation < 0)
                {
                    finalRotation = 360 + finalRotation;
                }
                if (finalRotation > 360)
                {
                    finalRotation = 360 - finalRotation;
                }

                float totalRotation = MathHelper.ToRadians(finalRotation);
                Quaternion finalOrientation = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1.0f), totalRotation);

                selectedBrick = new Tuple<SolidThing, Quaternion, float, Vector3>
                        (selectedBrick.Item1, finalOrientation, selectedBrick.Item3, selectedBrick.Item4);

                //Zooms==================================================                
                Vector3 newPosition = selectedBrick.Item1.Position;
                Vector3 direction = _viewManager.Position - selectedBrick.Item1.Position;                               
                direction.Normalize();
                float deltaAdd = 1 - e.Delta.ScaleX;
                deltaAdd *= JengaConstants.FORWARD_BACK_BLOCK_SPEED;
                newPosition = Vector3.Add(Vector3.Multiply(direction, deltaAdd), selectedBrick.Item1.Position);
                if (Vector3.Subtract(_viewManager.Position, newPosition).Length() > JengaConstants.MIN_CAMERA_DISTANCE
                    || Vector3.Subtract(_viewManager.Position, newPosition).Length() > Vector3.Subtract(_viewManager.Position, selectedBrick.Item1.Position).Length())
                   
                {
                    selectedBrick.Item1.IsActive = true;
                    selectedBrick.Item1.SetWorld(newPosition, selectedBrick.Item2);
                }
            }
        }
        /// <summary>
        /// Translate and scale the content when it is manipulated.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.ManipulationDeltaEventArgs"/> instance containing the event data.</param>
        private void ContentManipulationProcessor_Affine2DManipulationDelta(object sender, Manipulation2DDeltaEventArgs e)
        {
            if (GetMaxScale() == 1)
            {
                return;
            }

            // The inertia processor can move the content out of bounds.
            if (sender == _inertiaProcessor)
            {
                _translate.X  += e.Delta.TranslationX;
                _translate.Y  += e.Delta.TranslationY;
                _scale.ScaleX *= e.Delta.ScaleX;
                _scale.ScaleY *= e.Delta.ScaleY;
                return;
            }

            _spring.Stop(this);

            // Determine what scale to apply to the content.
            bool   returnControlToScatterViewItem = false;
            double scaleDelta = 1;
            double newScale   = _scale.ScaleX * e.Delta.ScaleX;

            if (_content.ActualWidth * newScale >= ActualWidth && newScale <= GetMaxScale())
            {
                // If the new scale is within the bounds, just use it directly.
                scaleDelta = e.Delta.ScaleX;
            }
            else if (e.Delta.ScaleX > 1)
            {
                // Apply friction to an increasing scale.
                scaleDelta = 1 + ((e.Delta.ScaleX - 1) * _friction);
            }
            else if (e.Delta.ScaleX < 1)
            {
                // Apply friction to a decreasing scale.
                scaleDelta = 1 - ((1 - e.Delta.ScaleX) * _friction);
                returnControlToScatterViewItem = _scale.ScaleX <= .95;
            }

            _scale.ScaleX *= scaleDelta;
            _scale.ScaleY *= scaleDelta;

            if (returnControlToScatterViewItem)
            {
                // If the content is scaled down to less than the default size, return control back to the ScatterViewItem.
                if (ScatterViewItem != null)
                {
                    TouchesCaptured.ToList().ForEach(c => c.Capture(ScatterViewItem));
                    _overridingScatterViewItem = false;
                }
            }

            // Move the content.
            _translate.X += e.Delta.TranslationX;
            _translate.Y += e.Delta.TranslationY;

            // Get the new bounds of the image.
            Rect bounds = GetContentBounds();

            if (bounds.TopLeft.X > 0 || bounds.BottomRight.X < ActualWidth)
            {
                // Apply friction if the content is out of bounds on the x-axis.
                _translate.X -= e.Delta.TranslationX;
                _translate.X += e.Delta.TranslationX * _friction;
            }

            if (bounds.TopLeft.Y > 0 || bounds.BottomRight.Y < ActualHeight)
            {
                // Apply friction if the content is out of bounds on the y-axis.
                _translate.Y -= e.Delta.TranslationY;
                _translate.Y += e.Delta.TranslationY * _friction;
            }
        }
Esempio n. 16
0
        //private void Window_ManipulationStarting(object sender, Manipulation2DStartedEventArgs e)
        //{
        //    //e.Handled = true;
        //    //e.ManipulationContainer = this;            
        //}

        private void Window_ManipulationDelta(object sender, Manipulation2DDeltaEventArgs e)
        {
            //e.Handled = true;
            unsolved_ManipulationDelta(sender, e);
        }
Esempio n. 17
0
        //==========================================================//
        /// <summary>
        /// Event handler for the manipulation and inertia processor's delta events. 
        /// Occurs whenever the manipulation or inertia processors processes or extrapolate 
        /// manipulator data
        /// </summary>
        /// <param name="sender">The manipulation or inertia processor that raised the event</param>
        /// <param name="e">The event args for the event</param>
        private void OnAffine2DDelta(object sender, Manipulation2DDeltaEventArgs e)
        {
            Debug.Assert(manipulating && sender is ManipulationProcessor2D ||
                extrapolating && sender is InertiaProcessor2D);

            Vector2 manipulationOrigin = new Vector2(e.OriginX, e.OriginY);
            Vector2 manipulationDelta = new Vector2(e.Delta.TranslationX, e.Delta.TranslationY);
            Vector2 previousOrigin = new Vector2(manipulationOrigin.X - e.Delta.TranslationX, manipulationOrigin.Y - e.Delta.TranslationY);
            float restrictedOrientation = RestrictOrientation(e.Delta.Rotation);
            // Scale is constrained (ScaleX==ScaleY), just use X
            float restrictedScale = RestrictScale(e.Delta.ScaleX);

            // Adjust the position of the item based on change in rotation
            if (restrictedOrientation != 0.0f)
            {
                Vector2 manipulationOffset = center - previousOrigin;
                Vector2 rotatedOffset = RotatePointVector(manipulationOffset, restrictedOrientation);
                Vector2 compensation = rotatedOffset - manipulationOffset;
                center += compensation;
            }

            // Adjust the position of the item based on change in scale
            if (restrictedScale != 1.0f)
            {
                Vector2 manipulationOffset = manipulationOrigin - center;
                Vector2 scaledOffset = manipulationOffset * restrictedScale;
                Vector2 compensation = manipulationOffset - scaledOffset;
                center += compensation;
            }

            // Rotate the item if it is allowed
            if (canRotate || canRotateFlick)
            {
                orientation += restrictedOrientation;
            }

            // Scale the item if it is allowed
            if (canScale || canScaleFlick)
            {
                scale *= restrictedScale;
            }

            // Translate the item if it is allowed
            if (canTranslate || canTranslateFlick)
            {
                center += new Vector2(e.Delta.TranslationX, e.Delta.TranslationY);
            }

            RestrictCenter();

            if (canRotate || canRotateFlick)
            {
                manipulationProcessor.Pivot = new ManipulationPivot2D
                {
                    X = center.X,
                    Y = center.Y,
                    Radius = Math.Max(ActualSize.X, ActualSize.Y) / 2.0f,
                };
            }

            SetConvertMatrix();
        }
Esempio n. 18
0
 /// <summary>
 /// Handles the Delta event of the ScatterManipulationProcessor control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.Windows.Input.Manipulations.Manipulation2DDeltaEventArgs"/> instance containing the event data.</param>
 private void ScatterManipulationProcessor_Delta(object sender, Manipulation2DDeltaEventArgs e)
 {
     if (!_overridingScatterViewItem && e.Delta.ScaleX >= 1 &&
         GetMaxScale() > 1 &&
         (Math.Abs(ScatterViewItem.ActualWidth - ScatterViewItem.MaxWidth) <= .1 || Math.Abs(ScatterViewItem.ActualHeight - ScatterViewItem.MaxHeight) <= .1))
     {
         // If the SVI is scalled up to its maximum, steal its contacts and begin scaling the content.
         _overridingScatterViewItem = true;
         ScatterViewItem.TouchesCaptured.ToList().ForEach(c => c.Capture(this));
     }
 }
Esempio n. 19
0
        /// <summary>
        /// Translate and scale the content when it is manipulated.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.ManipulationDeltaEventArgs"/> instance containing the event data.</param>
        private void ContentManipulationProcessor_Affine2DManipulationDelta(object sender, Manipulation2DDeltaEventArgs e)
        {
            if (GetMaxScale() == 1)
            {
                return;
            }

            // The inertia processor can move the content out of bounds.
            if (sender == _inertiaProcessor)
            {
                _translate.X += e.Delta.TranslationX;
                _translate.Y += e.Delta.TranslationY;
                _scale.ScaleX *= e.Delta.ScaleX;
                _scale.ScaleY *= e.Delta.ScaleY;
                return;
            }

            _spring.Stop(this);

            // Determine what scale to apply to the content.
            bool returnControlToScatterViewItem = false;
            double scaleDelta = 1;
            double newScale = _scale.ScaleX * e.Delta.ScaleX;
            if (_content.ActualWidth * newScale >= ActualWidth && newScale <= GetMaxScale())
            {
                // If the new scale is within the bounds, just use it directly.
                scaleDelta = e.Delta.ScaleX;
            }
            else if (e.Delta.ScaleX > 1)
            {
                // Apply friction to an increasing scale.
                scaleDelta = 1 + ((e.Delta.ScaleX - 1) * _friction);
            }
            else if (e.Delta.ScaleX < 1)
            {
                // Apply friction to a decreasing scale.
                scaleDelta = 1 - ((1 - e.Delta.ScaleX) * _friction);
                returnControlToScatterViewItem = _scale.ScaleX <= .95;
            }

            _scale.ScaleX *= scaleDelta;
            _scale.ScaleY *= scaleDelta;

            if (returnControlToScatterViewItem)
            {
                // If the content is scaled down to less than the default size, return control back to the ScatterViewItem.
                if (ScatterViewItem != null)
                {
                    TouchesCaptured.ToList().ForEach(c => c.Capture(ScatterViewItem));
                    _overridingScatterViewItem = false;
                }
            }

            // Move the content.
            _translate.X += e.Delta.TranslationX;
            _translate.Y += e.Delta.TranslationY;

            // Get the new bounds of the image.
            Rect bounds = GetContentBounds();

            if (bounds.TopLeft.X > 0 || bounds.BottomRight.X < ActualWidth)
            {
                // Apply friction if the content is out of bounds on the x-axis.
                _translate.X -= e.Delta.TranslationX;
                _translate.X += e.Delta.TranslationX * _friction;
            }

            if (bounds.TopLeft.Y > 0 || bounds.BottomRight.Y < ActualHeight)
            {
                // Apply friction if the content is out of bounds on the y-axis.
                _translate.Y -= e.Delta.TranslationY;
                _translate.Y += e.Delta.TranslationY * _friction;
            }
        }
        /// <summary>
        /// Update the position of the Value and the thumb each delta. 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnAffine2DInertiaDelta(object sender, Manipulation2DDeltaEventArgs e)
        {
            float valueX = Value + ToValueSpace(e.Delta.TranslationX);

            valueX = FlickUtilities.Clamp(valueX, 0, 1);

            UpdatedValueInValueSpace(valueX);
        }
Esempio n. 21
0
 /// <summary>
 /// Extract the Manipulation Data and write it into our Dictionary
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnAffine2DDelta(object sender, Manipulation2DDeltaEventArgs e)
 {
     ReadOnlyTouchPointCollection currentContacts = contactTarget.GetState();
     foreach (TouchPoint c in currentContacts)
     {
         if (c.X == e.OriginX && c.Y == e.OriginY)
         {
             // BugFix
             // Apparently this event handling is not thread-safe
             // Once the surface is reporting a bunch of touches (~30 in testing)
             // It will try to add a moving touch multiple times to this dictionary.
             //
             // I've fixed this by only taking the last touch
             // and just skip all the inbetween touches.
             _contactManipulationData[c.Id] = e;
         }
     }
 }
Esempio n. 22
0
        /// <summary>
        /// Update the changes to inertia processing.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnAffine2DInertiaDelta(object sender, Manipulation2DDeltaEventArgs e)
        {
            if ((Orientation & Orientation.Horizontal) != 0)
            {
                // Inertia and Manipulations are both processed in ScreenSpace so we need to convert to value space and updated.
                float valueX = horizontalScrollBarStateMachine.Value + ConvertFromHorizontalScreenToValueSpace(e.Delta.TranslationX);

                // Clamp X
                valueX = FlickUtilities.Clamp(valueX, 0, 1);

                horizontalScrollBarStateMachine.Value = valueX;
            }

            if ((Orientation & Orientation.Vertical) != 0)
            {
                float valueY = verticalScrollBarStateMachine.Value + ConvertFromVerticalScreenToValueSpace(e.Delta.TranslationY);

                // Clamp Y
                valueY = FlickUtilities.Clamp(valueY, 0, 1);

                // Update the scrollbars which will update the scroll viewer.

                verticalScrollBarStateMachine.Value = valueY;
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Handles the Affine2DManipulationDelta event of the ManipulationProcessor. Attempts to distinguish scroll gestures
        /// from those intended to manipulate the parent ScatterViewItem.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.Manipulation2DDeltaEventArgs"/> instance containing the event data.</param>
        private void ManipulationProcessor_Delta(object sender, Manipulation2DDeltaEventArgs e)
        {
            if (_scatterViewItem == null)
            {
                // Hook up an event to the parent SVI. When it loses a contact, the ScrollViewer should capture them again.
                _scatterViewItem = AssociatedObject.FindVisualParent <ScatterViewItem>();
                _scatterViewItem.PreviewTouchUp += ScatterViewItem_PreviewContactUp;
            }

            if (_scatterViewItem == null)
            {
                // There's no SVI, so don't do anything.
                return;
            }

            if (e.Delta.ExpansionX != 0 || e.Delta.ExpansionY != 0 || e.Delta.Rotation != 0)
            {
                // If any scale or rotation is detected, pass that to the SVI.
                GiveControlToScatterViewItem();
                return;
            }

            Vector translation = new Vector((double)e.Cumulative.TranslationX, (double)e.Cumulative.TranslationY);

            if (Math.Abs(translation.Length) < 10)
            {
                // There's no translation, so don't do anything.
                return;
            }

            if (AssociatedObject.ComputedHorizontalScrollBarVisibility == Visibility.Collapsed && AssociatedObject.ComputedVerticalScrollBarVisibility == Visibility.Collapsed)
            {
                // There are no scrollbars, so pass all translations to the SVI.
                GiveControlToScatterViewItem();
                return;
            }

            if (translation.Length >= SensitivityDistance)
            {
                // The scroll has gone for some distance, so assume the gesture is intended as a scroll and never do a drag.
                _manipulationProcessor.CompleteManipulation(DateTime.UtcNow.Ticks);
                return;
            }

            double translationAngle = Math.Abs(Math.Atan2(e.Cumulative.TranslationX, e.Cumulative.TranslationY) * (180 / Math.PI));

            if (AssociatedObject.ComputedVerticalScrollBarVisibility == Visibility.Visible && AssociatedObject.ComputedHorizontalScrollBarVisibility == Visibility.Collapsed)
            {
                // The ScrollViewer is scrolling vertically.
                if (translationAngle >= 90 - SensitivityAngle && translationAngle <= 90 + SensitivityAngle)
                {
                    // The gesture scrolled horizontally, so pass that to the SVI.
                    GiveControlToScatterViewItem();
                }
            }
            else if (AssociatedObject.ComputedVerticalScrollBarVisibility == Visibility.Collapsed && AssociatedObject.ComputedHorizontalScrollBarVisibility == Visibility.Visible)
            {
                // The ScrollViewer is scrolling horizontally.
                if (e.Cumulative.TranslationX < 0)
                {
                    // The gesture is scrolling to the left.
                    if (180 - translationAngle < SensitivityAngle)
                    {
                        // But it's close enough to vertical that it should go to the SVI.
                        GiveControlToScatterViewItem();
                    }
                }
                else if (e.Cumulative.TranslationX > 0)
                {
                    // The gesture is scrolling to the right.
                    if (translationAngle <= SensitivityAngle)
                    {
                        // But it's close enough to vertical that it should go to the SVI.
                        GiveControlToScatterViewItem();
                    }
                }
            }
        }
Esempio n. 24
0
 /// <summary>
 /// Extract the Manipulation Data and write it into our Dictionary
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnAffine2DDelta(object sender, Manipulation2DDeltaEventArgs e)
 {
     ReadOnlyTouchPointCollection currentContacts = contactTarget.GetState();
     foreach (TouchPoint c in currentContacts)
     {
         if (c.X == e.OriginX && c.Y == e.OriginY)
         {
             _contactManipulationData.Add(c.Id, e);
         }
     }
 }
        // </Snippet_ManipulationItem_OnManipulationStarted>

        // <Snippet_ManipulationItem_OnManipulationOrInertiaDelta>
        #region OnManipulationOrInertiaDelta
        private void OnManipulationOrInertiaDelta(object sender, Manipulation2DDeltaEventArgs e)
        {
            // The values obtained from e.Delta can be used to move, resize, or
            // change the orientation of the element that is being manipulated.
        }
Esempio n. 26
0
        //==========================================================//
        /// <summary>
        /// Event handler for the manipulation processor's delta event.
        /// Occurs whenever the manipulation processor processes manipulator data.
        /// </summary>
        /// <param name="sender">The manipulation processor that raised the event.</param>
        /// <param name="e">The event args for the event.</param>
        private void OnAffine2DDelta(object sender, Manipulation2DDeltaEventArgs e)
        {
            // Check the raw manipulation values
            float restrictedScale = RestrictScale(e.Delta.ScaleX);

            Vector2 restrictedTranslation = RestrictTranslation(e.Delta.TranslationX, e.Delta.TranslationY, restrictedScale);

            // Get the original and scaled offset from the manipulation origin to the center of the scatterview.
            Vector2 originalManipulationOffset = new Vector2 ( e.OriginX, e.OriginY ) - transformedCenter;
            Vector2 scaledManipulationOffset = originalManipulationOffset * restrictedScale;

            // Remember the original center point
            Vector2 originalCenter = transformedCenter;

            // Scale the item
            zoomFactor *= restrictedScale;

            // Move the center of the scatter view towards the manipulation origin
            transformedCenter += originalManipulationOffset - scaledManipulationOffset;

            // Apply the translation
            transformedCenter += restrictedTranslation;

            // Children will have to be updated too
            foreach (XnaScatterViewItem item in inactiveChildren)
            {
                Vector2 offsetToOriginalCenter = item.TransformedCenter - originalCenter;
                offsetToOriginalCenter *= restrictedScale;
                item.TransformedCenter = transformedCenter + offsetToOriginalCenter;

                item.ZoomFactor *= restrictedScale;
            }
        }
Esempio n. 27
0
        private void unsolved_ManipulationDelta(object sender, Manipulation2DDeltaEventArgs e)
        {
            Canvas element = scene;

            var matrix = GetUnsolvedTransform();

            //if (e.Delta.ScaleX < 1)
            //    if (matrix.M11 <= 1.0 || matrix.M22 <= 1.0)
            //        return;

            //matrix.ScaleAt(e.DeltaManipulation.Scale.X,
            //               e.DeltaManipulation.Scale.Y,
            //               e.ManipulationOrigin.X - this.ActualWidth / 2,
            //               e.ManipulationOrigin.Y - this.ActualHeight / 2);

            var xScale = (e.Delta.ScaleX + 2)/3;

            var finalFact = matrix.M11*xScale;
            if (finalFact > MAX_ZOOM || finalFact < MIN_ZOOM)
                return;

            matrix.ScaleAt(xScale,
                           xScale,
                           e.OriginX - this.ActualWidth/2,
                           e.OriginY - this.ActualHeight/2);

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

            matrix.Translate(e.Delta.TranslationX,
                             e.Delta.TranslationY);

            updateZoomFactor(matrix.M11);

            SetWorkingAreaTransform(matrix, e.Delta.TranslationX < 0,
                                    e.Delta.TranslationY < 0,
                                    e.Delta.ScaleX > 1,
                                    e.Delta.ScaleX < 1);
        }