예제 #1
0
 private void Scroller_StateChanged(muxc.ScrollViewer sender, object args)
 {
     // Checking if sender is idle and the scrollviewer has the mouse over itsself
     // since when using slider, the sender may sometimes still be idle while
     // user is still changing the slider
     if (sender.State == muxc.InteractionState.Idle && scroller2MouseIsOver)
     {
         ZoomSlider.Value = Math.Round(sender.ZoomFactor, (int)(10 * ZoomSlider.StepFrequency));
     }
 }
예제 #2
0
 private void Scroller_StateChanged(muxc.ScrollViewer sender, object args)
 {
     // each time it comes to rest update the slider to reflect the current zoom factor
     if (sender.State == muxc.InteractionState.Idle)
     {
         ZoomSlider.Value         = Math.Round(sender.ZoomFactor, (int)(10 * ZoomSlider.StepFrequency));
         ZoomSlider.ValueChanged += ZoomSlider_ValueChanged;
     }
     else
     {
         ZoomSlider.ValueChanged -= ZoomSlider_ValueChanged;
     }
 }
예제 #3
0
        private void Scroller4_ZoomAnimationStarting(muxc.ScrollViewer sender, muxc.ZoomAnimationStartingEventArgs args)
        {
            try
            {
                ScalarKeyFrameAnimation stockKeyFrameAnimation = args.Animation as ScalarKeyFrameAnimation;

                if (stockKeyFrameAnimation != null)
                {
                    ScalarKeyFrameAnimation customKeyFrameAnimation = stockKeyFrameAnimation;

                    if (nameof(ZoomAnimationOptions.Default) != (string)cbZoomAnimation.SelectedItem)
                    {
                        float targetZoomFactor = (float)zoomFactorSlider.Value;

                        customKeyFrameAnimation = stockKeyFrameAnimation.Compositor.CreateScalarKeyFrameAnimation();
                        float deltaZoomFactor = (float)(targetZoomFactor - sender.ZoomFactor);

                        switch ((string)cbZoomAnimation.SelectedItem)
                        {
                        case nameof(ZoomAnimationOptions.Custom1):
                            // "Accordion" case
                            for (int step = 0; step < 3; step++)
                            {
                                customKeyFrameAnimation.InsertKeyFrame(
                                    1.0f - (0.4f / (float)Math.Pow(2, step)),
                                    targetZoomFactor + 0.1f * deltaZoomFactor);
                                deltaZoomFactor /= -2.0f;
                            }

                            customKeyFrameAnimation.InsertKeyFrame(1.0f, targetZoomFactor);
                            break;

                        case nameof(ZoomAnimationOptions.Custom2):
                            // "Teleportation" case

                            CubicBezierEasingFunction cubicBezierStart = stockKeyFrameAnimation.Compositor.CreateCubicBezierEasingFunction(
                                new Vector2(1.0f, 0.0f),
                                new Vector2(1.0f, 0.0f));

                            StepEasingFunction stepEasingFunc = stockKeyFrameAnimation.Compositor.CreateStepEasingFunction(1);

                            CubicBezierEasingFunction cubicBezierEnd = stockKeyFrameAnimation.Compositor.CreateCubicBezierEasingFunction(
                                new Vector2(0.0f, 1.0f),
                                new Vector2(0.0f, 1.0f));

                            customKeyFrameAnimation.InsertKeyFrame(
                                0.499999f,
                                targetZoomFactor - 0.75f * deltaZoomFactor,
                                cubicBezierStart);
                            customKeyFrameAnimation.InsertKeyFrame(
                                0.5f,
                                targetZoomFactor - 0.25f * deltaZoomFactor,
                                stepEasingFunc);
                            customKeyFrameAnimation.InsertKeyFrame(
                                1.0f,
                                targetZoomFactor,
                                cubicBezierEnd);
                            break;

                        default:
                            break;
                        }

                        customKeyFrameAnimation.Duration = stockKeyFrameAnimation.Duration;
                        args.Animation = customKeyFrameAnimation;
                    }

                    if (!string.IsNullOrWhiteSpace(tbZoomDuration.Text))
                    {
                        double durationOverride = Convert.ToDouble(tbZoomDuration.Text);
                        customKeyFrameAnimation.Duration = TimeSpan.FromMilliseconds(durationOverride);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
예제 #4
0
        private void Scroller4_ScrollAnimationStarting(muxc.ScrollViewer sender, muxc.ScrollAnimationStartingEventArgs args)
        {
            try
            {
                Vector3KeyFrameAnimation stockKeyFrameAnimation = args.Animation as Vector3KeyFrameAnimation;

                if (stockKeyFrameAnimation != null)
                {
                    Vector3KeyFrameAnimation customKeyFrameAnimation = stockKeyFrameAnimation;

                    if (nameof(ScrollAnimationOptions.Default) != (string)cbAnimation.SelectedItem)
                    {
                        double targetHorizontalOffset   = args.EndPosition.X;
                        float  targetHorizontalPosition = ComputeHorizontalPositionFromOffset(sender.Content, targetHorizontalOffset, sender.ZoomFactor);

                        double targetVerticalOffset   = args.EndPosition.Y;
                        float  targetVerticalPosition = ComputeVerticalPositionFromOffset(sender.Content, targetVerticalOffset, sender.ZoomFactor);

                        customKeyFrameAnimation = stockKeyFrameAnimation.Compositor.CreateVector3KeyFrameAnimation();

                        float deltaHorizontalPosition = (float)(targetHorizontalOffset - sender.HorizontalOffset);
                        float deltaVerticalPosition   = (float)(targetVerticalOffset - sender.VerticalOffset);

                        switch ((string)cbAnimation.SelectedItem)
                        {
                        case nameof(ScrollAnimationOptions.Custom1):
                            // "Accordion" case
                            for (int keyframe = 0; keyframe < 3; keyframe++)
                            {
                                customKeyFrameAnimation.InsertKeyFrame(
                                    1.0f - (0.4f / (float)Math.Pow(2, keyframe)),
                                    new Vector3(targetHorizontalPosition + 0.1f * deltaHorizontalPosition, targetVerticalPosition + 0.1f * deltaVerticalPosition, 0.0f));

                                deltaHorizontalPosition /= -2.0f;
                                deltaVerticalPosition   /= -2.0f;
                            }

                            customKeyFrameAnimation.InsertKeyFrame(1.0f, new Vector3(targetHorizontalPosition, targetVerticalPosition, 0.0f));
                            break;

                        case nameof(ScrollAnimationOptions.Custom2):
                            // "Teleportation" case
                            CubicBezierEasingFunction cubicBezierStart = stockKeyFrameAnimation.Compositor.CreateCubicBezierEasingFunction(
                                new Vector2(1.0f, 0.0f),
                                new Vector2(1.0f, 0.0f));

                            StepEasingFunction step = stockKeyFrameAnimation.Compositor.CreateStepEasingFunction(1);

                            CubicBezierEasingFunction cubicBezierEnd = stockKeyFrameAnimation.Compositor.CreateCubicBezierEasingFunction(
                                new Vector2(0.0f, 1.0f),
                                new Vector2(0.0f, 1.0f));

                            customKeyFrameAnimation.InsertKeyFrame(
                                0.499999f,
                                new Vector3(targetHorizontalPosition - 0.75f * deltaHorizontalPosition, targetVerticalPosition - 0.75f * deltaVerticalPosition, 0.0f),
                                cubicBezierStart);
                            customKeyFrameAnimation.InsertKeyFrame(
                                0.5f,
                                new Vector3(targetHorizontalPosition - 0.25f * deltaHorizontalPosition, targetVerticalPosition - 0.25f * deltaVerticalPosition, 0.0f),
                                step);
                            customKeyFrameAnimation.InsertKeyFrame(
                                1.0f,
                                new Vector3(targetHorizontalPosition, targetVerticalPosition, 0.0f),
                                cubicBezierEnd);
                            break;

                        default:
                            break;
                        }

                        customKeyFrameAnimation.Duration = stockKeyFrameAnimation.Duration;
                    }

                    if (!string.IsNullOrWhiteSpace(tbAnimDuration.Text))
                    {
                        // Override animation duration
                        double durationOverride = Convert.ToDouble(tbAnimDuration.Text);
                        customKeyFrameAnimation.Duration = TimeSpan.FromMilliseconds(durationOverride);
                    }

                    args.Animation = customKeyFrameAnimation;
                }
            }
            catch (Exception ex)
            {
            }
        }