using System; using System.Collections.Generic; using System.Text; using Avalonia.Collections; using System.ComponentModel; using Avalonia.Animation.Utils; using System.Reactive.Linq; using System.Linq; using Avalonia.Media; namespace Avalonia.Animation.Keyframes { /// /// Key frames that handles properties. /// public class TransformKeyFrames : KeyFrames { DoubleKeyFrames childKeyFrames; /// public override IDisposable Apply(Animation animation, Animatable control, IObservable obsMatch) { var ctrl = (Visual)control; // Check if the Target Property is Transform derived. if (typeof(Transform).IsAssignableFrom(Property.OwnerType) && ctrl.RenderTransform != null) { var renderTransformType = ctrl.RenderTransform.GetType(); if (childKeyFrames == null) { InitializeInternalDoubleKeyFrames(); } // It's only 1 transform object so let's target that. if (renderTransformType == Property.OwnerType) { return childKeyFrames.Apply(animation, ctrl.RenderTransform, obsMatch); } // Try if the control's RenderTransform is a TransformGroup and find // the target there. else if (renderTransformType == typeof(TransformGroup)) { foreach (Transform transform in ((TransformGroup)ctrl.RenderTransform).Children) { if (transform.GetType() == Property.OwnerType) { return childKeyFrames.Apply(animation, transform, obsMatch); } } } //throw new InvalidOperationException($"TransformKeyFrame hasn't found an appropriate Transform object with type {Property.OwnerType} in target {control}."); return null; } else { throw new Exception($"Unsupported property {Property}"); } } void InitializeInternalDoubleKeyFrames() { childKeyFrames = new DoubleKeyFrames(); foreach (KeyFrame keyframe in this) { childKeyFrames.Add(keyframe); } childKeyFrames.Property = Property; } /// public override IObservable DoInterpolation(Animation animation, Animatable control) { return null; } } }