port from perforce
This commit is contained in:
77
aiwaz/AiwazAnimator/HistoricalFloat.cs
Normal file
77
aiwaz/AiwazAnimator/HistoricalFloat.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
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<Func<float>> ObservableFloats;
|
||||
private Dictionary<Func<float>, List<float>> History;
|
||||
|
||||
public HistoricalFloat()
|
||||
{
|
||||
ObservableFloats = new List<Func<float>>();
|
||||
History = new Dictionary<Func<float>, List<float>>();
|
||||
}
|
||||
|
||||
public void Add(Func<float> ObservableFloat)
|
||||
{
|
||||
ObservableFloats.Add(ObservableFloat);
|
||||
History[ObservableFloat] = new List<float>();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user