I'm using AvalonEdit to create an ANSI terminal that properly color codes and implements some styles like underline and reverse (it works wonderfully for that, this isn't a full VT100 kind of thing).
In AvalonEdit a DocumentColorizingTransformer
to transform ANSI color codes into colored text or styled text. Last night I was working on implementing the ANSI Blink. I got the blink working with this section of code:
else if (color.AnsiColor is Blink)
{
// The color animation of the pulse, use the opacity to simulate blinking
var da = new DoubleAnimation
{
Duration = new Duration(TimeSpan.FromMilliseconds(500)),
From = 0,
To = 1,
AutoReverse = true
RepeatBehavior = RepeatBehavior.Forever
};
// Get the foreground
var foreground = element.TextRunProperties.ForegroundBrush;
// Clone the foreground so it's not frozen and we can run animations on it.
var blinkForeground = foreground.Clone();
// Set the new foreground.
element.TextRunProperties.SetForegroundBrush(blinkForeground);
// Blink Blink Blink Blink
blinkForeground.BeginAnimation(SolidColorBrush.OpacityProperty, da);
}
Obviously I want this text to blink forever while it's on the screen which is why I set the RepeatBehavior to forever. However, it continues to use CPU even after it's scrolled off of the visible part of the screen (it may not be rendering but the Animation seems to still be running).
My question:
How does one go about stopping an animation on a piece of text when it's scrolled out of the visible view (without necessarily having to go through -everything- in the AvalonEdit box which could be very, very large and not feasible to do performance wise). If I could stop the animation when it goes off screen and then restart it when ColorizeLine(DocumentLine line)
fires that would be ideal. With AvalonEdit I know when something comes through ColorizeLine
it's visible, but I don't necessarily know at that point what's not visible. I considered keeping a list of references to all the double animations but I still unaware of when they're visible on the screen.
Any other ideas or thoughts on how I can approach this?