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.Navigation; using System.Windows.Shapes; using System.Windows.Media; namespace AiwazAnimator { public class HistoricalFloat : FrameworkElement { private List> ObservableFloats; private Dictionary, List> History; public HistoricalFloat() { ObservableFloats = new List>(); History = new Dictionary, List>(); } public void Add(Func ObservableFloat) { ObservableFloats.Add(ObservableFloat); History[ObservableFloat] = new List(); } public void Tick() { foreach (var f in ObservableFloats) { History[f].Add(f()); while (History[f].Count > 128) History[f].RemoveAt(0); } this.InvalidateVisual(); } protected override void OnRender(DrawingContext dc) { base.OnRender(dc); SolidColorBrush b = new SolidColorBrush(); b.Color = Colors.Black; Pen p = new Pen(Brushes.Green, 1); dc.DrawRectangle(b, p, new Rect(this.RenderSize)); int y = 0; int height = 50; foreach (var f in ObservableFloats) { float x = 128 - History[f].Count; Point oldPoint = new Point(-1, -1); foreach (var val in History[f]) { float newVal = val; if (newVal > 1) newVal = 1; if (newVal < 0) newVal = 0; Point newPoint = new Point((x * RenderSize.Width) / 128, y + 2 + height * (1.0f - newVal)); if (oldPoint.X != -1) dc.DrawLine(p, oldPoint, newPoint); x++; oldPoint = newPoint; } y += height + 4; } } } }