예제 #1
0
        internal static Storyboard TranslateXFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = (element.RenderTransform as CompositeTransform) ?? new CompositeTransform();

            transform.TranslateX = settings.OffsetX.GetCalculatedOffset(element, OffsetTarget.X);

            SetRenderTransform(element, settings, transform);

            element.ApplyAnimation(settings, transform.TranslateX, 0, "(UIElement.RenderTransform).(CompositeTransform.TranslateX)", ref storyboard);

            return(storyboard);
        }
예제 #2
0
        // ====================
        // ROTATE
        // ====================

        internal static Storyboard RotateTo(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = GetFrameworkElementTransform(element, settings) ?? CreateTransformGroup();
            var rotate    = transform.Children[ROTATE_INDEX] as RotateTransform;

            SetTransform(element, settings, transform, updateTransformCenterPoint: true);

            element.ApplyAnimation(settings, rotate.Angle, settings.Rotation,
                                   $"{GetTransformType(settings)}Transform.Children[{ROTATE_INDEX}].Angle", ref storyboard);

            return(storyboard);
        }
예제 #3
0
        internal static Storyboard RotateFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = (element.RenderTransform as CompositeTransform) ?? new CompositeTransform();

            transform.Rotation = settings.Rotation;

            SetRenderTransform(element, settings, transform, updateTransformCenterPoint: true);

            element.ApplyAnimation(settings, settings.Rotation, 0, "(UIElement.RenderTransform).(CompositeTransform.Rotation)", ref storyboard);

            return(storyboard);
        }
예제 #4
0
        internal static Storyboard TranslateYTo(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = (element.RenderTransform as TransformGroup) ?? CreateTransformGroup();
            var translate = transform.Children[TRANSLATE_INDEX] as TranslateTransform;

            SetTransform(element, settings, transform);

            element.ApplyAnimation(settings, translate.Y, settings.OffsetY.GetCalculatedOffset(element, OffsetTarget.Y),
                                   $"{GetTransformType(settings)}Transform.Children[{TRANSLATE_INDEX}].Y", ref storyboard);

            return(storyboard);
        }
예제 #5
0
        internal static Storyboard ScaleYTo(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = GetFrameworkElementTransform(element, settings) ?? CreateTransformGroup();
            var scale     = transform.Children[SCALE_INDEX] as ScaleTransform;

            SetTransform(element, settings, transform, updateTransformCenterPoint: true);

            element.ApplyAnimation(settings, scale.ScaleY, settings.ScaleY,
                                   $"{GetTransformType(settings)}Transform.Children[{SCALE_INDEX}].ScaleY", ref storyboard);

            return(storyboard);
        }
예제 #6
0
        private static void ApplyAnimation(this FrameworkElement element, AnimationSettings settings, Color from, Color to, string targetProperty, ref Storyboard storyboard)
        {
            var anim = new ColorAnimation()
            {
                From           = from,
                To             = to,
                Duration       = new Duration(TimeSpan.FromMilliseconds(settings.Duration)),
                BeginTime      = TimeSpan.FromMilliseconds(settings.Delay),
                EasingFunction = settings.GetEase()
            };

            element.ApplyAnimationCore(anim, settings, from.ToString(), to.ToString(), targetProperty, ref storyboard);
        }
        internal static Storyboard RotateFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = (element.RenderTransform as TransformGroup) ?? CreateTransformGroup();
            var rotate    = transform.Children[ROTATE_INDEX] as RotateTransform;

            rotate.Angle = settings.Rotation;

            SetRenderTransform(element, settings, transform, updateTransformCenterPoint: true);

            element.ApplyAnimation(settings, settings.Rotation, 0, $"RenderTransform.Children[{ROTATE_INDEX}].Angle", ref storyboard);

            return(storyboard);
        }
        // ====================
        // FADE
        // ====================

        internal static Storyboard FadeTo(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            // Since a previous animation can have a "hold" on the Opacity property, we must "release" it before
            // setting a new value. See the Remarks section of the AttachedProperty for more info.
            if (Animations.GetAllowOpacityReset(element))
            {
                element.BeginAnimation(UIElement.OpacityProperty, null);
            }

            element.ApplyAnimation(settings, element.Opacity, settings.Opacity, "Opacity", ref storyboard);

            return(storyboard);
        }
        internal static Storyboard TranslateYFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = (element.RenderTransform as TransformGroup) ?? CreateTransformGroup();
            var translate = transform.Children[TRANSLATE_INDEX] as TranslateTransform;

            translate.Y = settings.OffsetY;

            SetRenderTransform(element, settings, transform);

            element.ApplyAnimation(settings, settings.OffsetY, 0, $"RenderTransform.Children[{TRANSLATE_INDEX}].Y", ref storyboard);

            return(storyboard);
        }
예제 #10
0
        internal static Storyboard TranslateXFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = (element.RenderTransform as TransformGroup) ?? CreateTransformGroup();
            var translate = transform.Children[TRANSLATE_INDEX] as TranslateTransform;

            translate.X = settings.OffsetX.GetCalculatedOffset(element, OffsetTarget.X);

            SetRenderTransform(element, settings, transform);

            element.ApplyAnimation(settings, translate.X, 0, $"RenderTransform.Children[{TRANSLATE_INDEX}].X", ref storyboard);

            return(storyboard);
        }
        internal static Storyboard ScaleYFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = (element.RenderTransform as TransformGroup) ?? CreateTransformGroup();
            var scale     = transform.Children[SCALE_INDEX] as ScaleTransform;

            scale.ScaleY = settings.ScaleY;

            SetRenderTransform(element, settings, transform, updateTransformCenterPoint: true);

            element.ApplyAnimation(settings, settings.ScaleY, 1, $"RenderTransform.Children[{SCALE_INDEX}].ScaleY", ref storyboard);

            return(storyboard);
        }
예제 #12
0
        internal static void FadeFrom(this FrameworkElement element, AnimationSettings settings, ref AnimationGroup group)
        {
            group.CreateAnimations(element, settings,
                                   animGroup =>
            {
                ElementCompositionPreview.GetElementVisual(element).Opacity = (float)settings.Opacity;

                return(animGroup.CreateScalarAnimation <FadeAnimation>(
                           element,
                           settings,
                           to: 1));
            });
        }
예제 #13
0
        internal static Storyboard ScaleXFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = GetFrameworkElementTransform(element, settings) ?? CreateTransformGroup();
            var scale     = transform.Children[SCALE_INDEX] as ScaleTransform;

            scale.ScaleX = settings.ScaleX;

            SetTransform(element, settings, transform, updateTransformCenterPoint: true);

            element.ApplyAnimation(settings, settings.ScaleX, 1,
                                   $"{(settings.TransformOn == TransformationType.Render ? "Render" : "Layout")}Transform.Children[{SCALE_INDEX}].ScaleX", ref storyboard);

            return(storyboard);
        }
예제 #14
0
        internal static Storyboard TranslateYFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = (element.RenderTransform as TransformGroup) ?? CreateTransformGroup();
            var translate = transform.Children[TRANSLATE_INDEX] as TranslateTransform;

            translate.Y = settings.OffsetY.GetCalculatedOffset(element, OffsetTarget.Y);

            SetRenderTransform(element, settings, transform);

            element.ApplyAnimation(settings, translate.Y, 0,
                                   $"{(settings.TransformOn == TransformationType.Render ? "Render" : "Layout")}Transform.Children[{TRANSLATE_INDEX}].Y", ref storyboard);

            return(storyboard);
        }
예제 #15
0
 void FadeToolTipOut(UISettings uiSettings, AnimationSettings animSettings)
 {
     uiSettings.textColor.a    = Mathf.Lerp(uiSettings.textColor.a, 0, animSettings.textSmooth * Time.deltaTime);
     uiSettings.text.color     = uiSettings.textColor;
     uiSettings.textBoxColor.a = Mathf.Lerp(uiSettings.textBoxColor.a, 0, animSettings.textSmooth * Time.deltaTime);
     uiSettings.textBox.color  = uiSettings.textBoxColor;
     if (uiSettings.textBoxColor.a < 0.01f)
     {
         uiSettings.opening = false;
         animSettings.Initialize();
         uiSettings.Initialize();
         lifeTimer = 0;
     }
 }
예제 #16
0
        internal static Storyboard FadeFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            // TODO: Investigate to determine the use-case of having the need for calling BeginAnimation() in WPF

            // Since a previous animation can have a "hold" on the Opacity property, we must "release" it before setting a new value:
            // https://docs.microsoft.com/en-us/dotnet/framework/wpf/graphics-multimedia/how-to-set-a-property-after-animating-it-with-a-storyboard?view=netframework-4.7.2#remove-an-animation-from-an-individual-property
            //element.BeginAnimation(UIElement.OpacityProperty, null);

            element.Opacity = settings.Opacity;

            element.ApplyAnimation(settings, settings.Opacity, 1, "Opacity", ref storyboard);

            return(storyboard);
        }
예제 #17
0
        internal static void ScaleZFrom(this FrameworkElement element, AnimationSettings settings, ref AnimationGroup group)
        {
            group.CreateAnimations(element, settings,
                                   animGroup =>
            {
                var visual = ElementCompositionPreview.GetElementVisual(element);

                visual.Scale = new Vector3(visual.Scale.X, visual.Scale.Y, (float)settings.ScaleZ);

                return(animGroup.CreateScalarAnimation <ScaleZAnimation>(
                           element,
                           settings,
                           to: 1f));
            });
        }
예제 #18
0
        private static void AnimateVisibleItem(ListBox lb, ListBoxItem lbi, AnimationSettings settings, double interElementDelay)
        {
            // According to MSDN: When CanContentScroll is true, the values of the ExtentHeight,
            // ScrollableHeight, ViewportHeight, and VerticalOffset properties are number of items.

            var scroller            = lb?.FindDescendant <ScrollViewer>();
            var indexFromVisibleTop = lb.ItemContainerGenerator.IndexFromContainer(lbi) - scroller.VerticalOffset;

            // Create a clone of 'settings'
            var itemSettings = new AnimationSettings().ApplyOverrides(settings);

            itemSettings.Delay += indexFromVisibleTop * interElementDelay;

            Animations.RunAnimation(lbi, settings: itemSettings);
        }
예제 #19
0
        internal static void RotateFrom(this FrameworkElement element, AnimationSettings settings, ref AnimationGroup group)
        {
            group.CreateAnimations(element, settings,
                                   animGroup =>
            {
                var visual = ElementCompositionPreview.GetElementVisual(element);

                visual.RotationAngleInDegrees = (float)settings.Rotation;

                return(animGroup.CreateScalarAnimation <RotateAnimation>(
                           element,
                           settings,
                           to: 0));
            });
        }
예제 #20
0
        // ====================
        // COLOR
        // ====================

        internal static Storyboard ColorTo(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            Color fromColor    = Colors.Transparent;
            var   propertyPath = string.Empty;

            switch (settings.ColorOn)
            {
            case ColorTarget.Background when element is Control ctl && ctl.Background is SolidColorBrush brush:
                propertyPath = "(Control.Background).(SolidColorBrush.Color)";
                fromColor    = brush.Color;
                break;

            case ColorTarget.Foreground when element is Control ctl && ctl.Foreground is SolidColorBrush brush:
                propertyPath = "(Control.Foreground).(SolidColorBrush.Color)";
                fromColor    = brush.Color;
                break;

            case ColorTarget.BorderBrush when element is Control ctl && ctl.BorderBrush is SolidColorBrush brush:
                propertyPath = "(Control.BorderBrush).(SolidColorBrush.Color)";
                fromColor    = brush.Color;
                break;

            case ColorTarget.Foreground when element is TextBlock tb && tb.Foreground is SolidColorBrush brush:
                propertyPath = "(TextBlock.Foreground).(SolidColorBrush.Color)";
                fromColor    = brush.Color;
                break;

            case ColorTarget.Fill when element is Shape shp && shp.Fill is SolidColorBrush brush:
                propertyPath = "(Shape.Fill).(SolidColorBrush.Color)";
                fromColor    = brush.Color;
                break;

            case ColorTarget.Stroke when element is Shape shp && shp.Stroke is SolidColorBrush brush:
                propertyPath = "(Shape.Stroke).(SolidColorBrush.Color)";
                fromColor    = brush.Color;
                break;

            default:
                const string message =
                    "$Cannot animate the ColorAnimation. Make sure the animation is applied on a Control, TextBlock, or Shape. " +
                    "Also make sure that an existing brush exists on the corresponding property (Background, Foreground, BorderBrush, Fill, or Stroke).";
                throw new ArgumentException(message);
            }

            element.ApplyAnimation(settings, fromColor, settings.Color, propertyPath, ref storyboard);

            return(storyboard);
        }
예제 #21
0
        private static void SetTransform(FrameworkElement element, AnimationSettings settings, TransformGroup transform, bool updateTransformCenterPoint = false)
        {
            if (settings.TransformOn == TransformationType.Layout)
            {
                element.LayoutTransform = transform;
            }
            else
            {
                element.RenderTransform = transform;

                if (updateTransformCenterPoint)
                {
                    element.RenderTransformOrigin = settings.TransformCenterPoint;
                }
            }
        }
예제 #22
0
        internal static ActiveTimeline <T> Add <T>(
            this ConcurrentDictionary <Guid, ActiveTimeline <T> > actives,
            T timeline, AnimationSettings settings,
            FrameworkElement element,
            AnimationState state,
            IterationBehavior iterationBehavior,
            int iterationCount,
            bool isSequence,
            int sequenceOrder = 0)
            where T : DependencyObject
        {
            var elementGuid  = Animations.GetElementGuid(element);
            var timelineGuid = Guid.NewGuid();

            if (elementGuid.Equals(Guid.Empty))
            {
                elementGuid = Guid.NewGuid();
            }

            Animations.SetElementGuid(element, elementGuid);

            if (timeline != null)
            {
                Animations.SetElementGuid(timeline, elementGuid);
                Animations.SetTimelineGuid(timeline, timelineGuid);
            }

            var active = new ActiveTimeline <T>()
            {
                ElementGuid       = elementGuid,
                Timeline          = timeline,
                Settings          = settings,
                Element           = element,
                State             = state,
                IterationBehavior = iterationBehavior,
                IterationCount    = iterationCount,
                IsSequence        = isSequence,
                SequenceOrder     = sequenceOrder
            };

            if (actives.TryAdd(timelineGuid, active) && Animations.EnableActiveTimelinesLogging == LogLevel.Debug)
            {
                LogActiveTimelines(actives, "Active timeline added");
            }

            return(active);
        }
예제 #23
0
        internal static void ScaleZFrom(this FrameworkElement element, AnimationSettings settings, ref AnimationGroup group)
        {
            group.CreateAnimations(element, settings,
                                   animGroup =>
            {
                animGroup.CreateScalarAnimation <ScaleZAnimation>(
                    element,
                    settings,
                    to: (float)settings.ScaleZ,
                    duration: 1,
                    isFrom: true);

                return(animGroup.CreateScalarAnimation <ScaleZAnimation>(
                           element,
                           settings,
                           to: 1f));
            });
        }
예제 #24
0
        internal static void FadeFrom(this FrameworkElement element, AnimationSettings settings, ref AnimationGroup group)
        {
            group.CreateAnimations(element, settings,
                                   animGroup =>
            {
                animGroup.CreateScalarAnimation <FadeAnimation>(
                    element,
                    settings,
                    to: settings.Opacity,
                    duration: 1,
                    isFrom: true);

                return(animGroup.CreateScalarAnimation <FadeAnimation>(
                           element,
                           settings,
                           to: 1));
            });
        }
예제 #25
0
        internal static void TranslateXFrom(this FrameworkElement element, AnimationSettings settings, ref AnimationGroup group)
        {
            group.CreateAnimations(element, settings,
                                   animGroup =>
            {
                animGroup.CreateScalarAnimation <TranslateXAnimation>(
                    element,
                    settings,
                    to: (float)settings.OffsetX,
                    duration: 1,
                    isFrom: true);

                return(animGroup.CreateScalarAnimation <TranslateXAnimation>(
                           element,
                           settings,
                           to: 0f));
            });
        }
예제 #26
0
        internal static Storyboard ScaleYFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform     = GetFrameworkElementTransform(element, settings) ?? CreateTransformGroup();
            var currentScaleX = (transform.Children[SCALE_INDEX] as ScaleTransform)?.ScaleX ?? 1;

            transform.Children[SCALE_INDEX] = new ScaleTransform()
            {
                ScaleX = currentScaleX,
                ScaleY = settings.ScaleY
            };

            SetTransform(element, settings, transform, updateTransformCenterPoint: true);

            element.ApplyAnimation(settings, settings.ScaleY, 1,
                                   $"{GetTransformType(settings)}Transform.Children[{SCALE_INDEX}].ScaleY", ref storyboard);

            return(storyboard);
        }
예제 #27
0
        internal static void TintFrom(this FrameworkElement element, AnimationSettings settings, ref AnimationGroup group)
        {
            group.CreateAnimations(element, settings,
                                   animGroup =>
            {
                animGroup.CreateEffectAnimation <TintAnimation, Color>(
                    element,
                    settings,
                    to: settings.Tint,
                    duration: 1,
                    isFrom: true);

                return(animGroup.CreateEffectAnimation <TintAnimation, Color>(
                           element,
                           settings,
                           to: AnimationSettings.DEFAULT_TINT));
            });
        }
예제 #28
0
        internal static void SaturateFrom(this FrameworkElement element, AnimationSettings settings, ref AnimationGroup group)
        {
            group.CreateAnimations(element, settings,
                                   animGroup =>
            {
                animGroup.CreateEffectAnimation <SaturateAnimation, double>(
                    element,
                    settings,
                    to: settings.Saturation,
                    duration: 1,
                    isFrom: true);

                return(animGroup.CreateEffectAnimation <SaturateAnimation, double>(
                           element,
                           settings,
                           to: AnimationSettings.DEFAULT_SATURATION));
            });
        }
예제 #29
0
        internal static void BlurFrom(this FrameworkElement element, AnimationSettings settings, ref AnimationGroup group)
        {
            group.CreateAnimations(element, settings,
                                   animGroup =>
            {
                animGroup.CreateEffectAnimation <BlurAnimation, double>(
                    element,
                    settings,
                    to: settings.BlurRadius,
                    duration: 1,
                    isFrom: true);

                return(animGroup.CreateEffectAnimation <BlurAnimation, double>(
                           element,
                           settings,
                           to: 0));
            });
        }
예제 #30
0
 void OpenHeightToWidth(UISettings uiSettings, AnimationSettings animSettings)
 {
     if (!animSettings.heightOpen)
     {
         OpenHeight(uiSettings, animSettings);
     }
     else
     {
         OpenWidth(uiSettings, animSettings);
     }
     if (!animSettings2.heightOpen)
     {
         OpenHeight(uiSettings, animSettings);
     }
     else
     {
         OpenWidth(uiSettings, animSettings);
     }
 }