using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using AiwazAnimator.Animations;
using System.Diagnostics;
namespace AiwazAnimator
{
///
/// Interaction logic for AddAnimationWindow.xaml
///
public partial class AddAnimationWindow : Window
{
private MainWindow MainWindow;
private List Targets;
public AddAnimationWindow(MainWindow mainWindow)
{
MainWindow = mainWindow;
InitializeComponent();
Targets = new List();
foreach (var property in MainWindow.GetType().GetProperties())
{
foreach (var attribute in property.GetCustomAttributes(false))
{
if (attribute.GetType().Equals(typeof(Animateable)))
{
Targets.Add(property.Name);
}
}
}
cmbTarget.ItemsSource = Targets;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Animation a = null;
switch (cmbInterpolation.SelectedIndex)
{
case 0: a = new LinearAnimation(); break;
case 1: a = new CosineAnimation(); break;
}
if (a != null)
{
a.StartTime = float.Parse(txtStartTime.Text);
a.EndTime = float.Parse(txtEndTime.Text);
a.StartValue = float.Parse(txtStartValue.Text);
a.EndValue = float.Parse(txtEndValue.Text);
foreach (var property in MainWindow.GetType().GetProperties())
{
if (property.Name != cmbTarget.Text)
continue;
foreach (var attribute in property.GetCustomAttributes(false))
{
if (attribute.GetType().Equals(typeof(Animateable)))
{
a.ValueGetter = () => { return (float)property.GetValue(MainWindow, null); };
a.ValueSetter = (v) => { property.SetValue(MainWindow, v, null); };
a.ValueNamer = () => { return property.Name; };
}
}
break;
}
MainWindow.AnimationManager.Animations.Add(a);
}
this.Close();
}
}
}