// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using Tango.Scripting.Editors.Document;
namespace Tango.Scripting.Editors.Rendering
{
/// <summary>
/// EventArgs for the <see cref="TextView.VisualLineConstructionStarting"/> event.
/// </summary>
public class VisualLineConstructionStartEventArgs : EventArgs
{
/// <summary>
/// Gets/Sets the first line that is visible in the TextView.
/// </summary>
public DocumentLine FirstLineInView { get; private set; }
/// <summary>
/// Creates a new VisualLineConstructionStartEventArgs instance.
/// </summary>
public VisualLineConstructionStartEventArgs(DocumentLine firstLineInView)
{
if (firstLineInView == nullusing Tango.Editors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;
/// <exclude/>
/// <summary>
/// A collection of <see cref="UIElement"/> and <see cref="IAnimatable"/> extension methods.
/// </summary>
internal static class UIElementExtension
{
/// <summary>
/// Starts the double animation.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="property">The property.</param>
/// <param name="animation">The animation.</param>
/// <param name="to">To.</param>
/// <param name="from">From.</param>
/// <returns></returns>
internal static DoubleAnimation StartDoubleAnimation(this IAnimatable element, DependencyProperty property, ConfigurationAnimation animation, double to, double? from = null)
{
DoubleAnimation ani = new DoubleAnimation();
ani.AccelerationRatio = animation.AccelerationRatio;
ani.DecelerationRatio = animation.DecelerationRatio;
if (animation.EasingFunction != null)
{
ani.EasingFunction = animation.EasingFunction;
}
if (from != null && !double.IsNaN(from.Value))
{
ani.From = from.Value;
}
ani.Duration = new Duration(animation.Duration);
if (double.IsNaN((double)(element as DependencyObject).GetValue(property)) || animation.Duration == TimeSpan.FromSeconds(0))
{
element.BeginAnimation(property, null);
(element as DependencyObject).SetValue(property, to);
return ani;
}
ani.Completed += (x, y) =>
{
element.BeginAnimation(property, null);
(element as DependencyObject).SetValue(property, to);
animation.RaiseAnimationCompleted(element);
};
if (!double.IsNaN(to))
{
ani.To = to;
element.BeginAnimation(property, ani);
}
else
{
element.BeginAnimation(property, null, HandoffBehavior.Compose);
(element as DependencyObject).SetValue(property, to);
}
return ani;
}
internal static ColorAnimation StartColorAnimation(this IAnimatable element, DependencyProperty property, ConfigurationAnimation animation, Color to)
{
ColorAnimation ani = new ColorAnimation();
ani.AccelerationRatio = animation.AccelerationRatio;
ani.DecelerationRatio = animation.DecelerationRatio;
if (animation.EasingFunction != null)
{
ani.EasingFunction = animation.EasingFunction;
}
ani.Duration = new Duration(animation.Duration);
ani.Completed += (x, y) =>
{
element.BeginAnimation(property, null);
(element as DependencyObject).SetValue(property, to);
animation.RaiseAnimationCompleted(element);
};
ani.To = to;
element.BeginAnimation(property, ani);
return ani;
}
/// <summary>
/// Gets the double animation.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="property">The property.</param>
/// <param name="animation">The animation.</param>
/// <param name="to">To.</param>
/// <param name="from">From.</param>
/// <returns></returns>
internal static AnimationSetup GetDoubleAnimation(this UIElement element, DependencyProperty property, ConfigurationAnimation animation, double to, double? from = null)
{
DoubleAnimation ani = new DoubleAnimation();
ani.AccelerationRatio = animation.AccelerationRatio;
ani.DecelerationRatio = animation.DecelerationRatio;
if (animation.EasingFunction != null)
{
ani.EasingFunction = animation.EasingFunction;
}
if (from != null && !double.IsNaN(from.Value))
{
ani.From = from.Value;
}
ani.Duration = new Duration(animation.Duration);
if (double.IsNaN((double)element.GetValue(property)) || animation.Duration == TimeSpan.FromSeconds(0))
{
//element.BeginAnimation(property, null);
//element.SetValue(property, to);
return new AnimationSetup(ani, element, property);
}
ani.Completed += (x, y) =>
{
Storyboard story = new Storyboard();
element.BeginAnimation(property, null);
element.SetValue(property, to);
animation.RaiseAnimationCompleted(element);
};
if (!double.IsNaN(to))
{
ani.To = to;
//element.BeginAnimation(property, ani);
}
else
{
//element.BeginAnimation(property, null, HandoffBehavior.Compose);
//element.SetValue(property, to);
}
return new AnimationSetup(ani, element, property);
}
/// <summary>
/// Starts the int32 animation.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="property">The property.</param>
/// <param name="animation">The animation.</param>
/// <param name="to">To.</param>
/// <returns></returns>
internal static Int32Animation StartInt32Animation(this UIElement element, DependencyProperty property, ConfigurationAnimation animation, Int32 to)
{
Int32Animation ani = new Int32Animation();
ani.AccelerationRatio = animation.AccelerationRatio;
ani.DecelerationRatio = animation.DecelerationRatio;
if (animation.EasingFunction != null)
{
ani.EasingFunction = animation.EasingFunction;
}
ani.Duration = new Duration(animation.Duration);
ani.Completed += (x, y) =>
{
element.BeginAnimation(property, null);
element.SetValue(property, to);
animation.RaiseAnimationCompleted(element);
};
if (!double.IsNaN(to))
{
ani.To = to;
element.BeginAnimation(property, ani);
}
else
{
element.BeginAnimation(property, null, HandoffBehavior.Compose);
element.SetValue(property, to);
}
return ani;
}
/// <summary>
/// Starts the point animation.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="property">The property.</param>
/// <param name="animation">The animation.</param>
/// <param name="to">To.</param>
/// <returns></returns>
internal static PointAnimation StartPointAnimation(this UIElement element, DependencyProperty property, ConfigurationAnimation animation, Point to)
{
PointAnimation ani = new PointAnimation();
ani.AccelerationRatio = animation.AccelerationRatio;
ani.DecelerationRatio = animation.DecelerationRatio;
if (animation.EasingFunction != null)
{
ani.EasingFunction = animation.EasingFunction;
}
ani.To = to;
ani.Duration = new Duration(animation.Duration);
ani.Completed += (x, y) =>
{
element.BeginAnimation(property, null);
element.SetValue(property, to);
animation.RaiseAnimationCompleted(element);
};
element.BeginAnimation(property, ani);
return ani;
}
/// <summary>
/// Starts the point3 d animation.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="property">The property.</param>
/// <param name="animation">The animation.</param>
/// <param name="to">To.</param>
/// <returns></returns>
internal static Point3DAnimation StartPoint3DAnimation(this IAnimatable element, DependencyProperty property, ConfigurationAnimation animation, Point3D to)
{
Point3DAnimation ani = new Point3DAnimation();
ani.AccelerationRatio = animation.AccelerationRatio;
ani.DecelerationRatio = animation.DecelerationRatio;
if (animation.EasingFunction != null)
{
ani.EasingFunction = animation.EasingFunction;
}
ani.To = to;
ani.Duration = new Duration(animation.Duration);
ani.Completed += (x, y) =>
{
element.BeginAnimation(property, null);
(element as DependencyObject).SetValue(property, to);
animation.RaiseAnimationCompleted(element);
};
element.BeginAnimation(property, ani);
return ani;
}
/// <summary>
/// Starts the vector3 d animation.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="property">The property.</param>
/// <param name="animation">The animation.</param>
/// <param name="to">To.</param>
/// <returns></returns>
internal static Vector3DAnimation StartVector3DAnimation(this IAnimatable element, DependencyProperty property, ConfigurationAnimation animation, Vector3D to)
{
Vector3DAnimation ani = new Vector3DAnimation();
ani.AccelerationRatio = animation.AccelerationRatio;
ani.DecelerationRatio = animation.DecelerationRatio;
if (animation.EasingFunction != null)
{
ani.EasingFunction = animation.EasingFunction;
}
ani.To = to;
ani.Duration = new Duration(animation.Duration);
ani.Completed += (x, y) =>
{
element.BeginAnimation(property, null);
(element as DependencyObject).SetValue(property, to);
animation.RaiseAnimationCompleted(element);
};
element.BeginAnimation(property, ani);
return ani;
}
}