Exemplo n.º 1
0
        private void IllustrationOriginalImage_OnManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
        {
            var renderedImageWidth  = IllustrationOriginalImage.ActualWidth * GetZoomFactor();
            var renderedImageHeight = IllustrationOriginalImage.ActualHeight * GetZoomFactor();
            var containerWidth      = IllustrationOriginalImageContainer.ActualWidth;
            var containerHeight     = IllustrationOriginalImageContainer.ActualHeight;
            var pos = IllustrationOriginalImage.TransformToVisual(IllustrationOriginalImageContainer).TransformPoint(new Point(0, 0));

            var          sb = new Storyboard();
            var          animationDuration  = TimeSpan.FromMilliseconds(200);
            const string translateXProperty = nameof(CompositeTransform.TranslateX);
            const string translateYProperty = nameof(CompositeTransform.TranslateY);
            var          xLowerBound        = -(renderedImageWidth - containerWidth);
            var          yLowerBound        = -(renderedImageHeight - containerHeight);

            switch (pos.X)
            {
            case var x when x <xLowerBound && renderedImageWidth> containerWidth:
                sb.Children.Add(IllustrationOriginalImageRenderTransform.CreateDoubleAnimation(translateXProperty, DoubleAnimationTemplate(xLowerBound - x)));
                break;

            case > 0 when renderedImageWidth > containerWidth:
                sb.Children.Add(IllustrationOriginalImageRenderTransform.CreateDoubleAnimation(translateXProperty, DoubleAnimationTemplate(-pos.X)));
                break;
            }

            switch (pos.Y)
            {
            case var y when y <yLowerBound && renderedImageHeight> containerHeight:
                sb.Children.Add(IllustrationOriginalImageRenderTransform.CreateDoubleAnimation(translateYProperty, DoubleAnimationTemplate(yLowerBound - y)));
                break;

            case > 0 when renderedImageHeight > containerHeight:
                sb.Children.Add(IllustrationOriginalImageRenderTransform.CreateDoubleAnimation(translateYProperty, DoubleAnimationTemplate(-pos.Y)));
                break;
            }

            if (sb.Children.Any())
            {
                sb.Begin();
            }

            Func <DoubleAnimation> DoubleAnimationTemplate(double by) => () => new DoubleAnimation
            {
                Duration = animationDuration, EasingFunction = _easingFunction, By = @by
            };
        }
Exemplo n.º 2
0
        private void ResetImagePosition()
        {
            if (IllustrationOriginalImageRenderTransform.TranslateX != 0)
            {
                IllustrationOriginalImageRenderTransform.CreateDoubleAnimation(
                    nameof(CompositeTransform.TranslateX),
                    to: 0,
                    duration: TimeSpan.FromMilliseconds(100),
                    easingFunction: _easingFunction).BeginStoryboard();
            }

            if (IllustrationOriginalImageRenderTransform.TranslateY != 0)
            {
                IllustrationOriginalImageRenderTransform.CreateDoubleAnimation(
                    nameof(CompositeTransform.TranslateY),
                    to: 0,
                    duration: TimeSpan.FromMilliseconds(100),
                    easingFunction: _easingFunction).BeginStoryboard();
            }
        }
Exemplo n.º 3
0
        public void Zoom(double delta)
        {
            if (IllustrationOriginalImageRenderTransform.TranslateX != 0)
            {
                UIHelper.CreateStoryboard(IllustrationOriginalImageRenderTransform.CreateDoubleAnimation(nameof(CompositeTransform.TranslateX), () => new DoubleAnimation
                {
                    To             = 0,
                    Duration       = TimeSpan.FromMilliseconds(100),
                    EasingFunction = _easingFunction
                })).Begin();
            }

            if (IllustrationOriginalImageRenderTransform.TranslateY != 0)
            {
                UIHelper.CreateStoryboard(IllustrationOriginalImageRenderTransform.CreateDoubleAnimation(nameof(CompositeTransform.TranslateY), () => new DoubleAnimation
                {
                    To             = 0,
                    Duration       = TimeSpan.FromMilliseconds(100),
                    EasingFunction = _easingFunction
                })).Begin();
            }

            var factor = GetZoomFactor();

            switch (delta)
            {
            case < 0 when factor > MinZoomFactor:
            case > 0 when factor < MaxZoomFactor:
                delta = (factor + delta) switch
                {
                    > MaxZoomFactor => MaxZoomFactor - factor,
                    < MinZoomFactor => - (factor - MinZoomFactor),
                    _ => delta
                };
                IllustrationOriginalImageRenderTransform.ScaleX += delta;
                IllustrationOriginalImageRenderTransform.ScaleY += delta;
                break;
            }