/// <summary>Creates a new <see cref="EffectController"/> instance.</summary> internal EffectController(Effect effect, EffectCallback effectCallback) { SourceEffect = effect; SourceEffect.Validate(); RuntimeEffect = SourceEffect.Decompose(); State = EffectState.Playing; _rootTimeline = new ParallelTimeline(); RuntimeEffect.DefineTimeline(_rootTimeline, TimeSpan.Zero); if (!GlobalSpeedRatio.IsOne()) { _rootTimeline.SpeedRatio = GlobalSpeedRatio; } _rootTimeline.CurrentStateInvalidated += _rootClockStateChanged; _rootTimeline.Completed += _rootClockCompleted; _effectCallback = effectCallback; _rootClock = _rootTimeline.CreateClock(); var count = RuntimeEffect.ApplyClocks(_rootClock, 0); if (count > 0) { _rootClock.Controller.Begin(); } else { State = EffectState.Completed; _rootClock.Controller.Remove(); if (effectCallback != null) { GuiTimer.StartAfterRender(t => effectCallback(this)); } } }
/// <summary>Creates a new <see cref="VectorEffect"/> instance from the given prototype.</summary> public VectorEffect(Effect prototype) : base() { CopyFrom(prototype); }
/// <summary>Creates a new <see cref="ThicknessEffect"/> instance from the given prototype.</summary> public ThicknessEffect(Effect prototype) : base() { CopyFrom(prototype); }
/// <summary>Creates a new <see cref="ActionEffect"/> instance from the given prototype.</summary> public ActionEffect(Effect prototype) : base() { CopyFrom(prototype); }
/// <summary>Creates a new <see cref="CenterShiftEffect"/> instance from the given prototype.</summary> public CenterShiftEffect(Effect prototype) : base() { CopyFrom(prototype); }
/// <summary>Creates a new <see cref="ParallelEffect"/> instance from the given prototype and child effects.</summary> public ParallelEffect(Effect prototype, params Effect[] children) : this(prototype) { foreach (var childEffect in children) { Children.Add(childEffect); } }
/// <summary>Creates a new <see cref="NumericEffect"/> instance from the given prototype.</summary> public NumericEffect(Effect prototype) : base() { CopyFrom(prototype); }
/// <summary>Creates a new <see cref="MoveEffect"/> instance from the given prototype.</summary> public MoveEffect(Effect prototype) : base() { CopyFrom(prototype); }
/// <summary>Adds a new effect to the end of the child effects collection.</summary> /// <param name="effect">The child effect to add.</param> public void Add(Effect effect) { Children.Add(effect); }
/// <summary>Creates a new <see cref="RotateEffect"/> instance from the given prototype.</summary> public RotateEffect(Effect prototype) : base() { CopyFrom(prototype); }
/// <summary>Creates a new <see cref="SetterEffect"/> instance from the given prototype.</summary> public SetterEffect(Effect prototype) : base() { CopyFrom(prototype); }
/// <summary/> internal void ApplyLayoutEffect(ParallelEffect timeline, Effect prototype) { if (ComputedVisibility != Visibility) { Visibility = ComputedVisibility; if (Visibility == Visibility.Visible) { X = Canvas.ActualWidth / 2; Y = Canvas.ActualHeight / 2; } } if (Visibility == Visibility.Visible) { timeline.Add(new MoveEffect(prototype) { Target = this, ToX = ComputedPosition.X, ToY = ComputedPosition.Y }); } }
/// <summary/> protected override Freezable CreateInstanceCore(Effect prototype) { return new SequenceEffect(prototype); }
/// <summary>Creates a new <see cref="SequenceEffect"/> instance from the given prototype.</summary> public SequenceEffect(Effect prototype) : this() { CopyFrom(prototype); }
/// <summary>Copies the given prototype effect onto this effect.</summary> /// <remarks>The operation looks for and copies all applicable properties from the prototype onto this effect. A prototype property /// is considered applicable for copying if it is defined on the effect's type and it has not been set yet to any value. The copy /// is a shallow copy (i.e., child effects are not copied).</remarks> /// <param name="prototype">The prototype effect to copy from.</param> protected void CopyFrom(Effect prototype) { if (prototype == null) return; var localProperties = prototype.GetLocalValueEnumerator(); while (localProperties.MoveNext()) { var property = localProperties.Current.Property; var value = localProperties.Current.Value; if (this.IsLocalValue(property)) continue; if (!this.IsA(property.OwnerType)) continue; if (property == ElementEffect.TargetProperty) { if (!this.IsA<ElementEffect>()) continue; var targetType = GetType().GetAttribute((EffectAppliesToAttribute a) => a.TargetType, true); if (!value.IsA(targetType)) continue; } SetValue(property, value); } }
/// <summary>Inserts a new effect at the specified index in the child effects collection.</summary> /// <param name="index">The index at which to insert the child effect.</param> /// <param name="effect">The child effect to insert.</param> public void Insert(int index, Effect effect) { Children.Insert(index, effect); }
/// <summary>Creates a new <see cref="ParallelEffect"/> instance from the given prototype.</summary> public ParallelEffect(Effect prototype) : this() { CopyFrom(prototype); }
/// <summary>Removes an effect from the child effects collection.</summary> /// <param name="effect">The child effect to remove.</param> public bool Remove(Effect effect) { return Children.Remove(effect); }
/// <summary/> protected override Freezable CreateInstanceCore(Effect prototype) { return new ParallelEffect(prototype); }
/// <summary/> protected abstract Freezable CreateInstanceCore(Effect copy);
/// <summary>Creates a new <see cref="ScaleEffect"/> instance from the given prototype.</summary> public ScaleEffect(Effect prototype) : base() { CopyFrom(prototype); }
/// <summary/> protected internal override Effect Decompose() { var count = Children.Count; var decomposition = new Effect[count]; var wasDecomposed = false; var effect = this; for (var i=0; i<count; i++) { var c = Children[i]; var d = c.Decompose(); if (d != c) { wasDecomposed = true; if (c is AtomicEffect) { d = d.Decompose(); } } decomposition[i] = d; } if (wasDecomposed) { effect = (CompositeEffect)CreateInstanceCore(this); for (var i=0; i<count; i++) { effect.Children.Add(decomposition[i]); } } return effect; }
/// <summary>Creates a new <see cref="TransformEffect"/> instance from the given prototype.</summary> public TransformEffect(Effect prototype) : base() { CopyFrom(prototype); }
/// <summary>Creates a new <see cref="SkewEffect"/> instance from the given prototype.</summary> public SkewEffect(Effect prototype) : base() { CopyFrom(prototype); }
/// <summary>Creates a new <see cref="RectEffect"/> instance from the given prototype.</summary> public RectEffect(Effect prototype) : base() { CopyFrom(prototype); }
/// <summary>Creates a new <see cref="EffectData"/> instance from the given prototype.</summary> public EffectData(Effect prototype) : base() { CopyFrom(prototype); }