示例#1
0
        /*
         * Metodo per zoom sull'immagine
         */
        private void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            switch (e.Status)
            {
            case GestureStatus.Started:
                lastScale  = e.Scale;
                startScale = Scale;
                AnchorX    = e.ScaleOrigin.X;
                AnchorY    = e.ScaleOrigin.Y;
                break;

            case GestureStatus.Running:
                if (e.Scale < 0 || Math.Abs(lastScale - e.Scale) > (lastScale * 1.3) - lastScale)
                {
                    return;
                }
                lastScale = e.Scale;
                var current = Scale + (e.Scale - 1) * startScale;
                Scale = Clamp(current, MIN_SCALE * (1 - OVERSHOOT), MAX_SCALE * (1 + OVERSHOOT));
                break;

            case GestureStatus.Completed:
                if (Scale > MAX_SCALE)
                {
                    Scale = MAX_SCALE;
                }
                else if (Scale < MIN_SCALE)
                {
                    Scale = MIN_SCALE;
                }
                break;
            }
        }
示例#2
0
        private async void PinchGestureRecognizer_PinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            if (e.Status == GestureStatus.Started)
            {
                startScale = ContentLayout.Scale;
            }
            if (e.Status == GestureStatus.Running)
            {
                // Calculate the scale factor to be applied.
                currentScale += (e.Scale - 1) * startScale;
                currentScale  = currentScale.Clamp(.8, 1.5);
            }
            if (e.Status == GestureStatus.Completed)
            {
                if (currentScale < 1 && !isVideoControlShown)
                {
                    await mViewContainer.PushViewAsync(new VideoControlView(),
                                                       DefaultAnimationBehavior.ScaleFromLargeAndFadeInOut,
                                                       otherAnimations : new Animation(v => ContentLayout.Scale = v, 1, startScale *currentScale, Easing.SinInOut));

                    isVideoControlShown = true;
                }
                else if (currentScale > 1 && isVideoControlShown)
                {
                    await mViewContainer.PopViewAsync(DefaultAnimationBehavior.ScaleFromLargeAndFadeInOut,
                                                      otherAnimation : new Animation(v => ContentLayout.Scale = v, startScale, 1, Easing.SinInOut));

                    isVideoControlShown = false;
                }
            }
        }
示例#3
0
        private void PinchUpdated_Event(object sender, PinchGestureUpdatedEventArgs e)
        {
            return;

            /*
             * Image img = (Image)sender;
             * switch (e.Status)
             * {
             *  case GestureStatus.Started:
             *      {
             *          this.startScale = this.Scale;
             *      }
             *      break;
             *  case GestureStatus.Running:
             *      this.currentScale += (e.Scale - 1) * this.startScale;
             *      this.currentScale = Math.Max(1, this.currentScale);
             *      this.Scale = currentScale;
             *      break;
             *  case GestureStatus.Completed:
             *      break;
             *  default:
             *      break;
             * }
             */
        }
示例#4
0
        // Pinching MemoBoard
        void OnPinchMemoBoard(object sender, PinchGestureUpdatedEventArgs e)
        {
            AbsoluteLayout PinchedObject = (AbsoluteLayout)sender;

            switch (e.Status)
            {
            case GestureStatus.Started:
                StatusLabel.Text = "Pinching MemoBoard";
                break;

            case GestureStatus.Running:
                PinchedObject.Scale *= e.Scale;

                Label1.Text = string.Format("ScaleOrigin = ( {0:0.00} , {1:0.00} )",
                                            e.ScaleOrigin.X, e.ScaleOrigin.Y);
                Label2.Text = string.Format("e.Scale = {0:0.00},  e.Scale Total = {1:0.00}",
                                            e.Scale, PinchedObject.Scale);

                break;

            case GestureStatus.Completed:
#if BoxDisplay
                // Red BoxView
                box1.TranslationX = PinchedObject.TranslationX;
                box1.TranslationY = PinchedObject.TranslationY;
                // Blue BoxView
                box2.TranslationX = PinchedObject.TranslationX + PinchedObject.Width;
                box2.TranslationY = PinchedObject.TranslationY + PinchedObject.Height;
#endif

                StatusLabel.Text = "MemoBoard Pinch Completed";
                break;
            }
        }
示例#5
0
        private void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            switch (e.Status)
            {
            case GestureStatus.Started:
                _startScale = Scale;
                AnchorX     = e.ScaleOrigin.X;
                AnchorY     = e.ScaleOrigin.Y;
                break;

            case GestureStatus.Running:
                double current = Scale + (e.Scale - 1) * _startScale;
                Scale = Clamp(current, MinScale * (1 - Overshoot), MaxScale * (1 + Overshoot));
                break;

            case GestureStatus.Completed:
                if (Scale > MaxScale)
                {
                    this.ScaleTo(MaxScale, 250, Easing.SpringOut);
                }
                else if (Scale < MinScale)
                {
                    this.ScaleTo(MinScale, 250, Easing.SpringOut);
                }
                break;
            }
        }
示例#6
0
 private void PinchGestureRecognizer_PinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
 {
     if (e.Status == GestureStatus.Started)
     {
         startScale      = Content.Scale;
         Content.AnchorX = 0;
         Content.AnchorY = 0;
     }
     if (e.Status == GestureStatus.Running)
     {
         currentScale += (e.Scale - 1) * startScale;
         currentScale  = Math.Max(1, currentScale);
         double renderedX   = Content.X + xOffset;
         double deltaX      = renderedX / Width;
         double deltaWidth  = Width / (Content.Width * startScale);
         double originX     = (e.ScaleOrigin.X - deltaX) * deltaWidth;
         double renderedY   = Content.Y + yOffset;
         double deltaY      = renderedY / Height;
         double deltaHeight = Height / (Content.Height * startScale);
         double originY     = (e.ScaleOrigin.Y - deltaY) * deltaHeight;
         double targetX     = xOffset - (originX * Content.Width) * (currentScale - startScale);
         double targetY     = yOffset - (originY * Content.Height) * (currentScale - startScale);
         Content.TranslationX = targetX.Clamp(-Content.Width * (currentScale - 1), 0);
         Content.TranslationY = targetY.Clamp(-Content.Height * (currentScale - 1), 0);
         Content.Scale        = currentScale;
     }
     if (e.Status == GestureStatus.Completed)
     {
         xOffset = Content.TranslationX;
         yOffset = Content.TranslationY;
     }
 }
示例#7
0
        //private void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        //{
        //    switch (e.Status)
        //    {
        //        case GestureStatus.Started:
        //            StartScale = Scale;
        //            AnchorX = e.ScaleOrigin.X;
        //            AnchorY = e.ScaleOrigin.Y;
        //            break;
        //        case GestureStatus.Running:
        //            double current = Scale + (e.Scale - 1) * StartScale;
        //            Scale = Clamp(current, MIN_SCALE * (1 - OVERSHOOT), MAX_SCALE * (1 + OVERSHOOT));
        //            break;
        //        case GestureStatus.Completed:
        //            if (Scale > MAX_SCALE)
        //                this.ScaleTo(MAX_SCALE, 250, Easing.SpringOut);
        //            else if (Scale < MIN_SCALE)
        //                this.ScaleTo(MIN_SCALE, 250, Easing.SpringOut);
        //            break;
        //    }
        //}

        private void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            switch (e.Status)
            {
            case GestureStatus.Started: LastScale = e.Scale; StartScale = Scale; AnchorX = e.ScaleOrigin.X; AnchorY = e.ScaleOrigin.Y; break;

            case GestureStatus.Running:
                if (e.Scale < 0 || Math.Abs(LastScale - e.Scale) > (LastScale * 1.3) - LastScale)
                {       // e.Scale sometimes returns wildly different values from one update to the next. This causes flickering
                        // By removing values that are too far off, we smooth that out.
                    return;
                }
                LastScale = e.Scale;
                var current = Scale + (e.Scale - 1) * StartScale;
                Scale = Clamp(current, MIN_SCALE * (1 - OVERSHOOT), MAX_SCALE * (1 + OVERSHOOT));
                break;

            case GestureStatus.Completed:
                if (Scale > MAX_SCALE)
                {
                    this.ScaleTo(MAX_SCALE, 250, Easing.SpringOut);
                }
                else if (Scale < MIN_SCALE)
                {
                    this.ScaleTo(MIN_SCALE, 250, Easing.SpringOut);
                }
                break;
            }
        }
示例#8
0
        private void PinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            switch (e.Status)
            {
            case GestureStatus.Started:
                _startScale      = InkCanvasView.ZoomFactor;
                _currentScale    = InkCanvasView.ZoomFactor;
                _startedWithZoom = true;
                break;

            case GestureStatus.Running:
                // Calculate the scale factor to be applied.
                _currentScale += (e.Scale - 1) * _startScale;
                _currentScale  = _currentScale.Clamp(MinZoomFactor, MaxZoomFactor);

                // Apply scale factor
                InkCanvasView.ZoomFactor = _currentScale;

                _xOffset = InkCanvasView.HorizontalOffset;
                _yOffset = InkCanvasView.VerticalOffset;
                break;

            case GestureStatus.Completed:
                break;
            }
        }
示例#9
0
        private void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            switch (e.Status)
            {
            case GestureStatus.Started:
                StartScale = Scale;
                AnchorX    = e.ScaleOrigin.X;
                AnchorY    = e.ScaleOrigin.Y;
                break;

            case GestureStatus.Running:
                double current = Scale + (e.Scale - 1) * StartScale;
                Scale = Clamp(current, MIN_SCALE * (1 - OVERSHOOT), MAX_SCALE * (1 + OVERSHOOT));
                break;

            case GestureStatus.Completed:
                if (Scale > MAX_SCALE)
                {
                    this.ScaleTo(MAX_SCALE, 250, Easing.SpringOut);
                }
                else if (Scale < MIN_SCALE)
                {
                    this.ScaleTo(MIN_SCALE, 250, Easing.SpringOut);
                }
                break;
            }
        }
示例#10
0
        private void PinchUpdated_Event(object sender, PinchGestureUpdatedEventArgs e)
        {
            Image img = (Image)sender;

            switch (e.Status)
            {
            case GestureStatus.Started:
            {
                this.startScale = this.Scale;
            }
            break;

            case GestureStatus.Running:
                this.currentScale += (e.Scale - 1) * this.startScale;
                this.currentScale  = Math.Max(1, this.currentScale);
                this.Scale         = currentScale;
                break;

            case GestureStatus.Completed:
                break;

            default:
                break;
            }
        }
 private void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
 {
     if (e.Status == GestureStatus.Started)
     {
         lastScaleTransformation = scaleTransformation;
         gestureActivated        = true;
     }
     else if (e.Status == GestureStatus.Canceled)
     {
         scaleTransformation = lastScaleTransformation;
         gestureActivated    = false;
     }
     else if (e.Status == GestureStatus.Completed)
     {
         lastScaleTransformation = scaleTransformation;
         gestureActivated        = false;
     }
     else
     {
         scaleTransformation = scaleTransformation//.Translate(-(float)e.ScaleOrigin.X,-(float)e.ScaleOrigin.Y)
                               .Scale((float)e.Scale, (float)e.Scale);
         gestureActivated = false;
     }
     surface.Transformation = translateTransformation.Concat(scaleTransformation);
 }
        public void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            if (!IsEnabled)
            {
                return;
            }

            switch (e.Status)
            {
            case GestureStatus.Started:
                // Store the current scale factor applied to the wrapped user interface element,
                // and zero the components for the center point of the translate transform.
                startScale      = Content.Scale;
                Content.AnchorX = 0;
                Content.AnchorY = 0;

                break;

            case GestureStatus.Running:
                // Calculate the scale factor to be applied.
                currentScale += (e.Scale - 1) * startScale;
                currentScale  = Math.Max(MinimumScale, currentScale);

                // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
                // so get the X pixel coordinate.
                double renderedX  = Content.X + xOffset;
                double deltaX     = renderedX / Width;
                double deltaWidth = Width / (Content.Width * startScale);
                double originX    = (e.ScaleOrigin.X - deltaX) * deltaWidth;

                // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
                // so get the Y pixel coordinate.
                double renderedY   = Content.Y + yOffset;
                double deltaY      = renderedY / Height;
                double deltaHeight = Height / (Content.Height * startScale);
                double originY     = (e.ScaleOrigin.Y - deltaY) * deltaHeight;

                // Calculate the transformed element pixel coordinates.
                double targetX = xOffset - (originX * Content.Width) * (currentScale - startScale);
                double targetY = yOffset - (originY * Content.Height) * (currentScale - startScale);

                // Apply translation based on the change in origin.
                Content.TranslationX = Math.Min(0, Math.Max(targetX, -Content.Width * (currentScale - 1)));
                Content.TranslationY = Math.Min(0, Math.Max(targetY, -Content.Height * (currentScale - 1)));

                // Apply scale factor.
                Content.Scale = currentScale;

                break;

            case GestureStatus.Completed:
                // Store the translation delta's of the wrapped user interface element.
                xOffset     = Content.TranslationX;
                yOffset     = Content.TranslationY;
                Translation = new Point(xOffset, yOffset);

                break;
            }
        }
示例#13
0
 private void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
 {
     if (e.Status == GestureStatus.Running)
     {
         // Calculate the scale factor to be applied.
         videoView.MediaPlayer.Scale += (float)e.Scale - 1;
     }
 }
示例#14
0
        private void PinchGestureRecognizer_PinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            var status = e.Status;

            ((Image)sender).ScaleTo(e.Scale);

            Debug.Print(status.ToString());
        }
        private void PinchGesture_PinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            if (e.Status == GestureStatus.Started)
            {
                panGesture.PanUpdated -= OnPanUpdated;
                // Store the current scale factor applied to the wrapped user interface element,
                // and zero the components for the center point of the translate transform.
                startScale      = Content.Scale;
                Content.AnchorX = 0;
                Content.AnchorY = 0;
            }

            if (e.Status == GestureStatus.Running)
            {
                // Calculate the scale factor to be applied.
                var mesureScale = (e.Scale - 1) * startScale + currentScale;
                if (mesureScale > MAX_SCALE)
                {
                    return;
                }
                currentScale += (e.Scale - 1) * startScale;
                currentScale  = Math.Max(1, currentScale);

                // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
                // so get the X pixel coordinate.
                double renderedX  = Content.X + xOffset;
                double deltaX     = renderedX / Width;
                double deltaWidth = Width / (Content.Width * startScale);
                double originX    = (e.ScaleOrigin.X - deltaX) * deltaWidth;

                // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
                // so get the Y pixel coordinate.
                double renderedY   = Content.Y + yOffset;
                double deltaY      = renderedY / Height;
                double deltaHeight = Height / (Content.Height * startScale);
                double originY     = (e.ScaleOrigin.Y - deltaY) * deltaHeight;

                // Calculate the transformed element pixel coordinates.
                double targetX = xOffset - (originX * Content.Width) * (currentScale - startScale);
                double targetY = yOffset - (originY * Content.Height) * (currentScale - startScale);

                // Apply translation based on the change in origin.

                Content.TranslationX = targetX.Clamp(-Content.Width * (currentScale - 1), 0);
                Content.TranslationY = targetY.Clamp(-Content.Height * (currentScale - 1), 0);

                // Apply scale factor.
                Content.Scale = currentScale;
            }

            if (e.Status == GestureStatus.Completed)
            {
                panGesture.PanUpdated += OnPanUpdated;
                // Store the translation delta's of the wrapped user interface element.
                xOffset = Content.TranslationX;
                yOffset = Content.TranslationY;
            }
        }
示例#16
0
        private void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            switch (e.Status)
            {
            case GestureStatus.Started:
                // Store the current scale factor applied to the wrapped user interface element,
                // and zero the components for the center point of the translate transform.
                _startScale     = Content.Scale;
                Content.AnchorX = 0;
                Content.AnchorY = 0;
                break;

            case GestureStatus.Running:
            {
                // Calculate the scale factor to be applied.
                _currentScale += (e.Scale - 1) * _startScale;
                _currentScale  = Math.Max(1, _currentScale);

                // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
                // so get the X pixel coordinate.
                var renderedX  = Content.X + _xOffset;
                var deltaX     = renderedX / Width;
                var deltaWidth = Width / (Content.Width * _startScale);
                var originX    = (e.ScaleOrigin.X - deltaX) * deltaWidth;

                // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
                // so get the Y pixel coordinate.
                var renderedY   = Content.Y + _yOffset;
                var deltaY      = renderedY / Height;
                var deltaHeight = Height / (Content.Height * _startScale);
                var originY     = (e.ScaleOrigin.Y - deltaY) * deltaHeight;

                // Calculate the transformed element pixel coordinates.
                var targetX = _xOffset - (originX * Content.Width) * (_currentScale - _startScale);
                var targetY = _yOffset - (originY * Content.Height) * (_currentScale - _startScale);

                // Apply translation based on the change in origin.
                Content.TranslationX = targetX.Clamp(-Content.Width * (_currentScale - 1), 0);
                Content.TranslationY = targetY.Clamp(-Content.Height * (_currentScale - 1), 0);

                // Apply scale factor.
                Content.Scale = _currentScale;
                break;
            }

            case GestureStatus.Completed:
                // Store the translation delta's of the wrapped user interface element.
                _xOffset = Content.TranslationX;
                _yOffset = Content.TranslationY;
                break;

            case GestureStatus.Canceled:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#17
0
 private void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
 {
     switch (e.Status)
     {
     case GestureStatus.Running:
         noseImage.Scale *= e.Scale;
         break;
     }
 }
        private void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            if (!(BindingContext is GesturesPageViewModel vm))
            {
                return;
            }

            vm.Message = "Pinched : " + e.Status.ToString();
        }
        private void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            if (!(sender is ContentView parent))
            {
                return;
            }
            var content = parent.Content;

            switch (e.Status)
            {
            case GestureStatus.Started:
                // Store the current scale factor applied to the wrapped user interface element,
                // and zero the components for the center point of the translate transform.
                _startScale     = content.Scale;
                content.AnchorX = 0;
                content.AnchorY = 0;
                break;

            case GestureStatus.Running:
                // Calculate the scale factor to be applied.
                _currentScale += (e.Scale - 1) * _startScale;
                _currentScale  = Math.Max(1, _currentScale);

                // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
                // so get the X pixel coordinate.
                double renderedX  = content.X + _xOffset;
                double deltaX     = renderedX / parent.Width;
                double deltaWidth = parent.Width / (content.Width * _startScale);
                double originX    = (e.ScaleOrigin.X - deltaX) * deltaWidth;

                // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
                // so get the Y pixel coordinate.
                double renderedY   = content.Y + _yOffset;
                double deltaY      = renderedY / parent.Height;
                double deltaHeight = parent.Height / (content.Height * _startScale);
                double originY     = (e.ScaleOrigin.Y - deltaY) * deltaHeight;

                // Calculate the transformed element pixel coordinates.
                double targetX = _xOffset - (originX * content.Width) * (_currentScale - _startScale);
                double targetY = _yOffset - (originY * content.Height) * (_currentScale - _startScale);

                // Apply translation based on the change in origin.
                content.TranslationX = targetX.Clamp(-content.Width * (_currentScale - 1), 0);
                content.TranslationY = targetY.Clamp(-content.Height * (_currentScale - 1), 0);

                // Apply scale factor.
                content.Scale = _currentScale;
                break;

            case GestureStatus.Completed:
                // Store the translation delta's of the wrapped user interface element.
                _xOffset = content.TranslationX;
                _yOffset = content.TranslationY;
                break;
            }
        }
示例#20
0
 private void PinchGestureRecognizer_PinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
 {
     Console.WriteLine(e.Scale + "     " + e.Scale / grid_scale_origin + "    " + StackLayout2.Height);
     //StackLayout2.Scale = e.Scale * grid_scale_origin;
     //StackLayout2.HeightRequest = e.Scale / grid_scale_origin * grid_height_origin;
     foreach (var st in MyGrid.RowDefinitions)
     {
         st.Height = st.Height.Value + 1;
     }
 }
示例#21
0
 void PinchGesture_PinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
 {
     switch (e.Status)
     {
     case GestureStatus.Running:
         double current = (e.Scale - 1) / 2 * PanSpeed;
         _crop.ZoomFactor = Clamp(_crop.ZoomFactor + current, MIN_SCALE, MaxZoom);
         break;
     }
 }
示例#22
0
 private void OnPinch(object sender, PinchGestureUpdatedEventArgs e)
 {
     if (e.Scale > 1.0)
     {
         MainPageViewModel.Title = $"放大 {e.Scale}";
     }
     else
     {
         MainPageViewModel.Title = $"縮小 {e.Scale}";
     }
 }
示例#23
0
        private void PinchGesture_PinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            /* Storing the current Scale Factor of both Horizontal and Vertical Orientations with Anchor X an Anchor         Y This defines the Centralization of any image to the particular Orientations. */

            if (e.Status == GestureStatus.Started)
            {
                // We Store the current scale factor applied to the wrapped user interface element,
                // and zero the components for the center point of the translate transform.

                startScale      = Content.Scale;
                Content.AnchorX = 0;
                Content.AnchorY = 0;
            }

            if (e.Status == GestureStatus.Running)
            {
                // Calculate the scale factor to be applied.
                currentScale += (e.Scale - 1) * startScale;
                currentScale  = Math.Max(1, currentScale);

                // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
                // so get the X pixel coordinate.
                double renderedX  = Content.X + xOffset;
                double deltaX     = renderedX / Width;
                double deltaWidth = Width / (Content.Width * startScale);
                double originX    = (e.ScaleOrigin.X - deltaX) * deltaWidth;

                // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
                // so get the Y pixel coordinate.
                double renderedY   = Content.Y + yOffset;
                double deltaY      = renderedY / Height;
                double deltaHeight = Height / (Content.Height * startScale);
                double originY     = (e.ScaleOrigin.Y - deltaY) * deltaHeight;

                //With the Above X-Pixel coordinate and Y-Pixel coordinate we can calculate the Width and Height
                // calculate the transformed element pixel coordinates.
                double targetX = xOffset - (originX * Content.Width) * (currentScale - startScale);
                double targetY = yOffset - (originY * Content.Height) * (currentScale - startScale);

                // Apply translation based on the change in origin.
                Content.TranslationX = targetX.Clamp(-Content.Width * (currentScale - 1), 0);
                Content.TranslationY = targetY.Clamp(-Content.Height * (currentScale - 1), 0);

                // Apply scale factor.
                Content.Scale = currentScale;
            }

            if (e.Status == GestureStatus.Completed)
            {
                // Store the translation delta's of the wrapped user interface element.
                xOffset = Content.TranslationX;
                yOffset = Content.TranslationY;
            }
        }
示例#24
0
 private void HandlePinch(object sender, PinchGestureUpdatedEventArgs e)
 {
     switch (e.Status)
     {
     case GestureStatus.Running:
         SKPoint  pivotPt = ToUntransformedCanvasPt((float)(e.ScaleOrigin.X * _canvasV.Width), (float)(e.ScaleOrigin.Y * _canvasV.Height));
         SKMatrix deltaM  = SKMatrix.MakeScale((float)e.Scale, (float)e.Scale, pivotPt.X, pivotPt.Y);
         SKMatrix.PostConcat(ref _m, deltaM);
         _canvasV.InvalidateSurface();
         break;
     }
 }
示例#25
0
        private void PinchRecognizer_PinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            if (e.Status == GestureStatus.Completed)
            {
                this.currentScale = this.prevouseScale = this.totalScale = 0;
                return;
            }

            if (e.Status == GestureStatus.Started)
            {
                this.prevouseScale = e.Scale;
                return;
            }

            if (e.Status == GestureStatus.Running)
            {
                this.currentScale = e.Scale;
            }

            var  deltaScale = this.prevouseScale - this.currentScale;
            bool zoomOut    = deltaScale > 0;

            this.totalScale += System.Math.Abs(deltaScale);
            int currentSizeIndex = this.sizes.IndexOf(owner.ItemHeight);

            if (this.totalScale < 0.4)
            {
                return;
            }
            this.totalScale = 0;

            if (zoomOut)
            {
                // zoom out
                currentSizeIndex--;
                if (currentSizeIndex >= 0)
                {
                    double newSize = this.sizes[currentSizeIndex];
                    this.owner.ItemHeight = this.owner.ItemWidth = newSize;
                }
            }
            else
            {
                // zoom in
                currentSizeIndex++;
                if (currentSizeIndex <= this.sizes.Count - 1)
                {
                    double newSize = this.sizes[currentSizeIndex];
                    this.owner.ItemHeight = this.owner.ItemWidth = newSize;
                }
            }
        }
示例#26
0
        /// <summary>
        /// Implements Pinch/Zoom.
        /// </summary>
        /// <param name="sender">The sender object.</param>
        /// <param name="e">The event parameters.</param>
        private void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            if (_parent == null)
            {
                return;
            }

            if (!IsScaleEnabled)
            {
                return;
            }

            switch (e.Status)
            {
            case GestureStatus.Started:
                _startScale             = _parent.Content.Scale;
                _parent.Content.AnchorX = 0;
                _parent.Content.AnchorY = 0;

                break;

            case GestureStatus.Running:
                _currentScale += (e.Scale - 1) * _startScale;
                _currentScale  = Math.Max(1, _currentScale);

                var renderedX  = _parent.Content.X + _xOffset;
                var deltaX     = renderedX / _parent.Width;
                var deltaWidth = _parent.Width / (_parent.Content.Width * _startScale);
                var originX    = (e.ScaleOrigin.X - deltaX) * deltaWidth;

                var renderedY   = _parent.Content.Y + _yOffset;
                var deltaY      = renderedY / _parent.Height;
                var deltaHeight = _parent.Height / (_parent.Content.Height * _startScale);
                var originY     = (e.ScaleOrigin.Y - deltaY) * deltaHeight;

                var targetX = _xOffset - (originX * _parent.Content.Width) * (_currentScale - _startScale);
                var targetY = _yOffset - (originY * _parent.Content.Height) * (_currentScale - _startScale);

                _parent.Content.TranslationX = targetX.Clamp(-_parent.Content.Width * (_currentScale - 1), 0);
                _parent.Content.TranslationY = targetY.Clamp(-_parent.Content.Height * (_currentScale - 1), 0);

                _parent.Content.Scale = _currentScale;

                break;

            case GestureStatus.Completed:
                _xOffset = _parent.Content.TranslationX;
                _yOffset = _parent.Content.TranslationY;

                break;
            }
        }
示例#27
0
        void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            if (e.Status == GestureStatus.Started)
            {
                // Store the current scale factor applied to the wrapped user interface element,
                // and zero the components for the center point of the translate transform.
                startScale      = Content.Scale;
                Content.AnchorX = 0;
                Content.AnchorY = 0;
            }
            if (e.Status == GestureStatus.Running)
            {
                // Calculate the scale factor to be applied.
                currentScale += (e.Scale - 1) * startScale;
                currentScale  = Math.Max(.5, currentScale);

                // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
                // so get the X pixel coordinate.
                double renderedX  = Content.X + xOffset;
                double deltaX     = renderedX / Width;
                double deltaWidth = Width / (Content.Width * startScale);
                double originX    = (e.ScaleOrigin.X - deltaX) * deltaWidth;

                // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
                // so get the Y pixel coordinate.
                double renderedY   = Content.Y + yOffset;
                double deltaY      = renderedY / Height;
                double deltaHeight = Height / (Content.Height * startScale);
                double originY     = (e.ScaleOrigin.Y - deltaY) * deltaHeight;

                // Calculate the transformed element pixel coordinates.
                double targetX = xOffset - (originX * Content.Width) * (currentScale - startScale);
                double targetY = yOffset - (originY * Content.Height) * (currentScale - startScale);

                // Apply translation based on the change in origin.
                Content.TranslationX = targetX.Clamp(-Content.Width * (currentScale - 1), 0);
                Content.TranslationY = targetY.Clamp(-Content.Height * (currentScale - 1), 0);

                // Apply scale factor
                Content.Scale = currentScale;
                Debug.WriteLine("DEBUG:Pinch Running" + " Content.Scale:" + Content.Scale.ToString());
            }
            if (e.Status == GestureStatus.Completed)
            {
                // Store the translation delta's of the wrapped user interface element.
                xOffset = Content.TranslationX;
                yOffset = Content.TranslationY;
                Debug.WriteLine("DEBUG:Pinch Complet" + " Content.Scale:" + Content.Scale.ToString());
            }
        }
示例#28
0
        void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            if (e.Status == GestureStatus.Started)
            {
                // Store the current scale factor applied to the wrapped user interface element,
                // and zero the components for the center point of the translate transform.
                this.startScale      = this.Content.Scale;
                this.Content.AnchorX = 0;
                this.Content.AnchorY = 0;
            }

            if (e.Status == GestureStatus.Running)
            {
                // Calculate the scale factor to be applied.
                this.currentScale += (e.Scale - 1) * this.startScale;
                this.currentScale  = Math.Max(1, this.currentScale);

                // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
                // so get the X pixel coordinate.
                double renderedX  = this.Content.X + this.xOffset;
                double deltaX     = renderedX / this.Width;
                double deltaWidth = this.Width / (this.Content.Width * this.startScale);
                double originX    = (e.ScaleOrigin.X - deltaX) * deltaWidth;

                // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
                // so get the Y pixel coordinate.
                double renderedY   = this.Content.Y + this.yOffset;
                double deltaY      = renderedY / this.Height;
                double deltaHeight = this.Height / (this.Content.Height * this.startScale);
                double originY     = (e.ScaleOrigin.Y - deltaY) * deltaHeight;

                // Calculate the transformed element pixel coordinates.
                double targetX = this.xOffset - (originX * this.Content.Width) * (this.currentScale - this.startScale);
                double targetY = this.yOffset - (originY * this.Content.Height) * (this.currentScale - this.startScale);

                // Apply translation based on the change in origin.
                this.Content.TranslationX = targetX.Clamp(-this.Content.Width * (this.currentScale - 1), 0);
                this.Content.TranslationY = targetY.Clamp(-this.Content.Height * (this.currentScale - 1), 0);

                // Apply scale factor.
                this.Content.Scale = this.currentScale;
            }

            if (e.Status == GestureStatus.Completed)
            {
                // Store the translation delta's of the wrapped user interface element.
                this.xOffset = this.Content.TranslationX;
                this.yOffset = this.Content.TranslationY;
            }
        }
        /// <summary>
        /// Implements Pinch/Zoom.
        /// </summary>
        /// <param name="sender">The sender object.</param>
        /// <param name="e">The event parameters.</param>
        private void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            if (_parent == null)
            {
                return;
            }

            if (!IsScaleEnabled)
            {
                return;
            }

            switch (e.Status)
            {
            case GestureStatus.Started:
                _isPinching             = true;
                _startScale             = _parent.Content.Scale;
                _parent.Content.AnchorX = 0;
                _parent.Content.AnchorY = 0;
                _lastScale = e.Scale;
                IsZoomed   = true;
                break;

            case GestureStatus.Running:
                _isPinching = true;
                if (e.Scale < 0 || Math.Abs(_lastScale - e.Scale) > (_lastScale * 1.3) - _lastScale)
                {
                    return;
                }
                _lastScale = e.Scale;

                ExecuteScaling(e.Scale, e.ScaleOrigin.X, e.ScaleOrigin.Y);

                break;

            case GestureStatus.Completed:
                EndGesture();
                if (Math.Abs(_currentScale - 1) < 0.025)
                {
                    IsZoomed = false;
                }
                else
                {
                    IsZoomed = true;
                }
                _lastPinch  = DateTime.UtcNow;
                _isPinching = false;
                break;
            }
        }
示例#30
0
        private void OnPinchSample(object sender, PinchGestureUpdatedEventArgs e)
        {
            var size = canvas.CanvasSize;

            if (glview.IsVisible)
            {
                size = glview.CanvasSize;
            }

            Sample?.Pinch(
                (GestureState)(int)e.Status,
                (float)e.Scale,
                new SKPoint((float)e.ScaleOrigin.X * size.Width, (float)e.ScaleOrigin.Y * size.Height));
            RefreshSamples();
        }
		void OnPinchUpdated (object sender, PinchGestureUpdatedEventArgs e)
		{
			if (e.Status == GestureStatus.Started) {
				// Store the current scale factor applied to the wrapped user interface element,
				// and zero the components for the center point of the translate transform.
				startScale = Content.Scale;
				Content.AnchorX = 0;
				Content.AnchorY = 0;
			}
			if (e.Status == GestureStatus.Running) {
				// Calculate the scale factor to be applied.
				currentScale += (e.Scale - 1) * startScale;
				currentScale = Math.Max (1, currentScale);

				// The ScaleOrigin is in relative coordinates to the wrapped user interface element,
				// so get the X pixel coordinate.
				double renderedX = Content.X + xOffset;
				double deltaX = renderedX / Width;
				double deltaWidth = Width / (Content.Width * startScale);
				double originX = (e.ScaleOrigin.X - deltaX) * deltaWidth;

				// The ScaleOrigin is in relative coordinates to the wrapped user interface element,
				// so get the Y pixel coordinate.
				double renderedY = Content.Y + yOffset;
				double deltaY = renderedY / Height;
				double deltaHeight = Height / (Content.Height * startScale);
				double originY = (e.ScaleOrigin.Y - deltaY) * deltaHeight;

				// Calculate the transformed element pixel coordinates.
				double targetX = xOffset - (originX * Content.Width) * (currentScale - startScale);
				double targetY = yOffset - (originY * Content.Height) * (currentScale - startScale);

				// Apply translation based on the change in origin.
				Content.TranslationX = targetX.Clamp (-Content.Width * (currentScale - 1), 0);
				Content.TranslationY = targetY.Clamp (-Content.Height * (currentScale - 1), 0);

				// Apply scale factor
				Content.Scale = currentScale;
			}
			if (e.Status == GestureStatus.Completed) {
				// Store the translation delta's of the wrapped user interface element.
				xOffset = Content.TranslationX;
				yOffset = Content.TranslationY;
			}
		}
示例#32
0
 private void PinchUpdated_Event(object sender, PinchGestureUpdatedEventArgs e)
 {
     Image img = (Image)sender;
     switch (e.Status)
     {
         case GestureStatus.Started:
             {
                 this.startScale = this.Scale;
             }
             break;
         case GestureStatus.Running:
             this.currentScale += (e.Scale - 1) * this.startScale;
             this.currentScale = Math.Max(1, this.currentScale);
             this.Scale = currentScale;
             break;
         case GestureStatus.Completed:
             break;
         default:
             break;
     }
 }
		public void PinchImage(PinchGestureUpdatedEventArgs e)
		{
			if (e.Status == GestureStatus.Completed) 
			{
				mX = CurrentXOffset;
				mY = CurrentYOffset;
			}
			else if (e.Status == GestureStatus.Running) 
			{
				CurrentZoomFactor += (e.Scale - 1) * CurrentZoomFactor * mRatioZoom;
				CurrentZoomFactor = Math.Max (1, CurrentZoomFactor);

				CurrentXOffset = (e.ScaleOrigin.X * mRatioPan) + mX;
				CurrentYOffset = (e.ScaleOrigin.Y * mRatioPan) + mY;
				ReloadImage ();
			}
		}
示例#34
0
		void OnPinchUpdated (object sender, PinchGestureUpdatedEventArgs e) {
			if (e.Status == GestureStatus.Started) {
				startScale = relativeLayoutTest.Scale;
				xOffset = relativeLayoutTest.TranslationX;
				yOffset = relativeLayoutTest.TranslationY;
				relativeLayoutTest.AnchorX = 0;
				relativeLayoutTest.AnchorY = 0;
			}
			if (e.Status == GestureStatus.Running) {
				currentScale += (e.Scale - 1) * startScale;
				currentScale = Math.Max (1, currentScale);

				double renderedX = relativeLayoutTest.X + xOffset;
				double deltaX = renderedX / Width;
				double deltaWidth = Width / (relativeLayoutTest.Width * startScale);
				double originX = (e.ScaleOrigin.X - deltaX) * deltaWidth;

				double renderedY = relativeLayoutTest.Y + yOffset;
				double deltaY = renderedY / Height;
				double deltaHeight = Height / (relativeLayoutTest.Height * startScale);
				double originY = (e.ScaleOrigin.Y - deltaY) * deltaHeight;

				double targetX = xOffset - (originX * relativeLayoutTest.Width) * (currentScale - startScale);
				double targetY = yOffset - (originY * relativeLayoutTest.Height) * (currentScale - startScale);

				relativeLayoutTest.TranslationX = targetX;
				relativeLayoutTest.TranslationY = targetY;
				relativeLayoutTest.Scale = currentScale;

				if (((int) relativeLayoutTest.TranslationX) > 0) {
					relativeLayoutTest.TranslationX = 0;
				} else if ((((int) relativeLayoutTest.TranslationX) + (relativeLayoutTest.Width * relativeLayoutTest.Scale)) < App.coreView.Width) {
					relativeLayoutTest.TranslationX = (App.coreView.Width - (relativeLayoutTest.Width * relativeLayoutTest.Scale));
				}
			}
		}