Browse Source

Minor Fixes pt. 2

pull/1461/head
Jumar Macato 8 years ago
parent
commit
7693836c43
  1. 26
      samples/RenderTest/Pages/AnimationsPage.xaml
  2. 67
      samples/RenderTest/Pages/AnimationsPage.xaml.cs
  3. 2
      src/Avalonia.Animation/Animatable.cs
  4. 15
      src/Avalonia.Animation/Keyframes/KeyFrame.cs
  5. 42
      src/Avalonia.Animation/Keyframes/KeyFrames.cs

26
samples/RenderTest/Pages/AnimationsPage.xaml

@ -1,11 +1,16 @@
<UserControl xmlns="https://github.com/avaloniaui">
<UserControl.Styles>
<Styles>
<Style Selector="Rectangle.Test">
<Setter Property="Margin" Value="15"/>
<Setter Property="Width" Value="100"/>
<Setter Property="Height" Value="100"/>
</Style>
<Style Selector="Rectangle.Test">
<Setter Property="Margin" Value="15"/>
<Setter Property="Width" Value="100"/>
<Setter Property="Height" Value="100"/>
</Style>
<Style Selector="Border.Test">
<Setter Property="Margin" Value="15"/>
<Setter Property="Width" Value="100"/>
<Setter Property="Height" Value="100"/>
</Style>
<Style Selector="Rectangle.Rect1:pointerover">
<Style.Animations>
<Animation Duration="0:0:2.5" Easing="BounceEaseInOut">
@ -41,7 +46,7 @@
</Animation>
</Style.Animations>
</Style>
<Style Selector="Rectangle.Rect4:pointerover">
<Style Selector="Border.Rect4:pointerover">
<Style.Animations>
<Animation Duration="0:0:3" Easing="CircularEaseInOut">
<TransformKeyFrames Property="SkewTransform.AngleX">
@ -79,11 +84,12 @@
<TranslateTransform/>
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Classes="Test Rect4" Fill="SeaGreen">
<Rectangle.RenderTransform>
<Border Classes="Test Rect4" Background="SeaGreen">
<Border.RenderTransform>
<SkewTransform/>
</Rectangle.RenderTransform>
</Rectangle>
</Border.RenderTransform>
<Path Fill="White" Stretch="Uniform" Data="F1 M 16.6309,18.6563C 17.1309,8.15625 29.8809,14.1563 29.8809,14.1563C 30.8809,11.1563 34.1308,11.4063 34.1308,11.4063C 33.5,12 34.6309,13.1563 34.6309,13.1563C 32.1309,13.1562 31.1309,14.9062 31.1309,14.9062C 41.1309,23.9062 32.6309,27.9063 32.6309,27.9062C 24.6309,24.9063 21.1309,22.1562 16.6309,18.6563 Z M 16.6309,19.9063C 21.6309,24.1563 25.1309,26.1562 31.6309,28.6562C 31.6309,28.6562 26.3809,39.1562 18.3809,36.1563C 18.3809,36.1563 18,38 16.3809,36.9063C 15,36 16.3809,34.9063 16.3809,34.9063C 16.3809,34.9063 10.1309,30.9062 16.6309,19.9063 Z"/>
</Border>
</StackPanel>
</StackPanel>

67
samples/RenderTest/Pages/AnimationsPage.xaml.cs

@ -14,77 +14,12 @@ namespace RenderTest.Pages
{
public AnimationsPage()
{
this.InitializeComponent();
// this.CreateAnimations();
InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
private void CreateAnimations()
{
const int Count = 100;
var panel = new WrapPanel();
for (var i = 0; i < Count; ++i)
{
Ellipse ellipse;
var element = new Panel
{
Children =
{
(ellipse = new Ellipse
{
Name = $"ellipse{i}",
Width = 100,
Height = 100,
Fill = Brushes.Blue,
}),
new Path
{
Data = StreamGeometry.Parse(
"F1 M 16.6309,18.6563C 17.1309,8.15625 29.8809,14.1563 29.8809,14.1563C 30.8809,11.1563 34.1308,11.4063 34.1308,11.4063C 33.5,12 34.6309,13.1563 34.6309,13.1563C 32.1309,13.1562 31.1309,14.9062 31.1309,14.9062C 41.1309,23.9062 32.6309,27.9063 32.6309,27.9062C 24.6309,24.9063 21.1309,22.1562 16.6309,18.6563 Z M 16.6309,19.9063C 21.6309,24.1563 25.1309,26.1562 31.6309,28.6562C 31.6309,28.6562 26.3809,39.1562 18.3809,36.1563C 18.3809,36.1563 18,38 16.3809,36.9063C 15,36 16.3809,34.9063 16.3809,34.9063C 16.3809,34.9063 10.1309,30.9062 16.6309,19.9063 Z"),
Fill = Brushes.Green,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
RenderTransform = new ScaleTransform(2, 2),
}
},
Margin = new Thickness(4),
RenderTransform = new ScaleTransform(),
};
//var start = Animate.Stopwatch.Elapsed;
//var index = i % (Count / 2);
//var degrees = Animate.Timer
// .Select(x => (x - start).TotalSeconds)
// .Where(x => (x % Count) >= index && (x % Count) < index + 1)
// .Select(x => (x % 1) / 1);
//element.RenderTransform.Bind(
// ScaleTransform.ScaleXProperty,
// degrees,
// BindingPriority.Animation);
ellipse.PointerEnter += Ellipse_PointerEnter;
ellipse.PointerLeave += Ellipse_PointerLeave;
panel.Children.Add(element);
}
Content = panel;
}
private void Ellipse_PointerEnter(object sender, PointerEventArgs e)
{
((Ellipse)sender).Fill = Brushes.Red;
}
private void Ellipse_PointerLeave(object sender, PointerEventArgs e)
{
((Ellipse)sender).Fill = Brushes.Blue;
}
}
}

2
src/Avalonia.Animation/Animatable.cs

@ -16,7 +16,7 @@ namespace Avalonia.Animation
public class Animatable : AvaloniaObject
{
/// <summary>
///
/// Defines the <see cref="Transitions"/> property.
/// </summary>
public static readonly StyledProperty<Transitions.Transitions> TransitionsProperty =
AvaloniaProperty.Register<Animatable, Transitions.Transitions>(nameof(Transitions));

15
src/Avalonia.Animation/Keyframes/KeyFrame.cs

@ -25,7 +25,6 @@ namespace Avalonia.Animation.Keyframes
{
get
{
return _ktimeSpan;
}
set
@ -47,7 +46,6 @@ namespace Avalonia.Animation.Keyframes
{
get
{
return _kCue;
}
set
@ -61,18 +59,11 @@ namespace Avalonia.Animation.Keyframes
}
}
/// <summary>
/// The keyframe's target value.
/// </summary>
public object Value { get; set; }
///// <summary>
///// Initializes a new instance of the <see cref="KeyFrame"/> class.
///// </summary>
//public KeyFrame()
//{
//}
}

42
src/Avalonia.Animation/Keyframes/KeyFrames.cs

@ -11,7 +11,7 @@ using Avalonia.Data;
namespace Avalonia.Animation.Keyframes
{
/// <summary>
/// Base class for KeyFrames
/// Base class for KeyFrames objects
/// </summary>
public abstract class KeyFrames<T> : AvaloniaList<KeyFrame>, IKeyFrames
{
@ -27,7 +27,7 @@ namespace Avalonia.Animation.Keyframes
public Dictionary<double, T> ConvertedKeyframes = new Dictionary<double, T>();
private bool IsVerfifiedAndConverted;
/// <inheritdoc/>
public virtual IDisposable Apply(Animation animation, Animatable control, IObservable<bool> obsMatch)
{
@ -44,11 +44,41 @@ namespace Avalonia.Animation.Keyframes
});
}
/// <summary>
/// Represents a pair of keyframe, usually the
/// Start and End keyframes of a <see cref="KeyFrames{T}"/> object.
/// </summary>
public struct KeyFramePair
{
/// <summary>
/// Initializes this <see cref="KeyFramePair"/>
/// </summary>
/// <param name="FirstKeyFrame"></param>
/// <param name="LastKeyFrame"></param>
public KeyFramePair(KeyValuePair<double, T> FirstKeyFrame, KeyValuePair<double, T> LastKeyFrame) : this()
{
this.FirstKeyFrame = FirstKeyFrame;
this.SecondKeyFrame = LastKeyFrame;
}
/// <summary>
/// First <see cref="KeyFrame"/> object.
/// </summary>
public KeyValuePair<double, T> FirstKeyFrame { get; private set; }
/// <summary>
/// Second <see cref="KeyFrame"/> object.
/// </summary>
public KeyValuePair<double, T> SecondKeyFrame { get; private set; }
}
/// <summary>
/// Get the nearest pair of cue-time ordered keyframes
/// according to the given time parameter.
/// </summary>
public (KeyValuePair<double, T> firstKF, KeyValuePair<double, T> lastKF) GetKeyFramePairByTime(double t)
public KeyFramePair GetKeyFramePairByTime(double t)
{
KeyValuePair<double, T> firstCue, lastCue;
int kvCount = ConvertedKeyframes.Count();
@ -75,7 +105,7 @@ namespace Avalonia.Animation.Keyframes
firstCue = ConvertedKeyframes.First();
lastCue = ConvertedKeyframes.Last();
}
return (firstCue, lastCue);
return new KeyFramePair(firstCue, lastCue);
}
@ -83,7 +113,7 @@ namespace Avalonia.Animation.Keyframes
/// Returns an observable timer with the specific Animation
/// duration and delay and applies the Animation's easing function.
/// </summary>
public IObservable<double> GetKeyFramesTimer(Animation animation) =>
public IObservable<double> GetKeyFramesTimer(Animation animation) =>
Timing.GetTimer(animation.Duration, animation.Delay)
.Select(t => animation.Easing.Ease(t));
@ -149,7 +179,7 @@ namespace Avalonia.Animation.Keyframes
hasEndKey = true;
}
}
if (!hasStartKey && !hasEndKey)
throw new InvalidOperationException
($"{this.GetType().Name} must have a starting (0% cue) and ending (100% cue) keyframe.");

Loading…
Cancel
Save