Virtu/Library/FrameRateCounter.xaml.cs
Sean Fausett 1221690d97 Converted file line endings to Windows CRLF.
--HG--
extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4050814
2010-08-28 12:02:37 +00:00

43 lines
1.2 KiB
C#

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace Jellyfish.Library
{
public sealed partial class FrameRateCounter : UserControl
{
public FrameRateCounter()
{
InitializeComponent();
CompositionTarget.Rendering += OnCompositionTargetRendering;
}
private void OnCompositionTargetRendering(object sender, EventArgs e)
{
_frameCount++;
long time = DateTime.UtcNow.Ticks;
if (time - _lastTime >= TimeSpan.TicksPerSecond)
{
_lastTime = time;
FrameRate = _frameCount;
_frameCount = 0;
}
}
public static readonly DependencyProperty FrameRateProperty = DependencyProperty.Register("FrameRate", typeof(int), typeof(FrameRateCounter),
new PropertyMetadata(0));
public int FrameRate
{
get { return (int)GetValue(FrameRateProperty); }
set { SetValue(FrameRateProperty, value); }
}
private int _frameCount;
private long _lastTime;
}
}